Exemplo n.º 1
0
def test_floquet_parse_result_bad_metric():
    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=[
                        '1000gerbils',
                    ],
                    values=[
                        cirq_google.api.v2.metrics_pb2.Value(str_val='100_10'),
                    ],
                )
            ])),
    )
    with pytest.raises(ValueError, match='Unknown metric name 1000gerbils'):
        _ = request.parse_result(result)
Exemplo n.º 2
0
def test_floquet_parse_result_failure():
    gate = cirq.FSimGate(theta=np.pi / 4, phi=0.0)
    request = FloquetPhasedFSimCalibrationRequest(
        gate=gate,
        pairs=(),
        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.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)
Exemplo n.º 3
0
def test_floquet_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 = 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),
                    ],
                )
            ])),
    )

    assert request.parse_result(result) == 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,
        ),
    )