Exemplo n.º 1
0
def test_consistent_protocols():
    gate = coupler_pulse.CouplerPulse(hold_time=cirq.Duration(nanos=10),
                                      coupling_mhz=25.0,
                                      rise_time=cirq.Duration(nanos=18))
    cirq.testing.assert_implements_consistent_protocols(
        gate,
        setup_code=
        'import cirq\nimport numpy as np\nimport sympy\nimport cirq_google',
        qubit_count=2,
    )
    assert gate.num_qubits() == 2
Exemplo n.º 2
0
def test_coupler_pulse_str_repr():
    gate = coupler_pulse.CouplerPulse(hold_time=cirq.Duration(nanos=10),
                                      coupling_mhz=25.0,
                                      rise_time=cirq.Duration(nanos=18))
    assert (str(gate) == 'CouplerPulse(hold_time=10 ns, coupling_mhz=25.0, ' +
            'rise_time=18 ns, padding_time=2500.0 ps)')
    assert (repr(
        gate) == 'cirq_google.experimental.ops.coupler_pulse.CouplerPulse(' +
            'hold_time=cirq.Duration(nanos=10), ' + 'coupling_mhz=25.0, ' +
            'rise_time=cirq.Duration(nanos=18), ' +
            'padding_time=cirq.Duration(picos=2500.0))')
Exemplo n.º 3
0
def test_coupler_pulse_validation():
    with pytest.raises(ValueError, match='Full rise time'):
        _ = coupler_pulse.CouplerPulse(hold_time=cirq.Duration(nanos=20),
                                       coupling_mhz=25.0,
                                       rise_time=cirq.Duration(nanos=10))
    with pytest.raises(ValueError, match='hold_time must be between'):
        _ = coupler_pulse.CouplerPulse(
            hold_time=cirq.Duration(nanos=110),
            coupling_mhz=25.0,
            rise_time=cirq.Duration(nanos=120),
        )
    with pytest.raises(ValueError, match='hold_time must be between'):
        _ = coupler_pulse.CouplerPulse(hold_time=cirq.Duration(nanos=-10),
                                       coupling_mhz=25.0,
                                       rise_time=cirq.Duration(nanos=20))
    with pytest.raises(ValueError, match='padding_time must be between'):
        _ = coupler_pulse.CouplerPulse(
            hold_time=cirq.Duration(nanos=10),
            coupling_mhz=25.0,
            rise_time=cirq.Duration(nanos=20),
            padding_time=cirq.Duration(nanos=200),
        )
    with pytest.raises(ValueError, match='padding_time must be between'):
        _ = coupler_pulse.CouplerPulse(
            hold_time=cirq.Duration(nanos=10),
            coupling_mhz=25.0,
            rise_time=cirq.Duration(nanos=20),
            padding_time=cirq.Duration(nanos=-20),
        )
    with pytest.raises(ValueError, match='rise_time must be between'):
        _ = coupler_pulse.CouplerPulse(
            hold_time=cirq.Duration(nanos=10),
            coupling_mhz=25.0,
            rise_time=cirq.Duration(nanos=102),
        )
Exemplo n.º 4
0
def test_coupler_pulse_validation():
    with pytest.raises(ValueError, match='Total time of coupler pulse'):
        _ = coupler_pulse.CouplerPulse(
            hold_time=cirq.Duration(nanos=210), coupling_mhz=25.0, rise_time=cirq.Duration(nanos=10)
        )
    with pytest.raises(ValueError, match='hold_time must be greater'):
        _ = coupler_pulse.CouplerPulse(
            hold_time=cirq.Duration(nanos=-10), coupling_mhz=25.0, rise_time=cirq.Duration(nanos=20)
        )
    with pytest.raises(ValueError, match='Total time of coupler pulse'):
        _ = coupler_pulse.CouplerPulse(
            hold_time=cirq.Duration(nanos=10),
            coupling_mhz=25.0,
            rise_time=cirq.Duration(nanos=20),
            padding_time=cirq.Duration(nanos=200),
        )
    with pytest.raises(ValueError, match='padding_time must be greater'):
        _ = coupler_pulse.CouplerPulse(
            hold_time=cirq.Duration(nanos=10),
            coupling_mhz=25.0,
            rise_time=cirq.Duration(nanos=20),
            padding_time=cirq.Duration(nanos=-20),
        )
    with pytest.raises(ValueError, match='rise_time must be greater'):
        _ = coupler_pulse.CouplerPulse(
            hold_time=cirq.Duration(nanos=10), coupling_mhz=25.0, rise_time=cirq.Duration(nanos=-1)
        )
    with pytest.raises(ValueError, match='Total time of coupler pulse'):
        _ = coupler_pulse.CouplerPulse(
            hold_time=cirq.Duration(nanos=10), coupling_mhz=25.0, rise_time=cirq.Duration(nanos=302)
        )
Exemplo n.º 5
0
def test_coupler_pulse_circuit_diagram():
    a, b = cirq.LineQubit.range(2)
    gate = coupler_pulse.CouplerPulse(hold_time=cirq.Duration(nanos=10),
                                      coupling_mhz=25.0,
                                      rise_time=cirq.Duration(nanos=18))
    circuit = cirq.Circuit(gate(a, b))
    cirq.testing.assert_has_diagram(
        circuit,
        r"""
0: ───/‾‾(10 [email protected])‾‾\───
      │
1: ───/‾‾(10 [email protected])‾‾\───
""",
    )
Exemplo n.º 6
0
def test_sycamore_devices(device, qubit_size, layout_str):
    q0 = cirq.GridQubit(5, 3)
    q1 = cirq.GridQubit(5, 4)
    valid_sycamore_gates_and_ops = [
        cirq_google.SYC,
        cirq.SQRT_ISWAP,
        cirq.SQRT_ISWAP_INV,
        cirq.X,
        cirq.Y,
        cirq.Z,
        cirq.Z(q0).with_tags(cirq_google.PhysicalZTag()),
        coupler_pulse.CouplerPulse(hold_time=cirq.Duration(nanos=10),
                                   coupling_mhz=25.0),
        cirq.measure(q0),
        cirq.WaitGate(cirq.Duration(millis=5)),
        # TODO(#5050) Uncomment after GlobalPhaseGate support is added.
        # cirq.GlobalPhaseGate(-1.0),
    ]
    syc = cirq.FSimGate(theta=np.pi / 2, phi=np.pi / 6)(q0, q1)
    sqrt_iswap = cirq.FSimGate(theta=np.pi / 4, phi=0)(q0, q1)

    assert str(device) == layout_str
    assert len(device.metadata.qubit_pairs) == qubit_size
    assert all(gate_or_op in device.metadata.gateset
               for gate_or_op in valid_sycamore_gates_and_ops)
    assert len(device.metadata.gate_durations) == len(
        device.metadata.gateset.gates)
    assert any(
        isinstance(cgs, cirq_google.SycamoreTargetGateset)
        for cgs in device.metadata.compilation_target_gatesets)
    assert any(
        isinstance(cgs, cirq.SqrtIswapTargetGateset)
        for cgs in device.metadata.compilation_target_gatesets)

    device.validate_operation(syc)
    device.validate_operation(sqrt_iswap)

    assert next(
        (duration
         for gate_family, duration in device.metadata.gate_durations.items()
         if syc in gate_family),
        None,
    ) == cirq.Duration(nanos=12)
    assert next(
        (duration
         for gate_family, duration in device.metadata.gate_durations.items()
         if sqrt_iswap in gate_family),
        None,
    ) == cirq.Duration(nanos=32)
Exemplo n.º 7
0
def test_equality():
    eq = cirq.testing.EqualsTester()
    eq.add_equality_group(
        coupler_pulse.CouplerPulse(
            hold_time=cirq.Duration(nanos=10),
            coupling_mhz=25.0,
            rise_time=cirq.Duration(nanos=18),
            padding_time=cirq.Duration(nanos=4),
        ),
        coupler_pulse.CouplerPulse(
            hold_time=cirq.Duration(nanos=10),
            coupling_mhz=25.0,
            rise_time=cirq.Duration(nanos=18),
            padding_time=cirq.Duration(nanos=4),
        ),
    )
    eq.add_equality_group(
        coupler_pulse.CouplerPulse(
            hold_time=cirq.Duration(nanos=12),
            coupling_mhz=25.0,
            rise_time=cirq.Duration(nanos=18),
            padding_time=cirq.Duration(nanos=4),
        )
    )
    eq.add_equality_group(
        coupler_pulse.CouplerPulse(
            hold_time=cirq.Duration(nanos=10),
            coupling_mhz=26.0,
            rise_time=cirq.Duration(nanos=18),
            padding_time=cirq.Duration(nanos=4),
        )
    )
    eq.add_equality_group(
        coupler_pulse.CouplerPulse(
            hold_time=cirq.Duration(nanos=10),
            coupling_mhz=25.0,
            rise_time=cirq.Duration(nanos=28),
            padding_time=cirq.Duration(nanos=4),
        )
    )
    eq.add_equality_group(
        coupler_pulse.CouplerPulse(
            hold_time=cirq.Duration(nanos=10),
            coupling_mhz=25.0,
            rise_time=cirq.Duration(nanos=18),
            padding_time=cirq.Duration(nanos=40),
        )
    )