Beispiel #1
0
def test_state_to_op():
    assert state_to_operators(XKet) == XOp()
    assert state_to_operators(PxKet) == PxOp()
    assert state_to_operators(XBra) == XOp()
    assert state_to_operators(PxBra) == PxOp()
    assert state_to_operators(Ket) == Operator()
    assert state_to_operators(Bra) == Operator()

    assert state_to_operators(JxKet) == set([J2Op(), JxOp()])
    assert state_to_operators(JyKet) == set([J2Op(), JyOp()])
    assert state_to_operators(JzKet) == set([J2Op(), JzOp()])
    assert state_to_operators(JxBra) == set([J2Op(), JxOp()])
    assert state_to_operators(JyBra) == set([J2Op(), JyOp()])
    assert state_to_operators(JzBra) == set([J2Op(), JzOp()])

    assert state_to_operators(JxKet()) == set([J2Op(), JxOp()])
    assert state_to_operators(JyKet()) == set([J2Op(), JyOp()])
    assert state_to_operators(JzKet()) == set([J2Op(), JzOp()])
    assert state_to_operators(JxBra()) == set([J2Op(), JxOp()])
    assert state_to_operators(JyBra()) == set([J2Op(), JyOp()])
    assert state_to_operators(JzBra()) == set([J2Op(), JzOp()])

    assert operators_to_state(state_to_operators(XKet("test"))) == XKet("test")
    assert operators_to_state(state_to_operators(XBra("test"))) == XKet("test")
    assert operators_to_state(state_to_operators(XKet())) == XKet()
    assert operators_to_state(state_to_operators(XBra())) == XKet()

    raises(NotImplementedError, 'state_to_operators(XOp)')
Beispiel #2
0
def test_x():
    assert X.hilbert_space == L2(Interval(S.NegativeInfinity, S.Infinity))
    assert Commutator(X, Px).doit() == I*hbar
    assert apply_operators(X*XKet(x)) == x*XKet(x)
    assert XKet(x).dual_class == XBra
    assert XBra(x).dual_class == XKet
    assert (Dagger(XKet(y))*XKet(x)).doit() == DiracDelta(x-y)
    assert (PxBra(px)*XKet(x)).doit() ==\
        exp(-I*x*px/hbar)/sqrt(2*pi*hbar)
    assert represent(XKet(x)) == x
    assert XBra(x).position == x
Beispiel #3
0
def test_state_to_op():
    assert state_to_operators(XKet) == XOp()
    assert state_to_operators(PxKet) == PxOp()
    assert state_to_operators(XBra) == XOp()
    assert state_to_operators(PxBra) == PxOp()
    assert state_to_operators(Ket) == Operator()
    assert state_to_operators(Bra) == Operator()

    assert operators_to_state(state_to_operators(XKet("test"))) == XKet("test")
    assert operators_to_state(state_to_operators(XBra("test"))) == XKet("test")
    assert operators_to_state(state_to_operators(XKet())) == XKet()
    assert operators_to_state(state_to_operators(XBra())) == XKet()

    raises(NotImplementedError, lambda: state_to_operators(XOp))
Beispiel #4
0
def test_innerprod_represent():
    assert rep_innerproduct(x_ket) == InnerProduct(XBra("x_1"), x_ket).doit()
    assert rep_innerproduct(x_bra) == InnerProduct(x_bra, XKet("x_1")).doit()

    try:
        rep_innerproduct(x_op)
    except TypeError:
        return True
Beispiel #5
0
def test_p():
    assert Px.hilbert_space == L2(Interval(S.NegativeInfinity, S.Infinity))
    assert apply_operators(Px*PxKet(px)) == px*PxKet(px)
    assert PxKet(px).dual_class == PxBra
    assert PxBra(x).dual_class == PxKet
    assert (Dagger(PxKet(py))*PxKet(px)).doit() == DiracDelta(px-py)
    assert (XBra(x)*PxKet(px)).doit() ==\
        exp(I*x*px/hbar)/sqrt(2*pi*hbar)
    assert represent(PxKet(px)) == px
Beispiel #6
0
def test_p():
    assert Px.hilbert_space == L2(Interval(S.NegativeInfinity, S.Infinity))
    assert qapply(Px*PxKet(px)) == px*PxKet(px)
    assert PxKet(px).dual_class() == PxBra
    assert PxBra(x).dual_class() == PxKet
    assert (Dagger(PxKet(py))*PxKet(px)).doit() == DiracDelta(px-py)
    assert (XBra(x)*PxKet(px)).doit() ==\
        exp(I*x*px/hbar)/sqrt(2*pi*hbar)
    assert represent(PxKet(px)) == DiracDelta(px-px_1)

    rep_x = represent(PxOp(), basis = XOp)
    assert rep_x == -hbar*I*DiracDelta(x_1 - x_2)*DifferentialOperator(x_1)
    assert rep_x == represent(PxOp(), basis = XOp())
    assert rep_x == represent(PxOp(), basis = XKet)
    assert rep_x == represent(PxOp(), basis = XKet())

    assert represent(PxOp()*XKet(), basis=XKet) == \
           -hbar*I*DiracDelta(x - x_2)*DifferentialOperator(x)
    assert represent(XBra("y")*PxOp()*XKet(), basis=XKet) == \
           -hbar*I*DiracDelta(x-y)*DifferentialOperator(x)
Beispiel #7
0
def test_x():
    assert X.hilbert_space == L2(Interval(S.NegativeInfinity, S.Infinity))
    assert Commutator(X, Px).doit() == I * hbar
    assert qapply(X * XKet(x)) == x * XKet(x)
    assert XKet(x).dual_class() == XBra
    assert XBra(x).dual_class() == XKet
    assert (Dagger(XKet(y)) * XKet(x)).doit() == DiracDelta(x - y)
    assert (PxBra(px)*XKet(x)).doit() == \
        exp(-I*x*px/hbar)/sqrt(2*pi*hbar)
    assert represent(XKet(x)) == DiracDelta(x - x_1)
    assert represent(XBra(x)) == DiracDelta(-x + x_1)
    assert XBra(x).position == x
    assert represent(XOp() * XKet()) == x * DiracDelta(x - x_2)
    assert represent(XOp()*XKet()*XBra('y')) == \
        x*DiracDelta(x - x_3)*DiracDelta(x_1 - y)
    assert represent(XBra("y") * XKet()) == DiracDelta(x - y)
    assert represent(XKet() *
                     XBra()) == DiracDelta(x - x_2) * DiracDelta(x_1 - x)

    rep_p = represent(XOp(), basis=PxOp)
    assert rep_p == hbar * I * DiracDelta(px_1 -
                                          px_2) * DifferentialOperator(px_1)
    assert rep_p == represent(XOp(), basis=PxOp())
    assert rep_p == represent(XOp(), basis=PxKet)
    assert rep_p == represent(XOp(), basis=PxKet())

    assert represent(XOp()*PxKet(), basis=PxKet) == \
        hbar*I*DiracDelta(px - px_2)*DifferentialOperator(px)
Beispiel #8
0
def test_sympy__physics__quantum__cartesian__XBra():
    from sympy.physics.quantum.cartesian import XBra
    assert _test_args(XBra(x))
Beispiel #9
0
            assert lhs == rhs


def test_scalar_scipy_sparse():
    if not np:
        skip("numpy not installed.")
    if not scipy:
        skip("scipy not installed.")

    assert represent(Integer(1), format='scipy.sparse') == 1
    assert represent(Float(1.0), format='scipy.sparse') == 1.0
    assert represent(1.0 + I, format='scipy.sparse') == 1.0 + 1.0j


x_ket = XKet('x')
x_bra = XBra('x')
x_op = XOp('X')


def test_innerprod_represent():
    assert rep_innerproduct(x_ket) == InnerProduct(XBra("x_1"), x_ket).doit()
    assert rep_innerproduct(x_bra) == InnerProduct(x_bra, XKet("x_1")).doit()

    try:
        rep_innerproduct(x_op)
    except TypeError:
        return True


def test_operator_represent():
    basis_kets = enumerate_states(operators_to_state(x_op), 1, 2)
Beispiel #10
0
            assert lhs == rhs


def test_scalar_scipy_sparse():
    if not np:
        skip("numpy not installed.")
    if not scipy:
        skip("scipy not installed.")

    assert represent(Integer(1), format="scipy.sparse") == 1
    assert represent(Float(1.0), format="scipy.sparse") == 1.0
    assert represent(1.0 + I, format="scipy.sparse") == 1.0 + 1.0j


x_ket = XKet("x")
x_bra = XBra("x")
x_op = XOp("X")


def test_innerprod_represent():
    assert rep_innerproduct(x_ket) == InnerProduct(XBra("x_1"), x_ket).doit()
    assert rep_innerproduct(x_bra) == InnerProduct(x_bra, XKet("x_1")).doit()

    try:
        rep_innerproduct(x_op)
    except TypeError:
        return True


def test_operator_represent():
    basis_kets = enumerate_states(operators_to_state(x_op), 1, 2)