Exemple #1
0
def test_calibration_heatmap():
    calibration = cg.Calibration(_CALIBRATION_DATA)

    heatmap = calibration.heatmap('t1')
    figure = mpl.figure.Figure()
    axes = figure.add_subplot(111)
    heatmap.plot(axes)

    heatmap = calibration.heatmap('xeb')
    figure = mpl.figure.Figure()
    axes = figure.add_subplot(999)
    heatmap.plot(axes)

    with pytest.raises(ValueError, match="one or two qubits.*multi_qubit"):
        multi_qubit_data = Merge(
            """metrics: [{
                name: 'multi_qubit',
                targets: ['0_0', '0_1', '1_0'],
                values: [{double_val: 0.999}]}]""",
            v2.metrics_pb2.MetricsSnapshot(),
        )
        cg.Calibration(multi_qubit_data).heatmap('multi_qubit')
    with pytest.raises(ValueError, match="single metric values.*multi_value"):
        multi_qubit_data = Merge(
            """metrics: [{
                name: 'multi_value',
                targets: ['0_0'],
                values: [{double_val: 0.999}, {double_val: 0.001}]}]""",
            v2.metrics_pb2.MetricsSnapshot(),
        )
        cg.Calibration(multi_qubit_data).heatmap('multi_value')
def test_to_proto():
    calibration = cg.Calibration(_CALIBRATION_DATA)
    assert calibration == cg.Calibration(calibration.to_proto())
    invalid_value = cg.Calibration(
        metrics={'metric': {
            (cirq.GridQubit(1, 1), ): [1.1, {}]
        }})
    with pytest.raises(ValueError, match='Unsupported metric value'):
        invalid_value.to_proto()
Exemple #3
0
def test_calibrations_with_string_key():
    calibration = cg.Calibration(metrics={'metric1': {('alpha',): [0.1]}})
    expected_proto = Merge(
        """
        metrics: [{
          name: 'metric1'
          targets: ['alpha']
          values: [{double_val: 0.1}]
        }]
    """,
        v2.metrics_pb2.MetricsSnapshot(),
    )
    assert expected_proto == calibration.to_proto()
    assert calibration == cg.Calibration(expected_proto)
    assert calibration == cg.Calibration(calibration.to_proto())
def test_calibration_plot_histograms():
    calibration = cg.Calibration(_CALIBRATION_DATA)
    _, ax = mpl.pyplot.subplots(1, 1)
    calibration.plot_histograms(['t1', 'two_qubit_xeb'], ax, labels=['T1', 'XEB'])
    assert len(ax.get_lines()) == 4

    with pytest.raises(ValueError, match="single metric values.*multi_value"):
        multi_qubit_data = Merge(
            """metrics: [{
                name: 'multi_value',
                targets: ['0_0'],
                values: [{double_val: 0.999}, {double_val: 0.001}]}]""",
            v2.metrics_pb2.MetricsSnapshot(),
        )
        cg.Calibration(multi_qubit_data).plot_histograms('multi_value')
def test_calibration_heatmap():
    calibration = cg.Calibration(_CALIBRATION_DATA)

    heatmap = calibration.heatmap('t1')
    figure = mpl.figure.Figure()
    axes = figure.add_subplot(111)
    heatmap.plot(axes)
def test_calibration_timestamp_str():
    calibration = cg.Calibration(_CALIBRATION_DATA)
    assert calibration.timestamp_str(
        tz=datetime.timezone.utc) == '2019-07-08 00:00:00.021021+00:00'
    assert (calibration.timestamp_str(
        tz=datetime.timezone(datetime.timedelta(
            hours=1))) == '2019-07-08 01:00:00.021021+01:00')
def test_calibrations_with_string_key():
    calibration = cg.Calibration(metrics={'metric1': {('alpha', ): [0.1]}})
    expected_proto = Merge(
        """
        metrics: [{
          name: 'metric1'
          targets: ['alpha']
          values: [{double_val: 0.1}]
        }]
    """,
        v2.metrics_pb2.MetricsSnapshot(),
    )
    assert expected_proto == calibration.to_proto()
    assert calibration == cg.Calibration(expected_proto)
    assert calibration == cg.Calibration(calibration.to_proto())

    with pytest.raises(ValueError, match='was not a qubit'):
        calibration.key_to_qubit('alpha')
def test_calibration_metrics_dictionary():
    calibration = cg.Calibration(_CALIBRATION_DATA)

    t1s = calibration['t1']
    assert t1s == {
        (cirq.GridQubit(0, 0), ): [321],
        (cirq.GridQubit(0, 1), ): [911],
        (cirq.GridQubit(1, 0), ): [505]
    }
    assert len(calibration) == 3

    assert 't1' in calibration
    assert 't2' not in calibration

    for qubits, values in t1s.items():
        assert len(qubits) == 1
        assert len(values) == 1

    with pytest.raises(TypeError, match="was 1"):
        _ = calibration[1]
    with pytest.raises(KeyError, match='notit'):
        _ = calibration['notit']
def test_calibration_repr():
    calibration = cg.Calibration(_CALIBRATION_DATA)
    cirq.testing.assert_equivalent_repr(calibration)
def test_calibration_str():
    calibration = cg.Calibration(_CALIBRATION_DATA)
    assert str(
        calibration) == "Calibration(keys=['globalMetric', 't1', 'xeb'])"
Exemple #11
0
def test_calibration_plot():
    calibration = cg.Calibration(_CALIBRATION_DATA)
    _, axs = calibration.plot('two_qubit_xeb')
    assert axs[0].get_title() == 'Two Qubit Xeb'
    assert len(axs[1].get_lines()) == 2