-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand Floquet calibration to arbitrary FSim gates #4164
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
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.
Thank you Dmytro for doing this! The concepts contained here are a little bit complex. I've tried to explain some of them but feel free to ping me if some of my comments are not clear for you.
Hi Wojtek, I resolved most of your comments, and rewrote |
I added a test utilizing the engine simulator. Please take another look. |
Hi @mrwojtek, I addressed your comments and added more tests. PTAL. |
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.
Three minor issues and one question which maybe you could clarify for me and we are done I think.
engine_simulator = cirq_google.PhasedFSimEngineSimulator.create_from_dictionary( | ||
parameters={ | ||
(a, b): { | ||
cirq.FSimGate(theta=0, phi=np.pi): params_cz_ab, |
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.
Could you use cirq.CZ gate here and below?
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 can't, because cirq.CZ != FSimGate(theta=0, phi=np.pi), but gate translator converts all gates to FSimGate. So all gates in this map must be FSimGate, otherwise there will be no match.
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.
Yes, you're right. If this code will be used heavily in the future we might think about normalizing all gates to a common form inside the "create_from_dictionary" by using the converter itself. (Let's postpone it for now.)
I addressed issue with global_phase and other suggestions. |
engine_simulator = cirq_google.PhasedFSimEngineSimulator.create_from_dictionary( | ||
parameters={ | ||
(a, b): { | ||
cirq.FSimGate(theta=0, phi=np.pi): params_cz_ab, |
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.
Yes, you're right. If this code will be used heavily in the future we might think about normalizing all gates to a common form inside the "create_from_dictionary" by using the converter itself. (Let's postpone it for now.)
@balopat can we have approval from code owners for this? |
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.
LGTM % comment
@@ -1038,3 +1046,51 @@ def try_convert_sqrt_iswap_to_fsim(gate: cirq.Gate) -> Optional[PhaseCalibratedF | |||
return PhaseCalibratedFSimGate(cirq.FSimGate(theta=np.pi / 4, phi=0.0), 0.5) | |||
|
|||
return None | |||
|
|||
|
|||
def try_convert_gate_to_fsim(gate: cirq.Gate) -> Optional[PhaseCalibratedFSimGate]: |
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.
[Unrelated comment] We should work towards getting cirq.match()
! #2536
Goal of this PR is that circuits having any of these 2-qubit gates (sqrt(iSWAP), Sycamore) can be calibrated on real hardware. In #4164 I ensured that any FSim-compatible gate can be handled on compensation phase. But on characterization step we can support only these 2 gates, because only they are implemented in hardware (so far). For that: * Added method `try_convert_syc_or_sqrt_iswap_to_fsim` which is restriction of `try_convert_gate_to_fsim` on gates supported by hardware. * Used that method in `workflow.py` as gate translator everywhere where `try_convert_sqrt_iswap_to_fsim` was used. * Fixed a bug in `_merge_into_calibrations` so if there are calibrations for 2 different gates, it wouldn't fail with assertion error, but would append new calibration to the list of calibration. * Modified a test `test_run_zeta_chi_gamma_calibration_for_moments` so the circuit under test contains gates of 2 types.
* Added a method try_convert_gate_to_fsim which can convert to PhaseCalibratedFSimGate wide range of gates, including sqrt(iSWAP), Sycamore and Controlled-Z gates. * Used this method (instead of try_convert_sqrt_iswap_to_fsim) as default gate translator in all methods in workflow.py. As a result, compensation step Floquet calibration now works not only for sqrt(iSWAP), but also for: * all FSim gates (including Sycamore gate); * PhasedFSim gates (such that zeta=gamma=0); * all ISwapPow gates; * all PhasedISwapPow gates; * CZPow gates without global phase (including CZ). This change doesn't affect characterization step the Floquet calibration.
…mlib#4248) Goal of this PR is that circuits having any of these 2-qubit gates (sqrt(iSWAP), Sycamore) can be calibrated on real hardware. In quantumlib#4164 I ensured that any FSim-compatible gate can be handled on compensation phase. But on characterization step we can support only these 2 gates, because only they are implemented in hardware (so far). For that: * Added method `try_convert_syc_or_sqrt_iswap_to_fsim` which is restriction of `try_convert_gate_to_fsim` on gates supported by hardware. * Used that method in `workflow.py` as gate translator everywhere where `try_convert_sqrt_iswap_to_fsim` was used. * Fixed a bug in `_merge_into_calibrations` so if there are calibrations for 2 different gates, it wouldn't fail with assertion error, but would append new calibration to the list of calibration. * Modified a test `test_run_zeta_chi_gamma_calibration_for_moments` so the circuit under test contains gates of 2 types.
As a result, compensation step Floquet calibration now works not only for sqrt(iSWAP), but also for:
This change doesn't affect characterization step the Floquet calibration.