def operator_exprs(): """Prepare a list of operator algebra expressions""" hs1 = LocalSpace('q1', dimension=2) hs2 = LocalSpace('q2', dimension=2) A = OperatorSymbol("A", hs=hs1) B = OperatorSymbol("B", hs=hs1) C = OperatorSymbol("C", hs=hs2) a, b = symbols('a, b') A_ab = OperatorSymbol("A", a, b, hs=0) gamma = symbols('gamma') return [ OperatorSymbol("A", hs=hs1), OperatorSymbol("A_1", hs=hs1 * hs2), OperatorSymbol("A_1", symbols('alpha'), symbols('beta'), hs=hs1 * hs2), A_ab.diff(a, n=2).diff(b), A_ab.diff(a, n=2).diff(b).evaluate_at({a: 0}), OperatorSymbol("Xi_2", hs=(r'q1', 'q2')), OperatorSymbol("Xi_full", hs=1), IdentityOperator, ZeroOperator, Create(hs=1), Create(hs=LocalSpace(1, local_identifiers={'Create': 'b'})), Destroy(hs=1), Destroy(hs=LocalSpace(1, local_identifiers={'Destroy': 'b'})), Jz(hs=SpinSpace(1, spin=1)), Jz(hs=SpinSpace(1, spin=1, local_identifiers={'Jz': 'Z'})), Jplus(hs=SpinSpace(1, spin=1, local_identifiers={'Jplus': 'Jp'})), Jminus(hs=SpinSpace(1, spin=1, local_identifiers={'Jminus': 'Jm'})), Phase(0.5, hs=1), Phase(0.5, hs=LocalSpace(1, local_identifiers={'PhaseCC': 'Ph'})), Displace(0.5, hs=1), Squeeze(0.5, hs=1), LocalSigma('e', 'g', hs=LocalSpace(1, basis=('g', 'e'))), LocalSigma('e', 'e', hs=LocalSpace(1, basis=('g', 'e'))), A + B, A * B, A * C, 2 * A, 2j * A, (1 + 2j) * A, gamma**2 * A, -(gamma**2) / 2 * A, tr(A * C, over_space=hs2), Adjoint(A), Adjoint(A + B), PseudoInverse(A), NullSpaceProjector(A), A - B, 2 * A - sqrt(gamma) * (B + C), Commutator(A, B), ]
def test_quantum_symbols_with_symargs(): """Test properties and behavior of symbols with scalar arguments, through the example of an OperatorSymbol""" t = IndexedBase('t') i = IdxSym('i') j = IdxSym('j') alpha, beta = symbols('alpha, beta') A = OperatorSymbol("A", t[i], (alpha + 1)**2, hs=0) assert A.label == 'A' assert len(A.args) == 3 assert A.kwargs == {'hs': LocalSpace('0')} assert A._get_instance_key(A.args, A.kwargs) == ( OperatorSymbol, 'A', t[i], (alpha + 1)**2, ('hs', A.space), ) A_beta = OperatorSymbol("A", beta, (alpha + 1)**2, hs=0) assert A != A_beta assert A.substitute({t[i]: beta}) == A_beta half = sympy.sympify(1) / 2 assert A.sym_args == (t[i], (alpha + 1)**2) assert A.free_symbols == {symbols('t'), i, t[i], alpha} assert len(A.bound_symbols) == 0 assert A.simplify_scalar(sympy.expand) == OperatorSymbol("A", t[i], alpha**2 + 2 * alpha + 1, hs=0) assert A.diff(beta) == ZeroOperator assert A.diff(t[j]) == ZeroOperator assert OperatorSymbol("A", t[i], i, j, hs=0).diff(t[j]) == ZeroOperator assert A.diff(alpha) == OperatorDerivative(A, derivs=((alpha, 1), )) assert A.expand() == A series = A.series_expand(t[i], about=beta, order=2) assert len(series) == 3 assert series[0] == OperatorSymbol("A", beta, (alpha + 1)**2, hs=0) assert series[2] == half * OperatorDerivative( A, derivs=((t[i], 2), ), vals=((t[i], beta), ))