def test_validate_schedule_errors():
    d = square_device(2, 2, max_controls=3)
    s = cirq.Schedule(device=cirq.UnconstrainedDevice)
    q00 = cirq.GridQubit(0, 0)
    q01 = cirq.GridQubit(0, 1)
    q10 = cirq.GridQubit(1, 0)
    q11 = cirq.GridQubit(1, 1)
    us = cirq.Duration(nanos=10**3)
    ms = cirq.Duration(nanos=10**6)
    msone = cirq.Timestamp(nanos=10**6)
    mstwo = cirq.Timestamp(nanos=2*10**6)
    msthree = cirq.Timestamp(nanos=3*10**6)
    for qubit in d.qubits:
        s.include(cirq.ScheduledOperation(cirq.Timestamp(nanos=0), 100*us,
                                          cirq.X.on(qubit)))
    s.include(cirq.ScheduledOperation(msone, 100*us,
                                      cirq.TOFFOLI.on(q00,q01,q10)))
    s.include(cirq.ScheduledOperation(mstwo, 100*us, cirq.ParallelGateOperation(
        cirq.X, [q00, q01])))
    s.include(cirq.ScheduledOperation(mstwo, 100*us, cirq.ParallelGateOperation(
        cirq.Z, [q10, q11])))
    for qubit in d.qubits:
        s.include(cirq.ScheduledOperation(msthree,
                                          50*ms,
                                          cirq.GateOperation(
                                              cirq.MeasurementGate(1, qubit),
                                              [qubit])))
    d.validate_schedule(s)
    s.include(cirq.ScheduledOperation(cirq.Timestamp(nanos=10**9), 100*us,
                                      cirq.X.on(q00)))
    with pytest.raises(ValueError, match="Non-measurement operation after "
                       "measurement"):
        d.validate_schedule(s)
Beispiel #2
0
def test_validate_scheduled_operation_not_adjacent_exp_11_exp_w():
    d = square_device(3, 3, holes=[cirq.GridQubit(1, 1)])
    q0 = cirq.GridQubit(0, 0)
    p1 = cirq.GridQubit(1, 2)
    p2 = cirq.GridQubit(2, 2)
    s = cirq.Schedule(d, [
        cirq.ScheduledOperation.op_at_on(cirq.X(q0), cirq.Timestamp(), d),
        cirq.ScheduledOperation.op_at_on(cirq.CZ(p1, p2), cirq.Timestamp(), d),
    ])
    d.validate_schedule(s)
Beispiel #3
0
def test_validate_scheduled_operation_adjacent_exp_11_exp_z():
    d = square_device(3, 3, holes=[cirq.GridQubit(1, 1)])
    q0 = cirq.GridQubit(0, 0)
    q1 = cirq.GridQubit(1, 0)
    q2 = cirq.GridQubit(2, 0)
    s = cirq.Schedule(d, [
        cirq.ScheduledOperation.op_at_on(cirq.Z(q0), cirq.Timestamp(), d),
        cirq.ScheduledOperation.op_at_on(cirq.CZ(q1, q2), cirq.Timestamp(), d),
    ])
    d.validate_schedule(s)
Beispiel #4
0
def test_validate_scheduled_operation_XXPow_on_same_qubit():
    d = ion_device(3)
    q0 = cirq.LineQubit(0)
    q1 = cirq.LineQubit(1)
    q2 = cirq.LineQubit(2)
    s = cirq.Schedule(d, [
        cirq.ScheduledOperation.op_at_on(cirq.XX(q0, q1), cirq.Timestamp(), d),
        cirq.ScheduledOperation.op_at_on(cirq.XX(q1, q2), cirq.Timestamp(), d),
    ])
    with pytest.raises(ValueError):
        d.validate_schedule(s)
Beispiel #5
0
def test_validate_schedule_repeat_measurement_keys():
    d = ion_device(3)

    s = cirq.Schedule(d, [
        cirq.ScheduledOperation.op_at_on(
            cirq.measure(cirq.LineQubit(0), key='a'), cirq.Timestamp(), d),
        cirq.ScheduledOperation.op_at_on(
            cirq.measure(cirq.LineQubit(1), key='a'), cirq.Timestamp(), d),
    ])

    with pytest.raises(ValueError, match='Measurement key a repeated'):
        d.validate_schedule(s)
Beispiel #6
0
def test_validate_schedule_repeat_measurement_keys():
    d = square_device(3, 3)

    s = cirq.Schedule(d, [
        cirq.ScheduledOperation.op_at_on(
            cirq.measure(cirq.GridQubit(0, 0), key='a'), cirq.Timestamp(), d),
        cirq.ScheduledOperation.op_at_on(
            cirq.measure(cirq.GridQubit(0, 1), key='a'), cirq.Timestamp(), d),
    ])

    with pytest.raises(ValueError, message='Measurement key a repeated'):
        d.validate_schedule(s)
def test_validate_scheduled_operation_adjacent_exp_11_measure():
    d = square_device(3, 3, holes=[cirq.GridQubit(1, 1)])
    q0 = cirq.GridQubit(0, 0)
    q1 = cirq.GridQubit(1, 0)
    q2 = cirq.GridQubit(2, 0)
    s = cirq.Schedule(d, [
        cirq.ScheduledOperation.op_at_on(cg.XmonMeasurementGate().on(q0),
                                         cirq.Timestamp(), d),
        cirq.ScheduledOperation.op_at_on(cg.Exp11Gate().on(q1, q2),
                                         cirq.Timestamp(), d),
    ])
    d.validate_schedule(s)
Beispiel #8
0
def test_validate_scheduled_operation_adjacent_exp_11s_not_allowed():
    d = square_device(3, 3, holes=[cirq.GridQubit(1, 1)])
    q0 = cirq.GridQubit(0, 0)
    q1 = cirq.GridQubit(0, 1)
    p0 = cirq.GridQubit(1, 0)
    p1 = cirq.GridQubit(1, 1)
    s = cirq.Schedule(d, [
        cirq.ScheduledOperation.op_at_on(cirq.CZ(q0, q1), cirq.Timestamp(), d),
        cirq.ScheduledOperation.op_at_on(cirq.CZ(p0, p1), cirq.Timestamp(), d),
    ])
    with pytest.raises(ValueError, match='Adjacent Exp11 operations'):
        d.validate_schedule(s)
Beispiel #9
0
def test_validate_scheduled_operation_adjacent_XXPow_Z():
    d = ion_device(3)
    q0 = cirq.LineQubit(0)
    q1 = cirq.LineQubit(1)
    q2 = cirq.LineQubit(2)
    s = cirq.Schedule(d, [
        cirq.ScheduledOperation.op_at_on(cirq.Z(q0), cirq.Timestamp(), d),
        cirq.ScheduledOperation.op_at_on(cirq.XX(q1, q2), cirq.Timestamp(), d),
        cirq.ScheduledOperation.op_at_on(cirq.X(q1), cirq.Timestamp(), d),
        cirq.ScheduledOperation.op_at_on(cirq.measure(q2), cirq.Timestamp(),
                                         d),
    ])
    d.validate_schedule(s)
Beispiel #10
0
def test_serialize_schedule():
    q0 = cirq.GridQubit(1, 1)
    q1 = cirq.GridQubit(1, 2)
    scheduled_ops = [
        cirq.ScheduledOperation.op_at_on(cirq.CZ(q0, q1),
                                         cirq.Timestamp(nanos=0),
                                         device=cg.Bristlecone),
        cirq.ScheduledOperation.op_at_on(cirq.X(q0),
                                         cirq.Timestamp(nanos=200),
                                         device=cg.Bristlecone),
        cirq.ScheduledOperation.op_at_on(cirq.Z(q1),
                                         cirq.Timestamp(nanos=200),
                                         device=cg.Bristlecone),
        cirq.ScheduledOperation.op_at_on(cirq.measure(q0, key='a'),
                                         cirq.Timestamp(nanos=400),
                                         device=cg.Bristlecone)
    ]
    schedule = cirq.Schedule(device=cirq.google.Bristlecone,
                             scheduled_operations=scheduled_ops)
    expected = {
        'language': {
            'arg_function_language': '',
            'gate_set': 'xmon'
        },
        'schedule': {
            'scheduled_operations': [{
                'operation':
                cg.XMON.serialize_op_dict(cirq.CZ(q0, q1)),
                'start_time_picos':
                '0'
            }, {
                'operation':
                cg.XMON.serialize_op_dict(cirq.X(q0)),
                'start_time_picos':
                '200000',
            }, {
                'operation':
                cg.XMON.serialize_op_dict(cirq.Z(q1)),
                'start_time_picos':
                '200000',
            }, {
                'operation':
                cg.XMON.serialize_op_dict(cirq.measure(q0, key='a')),
                'start_time_picos':
                '400000',
            }]
        },
    }
    assert cg.XMON.serialize_dict(schedule) == expected
Beispiel #11
0
def test_deserialize_schedule():
    q0 = cirq.GridQubit(1, 1)
    q1 = cirq.GridQubit(1, 2)
    scheduled_ops = [
        cirq.ScheduledOperation.op_at_on(cirq.CZ(q0, q1),
                                         cirq.Timestamp(nanos=0),
                                         device=cg.Bristlecone),
        cirq.ScheduledOperation.op_at_on(cirq.X(q0),
                                         cirq.Timestamp(nanos=200),
                                         device=cg.Bristlecone),
        cirq.ScheduledOperation.op_at_on(cirq.Z(q1),
                                         cirq.Timestamp(nanos=200),
                                         device=cg.Bristlecone),
        cirq.ScheduledOperation.op_at_on(cirq.measure(q0, key='a'),
                                         cirq.Timestamp(nanos=400),
                                         device=cg.Bristlecone)
    ]
    schedule = cirq.Schedule(device=cirq.google.Bristlecone,
                             scheduled_operations=scheduled_ops)
    serialized = {
        'language': {
            'gate_set': 'xmon'
        },
        'schedule': {
            'scheduled_operations': [{
                'operation':
                cg.XMON.serialize_op(cirq.CZ(q0, q1)),
                'start_time_picos':
                0
            }, {
                'operation':
                cg.XMON.serialize_op(cirq.X(q0)),
                'start_time_picos':
                200000,
            }, {
                'operation':
                cg.XMON.serialize_op(cirq.Z(q1)),
                'start_time_picos':
                200000,
            }, {
                'operation':
                cg.XMON.serialize_op(cirq.measure(q0, key='a')),
                'start_time_picos':
                400000,
            }]
        },
    }
    assert cg.XMON.deserialize(serialized, cg.Bristlecone) == schedule
Beispiel #12
0
def test_query_overlapping_operations_inclusive():
    q = cirq.NamedQubit('q')
    zero = cirq.Timestamp(picos=0)
    ps = cirq.Duration(picos=1)
    op1 = cirq.ScheduledOperation(zero, 2 * ps, cirq.H(q))
    op2 = cirq.ScheduledOperation(zero + ps, 2 * ps, cirq.H(q))
    schedule = cirq.Schedule(device=UNCONSTRAINED_DEVICE,
                             scheduled_operations=[op2, op1])

    def query(t, d=cirq.Duration(), qubits=None):
        return schedule.query(time=t,
                              duration=d,
                              qubits=qubits,
                              include_query_end_time=True,
                              include_op_end_times=True)

    assert query(zero - 0.5 * ps, ps) == [op1]
    assert query(zero - 0.5 * ps, 2 * ps) == [op1, op2]
    assert query(zero, ps) == [op1, op2]
    assert query(zero + 0.5 * ps, ps) == [op1, op2]
    assert query(zero + ps, ps) == [op1, op2]
    assert query(zero + 1.5 * ps, ps) == [op1, op2]
    assert query(zero + 2.0 * ps, ps) == [op1, op2]
    assert query(zero + 2.5 * ps, ps) == [op2]
    assert query(zero + 3.0 * ps, ps) == [op2]
    assert query(zero + 3.5 * ps, ps) == []
Beispiel #13
0
def test_moment_by_moment_schedule_empty_moment_ignored():
    device = _TestDevice()
    qubits = device.qubits

    circuit = Circuit(
        [Moment([ops.H(qubits[0])]),
         Moment([]),
         Moment([ops.H(qubits[0])])])
    schedule = moment_by_moment_schedule(device, circuit)

    zero_ns = cirq.Timestamp()
    twenty_ns = cirq.Timestamp(nanos=20)
    assert set(schedule.scheduled_operations) == {
        ScheduledOperation.op_at_on(ops.H(qubits[0]), zero_ns, device),
        ScheduledOperation.op_at_on(ops.H(qubits[0]), twenty_ns, device),
    }
Beispiel #14
0
def test_query_timedelta():
    q = cirq.NamedQubit('q')
    zero = cirq.Timestamp(picos=0)
    ms = timedelta(microseconds=1000)
    op1 = cirq.ScheduledOperation(zero, 2 * ms, cirq.H(q))
    op2 = cirq.ScheduledOperation(zero + ms, 2 * ms, cirq.H(q))
    schedule = cirq.Schedule(device=UNCONSTRAINED_DEVICE,
                             scheduled_operations=[op2, op1])

    def query(t, d=timedelta(), qubits=None):
        return schedule.query(time=t,
                              duration=d,
                              qubits=qubits,
                              include_query_end_time=True,
                              include_op_end_times=True)

    assert query(zero - 0.5 * ms, ms) == [op1]
    assert query(zero - 0.5 * ms, 2 * ms) == [op1, op2]
    assert query(zero, ms) == [op1, op2]
    assert query(zero + 0.5 * ms, ms) == [op1, op2]
    assert query(zero + ms, ms) == [op1, op2]
    assert query(zero + 1.5 * ms, ms) == [op1, op2]
    assert query(zero + 2.0 * ms, ms) == [op1, op2]
    assert query(zero + 2.5 * ms, ms) == [op2]
    assert query(zero + 3.0 * ms, ms) == [op2]
    assert query(zero + 3.5 * ms, ms) == []
Beispiel #15
0
def test_query_point_operation_exclusive():
    q = cirq.NamedQubit('q')
    zero = cirq.Timestamp(picos=0)
    ps = cirq.Duration(picos=1)
    op = cirq.ScheduledOperation(zero, cirq.Duration(), cirq.H(q))
    schedule = cirq.Schedule(device=UNCONSTRAINED_DEVICE,
                             scheduled_operations=[op])

    assert schedule.query(time=zero,
                          include_query_end_time=False,
                          include_op_end_times=False) == []
    assert schedule.query(time=zero + ps,
                          include_query_end_time=False,
                          include_op_end_times=False) == []
    assert schedule.query(time=zero - ps,
                          include_query_end_time=False,
                          include_op_end_times=False) == []
    assert schedule.query(time=zero) == []
    assert schedule.query(time=zero + ps) == []
    assert schedule.query(time=zero - ps) == []

    assert schedule.query(time=zero, qubits=[]) == []
    assert schedule.query(time=zero, qubits=[q]) == []

    assert schedule.query(time=zero, duration=ps) == []
    assert schedule.query(time=zero - 0.5 * ps, duration=ps) == [op]
    assert schedule.query(time=zero - ps, duration=ps) == []
    assert schedule.query(time=zero - 2 * ps, duration=ps) == []
    assert schedule.query(time=zero - ps, duration=3 * ps) == [op]
    assert schedule.query(time=zero + ps, duration=ps) == []
Beispiel #16
0
def test_query_point_operation_inclusive():
    q = cirq.NamedQubit('q')
    zero = cirq.Timestamp(picos=0)
    ps = cirq.Duration(picos=1)
    op = cirq.ScheduledOperation(zero, cirq.Duration(), cirq.H(q))
    schedule = cirq.Schedule(device=UNCONSTRAINED_DEVICE,
                             scheduled_operations=[op])

    def query(t, d=cirq.Duration(), qubits=None):
        return schedule.query(time=t,
                              duration=d,
                              qubits=qubits,
                              include_query_end_time=True,
                              include_op_end_times=True)

    assert query(zero) == [op]
    assert query(zero + ps) == []
    assert query(zero - ps) == []

    assert query(zero, qubits=[]) == []
    assert query(zero, qubits=[q]) == [op]

    assert query(zero, ps) == [op]
    assert query(zero - 0.5 * ps, ps) == [op]
    assert query(zero - ps, ps) == [op]
    assert query(zero - 2 * ps, ps) == []
    assert query(zero - ps, 3 * ps) == [op]
    assert query(zero + ps, ps) == []
def test_validate_scheduled_operation_errors():
    d = square_device(2, 2)
    s = cirq.Schedule(device=cirq.UnconstrainedDevice)
    q00 = cirq.GridQubit(0, 0)
    so = cirq.ScheduledOperation(cirq.Timestamp(), cirq.Duration(nanos=1),
                                 cirq.X.on(q00))
    with pytest.raises(ValueError, match="Incompatible operation duration"):
        d.validate_scheduled_operation(s, so)
Beispiel #18
0
def test_moment_by_moment_schedule_two_moments():
    device = _TestDevice()
    qubits = device.qubits

    circuit = Circuit([
        Moment(ops.H(q) for q in qubits),
        Moment((ops.CZ(qubits[i], qubits[i + 1]) for i in range(0, 9, 3)))
    ])
    schedule = moment_by_moment_schedule(device, circuit)

    zero_ns = cirq.Timestamp()
    twenty_ns = cirq.Timestamp(nanos=20)
    expected_one_qubit = set(
        ScheduledOperation.op_at_on(ops.H(q), zero_ns, device) for q in qubits)
    expected_two_qubit = set(
        ScheduledOperation.op_at_on(ops.CZ(qubits[i], qubits[i + 1]),
                                    twenty_ns, device) for i in range(0, 9, 3))
    expected = expected_one_qubit.union(expected_two_qubit)
    assert set(schedule.scheduled_operations) == expected
Beispiel #19
0
def test_moment_by_moment_schedule_max_duration():
    device = _TestDevice()
    qubits = device.qubits

    circuit = Circuit([
        Moment([ops.H(qubits[0]),
                ops.CZ(qubits[1], qubits[2])]),
        Moment([ops.H(qubits[0])])
    ])
    schedule = moment_by_moment_schedule(device, circuit)

    zero_ns = cirq.Timestamp()
    fourty_ns = cirq.Timestamp(nanos=40)
    assert set(schedule.scheduled_operations) == {
        ScheduledOperation.op_at_on(ops.H(qubits[0]), zero_ns, device),
        ScheduledOperation.op_at_on(ops.CZ(qubits[1], qubits[2]), zero_ns,
                                    device),
        ScheduledOperation.op_at_on(ops.H(qubits[0]), fourty_ns, device),
    }
def test_serialize_deserialize_schedule():
    q0 = cirq.GridQubit(1, 1)
    q1 = cirq.GridQubit(1, 2)
    scheduled_ops = [
        cirq.ScheduledOperation.op_at_on(cirq.X(q0),
                                         cirq.Timestamp(nanos=0),
                                         device=cg.Bristlecone),
        cirq.ScheduledOperation.op_at_on(cirq.X(q1),
                                         cirq.Timestamp(nanos=200),
                                         device=cg.Bristlecone),
        cirq.ScheduledOperation.op_at_on(cirq.X(q0),
                                         cirq.Timestamp(nanos=400),
                                         device=cg.Bristlecone),
    ]
    schedule = cirq.Schedule(device=cirq.google.Bristlecone,
                             scheduled_operations=scheduled_ops)

    proto = {
        'language': {
            'arg_function_language': '',
            'gate_set': 'my_gate_set'
        },
        'schedule': {
            'scheduled_operations': [
                {
                    'operation': X_SERIALIZER.to_proto_dict(cirq.X(q0)),
                    'start_time_picos': '0'
                },
                {
                    'operation': X_SERIALIZER.to_proto_dict(cirq.X(q1)),
                    'start_time_picos': '200000',
                },
                {
                    'operation': X_SERIALIZER.to_proto_dict(cirq.X(q0)),
                    'start_time_picos': '400000',
                },
            ]
        },
    }
    assert proto == MY_GATE_SET.serialize_dict(schedule)
    assert MY_GATE_SET.deserialize_dict(proto,
                                        cirq.google.Bristlecone) == schedule
Beispiel #21
0
def test_the_test_device():
    device = _TestDevice()

    device.validate_gate(cirq.H)
    with pytest.raises(ValueError):
        device.validate_gate(cirq.X)

    device.validate_operation(cirq.H(cirq.LineQubit(0)))
    with pytest.raises(ValueError):
        device.validate_operation(NotImplementedOperation())

    device.validate_schedule(Schedule(device, []))

    device.validate_schedule(
        Schedule(device, [
            ScheduledOperation.op_at_on(cirq.H(cirq.LineQubit(0)),
                                        cirq.Timestamp(), device),
            ScheduledOperation.op_at_on(
                cirq.CZ(cirq.LineQubit(0), cirq.LineQubit(1)),
                cirq.Timestamp(), device)
        ]))

    with pytest.raises(ValueError):
        device.validate_schedule(
            Schedule(device, [
                ScheduledOperation.op_at_on(NotImplementedOperation(),
                                            cirq.Timestamp(), device)
            ]))

    with pytest.raises(ValueError):
        device.validate_schedule(
            Schedule(device, [
                ScheduledOperation.op_at_on(cirq.X(cirq.LineQubit(0)),
                                            cirq.Timestamp(), device)
            ]))

    with pytest.raises(ValueError):
        device.validate_schedule(
            Schedule(device, [
                ScheduledOperation.op_at_on(cirq.H(cirq.NamedQubit('q')),
                                            cirq.Timestamp(), device)
            ]))

    with pytest.raises(ValueError):
        device.validate_schedule(
            Schedule(device, [
                ScheduledOperation.op_at_on(cirq.H(cirq.LineQubit(100)),
                                            cirq.Timestamp(), device)
            ]))

    with pytest.raises(ValueError):
        device.validate_schedule(
            Schedule(device, [
                ScheduledOperation.op_at_on(
                    cirq.CZ(cirq.LineQubit(1), cirq.LineQubit(3)),
                    cirq.Timestamp(), device)
            ]))
Beispiel #22
0
 def simple_schedule(q, start_picos=0, duration_micros=1, num_ops=1):
     time_picos = start_picos
     scheduled_ops = []
     for _ in range(num_ops):
         op = cirq.ScheduledOperation(
             cirq.Timestamp(picos=time_picos),
             timedelta(microseconds=duration_micros), cirq.H(q))
         scheduled_ops.append(op)
         time_picos += duration_micros * 10**6
     return cirq.Schedule(device=UNCONSTRAINED_DEVICE,
                          scheduled_operations=scheduled_ops)
Beispiel #23
0
 def simple_schedule(q, start_picos=0, duration_picos=1, num_ops=1):
     time_picos = start_picos
     scheduled_ops = []
     for _ in range(num_ops):
         op = cirq.ScheduledOperation(cirq.Timestamp(picos=time_picos),
                                      cirq.Duration(picos=duration_picos),
                                      cirq.H(q))
         scheduled_ops.append(op)
         time_picos += duration_picos
     return cirq.Schedule(device=UnconstrainedDevice,
                          scheduled_operations=scheduled_ops)
Beispiel #24
0
def test_moment_by_moment_schedule_moment_of_two_qubit_ops():
    device = _TestDevice()
    qubits = device.qubits

    circuit = Circuit(
        [Moment((ops.CZ(qubits[i], qubits[i + 1]) for i in range(0, 9, 3)))])
    schedule = moment_by_moment_schedule(device, circuit)

    zero_ns = cirq.Timestamp()
    expected = set(
        ScheduledOperation.op_at_on(ops.CZ(qubits[i], qubits[i + 1]), zero_ns,
                                    device) for i in range(0, 9, 3))
    assert set(schedule.scheduled_operations) == expected
Beispiel #25
0
def test_moment_by_moment_schedule_moment_of_single_qubit_ops():
    device = _TestDevice()
    qubits = device.qubits

    circuit = Circuit([
        Moment(ops.H(q) for q in qubits),
    ])
    schedule = moment_by_moment_schedule(device, circuit)

    zero_ns = cirq.Timestamp()
    assert set(schedule.scheduled_operations) == {
        ScheduledOperation.op_at_on(ops.H(q), zero_ns, device)
        for q in qubits
    }
Beispiel #26
0
def test_exclude():
    q = cirq.QubitId()
    zero = cirq.Timestamp(picos=0)
    ps = cirq.Duration(picos=1)
    op = cirq.ScheduledOperation(zero, ps, cirq.H(q))
    schedule = cirq.Schedule(device=UnconstrainedDevice,
                             scheduled_operations=[op])

    assert not schedule.exclude(
        cirq.ScheduledOperation(zero + ps, ps, cirq.H(q)))
    assert not schedule.exclude(cirq.ScheduledOperation(zero, ps, cirq.X(q)))
    assert schedule.query(time=zero, duration=ps * 10) == [op]
    assert schedule.exclude(cirq.ScheduledOperation(zero, ps, cirq.H(q)))
    assert schedule.query(time=zero, duration=ps * 10) == []
    assert not schedule.exclude(cirq.ScheduledOperation(zero, ps, cirq.H(q)))
Beispiel #27
0
def test_exclude():
    q = cirq.NamedQubit('q')
    zero = cirq.Timestamp(picos=0)
    ps = cirq.Duration(picos=1)
    op = cirq.ScheduledOperation(zero, ps, cirq.H(q))
    schedule = cirq.Schedule(device=UNCONSTRAINED_DEVICE,
                             scheduled_operations=[op])

    assert not schedule.exclude(
        cirq.ScheduledOperation(zero + ps, ps, cirq.H(q)))
    assert not schedule.exclude(cirq.ScheduledOperation(zero, ps, cirq.X(q)))
    assert schedule.query(time=zero, duration=ps * 10) == [op]
    assert schedule.exclude(cirq.ScheduledOperation(zero, ps, cirq.H(q)))
    assert schedule.query(time=zero, duration=ps * 10) == []
    assert not schedule.exclude(cirq.ScheduledOperation(zero, ps, cirq.H(q)))
Beispiel #28
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)
Beispiel #29
0
def test_query_overlapping_operations_exclusive():
    q = cirq.NamedQubit('q')
    zero = cirq.Timestamp(picos=0)
    ps = cirq.Duration(picos=1)
    op1 = cirq.ScheduledOperation(zero, 2 * ps, cirq.H(q))
    op2 = cirq.ScheduledOperation(zero + ps, 2 * ps, cirq.H(q))
    schedule = cirq.Schedule(device=UNCONSTRAINED_DEVICE,
                             scheduled_operations=[op2, op1])

    assert schedule.query(time=zero - 0.5 * ps, duration=ps) == [op1]
    assert schedule.query(time=zero - 0.5 * ps, duration=2 * ps) == [op1, op2]
    assert schedule.query(time=zero, duration=ps) == [op1]
    assert schedule.query(time=zero + 0.5 * ps, duration=ps) == [op1, op2]
    assert schedule.query(time=zero + ps, duration=ps) == [op1, op2]
    assert schedule.query(time=zero + 1.5 * ps, duration=ps) == [op1, op2]
    assert schedule.query(time=zero + 2.0 * ps, duration=ps) == [op2]
    assert schedule.query(time=zero + 2.5 * ps, duration=ps) == [op2]
    assert schedule.query(time=zero + 3.0 * ps, duration=ps) == []
    assert schedule.query(time=zero + 3.5 * ps, duration=ps) == []
Beispiel #30
0
def test_unitary():
    q = cirq.NamedQubit('q')
    zero = cirq.Timestamp(picos=0)
    ps = cirq.Duration(picos=1)
    op = cirq.ScheduledOperation(zero, ps, cirq.H(q))
    schedule = cirq.Schedule(device=UNCONSTRAINED_DEVICE,
                             scheduled_operations=[op])

    cirq.testing.assert_has_consistent_apply_unitary(schedule, qubit_count=1)
    np.testing.assert_allclose(cirq.unitary(schedule), cirq.unitary(cirq.H))
    assert cirq.has_unitary(schedule)

    schedule2 = cirq.Schedule(device=UNCONSTRAINED_DEVICE,
                              scheduled_operations=[
                                  cirq.ScheduledOperation(
                                      zero, ps,
                                      cirq.depolarize(0.5).on(q))
                              ])
    assert not cirq.has_unitary(schedule2)