Example #1
0
def test_to_2D():
    reg = Register3D.cuboid(2, 2, 2)
    with pytest.raises(ValueError, match="Atoms are not coplanar"):
        reg.to_2D()
    reg.to_2D(tol_width=6)

    reg = Register3D.cuboid(2, 2, 1)
    reg.to_2D()
Example #2
0
def test_cubic():
    # Check side
    with pytest.raises(ValueError, match="The number of atoms per side"):
        Register3D.cubic(0)

    # Check spacing
    with pytest.raises(ValueError, match="Spacing"):
        Register3D.cubic(2, 0.0)
Example #3
0
def test_creation():
    empty_dict = {}
    with pytest.raises(ValueError, match="Cannot create a Register with"):
        Register(empty_dict)

    coords = [(0, 0), (1, 0)]
    ids = ("q0", "q1")
    qubits = dict(zip(ids, coords))
    with pytest.raises(TypeError):
        Register(coords)
        Register(ids)

    with pytest.raises(ValueError, match="vectors of size 2"):
        Register.from_coordinates([(0, 1, 0, 1)])

    with pytest.raises(NotImplementedError,
                       match="a prefix and a set of labels"):
        Register.from_coordinates(coords, prefix="a", labels=["a", "b"])

    with pytest.raises(ValueError, match="vectors of size 3"):
        Register3D.from_coordinates([((1, 0), ), ((-1, 0), )])

    reg1 = Register(qubits)
    reg2 = Register.from_coordinates(coords, center=False, prefix="q")
    assert np.all(np.array(reg1._coords) == np.array(reg2._coords))
    assert reg1._ids == reg2._ids

    reg2b = Register.from_coordinates(coords, center=False, labels=["a", "b"])
    assert reg2b._ids == ("a", "b")

    with pytest.raises(ValueError, match="Label length"):
        Register.from_coordinates(coords, center=False, labels=["a", "b", "c"])

    reg3 = Register.from_coordinates(np.array(coords), prefix="foo")
    coords_ = np.array([(-0.5, 0), (0.5, 0)])
    assert reg3._ids == ("foo0", "foo1")
    assert np.all(reg3._coords == coords_)
    assert not np.all(coords_ == coords)

    reg4 = Register.rectangle(1, 2, spacing=1)
    assert np.all(reg4._coords == coords_)

    reg5 = Register.square(2, spacing=2)
    coords_ = np.array([(-1, -1), (1, -1), (-1, 1), (1, 1)], dtype=float)
    assert np.all(np.array(reg5._coords) == coords_)

    reg6 = Register.triangular_lattice(2, 2, spacing=4)
    coords_ = np.array([
        (-3, -np.sqrt(3)),
        (1, -np.sqrt(3)),
        (-1, np.sqrt(3)),
        (3, np.sqrt(3)),
    ])
    assert np.all(np.array(reg6._coords) == coords_)

    with pytest.raises(ValueError,
                       match="must only be 'layout' and 'trap_ids'"):
        Register(qubits, spacing=10, layout="square", trap_ids=(0, 1, 3))
Example #4
0
def test_equality_function():
    reg1 = Register({"c": (1, 2), "d": (8, 4)})
    assert_eq(reg1, reg1)
    assert_eq(reg1, Register({"d": (8, 4), "c": (1, 2)}))
    assert_ineq(reg1, Register({"c": (8, 4), "d": (1, 2)}))
    assert_ineq(reg1, Register({"c": (1, 2), "d": (8, 4), "e": (8, 4)}))
    assert_ineq(reg1, 10)

    reg2 = Register3D({"a": (1, 2, 3), "b": (8, 5, 6)})
    assert_eq(reg2, reg2)
    assert_eq(reg2, Register3D({"a": (1, 2, 3), "b": (8, 5, 6)}))
    assert_ineq(reg2, Register3D({"b": (1, 2, 3), "a": (8, 5, 6)}))
    assert_ineq(reg2,
                Register3D({
                    "a": (1, 2, 3),
                    "b": (8, 5, 6),
                    "e": (8, 5, 6)
                }))
    assert_ineq(reg2, 10)

    assert_ineq(reg1, reg2)
Example #5
0
def test_drawing3D():
    with pytest.raises(ValueError, match="Blockade radius"):
        reg = Register3D.from_coordinates([(1, 0, 0), (0, 0, 1)])
        reg.draw(blockade_radius=0.0)

    reg = Register3D.cubic(3, 8)
    with patch("matplotlib.pyplot.show"):
        with patch("matplotlib.pyplot.savefig"):
            reg.draw(fig_name="my_register.pdf")

    reg = Register3D.cuboid(1, 8, 2)
    with patch("matplotlib.pyplot.show"):
        reg.draw(blockade_radius=5, draw_half_radius=True, draw_graph=True)

    with pytest.raises(ValueError, match="'blockade_radius' to draw."):
        reg.draw(draw_half_radius=True)

    reg = Register3D.cuboid(2, 2, 2)
    with patch("matplotlib.pyplot.show"):
        reg.draw(
            blockade_radius=5,
            draw_half_radius=True,
            draw_graph=True,
            projection=False,
            with_labels=True,
        )
    with patch("matplotlib.pyplot.show"):
        reg.draw(
            blockade_radius=5,
            draw_half_radius=True,
            draw_graph=False,
            projection=True,
            with_labels=True,
        )

    reg = Register3D.cubic(1)
    with pytest.raises(NotImplementedError, match="Needs more than one atom"):
        reg.draw(blockade_radius=5, draw_half_radius=True)
Example #6
0
def test_orthorombic():
    # Check rows
    with pytest.raises(ValueError, match="The number of rows"):
        Register3D.cuboid(0, 2, 2)

    # Check columns
    with pytest.raises(ValueError, match="The number of columns"):
        Register3D.cuboid(2, 0, 2)

    # Check layers
    with pytest.raises(ValueError, match="The number of layers"):
        Register3D.cuboid(2, 2, 0)

    # Check spacing
    with pytest.raises(ValueError, match="Spacing"):
        Register3D.cuboid(2, 2, 2, 0.0)
Example #7
0
def test_draw_register():
    # Draw 2d register from sequence
    reg = Register({"q0": (0, 0), "q1": (10, 10), "q2": (-10, -10)})
    targets = ["q0", "q2"]
    pulse = Pulse.ConstantPulse(100, 10, 0, 0)
    seq = Sequence(reg, MockDevice)
    seq.declare_channel("ch_xy", "mw_global")
    seq.add(pulse, "ch_xy")
    seq.config_slm_mask(targets)
    with patch("matplotlib.pyplot.show"):
        seq.draw(draw_register=True)

    # Draw 3d register from sequence
    reg3d = Register3D.cubic(3, 8)
    seq3d = Sequence(reg3d, MockDevice)
    seq3d.declare_channel("ch_xy", "mw_global")
    seq3d.add(pulse, "ch_xy")
    seq3d.config_slm_mask([6, 15])
    with patch("matplotlib.pyplot.show"):
        seq3d.draw(draw_register=True)
Example #8
0
def test_register_3d():
    reg = Register3D({"a": (1, 2, 3), "b": (8, 5, 6)})
    seq = Sequence(reg, device=MockDevice)
    assert reg == encode_decode(seq).register