Skip to content

Commit

Permalink
Remove DMM from devices and finish UTs
Browse files Browse the repository at this point in the history
  • Loading branch information
HGSilveri committed Jul 20, 2023
1 parent dfa0d9a commit 742aa1b
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 26 deletions.
19 changes: 9 additions & 10 deletions pulser-core/pulser/devices/_devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import numpy as np

from pulser.channels import Raman, Rydberg
from pulser.channels.dmm import DMM
from pulser.channels.eom import RydbergBeam, RydbergEOM
from pulser.devices._device_datacls import Device
from pulser.register.special_layouts import TriangularLatticeLayout
Expand Down Expand Up @@ -57,6 +56,15 @@
max_duration=2**26,
),
),
# TODO: Add DMM once it is supported for serialization
# dmm_objects=(
# DMM(
# clock_period=4,
# min_duration=16,
# max_duration=2**26,
# bottom_detuning=-20,
# ),
# ),
)

IroiseMVP = Device(
Expand All @@ -83,15 +91,6 @@
),
),
),
dmm_objects=(
DMM(
clock_period=4,
min_duration=16,
max_duration=2**26,
mod_bandwidth=16,
bottom_detuning=-20,
),
),
)

AnalogDevice = Device(
Expand Down
1 change: 1 addition & 0 deletions pulser-core/pulser/devices/_mock_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,5 @@
Raman.Local(None, None, max_duration=None),
Microwave.Global(None, None, max_duration=None),
),
# TODO: Add DMM once it is supported for serialization
)
45 changes: 42 additions & 3 deletions tests/test_abstract_repr.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

from pulser import Pulse, Register, Register3D, Sequence, devices
from pulser.channels import Rydberg
from pulser.channels.dmm import DMM
from pulser.channels.eom import RydbergBeam, RydbergEOM
from pulser.devices import AnalogDevice, Chadoq2, Device, IroiseMVP, MockDevice
from pulser.json.abstract_repr.deserializer import (
Expand Down Expand Up @@ -66,7 +67,7 @@ class TestDevice:
@pytest.fixture(
params=[
Chadoq2,
replace(IroiseMVP, dmm_objects=()),
IroiseMVP,
MockDevice,
AnalogDevice,
]
Expand Down Expand Up @@ -242,6 +243,46 @@ def test_optional_channel_fields(self, ch_obj):
dev_str = device.to_abstract_repr()
assert device == deserialize_device(dev_str)

@pytest.fixture
def chadoq2_with_dmm(self):
# TODO: Delete once Chadoq2 actually has a DMM
dmm = DMM(
bottom_detuning=-1,
clock_period=1,
min_duration=1,
max_duration=1e6,
mod_bandwidth=20,
)
return replace(Chadoq2, dmm_objects=(dmm,))

@pytest.mark.xfail(
raises=jsonschema.exceptions.ValidationError, strict=True
)
def test_abstract_repr_dmm_serialize(self, chadoq2_with_dmm):
chadoq2_with_dmm.to_abstract_repr()

@pytest.mark.xfail(raises=DeserializeDeviceError, strict=True)
@pytest.mark.parametrize(
"skip_validation",
[
False, # Fails validation
True, # Fails because the DMM channel is deserialized as Rydberg
],
)
def test_abstract_repr_dmm_deserialize(
self, chadoq2_with_dmm, monkeypatch, skip_validation
):
ser_device = json.dumps(chadoq2_with_dmm, cls=AbstractReprEncoder)
if skip_validation:

def dummy(*args, **kwargs):
return True

# Patches jsonschema.validate with a function that returns True
monkeypatch.setattr(jsonschema, "validate", dummy)
device = deserialize_device(ser_device)
assert device == chadoq2_with_dmm


def validate_schema(instance):
with open(
Expand Down Expand Up @@ -698,7 +739,6 @@ def test_mappable_register(self, triangular_lattice):
]
assert abstract["variables"]["var"] == dict(type="int", value=[0])

@pytest.mark.xfail
def test_eom_mode(self, triangular_lattice):
reg = triangular_lattice.hexagonal_register(7)
seq = Sequence(reg, IroiseMVP)
Expand Down Expand Up @@ -1392,7 +1432,6 @@ def test_deserialize_parametrized_pulse(self, op, pulse_cls):
else:
assert pulse.kwargs["detuning"] == 1

@pytest.mark.xfail
def test_deserialize_eom_ops(self):
s = _get_serialized_seq(
operations=[
Expand Down
13 changes: 0 additions & 13 deletions tests/test_devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,16 +418,3 @@ def test_dmm_channels():
)
assert not dmm.is_virtual()
assert DMM().is_virtual()


@pytest.mark.xfail
def test_abstract_repr_dmm():
dmm = DMM(
bottom_detuning=-1,
clock_period=1,
min_duration=1,
max_duration=1e6,
mod_bandwidth=20,
)
device = replace(Chadoq2, dmm_objects=(dmm,))
device.to_abstract_repr()

0 comments on commit 742aa1b

Please sign in to comment.