Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 23 additions & 16 deletions pylabrobot/centrifuge/centrifuge.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,18 +134,22 @@ def serialize(self) -> dict:

@classmethod
def deserialize(cls, data: dict, allow_marshal: bool = False):
backend = CentrifugeBackend.deserialize(data["backend"])
buckets = tuple(ResourceHolder.deserialize(bucket) for bucket in data["buckets"])
assert len(buckets) == 2
buckets_data = data.get("buckets")
buckets = (
tuple(ResourceHolder.deserialize(bucket) for bucket in buckets_data) if buckets_data else None
)
if buckets is not None:
assert len(buckets) == 2
rotation_data = data.get("rotation")
return cls(
backend=backend,
backend=CentrifugeBackend.deserialize(data["backend"]),
name=data["name"],
size_x=data["size_x"],
size_y=data["size_y"],
size_z=data["size_z"],
rotation=Rotation.deserialize(data["rotation"]),
category=data["category"],
model=data["model"],
rotation=deserialize(rotation_data) if rotation_data else None,
category=data.get("category"),
model=data.get("model"),
buckets=buckets,
)

Expand Down Expand Up @@ -228,15 +232,18 @@ def serialize(self) -> dict:

@classmethod
def deserialize(cls, data: dict, allow_marshal: bool = False):
resource_data = data.get("resource", {})
machine_data = data.get("machine", {})
rotation_data = resource_data.get("rotation")
return cls(
backend=LoaderBackend.deserialize(data["machine"]["backend"]),
backend=LoaderBackend.deserialize(machine_data["backend"]),
centrifuge=Centrifuge.deserialize(data["centrifuge"]),
name=data["resource"]["name"],
size_x=data["resource"]["size_x"],
size_y=data["resource"]["size_y"],
size_z=data["resource"]["size_z"],
child_location=deserialize(data["resource"]["child_location"]),
rotation=deserialize(data["resource"]["rotation"]),
category=data["resource"]["category"],
model=data["resource"]["model"],
name=resource_data["name"],
size_x=resource_data["size_x"],
size_y=resource_data["size_y"],
size_z=resource_data["size_z"],
child_location=deserialize(resource_data["child_location"]),
rotation=deserialize(rotation_data) if rotation_data else None,
category=resource_data.get("category"),
model=resource_data.get("model"),
)
15 changes: 0 additions & 15 deletions pylabrobot/io/serial.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,21 +329,6 @@ def serialize(self):
"dsrdtr": self.dsrdtr,
}

@classmethod
def deserialize(cls, data: dict) -> "Serial":
return cls(
human_readable_device_name=data["human_readable_device_name"],
port=data["port"],
baudrate=data["baudrate"],
bytesize=data["bytesize"],
parity=data["parity"],
stopbits=data["stopbits"],
write_timeout=data["write_timeout"],
timeout=data["timeout"],
rtscts=data["rtscts"],
dsrdtr=data["dsrdtr"],
)


class SerialValidator(Serial):
def __init__(
Expand Down
14 changes: 0 additions & 14 deletions pylabrobot/io/socket.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,20 +99,6 @@ def serialize(self):
"write_timeout": self._write_timeout,
}

@classmethod
def deserialize(cls, data: dict) -> "Socket":
kwargs = {}
if "read_timeout" in data:
kwargs["read_timeout"] = data["read_timeout"]
if "write_timeout" in data:
kwargs["write_timeout"] = data["write_timeout"]
return cls(
human_readable_device_name=data["human_readable_device_name"],
host=data["host"],
port=data["port"],
**kwargs,
)

async def write(self, data: bytes, timeout: Optional[float] = None) -> None:
"""Wrapper around StreamWriter.write with lock and io logging.
Does not retry on timeouts.
Expand Down
1 change: 1 addition & 0 deletions pylabrobot/machines/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def serialize(self) -> dict:

@classmethod
def deserialize(cls, data: dict):
data = data.copy()
class_name = data.pop("type")
subclass = find_subclass(class_name, cls=cls)
if subclass is None:
Expand Down
7 changes: 0 additions & 7 deletions pylabrobot/pumps/calibration.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,6 @@ def serialize(self) -> dict:
"calibration_mode": self.calibration_mode,
}

@classmethod
def deserialize(cls, data: dict) -> PumpCalibration:
return cls(
calibration=data["calibration"],
calibration_mode=data["calibration_mode"],
)

@classmethod
def load_from_json(
cls,
Expand Down
3 changes: 1 addition & 2 deletions pylabrobot/pumps/pump.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ def deserialize(cls, data: dict):
data_copy = data.copy()
calibration_data = data_copy.pop("calibration", None)
if calibration_data is not None:
calibration = PumpCalibration.deserialize(calibration_data)
data_copy["calibration"] = calibration
data_copy["calibration"] = PumpCalibration(**calibration_data)
return super().deserialize(data_copy)

async def run_revolutions(self, num_revolutions: float):
Expand Down
3 changes: 1 addition & 2 deletions pylabrobot/pumps/pumparray.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ def deserialize(cls, data: dict):
data_copy = data.copy()
calibration_data = data_copy.pop("calibration", None)
if calibration_data is not None:
calibration = PumpCalibration.deserialize(calibration_data)
data_copy["calibration"] = calibration
data_copy["calibration"] = PumpCalibration(**calibration_data)
return super().deserialize(data_copy)

async def run_revolutions(
Expand Down
8 changes: 0 additions & 8 deletions pylabrobot/resources/barcode.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,5 @@ def serialize(self) -> dict:
"position_on_resource": self.position_on_resource,
}

@staticmethod
def deserialize(data: dict) -> "Barcode":
return Barcode(
data=data["data"],
symbology=data["symbology"],
position_on_resource=data["position_on_resource"],
)

def __str__(self) -> str:
return f'Barcode(data="{self.data}", symbology="{self.symbology}", position_on_resource="{self.position_on_resource}")'
41 changes: 5 additions & 36 deletions pylabrobot/resources/carrier_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,13 +221,7 @@ def test_serialization(self):
"size_x": 135.0,
"size_y": 497.0,
"size_z": 13.0,
"location": None,
"rotation": {"type": "Rotation", "x": 0, "y": 0, "z": 0},
"category": "tip_carrier",
"model": None,
"barcode": None,
"preferred_pickup_location": None,
"parent_name": None,
"children": [
{
"name": "tip_car-0",
Expand All @@ -241,14 +235,9 @@ def test_serialization(self):
"y": 20,
"z": 30,
},
"rotation": {"type": "Rotation", "x": 0, "y": 0, "z": 0},
"category": "resource_holder",
"child_location": {"type": "Coordinate", "x": 0, "y": 0, "z": 0},
"children": [],
"parent_name": "tip_car",
"model": None,
"barcode": None,
"preferred_pickup_location": None,
"child_location": {"type": "Coordinate", "x": 0, "y": 0, "z": 0},
},
{
"name": "tip_car-1",
Expand All @@ -262,14 +251,9 @@ def test_serialization(self):
"y": 50,
"z": 30,
},
"rotation": {"type": "Rotation", "x": 0, "y": 0, "z": 0},
"category": "resource_holder",
"child_location": {"type": "Coordinate", "x": 0, "y": 0, "z": 0},
"children": [],
"parent_name": "tip_car",
"model": None,
"barcode": None,
"preferred_pickup_location": None,
"child_location": {"type": "Coordinate", "x": 0, "y": 0, "z": 0},
},
{
"name": "tip_car-2",
Expand All @@ -283,14 +267,9 @@ def test_serialization(self):
"y": 80,
"z": 30,
},
"rotation": {"type": "Rotation", "x": 0, "y": 0, "z": 0},
"category": "resource_holder",
"child_location": {"type": "Coordinate", "x": 0, "y": 0, "z": 0},
"children": [],
"parent_name": "tip_car",
"model": None,
"barcode": None,
"preferred_pickup_location": None,
"child_location": {"type": "Coordinate", "x": 0, "y": 0, "z": 0},
},
{
"name": "tip_car-3",
Expand All @@ -304,14 +283,9 @@ def test_serialization(self):
"y": 130,
"z": 30,
},
"rotation": {"type": "Rotation", "x": 0, "y": 0, "z": 0},
"category": "resource_holder",
"child_location": {"type": "Coordinate", "x": 0, "y": 0, "z": 0},
"children": [],
"parent_name": "tip_car",
"model": None,
"barcode": None,
"preferred_pickup_location": None,
"child_location": {"type": "Coordinate", "x": 0, "y": 0, "z": 0},
},
{
"name": "tip_car-4",
Expand All @@ -325,14 +299,9 @@ def test_serialization(self):
"y": 160,
"z": 30,
},
"rotation": {"type": "Rotation", "x": 0, "y": 0, "z": 0},
"category": "resource_holder",
"child_location": {"type": "Coordinate", "x": 0, "y": 0, "z": 0},
"children": [],
"parent_name": "tip_car",
"model": None,
"barcode": None,
"preferred_pickup_location": None,
"child_location": {"type": "Coordinate", "x": 0, "y": 0, "z": 0},
},
],
},
Expand Down
10 changes: 1 addition & 9 deletions pylabrobot/resources/container_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,12 @@ def compute_height_from_volume(volume):
"size_x": 10,
"size_y": 10,
"size_z": 10,
"type": "Container",
"material_z_thickness": 1,
"category": None,
"model": None,
"barcode": None,
"preferred_pickup_location": None,
"max_volume": 1000,
"compute_volume_from_height": serialize(compute_volume_from_height),
"compute_height_from_volume": serialize(compute_height_from_volume),
"height_volume_data": None,
"parent_name": None,
"rotation": {"type": "Rotation", "x": 0, "y": 0, "z": 0},
"type": "Container",
"children": [],
"location": None,
},
)

Expand Down
2 changes: 1 addition & 1 deletion pylabrobot/resources/deck.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def __init__(
def serialize(self) -> dict:
"""Serialize this deck."""
super_serialized = super().serialize()
del super_serialized["model"] # deck's don't typically have a model
super_serialized.pop("model", None) # deck's don't typically have a model
return super_serialized

def _check_naming_conflicts(self, resource: Resource):
Expand Down
13 changes: 1 addition & 12 deletions pylabrobot/resources/hamilton/tip_creators.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,24 +90,13 @@ def __repr__(self) -> str:

def serialize(self):
super_serialized = super().serialize()
del super_serialized["fitting_depth"] # inferred from tip size
super_serialized.pop("fitting_depth", None) # inferred from tip size
return {
**super_serialized,
"pickup_method": self.pickup_method.name,
"tip_size": self.tip_size.name,
}

@classmethod
def deserialize(cls, data):
return HamiltonTip(
name=data["name"],
has_filter=data["has_filter"],
total_tip_length=data["total_tip_length"],
maximal_volume=data["maximal_volume"],
tip_size=TipSize[data["tip_size"]],
pickup_method=TipPickupMethod[data["pickup_method"]],
)


def standard_volume_tip_no_filter(name: Optional[str] = None) -> HamiltonTip:
"""Deprecated. Use :func:`hamilton_tip_300uL` instead."""
Expand Down
2 changes: 1 addition & 1 deletion pylabrobot/resources/hamilton/vantage_decks.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,5 @@ def rails_to_location(self, rails: int) -> Coordinate:
def serialize(self) -> dict:
super_serialized = super().serialize()
for key in ["size_x", "size_y", "size_z", "num_rails"]:
super_serialized.pop(key)
super_serialized.pop(key, None)
return {"size": self.size, **super_serialized}
2 changes: 1 addition & 1 deletion pylabrobot/resources/petri_dish.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def __init__(
def serialize(self):
super_serialized = super().serialize()
for key in ["size_x", "size_y", "size_z"]:
del super_serialized[key]
super_serialized.pop(key, None)

return {
**super_serialized,
Expand Down
26 changes: 6 additions & 20 deletions pylabrobot/resources/petri_dish_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,15 @@ def test_petri_dish_serialization(self):
serialized,
{
"name": "petri_dish",
"type": "PetriDish",
"category": "petri_dish",
"diameter": 90.0,
"height": 15.0,
"max_volume": 121500.0,
"material_z_thickness": None,
"compute_volume_from_height": None,
"compute_height_from_volume": None,
"height_volume_data": None,
"parent_name": None,
"type": "PetriDish",
"children": [],
"location": None,
"rotation": {"type": "Rotation", "x": 0, "y": 0, "z": 0},
"max_volume": 121500.0,
"model": None,
"barcode": None,
"preferred_pickup_location": None,
"diameter": 90.0,
"height": 15.0,
},
)

Expand All @@ -44,18 +37,11 @@ def test_petri_dish_holder_serialization(self):
serialized,
{
"name": "petri_dish_holder",
"category": "petri_dish_holder",
"type": "PetriDishHolder",
"size_x": 127.76,
"size_y": 85.48,
"size_z": 14.5,
"parent_name": None,
"type": "PetriDishHolder",
"children": [],
"location": None,
"rotation": {"type": "Rotation", "x": 0, "y": 0, "z": 0},
"model": None,
"barcode": None,
"preferred_pickup_location": None,
"category": "petri_dish_holder",
},
)

Expand Down
19 changes: 0 additions & 19 deletions pylabrobot/resources/plate_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,25 +117,6 @@ def serialize(self) -> dict:
"plate_z_offset": self.plate_z_offset,
}

@classmethod
def deserialize(cls, data: dict, allow_marshal: bool = False) -> PlateAdapter:
return cls(
name=data["name"],
size_x=data["size_x"],
size_y=data["size_y"],
size_z=data["size_z"],
dx=data["dx"],
dy=data["dy"],
dz=data["dz"],
adapter_hole_size_x=data["adapter_hole_size_x"],
adapter_hole_size_y=data["adapter_hole_size_y"],
adapter_hole_dx=data["adapter_hole_dx"],
adapter_hole_dy=data["adapter_hole_dy"],
plate_z_offset=data["plate_z_offset"],
category=data.get("category"),
model=data.get("model"),
)

def compute_plate_location(self, resource: Plate) -> Coordinate:
"""Compute the location of the `Plate` child resource in relationship to the `PlateAdapter` to
align the `Plate` well-grid with the adapter's hole grid."""
Expand Down
Loading
Loading