Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve dnorm efficiency in unitary case #2416

Merged
merged 10 commits into from
May 9, 2024
Merged

Conversation

owenagnel
Copy link
Contributor

@owenagnel owenagnel commented May 5, 2024

Preliminaries

The diamond norm [1] is a commonly used metric in quantum information theory for calculating the distance between two quantum channels. It has a number of useful properties making it the gold standard [2] in the field for several applications. In general, a complex semidefinite program is required to calculate the diamond norm. Although elegant, this approach is very inefficient. Unfortunately, no alternative method has been discovered for calculating the diamond norm in the general case of CPTP channels.

However, in the special case where we are trying to calculate the difference between two unitary channels, a very efficient implementation exists. This makes use of an unproved theorem on page 29 of [1]. I have proved this theorem and elaborated an efficient algorithm to calculate the diamond distance between two unitaries as part of my masters thesis.

The current qutip implementation makes use of the semi-definite program formulation in [3] and only uses a simplified calculation on 2 qubit unitary differences.

The implementation of this novel approach is very simple - the hardest step involves diagonalising a unitary. Although time complexity is still exponential in the number of qubits, this implementation is far more efficient than the more general implementation. The Choi representation of the quantum channel isn't used and there is no need to solve a complicated semi-definite program (meaning I can do away with the cvxpy dependency).

Empirical testing

Results of empirical testing on my machine are reported below

3 qubit 4 qubit
current implementation 5.22 s 3min 21s
hyper-efficient implementation 924 µs 1.11 ms

Proposition

Given the popularity of the circuit model and unitary-based quantum computation, I believe a very efficient implementation of the diamond distance for unitaries would be incredibly valuable for the research community. Given how simple the change is (current tests already cover the test case), I think it would be a simple and worthwhile addition to qutip.

Citations

[1] D. Aharonov, A. Kitaev, and N. Nisan, “Quantum circuits with mixed states,” in Proceedings of the thirtieth annual ACM symposium on Theory of computing, pp. 20–30, 1998.
[2] A. Gilchrist, N. K. Langford, and M. A. Nielsen, “Distance measures to compare real and ideal quantum processes,” Physical Review A, vol. 71, no. 6, p. 062310, 2005
[3] J. Watrous, “Simpler semidefinite programs for completely bounded norms,” arXiv preprint arXiv:1207.5726, 2012.

@owenagnel owenagnel marked this pull request as draft May 5, 2024 18:12
@owenagnel owenagnel marked this pull request as ready for review May 5, 2024 18:36
@owenagnel owenagnel changed the title [Draft Pull Request] Improve dorm unitary case Improve dnorm efficiency in unitary case May 5, 2024
@owenagnel
Copy link
Contributor Author

owenagnel commented May 5, 2024

Note to reviewers:

  • Codeclimate is not passing because too many return statements... It's an easy fix but is it worth it?
  • Current tests already test for this new implementation (for two and three qubits)

doc/changes/2416.feature Outdated Show resolved Hide resolved
qutip/core/metrics.py Outdated Show resolved Hide resolved
@hodgestar
Copy link
Contributor

Thanks for tackling this (I think) long-standing too. I haven't done a thorough check but on a first pass it looks like a great improvement.

@owenagnel
Copy link
Contributor Author

Thanks for reviewing! Sounds good, will make those changes ASAP.

Quick disclaimer, I can't seem to install cvxpy on my machine without using anaconda, so I haven't run the qutip tests personally. I assume these run automatically in the pipeline. I have done a lot of testing independently though and the implementation seems to work very reliably (often giving more accurate results than the semidefinite program).

@coveralls
Copy link

coveralls commented May 5, 2024

Coverage Status

coverage: 86.124% (+0.03%) from 86.09%
when pulling 210e140 on owenagnel:master
into 320996b on qutip:master.

@hodgestar
Copy link
Contributor

Quick disclaimer, I can't seem to install cvxpy on my machine without using anaconda, so I haven't run the qutip tests personally. I assume these run automatically in the pipeline.

That's fine. The CI pipeline does test with cvxpy.

@owenagnel owenagnel requested a review from hodgestar May 7, 2024 16:54
@owenagnel
Copy link
Contributor Author

owenagnel commented May 7, 2024

Made another quick change. We know from Prop. 3.44 of (Watrous, 2018) that the diamond norm of CPTP channel is 1. So I added a quick if statement that checks this. Also refactored dnorm so there's only one return statement to make code climate happy. Looks like it's unhappy with something else and maybe made the logic harder to follow. Please advise if you have a preference. Again, can't really run tests locally, so approving the CI pipeline would be fantastic.

qutip/core/metrics.py Outdated Show resolved Hide resolved
Copy link
Member

@Ericgig Ericgig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will let @hodgestar re-review and merge, but looks good to me.
Thank you.

@owenagnel
Copy link
Contributor Author

I will let @hodgestar re-review and merge, but looks good to me.
Thank you.

Thanks for reviewing!

Copy link
Contributor

@hodgestar hodgestar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks again for this. I made some suggestions largely to clarify things.

Could you also add a test to the dnorm tests in test_metrics that explicitly tests the unitary case using rand_unitary to generate A and B?

qutip/core/metrics.py Outdated Show resolved Hide resolved
qutip/core/metrics.py Outdated Show resolved Hide resolved
qutip/core/metrics.py Outdated Show resolved Hide resolved
qutip/core/metrics.py Outdated Show resolved Hide resolved
qutip/core/metrics.py Outdated Show resolved Hide resolved
@hodgestar
Copy link
Contributor

Please also check my suggestions -- I am definitely not infallible!

@owenagnel
Copy link
Contributor Author

Please also check my suggestions -- I am definitely not infallible!

Should have addressed all these, all very good suggestions! Thanks for reviewing

@owenagnel owenagnel requested a review from hodgestar May 8, 2024 08:35
Copy link
Contributor

@hodgestar hodgestar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two tiny suggestions and then it looks good.

doc/changes/2416.feature Outdated Show resolved Hide resolved
qutip/core/metrics.py Outdated Show resolved Hide resolved
@owenagnel owenagnel requested a review from hodgestar May 8, 2024 10:36
@owenagnel owenagnel requested a review from Ericgig May 8, 2024 16:52
@owenagnel
Copy link
Contributor Author

Hi @Ericgig and @hodgestar. As it's the first time I've contributed, I was curious what the process is to merge. Do you wait for a new release or is it merged to main as soon as the PR has been approved?

@hodgestar hodgestar merged commit 7bb79e9 into qutip:master May 9, 2024
11 of 12 checks passed
@hodgestar
Copy link
Contributor

@owenagnel Thank you for an excellent contribution. Merged to master.

@owenagnel
Copy link
Contributor Author

Thank you for an excellent contribution. Merged to master.

Thanks both @hodgestar and @Ericgig for the very timely and helpful reviews!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants