Beispiel #1
0
def test_to_json():
    dev = PasqalDevice(qubits=[cirq.NamedQubit('q4')])
    d = dev._json_dict_()
    assert d == {"qubits": [cirq.NamedQubit('q4')]}
    vdev = PasqalVirtualDevice(control_radius=2, qubits=[TwoDQubit(0, 0)])
    d = vdev._json_dict_()
    assert d == {"control_radius": 2, "qubits": [cirq_pasqal.TwoDQubit(0, 0)]}
Beispiel #2
0
def test_value_equal():
    dev = PasqalDevice(qubits=[cirq.NamedQubit('q1')])

    assert PasqalDevice(qubits=[cirq.NamedQubit('q1')]) == dev

    dev = PasqalVirtualDevice(control_radius=1.0, qubits=[TwoDQubit(0, 0)])

    assert PasqalVirtualDevice(control_radius=1.0, qubits=[TwoDQubit(0, 0)]) == dev
Beispiel #3
0
def test_init_errors():
    line = cirq.devices.LineQubit.range(3)
    with pytest.raises(TypeError, match="Unsupported qubit type"):
        PasqalDevice(qubits=line)
    with pytest.raises(ValueError, match="Too many qubits"):
        generic_device(101)

    with pytest.raises(TypeError, match="Unsupported qubit type"):
        PasqalVirtualDevice(control_radius=1.0, qubits=[cirq.NamedQubit('q0')])

    with pytest.raises(TypeError, match="All qubits must be of same type."):
        PasqalVirtualDevice(control_radius=1.0,
                            qubits=[TwoDQubit(0, 0),
                                    cirq.GridQubit(1, 0)])

    with pytest.raises(
            ValueError,
            match="Control_radius needs to be a non-negative float"):
        square_virtual_device(control_r=-1.0, num_qubits=2)

    with pytest.raises(
            ValueError,
            match="Control_radius cannot be larger than "
            "3 times the minimal distance between qubits.",
    ):
        square_virtual_device(control_r=11.0, num_qubits=2)
Beispiel #4
0
def test_pasqal_converter():
    q = cirq.NamedQubit.range(2, prefix='q')
    g = cirq.testing.TwoQubitGate()

    class FakeOperation(cirq.ops.GateOperation):
        def __init__(self, gate, qubits):
            self._gate = gate
            self._qubits = qubits

        @property
        def qubits(self):
            return self._qubits

        def with_qubits(self, *new_qubits):
            return FakeOperation(self._gate, new_qubits)

    op = FakeOperation(g, q).with_qubits(*q)
    d = PasqalDevice(q)

    with pytest.raises(TypeError, match="Don't know how to work with"):
        d.decompose_operation(op)
Beispiel #5
0
def test_get_op_string():
    p_qubits = cirq.NamedQubit.range(2, prefix='q')
    p_device = PasqalDevice(p_qubits)
    noise_model = PasqalNoiseModel(p_device)
    circuit = cirq.Circuit()
    circuit.append(cirq.ops.HPowGate(exponent=0.5).on(p_qubits[0]))

    with pytest.raises(ValueError, match='Got unknown operation:'):
        for moment in circuit._moments:
            _ = noise_model.noisy_moment(moment, p_qubits)

    with pytest.raises(ValueError, match='Got unknown operation:'):
        _ = noise_model.get_op_string(circuit)
def test_noise_model_init():
    noise_model = PasqalNoiseModel(PasqalDevice([]))
    assert noise_model.noise_op_dict == {
        str(cirq.ops.YPowGate()): cirq.ops.depolarize(1e-2),
        str(cirq.ops.ZPowGate()): cirq.ops.depolarize(1e-2),
        str(cirq.ops.XPowGate()): cirq.ops.depolarize(1e-2),
        str(cirq.ops.HPowGate(exponent=1)): cirq.ops.depolarize(1e-2),
        str(cirq.ops.PhasedXPowGate(phase_exponent=0)): cirq.ops.depolarize(1e-2),
        str(cirq.ops.CNotPowGate(exponent=1)): cirq.ops.depolarize(3e-2),
        str(cirq.ops.CZPowGate(exponent=1)): cirq.ops.depolarize(3e-2),
        str(cirq.ops.CCXPowGate(exponent=1)): cirq.ops.depolarize(8e-2),
        str(cirq.ops.CCZPowGate(exponent=1)): cirq.ops.depolarize(8e-2),
    }
    with pytest.raises(TypeError, match="noise model varies between Pasqal's devices."):
        PasqalNoiseModel(cirq.devices.UNCONSTRAINED_DEVICE)
Beispiel #7
0
def test_default_noise():
    p_qubits = cirq.NamedQubit.range(2, prefix='q')
    p_device = PasqalDevice(qubits=p_qubits)
    noise_model = PasqalNoiseModel(p_device)
    circuit = cirq.Circuit()
    Gate_l = cirq.ops.CZPowGate(exponent=2)
    circuit.append(Gate_l.on(p_qubits[0], p_qubits[1]))
    p_circuit = cirq.Circuit(circuit, device=p_device)
    n_mts = []
    for moment in p_circuit._moments:
        n_mts.append(noise_model.noisy_moment(moment, p_qubits))

    assert n_mts == [[
        cirq.ops.CZPowGate(exponent=2).on(NamedQubit('q0'), NamedQubit('q1')),
        cirq.depolarize(p=0.05).on(NamedQubit('q0')),
        cirq.depolarize(p=0.05).on(NamedQubit('q1')),
    ]]
def test_noisy_moments():
    p_qubits = cirq.NamedQubit.range(2, prefix='q')
    p_device = PasqalDevice(qubits=p_qubits)
    noise_model = PasqalNoiseModel(p_device)
    circuit = cirq.Circuit()
    circuit.append(cirq.ops.CZ(p_qubits[0], p_qubits[1]))
    circuit.append(cirq.ops.Z(p_qubits[1]))
    p_circuit = cirq.Circuit(circuit)

    n_mts = []
    for moment in p_circuit._moments:
        n_mts.append(noise_model.noisy_moment(moment, p_qubits))

    assert n_mts == [
        [
            cirq.ops.CZ.on(NamedQubit('q0'), NamedQubit('q1')),
            cirq.depolarize(p=0.03).on(NamedQubit('q0')),
            cirq.depolarize(p=0.03).on(NamedQubit('q1')),
        ],
        [cirq.ops.Z.on(NamedQubit('q1')), cirq.depolarize(p=0.01).on(NamedQubit('q1'))],
    ]
Beispiel #9
0
def generic_device(num_qubits) -> PasqalDevice:
    return PasqalDevice(qubits=cirq.NamedQubit.range(num_qubits, prefix='q'))