def test_run_characterization_fails_when_invalid_arguments(): with pytest.raises(ValueError): assert workflow.run_characterizations([], None, 'qproc', cirq.google.FSIM_GATESET, max_layers_per_request=0) request = FloquetPhasedFSimCalibrationRequest( gate=SQRT_ISWAP_GATE, pairs=(), options=WITHOUT_CHI_FLOQUET_PHASED_FSIM_CHARACTERIZATION, ) engine = mock.MagicMock(spec=cirq.google.Engine) with pytest.raises(ValueError): assert workflow.run_characterizations([request], engine, None, cirq.google.FSIM_GATESET) with pytest.raises(ValueError): assert workflow.run_characterizations([request], engine, 'qproc', None) with pytest.raises(ValueError): assert workflow.run_characterizations([request], 0, 'qproc', cirq.google.FSIM_GATESET)
def test_run_characterization_with_simulator(): q_00, q_01, q_02, q_03 = [cirq.GridQubit(0, index) for index in range(4)] gate = SQRT_ISWAP_GATE 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, ), ) simulator = PhasedFSimEngineSimulator.create_with_ideal_sqrt_iswap() actual = workflow.run_characterizations([request], simulator) assert actual == [ PhasedFSimCalibrationResult( parameters={ (q_00, q_01): PhasedFSimCharacterization(theta=np.pi / 4, zeta=0.0, chi=None, gamma=None, phi=0.0), (q_02, q_03): PhasedFSimCharacterization(theta=np.pi / 4, zeta=0.0, chi=None, gamma=None, phi=0.0), }, gate=SQRT_ISWAP_GATE, options=FloquetPhasedFSimCalibrationOptions( characterize_theta=True, characterize_zeta=True, characterize_chi=False, characterize_gamma=False, characterize_phi=True, ), ) ]
def test_run_characterization_empty(): assert workflow.run_characterizations([], None, 'qproc', cirq.google.FSIM_GATESET) == []
def test_run_characterization(): 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, ), ) result = cirq.google.CalibrationResult( code=cirq.google.api.v2.calibration_pb2.SUCCESS, error_message=None, token=None, valid_until=None, metrics=cirq.google.Calibration( cirq.google.api.v2.metrics_pb2.MetricsSnapshot(metrics=[ cirq.google.api.v2.metrics_pb2.Metric( name='angles', targets=[ '0_qubit_a', '0_qubit_b', '0_theta_est', '0_zeta_est', '0_phi_est', '1_qubit_a', '1_qubit_b', '1_theta_est', '1_zeta_est', '1_phi_est', ], values=[ cirq.google.api.v2.metrics_pb2.Value(str_val='0_0'), cirq.google.api.v2.metrics_pb2.Value(str_val='0_1'), cirq.google.api.v2.metrics_pb2.Value(double_val=0.1), cirq.google.api.v2.metrics_pb2.Value(double_val=0.2), cirq.google.api.v2.metrics_pb2.Value(double_val=0.3), cirq.google.api.v2.metrics_pb2.Value(str_val='0_2'), cirq.google.api.v2.metrics_pb2.Value(str_val='0_3'), cirq.google.api.v2.metrics_pb2.Value(double_val=0.4), cirq.google.api.v2.metrics_pb2.Value(double_val=0.5), cirq.google.api.v2.metrics_pb2.Value(double_val=0.6), ], ) ])), ) job = cirq.google.engine.EngineJob('', '', '', None) job._calibration_results = [result] engine = mock.MagicMock(spec=cirq.google.Engine) engine.run_calibration.return_value = job progress_calls = [] def progress(step: int, steps: int) -> None: progress_calls.append((step, steps)) actual = workflow.run_characterizations([request], engine, 'qproc', cirq.google.FSIM_GATESET, progress_func=progress) expected = [ PhasedFSimCalibrationResult( parameters={ (q_00, q_01): PhasedFSimCharacterization(theta=0.1, zeta=0.2, chi=None, gamma=None, phi=0.3), (q_02, q_03): PhasedFSimCharacterization(theta=0.4, zeta=0.5, chi=None, gamma=None, phi=0.6), }, gate=gate, options=FloquetPhasedFSimCalibrationOptions( characterize_theta=True, characterize_zeta=True, characterize_chi=False, characterize_gamma=False, characterize_phi=True, ), ) ] assert actual == expected assert progress_calls == [(1, 1)]