+ from sympy import S, sqrt
+ from sympy.physics.quantum.dagger import Dagger
+ from sympy.physics.quantum.spin import JzKet
+ from sympy.physics.quantum.density import Density, fidelity
+ from sympy.physics.quantum.represent import represent
+
+ up =
+ from sympy.physics.quantum.spin import JzKet
+ from sympy.physics.quantum.density import Density, fidelity
+ from sympy.physics.quantum.represent import represent
+
+ up = JzKet(S(1)/2,S(1)/2)
+ down = JzKet(S(1)/2,-S(1)/2)
+ amp = 1/sqrt(2)
+ updown =
+ updown2 = (sqrt(3)/2 )* up + (1/2)*down
+
+ print fidelity(up_dm, up_dm)
+1
+ print fidelity(up_dm, down_dm) #orthogonal states
+0
+ print fidelity(up_dm, updown_dm).evalf().round(3)
+0.707
+
+
+state1 = represent(state1) if isinstance(state1,
+ print fidelity(up_dm, down_dm) #orthogonal states
+0
+ print fidelity(up_dm, updown_dm).evalf().round(3)
+0.707
+
+
+state1 = represent(state1) if isinstance(state1, Density) else state1
+state2 = represent(state2) if isinstance(state2, Density) else state2
+
**SymPy Bot Summary:** :eight_spoked_asterisk: All tests have passed.
*Test command:* setup.py test
*master hash*: dd8352a0582b91b286a98fabfb0af7486faeeb03
*branch hash*: 5f0bd5db5a386202f28265d65423435517e592ba
**Interpreter 1:** :eight_spoked_asterisk: All tests have passed.
*Interpreter:*
**SymPy Bot Summary:** :eight_spoked_asterisk: All tests have passed.
*Test command:* setup.py test
*master hash*: 3c2c3c755445737074de437f004143792f5057e3
*branch hash*: ac679d1dba3a92e2d1e03a311d2110b696cbce5d
**Interpreter 1:** :eight_spoked_asterisk: All tests have passed.
*Interpreter:*
This PR implements the basic functionality to compute fidelity on quantum
states.
@flacjacket and @ellisonbg please review.
You can merge this Pull Request by running:
git pull https://github.com/gdevanla/sympy fidelity_quantum_states
Or you can view, comment on it, or merge it online at: