Beispiel #1
0
def test_xeb_parse_result_failure():
    gate = cirq.FSimGate(theta=np.pi / 4, phi=0.0)
    request = XEBPhasedFSimCalibrationRequest(
        gate=gate,
        pairs=(),
        options=XEBPhasedFSimCalibrationOptions(
            fsim_options=XEBPhasedFSimCharacterizationOptions(
                characterize_theta=False,
                characterize_zeta=False,
                characterize_chi=False,
                characterize_gamma=False,
                characterize_phi=True,
            )),
    )

    result = cirq_google.CalibrationResult(
        code=cirq_google.api.v2.calibration_pb2.ERROR_CALIBRATION_FAILED,
        error_message="Test message",
        token=None,
        valid_until=None,
        metrics=cirq_google.Calibration(),
    )

    with pytest.raises(PhasedFSimCalibrationError, match='Test message'):
        request.parse_result(result)
Beispiel #2
0
def test_xeb_parse_result():
    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 = XEBPhasedFSimCalibrationRequest(
        gate=gate,
        pairs=((q_00, q_01), (q_02, q_03)),
        options=XEBPhasedFSimCalibrationOptions(
            fsim_options=XEBPhasedFSimCharacterizationOptions(
                characterize_theta=False,
                characterize_zeta=False,
                characterize_chi=False,
                characterize_gamma=False,
                characterize_phi=True,
            )),
    )

    result = _load_xeb_results_textproto()
    assert request.parse_result(result) == PhasedFSimCalibrationResult(
        parameters={
            (q_00, q_01): PhasedFSimCharacterization(phi=0.0,
                                                     theta=-0.7853981),
            (q_02, q_03): PhasedFSimCharacterization(phi=0.0,
                                                     theta=-0.7853981),
        },
        gate=gate,
        options=request.options,
    )
Beispiel #3
0
def test_xeb_to_calibration_layer():
    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 = XEBPhasedFSimCalibrationRequest(
        gate=gate,
        pairs=((q_00, q_01), (q_02, q_03)),
        options=XEBPhasedFSimCalibrationOptions(
            n_library_circuits=22,
            fsim_options=XEBPhasedFSimCharacterizationOptions(
                characterize_theta=True,
                characterize_zeta=True,
                characterize_chi=False,
                characterize_gamma=False,
                characterize_phi=True,
            ),
        ),
    )
    layer = request.to_calibration_layer()
    assert layer == cirq_google.CalibrationLayer(
        calibration_type='xeb_phased_fsim_characterization',
        program=cirq.Circuit([gate.on(q_00, q_01),
                              gate.on(q_02, q_03)]),
        args={
            'n_library_circuits': 22,
            'n_combinations': 10,
            'cycle_depths': '5_25_50_100_200_300',
            'fatol': 5e-3,
            'xatol': 5e-3,
            'characterize_theta': True,
            'characterize_zeta': True,
            'characterize_chi': False,
            'characterize_gamma': False,
            'characterize_phi': True,
            'theta_default': 0.0,
            'zeta_default': 0.0,
            'chi_default': 0.0,
            'gamma_default': 0.0,
            'phi_default': 0.0,
        },
    )

    # Serialize to proto
    calibration = v2.calibration_pb2.FocusedCalibration()
    new_layer = calibration.layers.add()
    new_layer.calibration_type = layer.calibration_type
    for arg in layer.args:
        arg_to_proto(layer.args[arg], out=new_layer.args[arg])
    cirq_google.SQRT_ISWAP_GATESET.serialize(layer.program,
                                             msg=new_layer.layer)
    with open(
            os.path.dirname(__file__) +
            '/test_data/xeb_calibration_layer.textproto') as f:
        desired_textproto = f.read()

    layer_str = str(new_layer)
    # Fix precision issues
    layer_str = re.sub(r'0.004999\d+', '0.005', layer_str)
    assert layer_str == desired_textproto