コード例 #1
0
def test_spin():
    assert operators_to_state(set([J2Op, JxOp])) == JxKet
    assert operators_to_state(set([J2Op, JyOp])) == JyKet
    assert operators_to_state(set([J2Op, JzOp])) == JzKet
    #FIXME ajgpitch 22 Sept 2019:
    # JxKet() etc seems to require positional arguments: 'j' and 'm'
    # So these tests cannot work
    # Probably easy to work out what 'j' and 'm' should be from the physics
    assert operators_to_state(set([J2Op(), JxOp()])) == JxKet()
    assert operators_to_state(set([J2Op(), JyOp()])) == JyKet()
    assert operators_to_state(set([J2Op(), JzOp()])) == JzKet()

    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])

    #FIXME ajgpitch 22 Sept 2019:
    # JxKet() etc seems to require positional arguments: 'j' and 'm'
    # So these tests cannot work
    # Probably easy to work out what 'j' and 'm' should be from the physics
    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()])
コード例 #2
0
ファイル: test_operatorset.py プロジェクト: lazovich/sympy
def test_op_to_state():
    assert operators_to_state(XOp) == XKet()
    assert operators_to_state(PxOp) == PxKet()
    assert operators_to_state(Operator) == Ket()

    assert operators_to_state(set([J2Op, JxOp])) == JxKet()
    assert operators_to_state(set([J2Op, JyOp])) == JyKet()
    assert operators_to_state(set([J2Op, JzOp])) == JzKet()
    assert operators_to_state(set([J2Op(), JxOp()])) ==  JxKet()
    assert operators_to_state(set([J2Op(), JyOp()])) ==  JyKet()
    assert operators_to_state(set([J2Op(), JzOp()])) ==  JzKet()

    assert state_to_operators(operators_to_state(XOp("Q"))) == XOp("Q")
    assert state_to_operators(operators_to_state(XOp())) == XOp()

    raises(NotImplementedError, 'operators_to_state(XKet)')
コード例 #3
0
def test_spin():
    assert operators_to_state({J2Op, JxOp}) == JxKet
    assert operators_to_state({J2Op, JyOp}) == JyKet
    assert operators_to_state({J2Op, JzOp}) == JzKet
    assert operators_to_state({J2Op(), JxOp()}) == JxKet
    assert operators_to_state({J2Op(), JyOp()}) == JyKet
    assert operators_to_state({J2Op(), JzOp()}) == JzKet

    assert state_to_operators(JxKet) == {J2Op, JxOp}
    assert state_to_operators(JyKet) == {J2Op, JyOp}
    assert state_to_operators(JzKet) == {J2Op, JzOp}
    assert state_to_operators(JxBra) == {J2Op, JxOp}
    assert state_to_operators(JyBra) == {J2Op, JyOp}
    assert state_to_operators(JzBra) == {J2Op, JzOp}

    assert state_to_operators(JxKet(S.Half, S.Half)) == {J2Op(), JxOp()}
    assert state_to_operators(JyKet(S.Half, S.Half)) == {J2Op(), JyOp()}
    assert state_to_operators(JzKet(S.Half, S.Half)) == {J2Op(), JzOp()}
    assert state_to_operators(JxBra(S.Half, S.Half)) == {J2Op(), JxOp()}
    assert state_to_operators(JyBra(S.Half, S.Half)) == {J2Op(), JyOp()}
    assert state_to_operators(JzBra(S.Half, S.Half)) == {J2Op(), JzOp()}
コード例 #4
0
ファイル: test_args.py プロジェクト: Visheshk/sympy
def test_sympy__physics__quantum__spin__J2Op():
    from sympy.physics.quantum.spin import J2Op
    assert _test_args(J2Op(0, 1))
コード例 #5
0
ファイル: test_operatorset.py プロジェクト: tuhina/sympy
def test_spin():
    assert operators_to_state(set([J2Op, JxOp])) == JxKet()
    assert operators_to_state(set([J2Op, JyOp])) == JyKet()
    assert operators_to_state(set([J2Op, JzOp])) == JzKet()
    assert operators_to_state(set([J2Op(), JxOp()])) == JxKet()
    assert operators_to_state(set([J2Op(), JyOp()])) == JyKet()
    assert operators_to_state(set([J2Op(), JzOp()])) == JzKet()

    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()])
コード例 #6
0
ファイル: test_operatorset.py プロジェクト: lazovich/sympy
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)')