Пример #1
0
def test_find_measurements_fill_mask():
    circuit = cirq.Circuit()
    circuit.append(cirq.measure(q(0, 0), q(0, 1), q(0, 2), key='k', invert_mask=[False, True]))
    measurements = v2.find_measurements(circuit)

    assert len(measurements) == 1
    m = measurements[0]
    _check_measurement(m, 'k', [q(0, 0), q(0, 1), q(0, 2)], 0, [False, True, False])
Пример #2
0
def test_find_measurements_simple_circuit():
    circuit = cirq.Circuit()
    circuit.append(cirq.measure(q(0, 0), q(0, 1), q(0, 2), key='k'))
    measurements = v2.find_measurements(circuit)

    assert len(measurements) == 1
    m = measurements[0]
    _check_measurement(m, 'k', [q(0, 0), q(0, 1), q(0, 2)], 0)
Пример #3
0
def test_multiple_measurements_different_slots():
    circuit = cirq.Circuit()
    circuit.append(cirq.measure(q(0, 0), q(0, 1), key='k0'))
    circuit.append(cirq.measure(q(0, 2), q(0, 0), key='k1'))
    measurements = v2.find_measurements(circuit)

    assert len(measurements) == 2
    m0, m1 = measurements
    _check_measurement(m0, 'k0', [q(0, 0), q(0, 1)], 0)
    _check_measurement(m1, 'k1', [q(0, 2), q(0, 0)], 1)
Пример #4
0
def test_multiple_measurements_shared_slots():
    circuit = cirq.Circuit()
    circuit.append([
        cirq.measure(q(0, 0), q(0, 1), key='k0'),
        cirq.measure(q(0, 2), q(1, 1), key='k1')
    ])
    circuit.append([
        cirq.measure(q(1, 0), q(0, 0), q(0, 1), key='k2'),
        cirq.measure(q(1, 1), q(0, 2), key='k3'),
    ])
    measurements = v2.find_measurements(circuit)

    assert len(measurements) == 4
    m0, m1, m2, m3 = measurements
    _check_measurement(m0, 'k0', [q(0, 0), q(0, 1)], 0)
    _check_measurement(m1, 'k1', [q(0, 2), q(1, 1)], 0)
    _check_measurement(m2, 'k2', [q(1, 0), q(0, 0), q(0, 1)], 1)
    _check_measurement(m3, 'k3', [q(1, 1), q(0, 2)], 1)
Пример #5
0
def test_find_measurements_with_tags():
    circuit = cirq.Circuit()
    circuit.append(
        cirq.measure(q(0, 0), q(0, 1), q(0, 2), key='k', invert_mask=[False, True, True]).with_tags(
            cirq_google.CalibrationTag('special')
        )
    )
    measurements = v2.find_measurements(circuit)

    assert len(measurements) == 1
    m = measurements[0]
    _check_measurement(
        m,
        'k',
        [q(0, 0), q(0, 1), q(0, 2)],
        0,
        [False, True, True],
        [cirq_google.CalibrationTag('special')],
    )
Пример #6
0
def test_find_measurements_non_grid_qubits():
    circuit = cirq.Circuit()
    circuit.append(cirq.measure(cirq.NamedQubit('a'), key='k'))
    with pytest.raises(ValueError, match='Expected GridQubits'):
        v2.find_measurements(circuit)
Пример #7
0
def test_find_measurements_duplicate_keys():
    circuit = cirq.Circuit()
    circuit.append(cirq.measure(q(0, 0), q(0, 1), key='k'))
    circuit.append(cirq.measure(q(0, 1), q(0, 2), key='k'))
    with pytest.raises(ValueError, match='Duplicate measurement key'):
        v2.find_measurements(circuit)