qiboteam / qibocal

Quantum calibration, characterization and validation module for Qibo.
https://qibo.science
Apache License 2.0
28 stars 4 forks source link

Two qubit state tomography #836

Closed stavros11 closed 1 month ago

stavros11 commented 1 month ago

State reconstruction is still TODO, for now I am plotting the probabilities (calculated from the shots) in the different measurement basis and comparing with theory.

Some examples from qw5q_platinum:

There is something wrong with the second. I am not sure if it is coming from a wrong phase in the CZ calibration, the tomography code, or the transpiler. Need to investigate more.

TODO:

Checklist:

codecov[bot] commented 1 month ago

Codecov Report

Attention: Patch coverage is 98.20359% with 3 lines in your changes are missing coverage. Please review.

Project coverage is 97.31%. Comparing base (fe7757e) to head (27584b2). Report is 30 commits behind head on main.

Additional details and impacted files [![Impacted file tree graph](https://app.codecov.io/gh/qiboteam/qibocal/pull/836/graphs/tree.svg?width=650&height=150&src=pr&token=3EA9ZUNKUY&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=qiboteam)](https://app.codecov.io/gh/qiboteam/qibocal/pull/836?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=qiboteam) ```diff @@ Coverage Diff @@ ## main #836 +/- ## ========================================== + Coverage 97.27% 97.31% +0.03% ========================================== Files 109 110 +1 Lines 8111 8259 +148 ========================================== + Hits 7890 8037 +147 - Misses 221 222 +1 ``` | [Flag](https://app.codecov.io/gh/qiboteam/qibocal/pull/836/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=qiboteam) | Coverage Δ | | |---|---|---| | [unittests](https://app.codecov.io/gh/qiboteam/qibocal/pull/836/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=qiboteam) | `97.31% <98.20%> (+0.03%)` | :arrow_up: | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=qiboteam#carryforward-flags-in-the-pull-request-comment) to find out more. | [Files](https://app.codecov.io/gh/qiboteam/qibocal/pull/836?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=qiboteam) | Coverage Δ | | |---|---|---| | [src/qibocal/protocols/\_\_init\_\_.py](https://app.codecov.io/gh/qiboteam/qibocal/pull/836?src=pr&el=tree&filepath=src%2Fqibocal%2Fprotocols%2F__init__.py&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=qiboteam#diff-c3JjL3FpYm9jYWwvcHJvdG9jb2xzL19faW5pdF9fLnB5) | `100.00% <100.00%> (ø)` | | | [...rc/qibocal/protocols/two\_qubit\_state\_tomography.py](https://app.codecov.io/gh/qiboteam/qibocal/pull/836?src=pr&el=tree&filepath=src%2Fqibocal%2Fprotocols%2Ftwo_qubit_state_tomography.py&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=qiboteam#diff-c3JjL3FpYm9jYWwvcHJvdG9jb2xzL3R3b19xdWJpdF9zdGF0ZV90b21vZ3JhcGh5LnB5) | `99.27% <99.27%> (ø)` | | | [src/qibocal/protocols/state\_tomography.py](https://app.codecov.io/gh/qiboteam/qibocal/pull/836?src=pr&el=tree&filepath=src%2Fqibocal%2Fprotocols%2Fstate_tomography.py&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=qiboteam#diff-c3JjL3FpYm9jYWwvcHJvdG9jb2xzL3N0YXRlX3RvbW9ncmFwaHkucHk=) | `98.51% <92.59%> (+0.09%)` | :arrow_up: | ... and [2 files with indirect coverage changes](https://app.codecov.io/gh/qiboteam/qibocal/pull/836/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=qiboteam)
stavros11 commented 1 month ago

I will mark this as ready for now, since it seems to be working, including the density matrix reconstruction. Here are some examples on qw5q_platinum: http://login.qrccluster.com:9000/JzsbXKB0T26IjrWFl2TNnQ== http://login.qrccluster.com:9000/OAqdcEbiTuK8707rI5zh1A==

One potential improvement is to attempt to merge this with the single qubit case, because currently a huge chuck of the code (and plotting) was copy-pasted, which I know is not ideal. However, I would wait for #813 to be merged before touching the single qubit tomography code. This could also be done later in another PR.

stavros11 commented 1 month ago

There is something wrong with the second. I am not sure if it is coming from a wrong phase in the CZ calibration, the tomography code, or the transpiler. Need to investigate more.

This is indeed a transpiler/compiler issue. If I use a circuit with Hadamard gates,

circuit = Circuit(2)
circuit.add(gates.H(0))
circuit.add(gates.H(1))
circuit.add(gates.CZ(0, 1))
circuit.add(gates.H(1))

I get the wrong Bell state: http://login.qrccluster.com:9000/s7AjawUQSZCPOLE0ONKhaQ==, while if I switch to GPI2 it works better:

circuit = Circuit(2)
circuit.add(gates.GPI2(0, phi=np.pi/2))
circuit.add(gates.GPI2(1, phi=np.pi/2))
circuit.add(gates.CZ(0, 1))
circuit.add(gates.X(0))
circuit.add(gates.GPI2(1, phi=np.pi/2))

http://login.qrccluster.com:9000/ls3iaInvQnOD_4TxKvkNLQ==

stavros11 commented 1 month ago

This should now be ready for review.

The changes in single qubit state tomography routine are basically moving some code aroung (mainly from _plot to a new function plot_reconstruction) so that I can import and reuse in the two qubit routine, to avoid copy pasting. Most likely it is possible to reduce the code repetition between these two routines even further, but this requires changing a few more things on the way the single qubit case is done, which I didn't want to do here.

Here are some examples on qw5q_platinum with the new plots:

Jacfomg commented 1 month ago

It looks good. Are we going to keep both plots ? If we do so, could we do something about the 1D plots with the color or bar transparency ?