示例#1
0
def test_distance_3D():
    with pytest.raises(TypeError):
        _ = ThreeDQubit(0, 0, 0).distance(cirq.GridQubit(0, 0))

    for x in np.arange(-2, 3):
        for y in np.arange(-2, 3):
            for z in np.arange(-2, 3):
                assert ThreeDQubit(0, 0, 0).distance(ThreeDQubit(
                    x, y, z)) == np.sqrt(x**2 + y**2 + z**2)
    def test_device_creation(self, control_radius):
        """Tests that the cirq.pasqal device is properly created"""

        dev = PasqalDevice(wires=2, shots=123, control_radius=control_radius)

        assert dev.num_wires == 2
        assert len(dev.qubits) == 2
        assert dev.shots == 123
        assert dev.short_name == "cirq.pasqal"
        assert dev.control_radius == control_radius
        assert dev.qubits == [ThreeDQubit(0, 0, 0), ThreeDQubit(control_radius / 2, 0, 0)]
        assert isinstance(dev, SimulatorDevice)
        assert isinstance(dev.cirq_device, PasqalVirtualDevice)
    def test_device_loading(self):
        """Tests that the cirq.pasqal device is properly loaded"""

        control_radius = 1.0
        dev = qml.device("cirq.pasqal", wires=2, control_radius=1.0)

        assert dev.num_wires == 2
        assert len(dev.qubits) == 2
        assert dev.shots is None
        assert dev.short_name == "cirq.pasqal"
        assert dev.control_radius == 1.0
        assert dev.qubits == sorted([ThreeDQubit(0, 0, 0), ThreeDQubit(control_radius / 2, 0, 0)])
        assert isinstance(dev, SimulatorDevice)
示例#4
0
def test_to_json_():
    q = ThreeDQubit(1.3, 1, 1)
    d = q._json_dict_()
    assert d == {
        'cirq_type': 'ThreeDQubit',
        'x': 1.3,
        'y': 1,
        'z': 1,
    }
    q = TwoDQubit(1.3, 1)
    d = q._json_dict_()
    assert d == {
        'cirq_type': 'TwoDQubit',
        'x': 1.3,
        'y': 1,
    }
示例#5
0
    def test_device_creation_threeDqubits_unordered(self, coord_idxs):
        """Tests that a PasqalDevice can be properly instantiated with ThreeDQubits that are not ordered following Cirq's convention."""

        qubits = [ThreeDQubit(*idxs) for idxs in coord_idxs]
        dev = PasqalDevice(wires=4, qubits=qubits, control_radius=3)

        assert dev.qubits == sorted(qubits)
示例#6
0
def test_qid_pairs():
    dev = PasqalVirtualDevice(
        1,
        qubits=[
            ThreeDQubit(0, 0, 0),
            ThreeDQubit(1, 0, 0),
            ThreeDQubit(0, 1, 0),
            ThreeDQubit(1, 1, 0),
            ThreeDQubit(1, 1, 1),
        ],
    )
    assert len(dev.qid_pairs()) == 5
    dev1 = PasqalVirtualDevice(
        5,
        qubits=[
            TwoDQubit(0, 0),
            TwoDQubit(3, 2),
            TwoDQubit(3, 4),
            TwoDQubit(3, 6),
        ],
    )
    assert len(dev1.qid_pairs()) == 5
示例#7
0
# Now, neutral-atom devices come with some physical restrictions.
# Specifically, in a particular three-dimensional configuration, qubits that
# are too distant from one another can't easily interact. Instead, there is
# a notion of a *control radius;* any atoms which are within the system's
# control radius can interact with one another. Qubits separated by a
# distance larger than the control radius cannot interact.
#
# In order to allow our Eiffel tower qubits to interact with
# one another more easily, we will artificially scale some dimensions
# when placing the atoms.

from cirq.pasqal import ThreeDQubit
xy_scale = 1.5
z_scale = 0.75
qubits = [
    ThreeDQubit(xy_scale * x, xy_scale * y, z_scale * z)
    for x, y, z in qubit_coords
]

##############################################################################
# To simulate a neutral-atom quantum computation, we can use the
# ``"cirq.pasqal"`` device, available via the
# `PennyLane-Cirq plugin <https://pennylane-cirq.readthedocs.io>`_.
# We will need to provide this device with the ``ThreeDQubit`` object that we created
# above. We also need to instantiate the device with a fixed control radius.

import pennylane as qml
num_wires = len(qubits)
control_radius = 32.4
dev = qml.device("cirq.pasqal",
                 control_radius=control_radius,
示例#8
0
def test_parrallelep_3D():
    assert ThreeDQubit.parallelep(1, 2, 2, x0=5, y0=6, z0=7) == [
        ThreeDQubit(5, 6, 7),
        ThreeDQubit(5, 7, 7),
        ThreeDQubit(5, 6, 8),
        ThreeDQubit(5, 7, 8),
    ]

    assert ThreeDQubit.parallelep(2, 2, 2) == [
        ThreeDQubit(0, 0, 0),
        ThreeDQubit(1, 0, 0),
        ThreeDQubit(0, 1, 0),
        ThreeDQubit(1, 1, 0),
        ThreeDQubit(0, 0, 1),
        ThreeDQubit(1, 0, 1),
        ThreeDQubit(0, 1, 1),
        ThreeDQubit(1, 1, 1),
    ]
示例#9
0
def test_cube_3D():
    assert ThreeDQubit.cube(2, x0=1, y0=1, z0=1) == [
        ThreeDQubit(1, 1, 1),
        ThreeDQubit(2, 1, 1),
        ThreeDQubit(1, 2, 1),
        ThreeDQubit(2, 2, 1),
        ThreeDQubit(1, 1, 2),
        ThreeDQubit(2, 1, 2),
        ThreeDQubit(1, 2, 2),
        ThreeDQubit(2, 2, 2),
    ]
    assert ThreeDQubit.cube(2) == [
        ThreeDQubit(0, 0, 0),
        ThreeDQubit(1, 0, 0),
        ThreeDQubit(0, 1, 0),
        ThreeDQubit(1, 1, 0),
        ThreeDQubit(0, 0, 1),
        ThreeDQubit(1, 0, 1),
        ThreeDQubit(0, 1, 1),
        ThreeDQubit(1, 1, 1),
    ]
示例#10
0
def test_grid_qubit_eq_3D():
    eq = cirq.testing.EqualsTester()
    eq.make_equality_group(lambda: ThreeDQubit(0, 0, 0))
    eq.make_equality_group(lambda: ThreeDQubit(1, 0, 0))
    eq.make_equality_group(lambda: ThreeDQubit(0, 1, 0))
    eq.make_equality_group(lambda: ThreeDQubit(50, 25, 25))
示例#11
0
def test_pasqal_qubit_ordering_3D():
    assert ThreeDQubit(0, 0, 1) >= ThreeDQubit(1, 0, 0)
    assert ThreeDQubit(0, 0, 1) >= ThreeDQubit(0, 1, 0)
    assert ThreeDQubit(0, 1, 0) >= ThreeDQubit(1, 0, 0)
    for i in range(8):
        v = [int(x) for x in bin(i)[2:].zfill(3)]

        assert ThreeDQubit(0, 0, 0) <= ThreeDQubit(v[0], v[1], v[2])
        assert ThreeDQubit(1, 1, 1) >= ThreeDQubit(v[0], v[1], v[2])

        if i >= 1:
            assert ThreeDQubit(0, 0, 0) < ThreeDQubit(v[0], v[1], v[2])
        if i < 7:
            assert ThreeDQubit(1, 1, 1) > ThreeDQubit(v[0], v[1], v[2])
示例#12
0
def test_comparison_key_3D():
    assert ThreeDQubit(3, 4, 5)._comparison_key() == (5, 4, 3)
    coords = (np.cos(np.pi / 2), np.sin(np.pi / 2), 0)
    assert ThreeDQubit(*coords) == ThreeDQubit(0, 1, 0)
示例#13
0
def test_pasqal_qubit_init_3D():
    q = ThreeDQubit(3, 4, 5)
    assert q.x == 3
    assert q.y == 4
    assert q.z == 5
示例#14
0
def test_str_():
    assert str(ThreeDQubit(4, -25, 109)) == '(4, -25, 109)'
    assert str(TwoDQubit(4, -25)) == '(4, -25)'
示例#15
0
def test_repr_():
    assert repr(ThreeDQubit(4, -25, 109)) == 'pasqal.ThreeDQubit(4, -25, 109)'
    assert repr(TwoDQubit(4, -25)) == 'pasqal.TwoDQubit(4, -25)'