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

Gate set tomography #1106

Open
wants to merge 236 commits into
base: master
Choose a base branch
from
Open

Gate set tomography #1106

wants to merge 236 commits into from

Conversation

mho291
Copy link

@mho291 mho291 commented Nov 24, 2023

One qubit calibration (empty circuit tomography)
Two qubit calibration (empty circuit tomography)
One qubit operator(s) gate set tomography
Two qubits operator(s) gate set tomography

Checklist:

  • Reviewers confirm new code works as expected.
  • Tests are passing.
  • Coverage does not decrease.
  • Documentation is updated.
  • Testing with QiboLab backend.

One qubit operator(s) gate set tomography
Two qubits operator(s) gate set tomography
One qubit basis operations gate set tomography
Two qubit basis operations gate set tomography
@mho291 mho291 assigned mho291 and unassigned mho291 Nov 24, 2023
@mho291 mho291 changed the title Added gate set tomography file Gate set tomography Nov 24, 2023
@scarrazza scarrazza added this to the Qibo 0.2.5 milestone Nov 29, 2023
@MatteoRobbiati MatteoRobbiati marked this pull request as ready for review November 29, 2023 09:09
Copy link
Contributor

@BrunoLiegiBastonLiegi BrunoLiegiBastonLiegi left a comment

Choose a reason for hiding this comment

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

Thanks @mho291 for implementing this. I left some comments below, I'm not finished yet, but in general I have the feeling that many code repetitions can be avoided. I would try to write some general functions that can be applied to all the different cases you encounter here. This would make the code much easier to follow and clean.

src/qibo/validation/gate_set_tomography.py Outdated Show resolved Hide resolved
src/qibo/validation/gate_set_tomography.py Outdated Show resolved Hide resolved
src/qibo/validation/gate_set_tomography.py Outdated Show resolved Hide resolved
src/qibo/validation/gate_set_tomography.py Outdated Show resolved Hide resolved
src/qibo/validation/gate_set_tomography.py Outdated Show resolved Hide resolved
src/qibo/validation/gate_set_tomography.py Outdated Show resolved Hide resolved
src/qibo/validation/gate_set_tomography.py Outdated Show resolved Hide resolved
src/qibo/validation/gate_set_tomography.py Outdated Show resolved Hide resolved
src/qibo/validation/gate_set_tomography.py Outdated Show resolved Hide resolved
src/qibo/validation/gate_set_tomography.py Outdated Show resolved Hide resolved
@mho291
Copy link
Author

mho291 commented Dec 6, 2023

Hi @BrunoLiegiBastonLiegi! Most of the issues you've raised have been resolved. Thanks so much for looking through the code and providing helpful comments. The code that I have in my local device has all the resolved issues implemented and it works. Perhaps we can discuss some of the outstanding issues before I do another push. Thanks a lot!

@BrunoLiegiBastonLiegi
Copy link
Contributor

Hi, thanks for addressing the comments, can you push your local changes such that I can give it a look please?

Copy link
Contributor

@BrunoLiegiBastonLiegi BrunoLiegiBastonLiegi left a comment

Choose a reason for hiding this comment

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

Thanks for the updates @mho291. I think that some improvements are possible for the GST_measure_* functions. I still have to go over the rest but I would focus on those first.

src/qibo/validation/gate_set_tomography.py Outdated Show resolved Hide resolved
src/qibo/validation/gate_set_tomography.py Outdated Show resolved Hide resolved
src/qibo/validation/gate_set_tomography.py Outdated Show resolved Hide resolved
src/qibo/validation/gate_set_tomography.py Outdated Show resolved Hide resolved
src/qibo/validation/gate_set_tomography.py Outdated Show resolved Hide resolved
src/qibo/validation/gate_set_tomography.py Outdated Show resolved Hide resolved
src/qibo/validation/gate_set_tomography.py Outdated Show resolved Hide resolved
src/qibo/validation/gate_set_tomography.py Outdated Show resolved Hide resolved
src/qibo/validation/gate_set_tomography.py Outdated Show resolved Hide resolved
src/qibo/validation/gate_set_tomography.py Outdated Show resolved Hide resolved
Copy link
Contributor

@BrunoLiegiBastonLiegi BrunoLiegiBastonLiegi left a comment

Choose a reason for hiding this comment

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

Thanks @mho291 for the updates. I made some further comments. In general I have the impression that this could be made a lot shorter by applying smarter design choices. Avoid hard coded definitions when possible, and try to write general helper functions that can be specialized for the different use cases. This would also make the code much easier to follow. Moreover, if there is a reference available for this implementation, please attach it to the first post in this PR.

src/qibo/validation/gate_set_tomography.py Outdated Show resolved Hide resolved
src/qibo/validation/gate_set_tomography.py Outdated Show resolved Hide resolved
src/qibo/validation/gate_set_tomography.py Outdated Show resolved Hide resolved
src/qibo/validation/gate_set_tomography.py Outdated Show resolved Hide resolved
src/qibo/validation/gate_set_tomography.py Outdated Show resolved Hide resolved
src/qibo/validation/gate_set_tomography.py Outdated Show resolved Hide resolved
src/qibo/validation/gate_set_tomography.py Outdated Show resolved Hide resolved
src/qibo/validation/gate_set_tomography.py Outdated Show resolved Hide resolved
src/qibo/validation/gate_set_tomography.py Outdated Show resolved Hide resolved
src/qibo/validation/gate_set_tomography.py Outdated Show resolved Hide resolved
@AlejandroSopena
Copy link
Contributor

Hi @mho291, can you push your latest changes so we can continue reviewing from there please?

@mho291
Copy link
Author

mho291 commented Dec 19, 2023

Hi @mho291, can you push your latest changes so we can continue reviewing from there please?

Just did. Sorry for the delay. I planned to push yesterday but I caught the covid bug.

Copy link

codecov bot commented Dec 19, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (465e88d) 100.00% compared to head (2592ec8) 100.00%.

Additional details and impacted files
@@            Coverage Diff            @@
##            master     #1106   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           69        71    +2     
  Lines        10110     10202   +92     
=========================================
+ Hits         10110     10202   +92     
Flag Coverage Δ
unittests 100.00% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@AlejandroSopena AlejandroSopena left a comment

Choose a reason for hiding this comment

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

Thanks. The implementation of the method seems correct. Just a few comments and suggestions to shorten the code and avoid redundancies.

src/qibo/validation/gate_set_tomography.py Outdated Show resolved Hide resolved
src/qibo/validation/gate_set_tomography.py Outdated Show resolved Hide resolved
src/qibo/validation/gate_set_tomography.py Outdated Show resolved Hide resolved
src/qibo/validation/gate_set_tomography.py Outdated Show resolved Hide resolved
src/qibo/validation/gate_set_tomography.py Outdated Show resolved Hide resolved
src/qibo/validation/gate_set_tomography.py Outdated Show resolved Hide resolved
@mho291
Copy link
Author

mho291 commented May 6, 2024

Hi @BrunoLiegiBastonLiegi ! I've been trying to get the tests to run but they don't seem to run. Any idea how we can get the tests to run? Thanks!

@BrunoLiegiBastonLiegi
Copy link
Contributor

Yeah, there was a problem with some dependencies, often this is due to changes in the pyproject.toml either in the branch, in master or even in other dependencies repo like qibojit and qibotn. Merging master and updating the lock with poetry lock did the trick.

@mho291
Copy link
Author

mho291 commented May 7, 2024

I see, thanks for the @BrunoLiegiBastonLiegi ! I see that the codecov is still not 100%, allow me to tidy it up. Cheers.

@mho291
Copy link
Author

mho291 commented May 10, 2024

Hi @BrunoLiegiBastonLiegi , the checks have passed. Could you kindly help to take a look and make necessary modifications so that we can merge soon? I'm hoping to start on the PEC as soon as possible. Thanks a lot!

Comment on lines +259 to +262
def test_GST_invertible_matrix():
T = np.array([[1, 1, 1, 1], [0, 0, 1, 0], [0, 0, 0, 1], [1, -1, 0, 0]])
matrices = GST(gate_set=[], Pauli_Liouville=True, T=T)
assert True
Copy link
Contributor

Choose a reason for hiding this comment

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

@AlejandroSopena do you have any idea how to test a different gauge for the matrix T? Worst case we could just exclude those lines from coverage.

@AlejandroSopena AlejandroSopena self-requested a review May 19, 2024 15:18
Copy link
Contributor

@AlejandroSopena AlejandroSopena left a comment

Choose a reason for hiding this comment

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

Thanks for the work @mho291.

As I understand it, the output of GST is just the noisy gates and optionally the Gram matrix called empty_matrix. But in general, GST should return the complete gate set, that is, the characterization of the gates $G_k$, the initial states $|\rho^l\rangle\rangle$, and the measurements $\langle\langle E^m_l |$. (see eq 46, 47, 48 in Nielsen_GST taking into account that their $B$ is our matrix T and $I$ denotes our empty_matrix) These elements depend on the matrix T, but when used to calculate expected values of a certain observable, the dependence on T disappears. To obtain the states and measurements, we should perform state tomopraphy and measurerement tomography, respectively and use eqs 47 and 48.

In PEC, this method is used to characterize (obtain a gate set: states, measurements, and gates) from a universal gate set, allowing ideal expected values to be decomposed as a combination of noisy expected values.

Following this scheme, I have doubts about how are you going treat the states and measurements. Are you going to consider noise-free states and measurements for PEC as proposed in the original paper Temme_EM or the more complete method proposed in Endo_EM_NISQ?

If the idea is to obtain the states and measurements through state and measurement tomography in #1097 I think it would be better to do it here to complete GST.

If you are going to consider noise-free states and measurements, for PEC it is enough to obtain only the gates through GST, but the method would not be complete. Even so, characterizing only the gates with the default matrix T is sufficiently useful information from an experimental point of view. In this case, since this has been open for quite some time, I suppose we can merge it and open an issue. The gauge to use in PEC should be the default matrix T, and it would not be possible to test other matrices T until GST is completed.

@scarrazza scarrazza modified the milestones: Qibo 0.2.8, Qibo 0.2.9 May 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

10 participants