Skip to content

Commit

Permalink
Tests for 'devices'
Browse files Browse the repository at this point in the history
  • Loading branch information
HGSilveri committed Nov 5, 2020
1 parent 3ce5217 commit 90ec82a
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ __pycache__/
env-pasqal-qutip/
.DS_Store
/*.ipynb
*.coverage
4 changes: 2 additions & 2 deletions pulser/devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def __init__(self, qubits):
raise TypeError("The qubits must be a in a dict or Register class "
"instance.")

self.check_array(list(register.qubits.values()))
self._check_array(list(register.qubits.values()))
self._register = register

@property
Expand Down Expand Up @@ -75,7 +75,7 @@ def qubits(self):
"""The dictionary of qubit names and their positions."""
return self._register.qubits

def check_array(self, atoms):
def _check_array(self, atoms):
if len(atoms) > self.max_atom_num:
raise ValueError("Too many atoms in the array, accepts at most"
"{} atoms.".format(self.max_atom_num))
Expand Down
1 change: 0 additions & 1 deletion tests/test_channels.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import pytest
import numpy as np

from pulser.channels import Raman, Rydberg

Expand Down
35 changes: 35 additions & 0 deletions tests/test_devices.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import pytest

from pulser import Register
from pulser.devices import Chadoq2


def test_init():
with pytest.raises(TypeError):
Chadoq2([1, 2, 4])
Chadoq2('q1')
Chadoq2(('a', 'b', 'c'))

qubits = dict(enumerate([(0, 0), (10, 0)]))
dev1 = Chadoq2(qubits)
reg = Register(qubits)
dev2 = Chadoq2(reg)
assert dev1.qubits == dev2.qubits


def test_check_array():
with pytest.raises(ValueError, match='Too many atoms'):
Chadoq2(Register.square(50))

coords = [(100, 0), (-100, 0)]
with pytest.raises(ValueError, match='at most 50um away from the center'):
Chadoq2(Register.from_coordinates(coords))

with pytest.raises(ValueError, match='must be 2D vectors'):
coords += [(-10, 4, 0)]
Chadoq2(dict(enumerate(coords)))

with pytest.raises(ValueError, match="don't respect the minimal distance"):
Chadoq2(Register.triangular_lattice(3, 4, spacing=3.9))

Chadoq2(Register.rectangle(5, 10, spacing=5))

0 comments on commit 90ec82a

Please sign in to comment.