<s> from sympy import ( Add , conjugate , diff , I , Integer , Mul , oo , pi , Pow , <EOL> Rational , sin , sqrt , Symbol , symbols , sympify ) <EOL> from sympy . utilities . pytest import raises <EOL> from sympy . physics . quantum . dagger import Dagger <EOL> from sympy . physics . quantum . qexpr import QExpr <EOL> from sympy . physics . quantum . state import ( <EOL> Ket , Bra , TimeDepKet , TimeDepBra , <EOL> KetBase , BraBase , StateBase , Wavefunction <EOL> ) <EOL> from sympy . physics . quantum . hilbert import HilbertSpace <EOL> x , y , t = symbols ( '<STR_LIT>' ) <EOL> class CustomKet ( Ket ) : <EOL> @ classmethod <EOL> def default_args ( self ) : <EOL> return ( "<STR_LIT:test>" , ) <EOL> class CustomKetMultipleLabels ( Ket ) : <EOL> @ classmethod <EOL> def default_args ( self ) : <EOL> return ( "<STR_LIT:r>" , "<STR_LIT>" , "<STR_LIT>" ) <EOL> class CustomTimeDepKet ( TimeDepKet ) : <EOL> @ classmethod <EOL> def default_args ( self ) : <EOL> return ( "<STR_LIT:test>" , "<STR_LIT:t>" ) <EOL> class CustomTimeDepKetMultipleLabels ( TimeDepKet ) : <EOL> @ classmethod <EOL> def default_args ( self ) : <EOL> return ( "<STR_LIT:r>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:t>" ) <EOL> def test_ket ( ) : <EOL> k = Ket ( '<STR_LIT:0>' ) <EOL> assert isinstance ( k , Ket ) <EOL> assert isinstance ( k , KetBase ) <EOL> assert isinstance ( k , StateBase ) <EOL> assert isinstance ( k , QExpr ) <EOL> assert k . label == ( Symbol ( '<STR_LIT:0>' ) , ) <EOL> assert k . hilbert_space == HilbertSpace ( ) <EOL> assert k . is_commutative is False <EOL> k = Ket ( '<STR_LIT>' ) <EOL> assert k . label == ( Symbol ( '<STR_LIT>' ) , ) <EOL> k = Ket ( x , y ) <EOL> assert k . label == ( x , y ) <EOL> assert k . hilbert_space == HilbertSpace ( ) <EOL> assert k . is_commutative is False <EOL> assert k . dual_class ( ) == Bra <EOL> assert k . dual == Bra ( x , y ) <EOL> assert k . subs ( x , y ) == Ket ( y , y ) <EOL> k = CustomKet ( ) <EOL> assert k == CustomKet ( "<STR_LIT:test>" ) <EOL> k = CustomKetMultipleLabels ( ) <EOL> assert k == CustomKetMultipleLabels ( "<STR_LIT:r>" , "<STR_LIT>" , "<STR_LIT>" ) <EOL> assert Ket ( ) == Ket ( '<STR_LIT>' ) <EOL> def test_bra ( ) : <EOL> b = Bra ( '<STR_LIT:0>' ) <EOL> assert isinstance ( b , Bra ) <EOL> assert isinstance ( b , BraBase ) <EOL> assert isinstance ( b , StateBase ) <EOL> assert isinstance ( b , QExpr ) <EOL> assert b . label == ( Symbol ( '<STR_LIT:0>' ) , ) <EOL> assert b . hilbert_space == HilbertSpace ( ) <EOL> assert b . is_commutative is False <EOL> b = Bra ( '<STR_LIT>' ) <EOL> assert b . label == ( Symbol ( '<STR_LIT>' ) , ) <EOL> b = Bra ( x , y ) <EOL> assert b . label == ( x , y ) <EOL> assert b . hilbert_space == HilbertSpace ( ) <EOL> assert b . is_commutative is False <EOL> assert b . dual_class ( ) == Ket <EOL> assert b . dual == Ket ( x , y ) <EOL> assert b . subs ( x , y ) == Bra ( y , y ) <EOL> assert Bra ( ) == Bra ( '<STR_LIT>' ) <EOL> def test_ops ( ) : <EOL> k0 = Ket ( <NUM_LIT:0> ) <EOL> k1 = Ket ( <NUM_LIT:1> ) <EOL> k = <NUM_LIT:2> * I * k0 - ( x / sqrt ( <NUM_LIT:2> ) ) * k1 <EOL> assert k == Add ( Mul ( <NUM_LIT:2> , I , k0 ) , <EOL> Mul ( Rational ( - <NUM_LIT:1> , <NUM_LIT:2> ) , x , Pow ( <NUM_LIT:2> , Rational ( <NUM_LIT:1> , <NUM_LIT:2> ) ) , k1 ) ) <EOL> def test_time_dep_ket ( ) : <EOL> k = TimeDepKet ( <NUM_LIT:0> , t ) <EOL> assert isinstance ( k , TimeDepKet ) <EOL> assert isinstance ( k , KetBase ) <EOL> assert isinstance ( k , StateBase ) <EOL> assert isinstance ( k , QExpr ) <EOL> assert k . label == ( Integer ( <NUM_LIT:0> ) , ) <EOL> assert k . args == ( Integer ( <NUM_LIT:0> ) , t ) <EOL> assert k . time == t <EOL> assert k . dual_class ( ) == TimeDepBra <EOL> assert k . dual == TimeDepBra ( <NUM_LIT:0> , t ) <EOL> assert k . subs ( t , <NUM_LIT:2> ) == TimeDepKet ( <NUM_LIT:0> , <NUM_LIT:2> ) <EOL> k = TimeDepKet ( x , <NUM_LIT:0.5> ) <EOL> assert k . label == ( x , ) <EOL> assert k . args == ( x , sympify ( <NUM_LIT:0.5> ) ) <EOL> k = CustomTimeDepKet ( ) <EOL> assert k . label == ( Symbol ( "<STR_LIT:test>" ) , ) <EOL> assert k . time == Symbol ( "<STR_LIT:t>" ) <EOL> assert k == CustomTimeDepKet ( "<STR_LIT:test>" , "<STR_LIT:t>" ) <EOL> k = CustomTimeDepKetMultipleLabels ( ) <EOL> assert k . label == ( Symbol ( "<STR_LIT:r>" ) , Symbol ( "<STR_LIT>" ) , Symbol ( "<STR_LIT>" ) ) <EOL> assert k . time == Symbol ( "<STR_LIT:t>" ) <EOL> assert k == CustomTimeDepKetMultipleLabels ( "<STR_LIT:r>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:t>" ) <EOL> assert TimeDepKet ( ) == TimeDepKet ( "<STR_LIT>" , "<STR_LIT:t>" ) <EOL> def test_time_dep_bra ( ) : <EOL> b = TimeDepBra ( <NUM_LIT:0> , t ) <EOL> assert isinstance ( b , TimeDepBra ) <EOL> assert isinstance ( b , BraBase ) <EOL> assert isinstance ( b , StateBase ) <EOL> assert isinstance ( b , QExpr ) <EOL> assert b . label == ( Integer ( <NUM_LIT:0> ) , ) <EOL> assert b . args == ( Integer ( <NUM_LIT:0> ) , t ) <EOL> assert b . time == t <EOL> assert b . dual_class ( ) == TimeDepKet <EOL> assert b . dual == TimeDepKet ( <NUM_LIT:0> , t ) <EOL> k = TimeDepBra ( x , <NUM_LIT:0.5> ) <EOL> assert k . label == ( x , ) <EOL> assert k . args == ( x , sympify ( <NUM_LIT:0.5> ) ) <EOL> assert TimeDepBra ( ) == TimeDepBra ( "<STR_LIT>" , "<STR_LIT:t>" ) <EOL> def test_bra_ket_dagger ( ) : <EOL> x = symbols ( '<STR_LIT:x>' , complex = True ) <EOL> k = Ket ( '<STR_LIT:k>' ) <EOL> b = Bra ( '<STR_LIT:b>' ) <EOL> assert Dagger ( k ) == Bra ( '<STR_LIT:k>' ) <EOL> assert Dagger ( b ) == Ket ( '<STR_LIT:b>' ) <EOL> assert Dagger ( k ) . is_commutative is False <EOL> k2 = Ket ( '<STR_LIT>' ) <EOL> e = <NUM_LIT:2> * I * k + x * k2 <EOL> assert Dagger ( e ) == conjugate ( x ) * Dagger ( k2 ) - <NUM_LIT:2> * I * Dagger ( k ) <EOL> def test_wavefunction ( ) : <EOL> x , y = symbols ( '<STR_LIT>' , real = True ) <EOL> L = symbols ( '<STR_LIT:L>' , positive = True ) <EOL> n = symbols ( '<STR_LIT:n>' , integer = True , positive = True ) <EOL> f = Wavefunction ( x ** <NUM_LIT:2> , x ) <EOL> p = f . prob ( ) <EOL> lims = f . limits <EOL> assert f . is_normalized is False <EOL> assert f . norm == oo <EOL> assert f ( <NUM_LIT:10> ) == <NUM_LIT:100> <EOL> assert p ( <NUM_LIT:10> ) == <NUM_LIT> <EOL> assert lims [ x ] == ( - oo , oo ) <EOL> assert diff ( f , x ) == Wavefunction ( <NUM_LIT:2> * x , x ) <EOL> raises ( NotImplementedError , lambda : f . normalize ( ) ) <EOL> assert conjugate ( f ) == Wavefunction ( conjugate ( f . expr ) , x ) <EOL> assert conjugate ( f ) == Dagger ( f ) <EOL> g = Wavefunction ( x ** <NUM_LIT:2> * y + y ** <NUM_LIT:2> * x , ( x , <NUM_LIT:0> , <NUM_LIT:1> ) , ( y , <NUM_LIT:0> , <NUM_LIT:2> ) ) <EOL> lims_g = g . limits <EOL> assert lims_g [ x ] == ( <NUM_LIT:0> , <NUM_LIT:1> ) <EOL> assert lims_g [ y ] == ( <NUM_LIT:0> , <NUM_LIT:2> ) <EOL> assert g . is_normalized is False <EOL> assert g . norm == sqrt ( <NUM_LIT> ) / <NUM_LIT:3> <EOL> assert g ( <NUM_LIT:2> , <NUM_LIT:4> ) == <NUM_LIT:0> <EOL> assert g ( <NUM_LIT:1> , <NUM_LIT:1> ) == <NUM_LIT:2> <EOL> assert diff ( diff ( g , x ) , y ) == Wavefunction ( <NUM_LIT:2> * x + <NUM_LIT:2> * y , ( x , <NUM_LIT:0> , <NUM_LIT:1> ) , ( y , <NUM_LIT:0> , <NUM_LIT:2> ) ) <EOL> assert conjugate ( g ) == Wavefunction ( conjugate ( g . expr ) , * g . args [ <NUM_LIT:1> : ] ) <EOL> assert conjugate ( g ) == Dagger ( g ) <EOL> h = Wavefunction ( sqrt ( <NUM_LIT:5> ) * x ** <NUM_LIT:2> , ( x , <NUM_LIT:0> , <NUM_LIT:1> ) ) <EOL> assert h . is_normalized is True <EOL> assert h . normalize ( ) == h <EOL> assert conjugate ( h ) == Wavefunction ( conjugate ( h . expr ) , ( x , <NUM_LIT:0> , <NUM_LIT:1> ) ) <EOL> assert conjugate ( h ) == Dagger ( h ) <EOL> piab = Wavefunction ( sin ( n * pi * x / L ) , ( x , <NUM_LIT:0> , L ) ) <EOL> assert piab . norm == sqrt ( L / <NUM_LIT:2> ) <EOL> assert piab ( L + <NUM_LIT:1> ) == <NUM_LIT:0> <EOL> assert piab ( <NUM_LIT:0.5> ) == sin ( <NUM_LIT:0.5> * n * pi / L ) <EOL> assert piab ( <NUM_LIT:0.5> , n = <NUM_LIT:1> , L = <NUM_LIT:1> ) == sin ( <NUM_LIT:0.5> * pi ) <EOL> assert piab . normalize ( ) == Wavefunction ( sqrt ( <NUM_LIT:2> ) / sqrt ( L ) * sin ( n * pi * x / L ) , ( x , <NUM_LIT:0> , L ) ) <EOL> assert conjugate ( piab ) == Wavefunction ( conjugate ( piab . expr ) , ( x , <NUM_LIT:0> , L ) ) <EOL> assert conjugate ( piab ) == Dagger ( piab ) <EOL> k = Wavefunction ( x ** <NUM_LIT:2> , '<STR_LIT:x>' ) <EOL> assert type ( k . variables [ <NUM_LIT:0> ] ) == Symbol </s>
