-
Notifications
You must be signed in to change notification settings - Fork 1.1k
(2/2) Add parameter sweep support for Pauli string measurements with readout mitigation #7569
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I found the difference. If you start with the following circuit:
0: ───────────────────────H───@───H───
│
1: ───────────────H───@───H───@───────
│
2: ───H───────@───H───@───────────────
│
3: ───H───@───@───────────────────────
│
4: ───H───@───────H───@───────────────
│
5: ───────────────H───@───H───@───────
│
6: ───────────────────────H───@───H───
and then measure X(q(0))*X(q(1))*X(q(2))*X(q(3))*X(q(4))*X(q(5))*X(q(6))
, the sweep version gives you
0: ───────────────────────H───@───H───PhX(phi0/2 - 1/2)^theta0───M('m')───
│ │
1: ───────────────H───@───H───@───────PhX(phi1/2 - 1/2)^theta1───M────────
│ │
2: ───H───────@───H───@───────────────PhX(phi2/2 - 1/2)^theta2───M────────
│ │
3: ───H───@───@───────────────────────PhX(phi3/2 - 1/2)^theta3───M────────
│ │
4: ───H───@───────H───@───────────────PhX(phi4/2 - 1/2)^theta4───M────────
│ │
5: ───────────────H───@───H───@───────PhX(phi5/2 - 1/2)^theta5───M────────
│ │
6: ───────────────────────H───@───H───PhX(phi6/2 - 1/2)^theta6───M────────
with the basis change all in the same moment, whereas in the batch version, you get
0: ───────────────────────────────H───────────@───H───────────Ry(-0.5π)───M('m')───
│ │
1: ───────────────H───────────@───H───────────@───Ry(-0.5π)───────────────M────────
│ │
2: ───H───────@───H───────────@───Ry(-0.5π)───────────────────────────────M────────
│ │
3: ───H───@───@───Ry(-0.5π)───────────────────────────────────────────────M────────
│ │
4: ───H───@───────H───────────@───Ry(-0.5π)───────────────────────────────M────────
│ │
5: ───────────────H───────────@───H───────────@───Ry(-0.5π)───────────────M────────
│ │
6: ───────────────────────────────H───────────@───H───────────Ry(-0.5π)───M────────
with the basis change done as early as possible. In this case, you get a higher-fidelity result with the basis change done as early as possible because you are insensitive to the dephasing that happens between the final basis change gate and the measurement, but that may not always be the intended behavior. Maybe we could add an insert_strategy argument so that users have the choice of whether to do the basis change all in the same penultimate moment or as early as possible.
Thanks, @ddddddanni! It looks like it is printing out the circuits for debugging, and you might want to remove that. |
Check out this pull request on See visual diffs & provide feedback on Jupyter Notebooks. Powered by ReviewNB |
Done! |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #7569 +/- ##
========================================
Coverage 99.37% 99.37%
========================================
Files 1078 1082 +4
Lines 96166 96761 +595
========================================
+ Hits 95563 96157 +594
- Misses 603 604 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are some things that @ddddddanni and I will keep investigating, but I think we can go ahead and merge this. I just want to clarify that this still has shuffling for the run_batch case, correct? Thanks!
Sure! I have re-enabled shuffling function |
@NoureldinYosri can you please review this PR? Thank you!! |
return operations | ||
|
||
|
||
def _pauli_strings_to_basis_change_with_sweep( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm having a déjà vu moment, didn't you write a similar method before?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have a giant PR https://github.com/quantumlib/Cirq/pull/7358/files which you reviewed long time ago. I break that PR into smaller ones: #7435 and this pr, per you requested.
For question you asked in #7358: https://screenshot.googleplex.com/6HHTPQdj3R6Vwfy and https://screenshot.googleplex.com/9kw8sR9Q8g4BnMF - each qubit can belong to many input pauli strings. Since input pauli strings are qubit-wise commuting, it's safe to do so. For example, input pauli strings could be {X(q_0)I(q_1), I(q_0)X(q_1)}, and this function returns params_dict{q_0:x basis change, q_1: x basis change}.
basis_change_circuits = [] | ||
input_circuit_unfrozen = input_circuit.unfreeze() | ||
for pauli_strings in pauli_string_groups: | ||
basis_change_circuit = circuits.Circuit( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that we don't really need an insert_strategy, we can just do
circuits.Circuit.from_moments(
*input_circuit,
_pauli_strings_to_basis_change_ops(pauli_strings, qid_list),
ops.measure(*qid_list, key="m"),
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We want to give users choices of whether to do the basis change all in the same penultimate moment or as early as possible. This was discussed https://screenshot.googleplex.com/4LPKcw4eYCSvP85.
basis_change_circuit = circuits.Circuit( | ||
input_circuit_unfrozen, | ||
_pauli_strings_to_basis_change_ops(pauli_strings, qid_list), | ||
ops.measure(*qid_list, key="m"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lets use a more meaningful key name
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
] | ||
measurement_op = ops.M(*qid_list, key="m") | ||
|
||
parameterized_circuit = circuits.Circuit( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.from_moments
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same above, we may want to allow users to control the insert strategy of basis changes.
sweep_params = [] | ||
for bitstr in random_bitstrings: | ||
sweep_params.append({exp: bit for exp, bit in zip(exp_symbols, bitstr)}) | ||
sweep_params.append({exp.name: bit for exp, bit in zip(exp_symbols, bitstr)}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how about str(exp)
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
Previous PR is #7435
This PR allow user to run measuring_pauli_strings in sweep mode. In this mode, the function uses parameterized circuits and sweeps parameters for both Pauli measurements and readout benchmarking