def test_run_calibration_validation_fails(): engine = cg.Engine( project_id='proj', proto_version=cg.engine.engine.ProtoVersion.V2, ) q1 = cirq.GridQubit(2, 3) q2 = cirq.GridQubit(2, 4) layer1 = cg.CalibrationLayer('xeb', cirq.Circuit(cirq.CZ(q1, q2)), {'num_layers': 42}) layer2 = cg.CalibrationLayer('readout', cirq.Circuit(cirq.measure(q1, q2)), {'num_samples': 4242}) with pytest.raises(ValueError, match='Processor id must be specified'): _ = engine.run_calibration(layers=[layer1, layer2], gate_set=cg.XMON, job_id='job-id') with pytest.raises(ValueError, match='Gate set must be specified'): _ = engine.run_calibration(layers=[layer1, layer2], processor_ids=['mysim'], job_id='job-id') with pytest.raises(ValueError, match='processor_id and processor_ids'): _ = engine.run_calibration(layers=[layer1, layer2], processor_ids=['mysim'], processor_id='mysim', gate_set=cg.XMON, job_id='job-id')
def test_run_calibration(client): setup_run_circuit_with_result_(client, _CALIBRATION_RESULTS_V2) engine = cg.Engine( project_id='proj', proto_version=cg.engine.engine.ProtoVersion.V2, ) q1 = cirq.GridQubit(2, 3) q2 = cirq.GridQubit(2, 4) layer1 = cg.CalibrationLayer('xeb', cirq.Circuit(cirq.CZ(q1, q2)), {'num_layers': 42}) layer2 = cg.CalibrationLayer('readout', cirq.Circuit(cirq.measure(q1, q2)), {'num_samples': 4242}) job = engine.run_calibration(gate_set=cg.FSIM_GATESET, layers=[layer1, layer2], job_id='job-id', processor_id='mysim') results = job.calibration_results() assert len(results) == 2 assert results[0].code == v2.calibration_pb2.SUCCESS assert results[0].error_message == 'First success' assert results[0].token == 'abc123' assert len(results[0].metrics) == 1 assert len(results[0].metrics['fidelity']) == 1 assert results[0].metrics['fidelity'][(q1, q2)] == [0.75] assert results[1].code == v2.calibration_pb2.SUCCESS assert results[1].error_message == 'Second success' # assert label is correct client().create_job.assert_called_once_with( project_id='proj', program_id='prog', job_id='job-id', processor_ids=['mysim'], run_context=_to_any( v2.run_context_pb2.RunContext(parameter_sweeps=[ v2.run_context_pb2.ParameterSweep(repetitions=1) ])), description=None, labels={'calibration': ''}, )