Fidelity of quantum states #1459

Merged
merged 8 commits into from Aug 11, 2012

Conversation

Projects
None yet
7 participants
@gdevanla
Contributor

gdevanla commented Aug 3, 2012

This PR implements the basic functionality to compute fidelity on quantum states.

@flacjacket and @ellisonbg please review.

@travisbot

This comment has been minimized.

Show comment
Hide comment
@travisbot

travisbot Aug 3, 2012

This pull request fails (merged 30311c8 into 9625918).

This pull request fails (merged 30311c8 into 9625918).

@travisbot

This comment has been minimized.

Show comment
Hide comment
@travisbot

travisbot Aug 3, 2012

This pull request fails (merged 82e3be2 into 9625918).

This pull request fails (merged 82e3be2 into 9625918).

@Krastanov

This comment has been minimized.

Show comment
Hide comment
@Krastanov

Krastanov Aug 3, 2012

Member

SymPy Bot Summary: 🔴 There were test failures.

@gdevanla: Please fix the test failures.

Test command: setup.py test
master hash: 9625918
branch hash: 82e3be2

Interpreter 1: ✳️ All tests have passed.

Interpreter: /usr/local/bin/python2.5 (2.5.6-final-0)
Architecture: Linux (64-bit)
Cache: yes

Test results html report: http://reviews.sympy.org/report/agZzeW1weTNyDAsSBFRhc2sY_ZMjDA

Interpreter 2: ✳️ All tests have passed.

Interpreter: /usr/bin/python2.7 (2.7.3-candidate-2)
Architecture: Linux (64-bit)
Cache: yes

Test results html report: http://reviews.sympy.org/report/agZzeW1weTNyDAsSBFRhc2sYqo8iDA

Interpreter 3: 🔴 There were test failures.

Interpreter: /usr/bin/python3.2 (3.2.3-candidate-2)
Architecture: Linux (64-bit)
Cache: yes

Test results html report: http://reviews.sympy.org/report/agZzeW1weTNyDAsSBFRhc2sY5_QiDA

Build HTML Docs: ✳️ All tests have passed.

Docs build command: make html-errors
Sphinx version: 1.1.3

Test results html report: http://reviews.sympy.org/report/agZzeW1weTNyDAsSBFRhc2sYju0iDA

Automatic review by SymPy Bot.

Member

Krastanov commented Aug 3, 2012

SymPy Bot Summary: 🔴 There were test failures.

@gdevanla: Please fix the test failures.

Test command: setup.py test
master hash: 9625918
branch hash: 82e3be2

Interpreter 1: ✳️ All tests have passed.

Interpreter: /usr/local/bin/python2.5 (2.5.6-final-0)
Architecture: Linux (64-bit)
Cache: yes

Test results html report: http://reviews.sympy.org/report/agZzeW1weTNyDAsSBFRhc2sY_ZMjDA

Interpreter 2: ✳️ All tests have passed.

Interpreter: /usr/bin/python2.7 (2.7.3-candidate-2)
Architecture: Linux (64-bit)
Cache: yes

Test results html report: http://reviews.sympy.org/report/agZzeW1weTNyDAsSBFRhc2sYqo8iDA

Interpreter 3: 🔴 There were test failures.

Interpreter: /usr/bin/python3.2 (3.2.3-candidate-2)
Architecture: Linux (64-bit)
Cache: yes

Test results html report: http://reviews.sympy.org/report/agZzeW1weTNyDAsSBFRhc2sY5_QiDA

Build HTML Docs: ✳️ All tests have passed.

Docs build command: make html-errors
Sphinx version: 1.1.3

Test results html report: http://reviews.sympy.org/report/agZzeW1weTNyDAsSBFRhc2sYju0iDA

Automatic review by SymPy Bot.

+ d1 = Density([state3, 0.70], [state4, 0.30])
+ d2 = Density([state3, 0.20], [state4, 0.80])
+ assert fidelity(d1, d1).round(3) == 1
+ assert fidelity(d1, d2).round(3) == 0.996

This comment has been minimized.

@certik

certik Aug 3, 2012

Member

This is wrong. You can't compare floating point numbers like that. You need to do it the following way:

abs(x-y) < 1e-3

Unless there is something that I am missing.

@certik

certik Aug 3, 2012

Member

This is wrong. You can't compare floating point numbers like that. You need to do it the following way:

abs(x-y) < 1e-3

Unless there is something that I am missing.

This comment has been minimized.

@gdevanla

gdevanla Aug 3, 2012

Contributor

Nope, my mistake. I was supposed to replace that with abs once I finished comparing some of my results with what QuTip was producing. Will fix it, now!

@gdevanla

gdevanla Aug 3, 2012

Contributor

Nope, my mistake. I was supposed to replace that with abs once I finished comparing some of my results with what QuTip was producing. Will fix it, now!

+ d2 = Density([state3, 0.20], [state4, 0.80])
+ assert fidelity(d1, d1).round(3) == 1
+ assert fidelity(d1, d2).round(3) == 0.996
+ assert fidelity(d1, d2).round(3) == fidelity(d2, d1).round(3)

This comment has been minimized.

@certik

certik Aug 3, 2012

Member

The same here.

@certik

certik Aug 3, 2012

Member

The same here.

+ #using qubits/density(mixed states)
+ d1 = Density([state3, 0.70], [state4, 0.30])
+ d2 = Density([state3, 0.20], [state4, 0.80])
+ assert fidelity(d1, d1).round(3) == 1

This comment has been minimized.

@certik

certik Aug 3, 2012

Member

And the same here.

@certik

certik Aug 3, 2012

Member

And the same here.

@travisbot

This comment has been minimized.

Show comment
Hide comment
@travisbot

travisbot Aug 4, 2012

This pull request passes (merged 0eea679 into 9625918).

This pull request passes (merged 0eea679 into 9625918).

@Krastanov

This comment has been minimized.

Show comment
Hide comment
@Krastanov

Krastanov Aug 4, 2012

Member

SymPy Bot Summary: ✳️ All tests have passed.

Test command: setup.py test
master hash: 9625918
branch hash: 0eea679

Interpreter 1: ✳️ All tests have passed.

Interpreter: /usr/local/bin/python2.5 (2.5.6-final-0)
Architecture: Linux (64-bit)
Cache: yes

Test results html report: http://reviews.sympy.org/report/agZzeW1weTNyDAsSBFRhc2sY_pMjDA

Interpreter 2: ✳️ All tests have passed.

Interpreter: /usr/bin/python2.7 (2.7.3-candidate-2)
Architecture: Linux (64-bit)
Cache: yes

Test results html report: http://reviews.sympy.org/report/agZzeW1weTNyDAsSBFRhc2sY4_8hDA

Interpreter 3: ✳️ All tests have passed.

Interpreter: /usr/bin/python3.2 (3.2.3-candidate-2)
Architecture: Linux (64-bit)
Cache: yes

Test results html report: http://reviews.sympy.org/report/agZzeW1weTNyDAsSBFRhc2sYj-0iDA

Build HTML Docs: ✳️ All tests have passed.

Docs build command: make html-errors
Sphinx version: 1.1.3

Test results html report: http://reviews.sympy.org/report/agZzeW1weTNyDAsSBFRhc2sYmowjDA

Automatic review by SymPy Bot.

Member

Krastanov commented Aug 4, 2012

SymPy Bot Summary: ✳️ All tests have passed.

Test command: setup.py test
master hash: 9625918
branch hash: 0eea679

Interpreter 1: ✳️ All tests have passed.

Interpreter: /usr/local/bin/python2.5 (2.5.6-final-0)
Architecture: Linux (64-bit)
Cache: yes

Test results html report: http://reviews.sympy.org/report/agZzeW1weTNyDAsSBFRhc2sY_pMjDA

Interpreter 2: ✳️ All tests have passed.

Interpreter: /usr/bin/python2.7 (2.7.3-candidate-2)
Architecture: Linux (64-bit)
Cache: yes

Test results html report: http://reviews.sympy.org/report/agZzeW1weTNyDAsSBFRhc2sY4_8hDA

Interpreter 3: ✳️ All tests have passed.

Interpreter: /usr/bin/python3.2 (3.2.3-candidate-2)
Architecture: Linux (64-bit)
Cache: yes

Test results html report: http://reviews.sympy.org/report/agZzeW1weTNyDAsSBFRhc2sYj-0iDA

Build HTML Docs: ✳️ All tests have passed.

Docs build command: make html-errors
Sphinx version: 1.1.3

Test results html report: http://reviews.sympy.org/report/agZzeW1weTNyDAsSBFRhc2sYmowjDA

Automatic review by SymPy Bot.

sympy/physics/quantum/density.py
+ >>> up = JzKet(S(1)/2,S(1)/2)
+ >>> down = JzKet(S(1)/2,-S(1)/2)
+ >>> amp = 1/sqrt(2)
+ >>> updown = (amp * up ) + (amp * down)

This comment has been minimized.

@certik

certik Aug 4, 2012

Member

You seem to have an extra space in (amp * up ). (This is minor.)

@certik

certik Aug 4, 2012

Member

You seem to have an extra space in (amp * up ). (This is minor.)

sympy/physics/quantum/density.py
+ >>> up_dm = represent(up * Dagger(up))
+ >>> down_dm = represent(down * Dagger(down))
+ >>> updown_dm = represent(updown * Dagger(updown))
+ >>> updown2 = (sqrt(3)/2 )* up + (1/2)*down

This comment has been minimized.

@certik

certik Aug 4, 2012

Member

I would format (sqrt(3)/2 )* up as (sqrt(3)/2) * up.

@certik

certik Aug 4, 2012

Member

I would format (sqrt(3)/2 )* up as (sqrt(3)/2) * up.

This comment has been minimized.

@flacjacket

flacjacket Aug 9, 2012

Member

I agree with Ondrej, but you don't ever use updown2

@flacjacket

flacjacket Aug 9, 2012

Member

I agree with Ondrej, but you don't ever use updown2

This comment has been minimized.

@certik

certik Aug 10, 2012

Member

@gdevanla, what's up with this? Should updown2 be removed?

@certik

certik Aug 10, 2012

Member

@gdevanla, what's up with this? Should updown2 be removed?

This comment has been minimized.

@gdevanla

gdevanla Aug 10, 2012

Contributor

@certik I missed that comment in my earlier push. Will address that soon.

@gdevanla

gdevanla Aug 10, 2012

Contributor

@certik I missed that comment in my earlier push. Will address that soon.

@certik

This comment has been minimized.

Show comment
Hide comment
@certik

certik Aug 4, 2012

Member

Otherwise it looks good. After you fix it, I'll merge it.

Member

certik commented Aug 4, 2012

Otherwise it looks good. After you fix it, I'll merge it.

sympy/physics/quantum/density.py
@@ -254,3 +253,73 @@ def entropy(density):
return -np.sum(eigvals*np.log(eigvals))
else:
raise ValueError("numpy.ndarray, scipy.sparse or sympy matrix expected")
+
+
+def fidelity(arg1, arg2):

This comment has been minimized.

@asmeurer

asmeurer Aug 4, 2012

Member

Maybe call these state1 and state2. That way the user can at least guess what the arguments should be from the function signature.

@asmeurer

asmeurer Aug 4, 2012

Member

Maybe call these state1 and state2. That way the user can at least guess what the arguments should be from the function signature.

sympy/physics/quantum/density.py
+
+
+ """
+ def sqrtm(mat):

This comment has been minimized.

@asmeurer

asmeurer Aug 4, 2012

Member

Matrix**Rational(1, 2) does exactly this already.

@asmeurer

asmeurer Aug 4, 2012

Member

Matrix**Rational(1, 2) does exactly this already.

@ellisonbg

This comment has been minimized.

Show comment
Hide comment
@ellisonbg

ellisonbg Aug 4, 2012

Member

One other thing we should add that is fidelity related. By taking the inverse cos of the fidelity you get an angle that is a metric on state space. I am not sure what to call this angle (might need to do some background research on it). A few details can be found on the wikipedia page for quantum fidelity.

Member

ellisonbg commented Aug 4, 2012

One other thing we should add that is fidelity related. By taking the inverse cos of the fidelity you get an angle that is a metric on state space. I am not sure what to call this angle (might need to do some background research on it). A few details can be found on the wikipedia page for quantum fidelity.

@gdevanla

This comment has been minimized.

Show comment
Hide comment
@gdevanla

gdevanla Aug 6, 2012

Contributor

@ellisonbg I am assuming you are referring to the 'Bures angle/distance', described in here : http://en.wikipedia.org/wiki/Bures_metric.

Contributor

gdevanla commented Aug 6, 2012

@ellisonbg I am assuming you are referring to the 'Bures angle/distance', described in here : http://en.wikipedia.org/wiki/Bures_metric.

@travisbot

This comment has been minimized.

Show comment
Hide comment
@travisbot

travisbot Aug 6, 2012

This pull request fails (merged ac679d1 into 9625918).

This pull request fails (merged ac679d1 into 9625918).

@Krastanov

This comment has been minimized.

Show comment
Hide comment
@Krastanov

Krastanov Aug 7, 2012

Member

SymPy Bot Summary: ✳️ All tests have passed.

Test command: setup.py test
master hash: 3c2c3c7
branch hash: ac679d1

Interpreter 1: ✳️ All tests have passed.

Interpreter: /usr/local/bin/python2.5 (2.5.6-final-0)
Architecture: Linux (64-bit)
Cache: yes

Test results html report: http://reviews.sympy.org/report/agZzeW1weTNyDAsSBFRhc2sYvd0iDA

Interpreter 2: ✳️ All tests have passed.

Interpreter: /usr/bin/python2.7 (2.7.3-candidate-2)
Architecture: Linux (64-bit)
Cache: yes

Test results html report: http://reviews.sympy.org/report/agZzeW1weTNyDAsSBFRhc2sYv7YiDA

Interpreter 3: ✳️ All tests have passed.

Interpreter: /usr/bin/python3.2 (3.2.3-candidate-2)
Architecture: Linux (64-bit)
Cache: yes

Test results html report: http://reviews.sympy.org/report/agZzeW1weTNyDAsSBFRhc2sYjrMjDA

Build HTML Docs: ✳️ All tests have passed.

Docs build command: make html-errors
Sphinx version: 1.1.3

Test results html report: http://reviews.sympy.org/report/agZzeW1weTNyDAsSBFRhc2sYm-0iDA

Automatic review by SymPy Bot.

Member

Krastanov commented Aug 7, 2012

SymPy Bot Summary: ✳️ All tests have passed.

Test command: setup.py test
master hash: 3c2c3c7
branch hash: ac679d1

Interpreter 1: ✳️ All tests have passed.

Interpreter: /usr/local/bin/python2.5 (2.5.6-final-0)
Architecture: Linux (64-bit)
Cache: yes

Test results html report: http://reviews.sympy.org/report/agZzeW1weTNyDAsSBFRhc2sYvd0iDA

Interpreter 2: ✳️ All tests have passed.

Interpreter: /usr/bin/python2.7 (2.7.3-candidate-2)
Architecture: Linux (64-bit)
Cache: yes

Test results html report: http://reviews.sympy.org/report/agZzeW1weTNyDAsSBFRhc2sYv7YiDA

Interpreter 3: ✳️ All tests have passed.

Interpreter: /usr/bin/python3.2 (3.2.3-candidate-2)
Architecture: Linux (64-bit)
Cache: yes

Test results html report: http://reviews.sympy.org/report/agZzeW1weTNyDAsSBFRhc2sYjrMjDA

Build HTML Docs: ✳️ All tests have passed.

Docs build command: make html-errors
Sphinx version: 1.1.3

Test results html report: http://reviews.sympy.org/report/agZzeW1weTNyDAsSBFRhc2sYm-0iDA

Automatic review by SymPy Bot.

sympy/physics/quantum/density.py
+ >>> updown_dm = represent(updown * Dagger(updown))
+ >>> updown2 = (sqrt(3)/2 )* up + (1/2)*down
+ >>>
+ >>> print fidelity(up_dm, up_dm)

This comment has been minimized.

@flacjacket

flacjacket Aug 9, 2012

Member

print is unnecessary here.

@flacjacket

flacjacket Aug 9, 2012

Member

print is unnecessary here.

sympy/physics/quantum/density.py
+
+ if (not isinstance(state1, Matrix) or
+ not isinstance(state2, Matrix)):
+ raise ValueError("state1 and state2 must be of type density or Matrix "

This comment has been minimized.

@flacjacket

flacjacket Aug 9, 2012

Member

Uppercase Density

@flacjacket

flacjacket Aug 9, 2012

Member

Uppercase Density

sympy/physics/quantum/density.py
+ "received type=%s for state1 and type=%s for state2" %
+ (type(state1), type(state2)))
+
+ if ( state1.shape != state2.shape and state1.rows == state2.cols):

This comment has been minimized.

@flacjacket

flacjacket Aug 9, 2012

Member

state1.rows != state2.cols
Though you could also use Matrix.is_square

@flacjacket

flacjacket Aug 9, 2012

Member

state1.rows != state2.cols
Though you could also use Matrix.is_square

@flacjacket

This comment has been minimized.

Show comment
Hide comment
@flacjacket

flacjacket Aug 9, 2012

Member

This is definitely out of my wheelhouse, but I can at least try to comment on more syntax related improvements.

Member

flacjacket commented Aug 9, 2012

This is definitely out of my wheelhouse, but I can at least try to comment on more syntax related improvements.

@Krastanov

This comment has been minimized.

Show comment
Hide comment
@Krastanov

Krastanov Aug 9, 2012

Member

SymPy Bot Summary: ✳️ All tests have passed.

Test command: setup.py test
master hash: dd8352a
branch hash: 5f0bd5d

Interpreter 1: ✳️ All tests have passed.

Interpreter: /usr/local/bin/python2.5 (2.5.6-final-0)
Architecture: Linux (64-bit)
Cache: yes

Test results html report: http://reviews.sympy.org/report/agZzeW1weTNyDAsSBFRhc2sYi_UiDA

Interpreter 2: ✳️ All tests have passed.

Interpreter: /usr/bin/python2.7 (2.7.3-candidate-2)
Architecture: Linux (64-bit)
Cache: yes

Test results html report: http://reviews.sympy.org/report/agZzeW1weTNyDAsSBFRhc2sYg5wjDA

Interpreter 3: ✳️ All tests have passed.

Interpreter: /usr/bin/python3.2 (3.2.3-candidate-2)
Architecture: Linux (64-bit)
Cache: yes

Test results html report: http://reviews.sympy.org/report/agZzeW1weTNyDAsSBFRhc2sYivUiDA

Build HTML Docs: ✳️ All tests have passed.

Docs build command: make html-errors
Sphinx version: 1.1.3

Test results html report: http://reviews.sympy.org/report/agZzeW1weTNyDAsSBFRhc2sYyd0iDA

Automatic review by SymPy Bot.

Member

Krastanov commented Aug 9, 2012

SymPy Bot Summary: ✳️ All tests have passed.

Test command: setup.py test
master hash: dd8352a
branch hash: 5f0bd5d

Interpreter 1: ✳️ All tests have passed.

Interpreter: /usr/local/bin/python2.5 (2.5.6-final-0)
Architecture: Linux (64-bit)
Cache: yes

Test results html report: http://reviews.sympy.org/report/agZzeW1weTNyDAsSBFRhc2sYi_UiDA

Interpreter 2: ✳️ All tests have passed.

Interpreter: /usr/bin/python2.7 (2.7.3-candidate-2)
Architecture: Linux (64-bit)
Cache: yes

Test results html report: http://reviews.sympy.org/report/agZzeW1weTNyDAsSBFRhc2sYg5wjDA

Interpreter 3: ✳️ All tests have passed.

Interpreter: /usr/bin/python3.2 (3.2.3-candidate-2)
Architecture: Linux (64-bit)
Cache: yes

Test results html report: http://reviews.sympy.org/report/agZzeW1weTNyDAsSBFRhc2sYivUiDA

Build HTML Docs: ✳️ All tests have passed.

Docs build command: make html-errors
Sphinx version: 1.1.3

Test results html report: http://reviews.sympy.org/report/agZzeW1weTNyDAsSBFRhc2sYyd0iDA

Automatic review by SymPy Bot.

@gdevanla

This comment has been minimized.

Show comment
Hide comment
@gdevanla

gdevanla Aug 11, 2012

Contributor

I believe I have addressed all comments in this PR. except for the one by @ellisonbg regarding the metric. But that change can go with a follow-up PR and need not be part of this.

Contributor

gdevanla commented Aug 11, 2012

I believe I have addressed all comments in this PR. except for the one by @ellisonbg regarding the metric. But that change can go with a follow-up PR and need not be part of this.

@ellisonbg

This comment has been minimized.

Show comment
Hide comment
@ellisonbg

ellisonbg Aug 11, 2012

Member

OK I think we can merge this.

Member

ellisonbg commented Aug 11, 2012

OK I think we can merge this.

ellisonbg added a commit that referenced this pull request Aug 11, 2012

@ellisonbg ellisonbg merged commit 3b77c94 into sympy:master Aug 11, 2012

1 check was pending

default The Travis build is in progress
Details
@travisbot

This comment has been minimized.

Show comment
Hide comment
@travisbot

travisbot Aug 11, 2012

This pull request passes (merged 02e7e5c into 9625918).

This pull request passes (merged 02e7e5c into 9625918).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment