Example #1
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)
Example #2
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)
Example #3
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])
Example #4
0
def test_find_measurements_simple_schedule():
    schedule = cirq.Schedule(
        device=cirq.UNCONSTRAINED_DEVICE,
        scheduled_operations=[
            cirq.ScheduledOperation(
                time=cirq.Timestamp(picos=10_000),
                duration=cirq.Duration(nanos=1000),
                operation=cirq.measure(q(0, 0), q(0, 1), q(0, 2), key='k'),
            ),
        ],
    )
    measurements = v2.find_measurements(schedule)

    assert len(measurements) == 1
    m = measurements[0]
    _check_measurement(m, 'k', [q(0, 0), q(0, 1), q(0, 2)], 10_000)
Example #5
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)
Example #6
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')],
    )
Example #7
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)
Example #8
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)