Esempio n. 1
0
def bit_flip_circuit(flip0, flip1):
    q1, q2 = XmonQubit(0, 0), XmonQubit(0, 1)
    g1, g2 = ExpWGate(half_turns=flip0)(q1), ExpWGate(half_turns=flip1)(q2)
    m1, m2 = XmonMeasurementGate('q1')(q1), XmonMeasurementGate('q2')(q2)
    circuit = Circuit()
    circuit.append([g1, g2, m1, m2])
    return circuit
Esempio n. 2
0
def test_measurement_keys_repeat(scheduler):
    circuit = Circuit()
    meas = XmonMeasurementGate('a')
    circuit.append([meas.on(Q1), X.on(Q1), X.on(Q2), meas.on(Q2)])
    simulator = xmon_simulator.XmonSimulator()
    with pytest.raises(ValueError, message='Repeated Measurement key a'):
        run(simulator, circuit, scheduler)
Esempio n. 3
0
def test_measurement_qubit_order(scheduler):
    circuit = Circuit()
    meas = XmonMeasurementGate(key='')
    circuit.append(X(Q2))
    circuit.append(X(Q1))
    circuit.append([meas.on(Q1, Q3, Q2)])
    simulator = xmon_simulator.XmonSimulator()
    result = run(simulator, circuit, scheduler)
    np.testing.assert_equal(result.measurements[''], [[True, False, True]])
Esempio n. 4
0
def test_inverted_measurement_multiple_qubits(scheduler):
    circuit = Circuit.from_ops(
        XmonMeasurementGate('a', invert_mask=(False, True))(Q1, Q2),
        XmonMeasurementGate('b', invert_mask=(True, False))(Q1, Q2),
        XmonMeasurementGate('c', invert_mask=(True, False))(Q2, Q1))
    simulator = xmon_simulator.XmonSimulator()
    result = run(simulator, circuit, scheduler)
    np.testing.assert_equal(result.measurements['a'], [[False, True]])
    np.testing.assert_equal(result.measurements['b'], [[True, False]])
    np.testing.assert_equal(result.measurements['c'], [[True, False]])
Esempio n. 5
0
def test_run(scheduler):
    np.random.seed(0)
    circuit = basic_circuit()
    circuit.append(
        [XmonMeasurementGate(key='a')(Q1),
         XmonMeasurementGate(key='b')(Q2)])

    simulator = xmon_simulator.XmonSimulator()
    result = run(simulator, circuit, scheduler)
    assert result.measurements == {'a': [False], 'b': [False]}
Esempio n. 6
0
def test_validate_circuit_repeat_measurement_keys():
    d = square_device(3, 3)

    circuit = Circuit()
    circuit.append([
        XmonMeasurementGate('a').on(XmonQubit(0, 0)),
        XmonMeasurementGate('a').on(XmonQubit(0, 1))
    ])

    with pytest.raises(ValueError, message='Measurement key a repeated'):
        d.validate_circuit(circuit)
Esempio n. 7
0
def test_run_no_sharing_few_qubits(scheduler):
    np.random.seed(0)
    circuit = basic_circuit()
    circuit.append(
        [XmonMeasurementGate(key='a')(Q1),
         XmonMeasurementGate(key='b')(Q2)])

    simulator = xmon_simulator.XmonSimulator(
        xmon_simulator.XmonOptions(min_qubits_before_shard=0))
    result = run(simulator, circuit, scheduler)
    np.testing.assert_equal(result.measurements['a'], [[False]])
    np.testing.assert_equal(result.measurements['b'], [[False]])
Esempio n. 8
0
def test_validate_schedule_repeat_measurement_keys():
    d = square_device(3, 3)

    s = Schedule(d, [
        ScheduledOperation.op_at_on(
            XmonMeasurementGate('a').on(XmonQubit(0, 0)), Timestamp(), d),
        ScheduledOperation.op_at_on(
            XmonMeasurementGate('a').on(XmonQubit(0, 1)), Timestamp(), d),
    ])

    with pytest.raises(ValueError, message='Measurement key a repeated'):
        d.validate_schedule(s)
Esempio n. 9
0
def test_inverted_measurement(scheduler):
    circuit = Circuit.from_ops(
        XmonMeasurementGate('a', invert_mask=(False, ))(Q1), X(Q1),
        XmonMeasurementGate('b', invert_mask=(False, ))(Q1),
        XmonMeasurementGate('c', invert_mask=(True, ))(Q1), X(Q1),
        XmonMeasurementGate('d', invert_mask=(True, ))(Q1))
    simulator = xmon_simulator.XmonSimulator()
    result = run(simulator, circuit, scheduler)
    assert {
        'a': [[False]],
        'b': [[True]],
        'c': [[False]],
        'd': [[True]]
    } == result.measurements
Esempio n. 10
0
def test_simulate_moment_steps():
    np.random.seed(0)
    circuit = basic_circuit()
    circuit.append(
        [XmonMeasurementGate(key='a')(Q1),
         XmonMeasurementGate(key='b')(Q2)])

    simulator = xmon_simulator.XmonSimulator()
    results = []
    for step in simulator.simulate_moment_steps(circuit):
        results.append(step)
    expected = [{}, {}, {}, {}, {'a': [False], 'b': [False]}]
    assert len(results) == len(expected)
    assert all(a.measurements == b for a, b in zip(results, expected))
Esempio n. 11
0
def test_composite_gates(scheduler):
    circuit = Circuit()
    circuit.append([X(Q1), CNOT(Q1, Q2)])
    m = XmonMeasurementGate('a')
    circuit.append([m(Q1, Q2)])

    simulator = xmon_simulator.XmonSimulator()
    result = run(simulator, circuit, scheduler)
    np.testing.assert_equal(result.measurements['a'], [[True, True]])
Esempio n. 12
0
def test_handedness_of_xmon_gates():
    circuit = Circuit.from_ops(
        ExpWGate(half_turns=-0.5).on(Q1),
        ExpZGate(half_turns=-0.5).on(Q1),
        ExpWGate(axis_half_turns=0.5, half_turns=0.5).on(Q1),
        XmonMeasurementGate(key='').on(Q1),
    )
    result = xmon_simulator.XmonSimulator().run(circuit)
    np.testing.assert_equal(result.measurements[''], [[True]])
Esempio n. 13
0
def test_handedness_of_basic_gates():
    circuit = Circuit.from_ops(
        X(Q1)**-0.5,
        Z(Q1)**-0.5,
        Y(Q1)**0.5,
        XmonMeasurementGate(key='').on(Q1),
    )
    result = xmon_simulator.XmonSimulator().run(circuit)
    np.testing.assert_equal(result.measurements[''], [[True]])
Esempio n. 14
0
def large_circuit():
    np.random.seed(0)
    qubits = [XmonQubit(i, 0) for i in range(10)]
    sqrt_x = ExpWGate(half_turns=0.5, axis_half_turns=0.0)
    cz = Exp11Gate()
    circuit = Circuit()
    for _ in range(11):
        circuit.append(
            [sqrt_x(qubit) for qubit in qubits if np.random.random() < 0.5])
        circuit.append([cz(qubits[i], qubits[i + 1]) for i in range(9)])
    circuit.append([XmonMeasurementGate(key='meas')(*qubits)])
    return circuit
Esempio n. 15
0
def test_run_circuit_sweep():
    circuit = Circuit.from_ops(
        ExpWGate(half_turns=Symbol('a')).on(Q1),
        XmonMeasurementGate('m').on(Q1),
    )

    sweep = Linspace('a', 0, 10, 11)
    simulator = xmon_simulator.XmonSimulator()

    for i, result in enumerate(
            simulator.run_sweep(circuit, sweep, repetitions=1)):
        assert result.params['a'] == i
        assert result.measurements['m'] == [i % 2 != 0]
Esempio n. 16
0
def test_measurement_multiple_measurements_qubit_order(scheduler):
    circuit = Circuit()
    measure_a = XmonMeasurementGate('a')
    measure_b = XmonMeasurementGate('b')
    circuit.append(X(Q1))
    circuit.append([measure_a.on(Q1, Q2)])
    circuit.append([measure_b.on(Q2, Q1)])
    simulator = xmon_simulator.XmonSimulator()
    result = run(simulator, circuit, scheduler)
    np.testing.assert_equal(result.measurements['a'], [[True, False]])
    np.testing.assert_equal(result.measurements['b'], [[False, True]])
 def circuit_init(meas=True):
     if meas:
         yield XmonMeasurementGate(key='q0')(q[0])
         yield XmonMeasurementGate(key='q1')(q[1])
         yield XmonMeasurementGate(key='q2')(q[2])
         yield XmonMeasurementGate(key='q3')(q[3])
def circuit_init(meas=True):
    if meas:
        yield XmonMeasurementGate(key='q0')(q[0])
Esempio n. 19
0
def circuit_init(meas=True):
    if meas:
        yield XmonMeasurementGate(key='q')(target_q)
Esempio n. 20
0
def circuit_init_again(meas=True):
    if meas:
        yield XmonMeasurementGate(key='qubit')(final)
Esempio n. 21
0
def deutsch_circuit_init(meas=True):
    yield cirq.H.on(q1)
    if meas:
        yield XmonMeasurementGate(key='q1')(q1)
Esempio n. 22
0
def test_validate_measurement_non_adjacent_qubits_ok():
    d = square_device(3, 3)

    d.validate_operation(
        ops.Operation(XmonMeasurementGate(key=''),
                      (XmonQubit(0, 0), XmonQubit(2, 0))))