Skip to content

Commit

Permalink
Updates to the Abstract Representation (#412)
Browse files Browse the repository at this point in the history
* Updates for the new JSON schema

* Further updates to the schema and serializer

* Fix internal bug in Sequence.build()

* Deserializer updates & UTs+ typing

* Bump version to 0.7.2

* Removing misplaced asserts

* Moving copy() and deepcopy() in Sequence.build()
  • Loading branch information
HGSilveri authored Oct 31, 2022
1 parent 84aa18b commit acfe979
Show file tree
Hide file tree
Showing 11 changed files with 502 additions and 125 deletions.
2 changes: 1 addition & 1 deletion VERSION.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.7.1
0.7.2
35 changes: 34 additions & 1 deletion pulser-core/pulser/json/abstract_repr/deserializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@
from pulser.json.exceptions import AbstractReprError
from pulser.parametrized import ParamObj, Variable
from pulser.pulse import Pulse
from pulser.register.mappable_reg import MappableRegister
from pulser.register.register import Register
from pulser.register.register_layout import RegisterLayout
from pulser.waveforms import (
BlackmanWaveform,
CompositeWaveform,
Expand All @@ -42,6 +44,7 @@
)

if TYPE_CHECKING: # pragma: no cover
from pulser.register.base_register import BaseRegister
from pulser.sequence import Sequence

with open(Path(__file__).parent / "schema.json") as f:
Expand Down Expand Up @@ -236,16 +239,46 @@ def deserialize_abstract_sequence(obj_str: str) -> Sequence:
device_name = obj["device"]
device = getattr(devices, device_name)

# Register Layout
layout = (
RegisterLayout(obj["layout"]["coordinates"])
if "layout" in obj
else None
)

# Register
reg: Union[BaseRegister, MappableRegister]
qubits = obj["register"]
reg = Register({q["name"]: (q["x"], q["y"]) for q in qubits})
if {"name", "x", "y"} == qubits[0].keys():
# Regular register
coords = [(q["x"], q["y"]) for q in qubits]
qubit_ids = [q["name"] for q in qubits]
if layout:
trap_ids = layout.get_traps_from_coordinates(*coords)
reg = layout.define_register(*trap_ids, qubit_ids=qubit_ids)
else:
reg = Register(dict(zip(qubit_ids, coords)))
else:
# Mappable register
assert (
layout is not None
), "Layout must be defined in a MappableRegister."
reg = MappableRegister(layout, *(d["qid"] for d in qubits))

seq = pulser.Sequence(reg, device)

# Channels
for name, channel_id in obj["channels"].items():
seq.declare_channel(name, channel_id)

# Magnetic field
if "magnetic_field" in obj:
seq.set_magnetic_field(*obj["magnetic_field"])

# SLM Mask
if "slm_mask_targets" in obj:
seq.config_slm_mask(obj["slm_mask_targets"])

# Variables
vars = {}
for name, desc in obj["variables"].items():
Expand Down
Loading

0 comments on commit acfe979

Please sign in to comment.