Exemplo n.º 1
0
def test_run_characterization_fails_when_invalid_arguments():
    with pytest.raises(ValueError):
        assert workflow.run_calibrations([],
                                         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_calibrations([request], engine, None,
                                         cirq_google.FSIM_GATESET)

    with pytest.raises(ValueError):
        assert workflow.run_calibrations([request], engine, 'qproc', None)

    with pytest.raises(ValueError):
        assert workflow.run_calibrations([request], 0, 'qproc',
                                         cirq_google.FSIM_GATESET)
Exemplo n.º 2
0
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_calibrations([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,
            ),
        )
    ]
Exemplo n.º 3
0
def test_run_characterization_empty():
    assert workflow.run_calibrations([], None, 'qproc',
                                     cirq_google.FSIM_GATESET) == []
Exemplo n.º 4
0
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_calibrations([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)]