Skip to content

Commit

Permalink
Update version of the Floquet calibration (#4557)
Browse files Browse the repository at this point in the history
* Support features of the Floquet calibration version 2

* Remove debug print and update floquet calibration version

* Add tests for version parameter

* Fix json serialization tests

* Improve tests
  • Loading branch information
mrwojtek committed Oct 19, 2021
1 parent 55507d5 commit 6562a05
Show file tree
Hide file tree
Showing 8 changed files with 84 additions and 4 deletions.
5 changes: 5 additions & 0 deletions cirq-google/cirq_google/calibration/phased_fsim.py
Expand Up @@ -570,6 +570,8 @@ class FloquetPhasedFSimCalibrationOptions(PhasedFSimCalibrationOptions):
characterize_gamma: bool
characterize_phi: bool
readout_error_tolerance: Optional[float] = None
version: int = 2
measure_qubits: Optional[Tuple[cirq.Qid, ...]] = None

def zeta_chi_gamma_correction_override(self) -> PhasedFSimCharacterization:
"""Gives a PhasedFSimCharacterization that can be used to override characterization after
Expand Down Expand Up @@ -664,6 +666,8 @@ def from_moment(cls, moment: cirq.Moment, options: FloquetPhasedFSimCalibrationO

def to_calibration_layer(self) -> CalibrationLayer:
circuit = cirq.Circuit(self.gate.on(*pair) for pair in self.pairs)
if self.options.measure_qubits is not None:
circuit += cirq.Moment(cirq.measure(*self.options.measure_qubits))
args: Dict[str, Any] = {
'est_theta': self.options.characterize_theta,
'est_zeta': self.options.characterize_zeta,
Expand All @@ -672,6 +676,7 @@ def to_calibration_layer(self) -> CalibrationLayer:
'est_phi': self.options.characterize_phi,
# Experimental option that should always be set to True.
'readout_corrections': True,
'version': self.options.version,
}
if self.options.readout_error_tolerance is not None:
# Maximum error of the diagonal elements of the two-qubit readout confusion matrix.
Expand Down
67 changes: 67 additions & 0 deletions cirq-google/cirq_google/calibration/phased_fsim_test.py
Expand Up @@ -118,6 +118,38 @@ def test_floquet_to_calibration_layer():
'est_gamma': False,
'est_phi': True,
'readout_corrections': True,
'version': 2,
},
)


def test_floquet_to_calibration_layer_with_version_override():
q_00, q_01, q_02, q_03 = [cirq.GridQubit(0, index) for index in range(4)]
gate = cirq.FSimGate(theta=np.pi / 4, phi=0.0)
request = FloquetPhasedFSimCalibrationRequest(
gate=gate,
pairs=((q_00, q_01), (q_02, q_03)),
options=FloquetPhasedFSimCalibrationOptions(
characterize_theta=True,
characterize_zeta=True,
characterize_chi=False,
characterize_gamma=False,
characterize_phi=True,
version=3,
),
)

assert request.to_calibration_layer() == cirq_google.CalibrationLayer(
calibration_type='floquet_phased_fsim_characterization',
program=cirq.Circuit([gate.on(q_00, q_01), gate.on(q_02, q_03)]),
args={
'est_theta': True,
'est_zeta': True,
'est_chi': False,
'est_gamma': False,
'est_phi': True,
'readout_corrections': True,
'version': 3,
},
)

Expand Down Expand Up @@ -150,6 +182,41 @@ def test_floquet_to_calibration_layer_readout_thresholds():
'readout_corrections': True,
'readout_error_tolerance': 0.4,
'correlated_readout_error_tolerance': 7 / 6 * 0.4 - 1 / 6,
'version': 2,
},
)


def test_floquet_to_calibration_layer_with_measure_qubits():
qubits = tuple(cirq.GridQubit(0, index) for index in range(5))
q_00, q_01, q_02, q_03, _ = qubits
gate = cirq.FSimGate(theta=np.pi / 4, phi=0.0)
request = FloquetPhasedFSimCalibrationRequest(
gate=gate,
pairs=((q_00, q_01), (q_02, q_03)),
options=FloquetPhasedFSimCalibrationOptions(
characterize_theta=True,
characterize_zeta=True,
characterize_chi=False,
characterize_gamma=False,
characterize_phi=True,
measure_qubits=qubits,
),
)

assert request.to_calibration_layer() == cirq_google.CalibrationLayer(
calibration_type='floquet_phased_fsim_characterization',
program=cirq.Circuit(
[gate.on(q_00, q_01), gate.on(q_02, q_03), cirq.measure(*qubits)],
),
args={
'est_theta': True,
'est_zeta': True,
'est_chi': False,
'est_gamma': False,
'est_phi': True,
'readout_corrections': True,
'version': 2,
},
)

Expand Down
Expand Up @@ -5,5 +5,7 @@
"characterize_chi": false,
"characterize_gamma": true,
"characterize_phi": false,
"readout_error_tolerance": 0.4
"readout_error_tolerance": 0.4,
"version": 2,
"measure_qubits": null
}
@@ -1 +1 @@
cirq_google.FloquetPhasedFSimCalibrationOptions(characterize_theta=True, characterize_zeta=True, characterize_chi=False, characterize_gamma=True, characterize_phi=False, readout_error_tolerance=0.4)
cirq_google.FloquetPhasedFSimCalibrationOptions(characterize_theta=True, characterize_zeta=True, characterize_chi=False, characterize_gamma=True, characterize_phi=False, readout_error_tolerance=0.4, version=2)
Expand Up @@ -38,6 +38,8 @@
"characterize_chi": false,
"characterize_gamma": false,
"characterize_phi": true,
"readout_error_tolerance": 0.4
"readout_error_tolerance": 0.4,
"version": 2,
"measure_qubits": null
}
}
Expand Up @@ -8,5 +8,6 @@ cirq_google.FloquetPhasedFSimCalibrationRequest(
characterize_gamma=False,
characterize_phi=True,
readout_error_tolerance=0.4,
version=2
),
)
Expand Up @@ -54,7 +54,9 @@
"characterize_chi": false,
"characterize_gamma": false,
"characterize_phi": true,
"readout_error_tolerance": 0.4
"readout_error_tolerance": 0.4,
"version": 2,
"measure_qubits": null
},
"project_id": "project_id",
"program_id": "program_id",
Expand Down
Expand Up @@ -15,6 +15,7 @@ cirq_google.PhasedFSimCalibrationResult(
characterize_gamma=False,
characterize_phi=True,
readout_error_tolerance=0.4,
version=2
),
project_id='project_id',
program_id='program_id',
Expand Down

0 comments on commit 6562a05

Please sign in to comment.