Skip to content

Commit 8a39286

Browse files
committed
refactor: replace custom data in msgs with struct
- Replaces available scans dict with a new model - Replaces numpy usage with structured data or casting to list depending on what seems appropriate
1 parent 9693717 commit 8a39286

37 files changed

Lines changed: 379 additions & 303 deletions

bec_ipython_client/tests/client_tests/test_ipython_live_updates.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def queue_elements(bec_client_mock):
2323
client = bec_client_mock
2424
request_msg = messages.ScanQueueMessage(
2525
scan_type="grid_scan",
26-
parameter={"args": {"samx": (-5, 5, 3)}, "kwargs": {}},
26+
parameter={"args": {"samx": [-5, 5, 3]}, "kwargs": {}},
2727
queue="primary",
2828
metadata={"RID": "something"},
2929
)
@@ -52,7 +52,7 @@ def queue_elements(bec_client_mock):
5252
def sample_request_msg():
5353
return messages.ScanQueueMessage(
5454
scan_type="grid_scan",
55-
parameter={"args": {"samx": (-5, 5, 3)}, "kwargs": {}},
55+
parameter={"args": {"samx": [-5, 5, 3]}, "kwargs": {}},
5656
queue="primary",
5757
metadata={"RID": "something"},
5858
)
@@ -232,7 +232,7 @@ def test_available_req_blocks_multiple_blocks(bec_client_mock):
232232

233233
request_msg = messages.ScanQueueMessage(
234234
scan_type="grid_scan",
235-
parameter={"args": {"samx": (-5, 5, 3)}, "kwargs": {}},
235+
parameter={"args": {"samx": [-5, 5, 3]}, "kwargs": {}},
236236
queue="primary",
237237
metadata={"RID": "test_rid"},
238238
)

bec_ipython_client/tests/client_tests/test_live_table.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def client_with_grid_scan(bec_client_mock):
5050
client = bec_client_mock
5151
request_msg = messages.ScanQueueMessage(
5252
scan_type="grid_scan",
53-
parameter={"args": {"samx": (-5, 5, 3)}, "kwargs": {}},
53+
parameter={"args": {"samx": [-5, 5, 3]}, "kwargs": {}},
5454
queue="primary",
5555
metadata={"RID": "something"},
5656
)
@@ -88,7 +88,7 @@ def test_sort_devices(self):
8888
(
8989
messages.ScanQueueMessage(
9090
scan_type="grid_scan",
91-
parameter={"args": {"samx": (-5, 5, 3)}, "kwargs": {}},
91+
parameter={"args": {"samx": [-5, 5, 3]}, "kwargs": {}},
9292
queue="primary",
9393
metadata={"RID": "something"},
9494
),
@@ -134,7 +134,7 @@ def test_wait_for_request_acceptance(self, client_with_grid_scan):
134134
def test_run_update(self, bec_client_mock, scan_item):
135135
request_msg = messages.ScanQueueMessage(
136136
scan_type="grid_scan",
137-
parameter={"args": {"samx": (-5, 5, 3)}, "kwargs": {}},
137+
parameter={"args": {"samx": [-5, 5, 3]}, "kwargs": {}},
138138
queue="primary",
139139
metadata={"RID": "something"},
140140
)
@@ -161,7 +161,7 @@ def test_run_update(self, bec_client_mock, scan_item):
161161
def test_run_update_without_monitored_devices(self, bec_client_mock, scan_item):
162162
request_msg = messages.ScanQueueMessage(
163163
scan_type="grid_scan",
164-
parameter={"args": {"samx": (-5, 5, 3)}, "kwargs": {}},
164+
parameter={"args": {"samx": [-5, 5, 3]}, "kwargs": {}},
165165
queue="primary",
166166
metadata={"RID": "something"},
167167
)
@@ -305,7 +305,6 @@ def test_print_table_data_hinted_value_with_precision(
305305
[
306306
# Commented out cases are not supported in unstructured serialized data, because msgpack doesn't distinguish
307307
# lists, tuples, or sets. To support this, ScanMessage must be refactored to support the type information directly
308-
# except for numpy arrays, which are currently special-cased but will be removed in a future refactor.
309308
# (np.int32(1), "1.00"),
310309
# (np.float64(1.00000), "1.00"),
311310
(0, "0.00"),
@@ -319,7 +318,7 @@ def test_print_table_data_hinted_value_with_precision(
319318
("1", "1"),
320319
# ((0, 1), "(0, 1)"),
321320
({"value": 0}, "{'value': 0}"),
322-
(np.array([0, 1]), "[0 1]"),
321+
# (np.array([0, 1]), "[0 1]"),
323322
# ({1, 2}, "{1, 2}"),
324323
],
325324
)

bec_ipython_client/tests/end-2-end/test_scans_e2e.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -918,7 +918,7 @@ def test_scan_repeat_decorator(bec_ipython_client_fixture):
918918
"update_frequency": 400,
919919
},
920920
"readoutPriority": "baseline",
921-
"deviceTags": {"user motors"},
921+
"deviceTags": ["user motors"],
922922
"enabled": True,
923923
"readOnly": False,
924924
}

bec_ipython_client/tests/end-2-end/test_scans_lib_e2e.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ def test_dap_fit(bec_client_lib):
217217
"hexapod": {
218218
"deviceClass": "ophyd_devices.SynDeviceOPAAS",
219219
"deviceConfig": {},
220-
"deviceTags": {"user motors"},
220+
"deviceTags": ["user motors"],
221221
"readoutPriority": "baseline",
222222
"enabled": True,
223223
"readOnly": False,
@@ -230,7 +230,7 @@ def test_dap_fit(bec_client_lib):
230230
"tolerance": 0.01,
231231
"update_frequency": 400,
232232
},
233-
"deviceTags": {"user motors"},
233+
"deviceTags": ["user motors"],
234234
"enabled": True,
235235
"readOnly": False,
236236
},
@@ -244,7 +244,7 @@ def test_dap_fit(bec_client_lib):
244244
"hexapod": {
245245
"deviceClass": "ophyd_devices.SynDeviceOPAAS",
246246
"deviceConfig": {},
247-
"deviceTags": {"user motors"},
247+
"deviceTags": ["user motors"],
248248
"readoutPriority": "baseline",
249249
"enabled": True,
250250
"readOnly": False,
@@ -258,7 +258,7 @@ def test_dap_fit(bec_client_lib):
258258
"update_frequency": 400,
259259
},
260260
"readoutPriority": "baseline",
261-
"deviceTags": {"user motors"},
261+
"deviceTags": ["user motors"],
262262
"enabled": True,
263263
"readOnly": False,
264264
},
@@ -272,7 +272,7 @@ def test_dap_fit(bec_client_lib):
272272
"hexapod": {
273273
"deviceClass": "ophyd_devices.SynDeviceOPAAS",
274274
"deviceConfig": {},
275-
"deviceTags": {"user motors"},
275+
"deviceTags": ["user motors"],
276276
"readoutPriority": "baseline",
277277
"enabled": True,
278278
"readOnly": False,
@@ -281,7 +281,7 @@ def test_dap_fit(bec_client_lib):
281281
"deviceClass": "ophyd_devices.utils.bec_utils.DeviceClassConnectionError",
282282
"deviceConfig": {},
283283
"readoutPriority": "baseline",
284-
"deviceTags": {"user motors"},
284+
"deviceTags": ["user motors"],
285285
"enabled": True,
286286
"readOnly": False,
287287
},
@@ -295,7 +295,7 @@ def test_dap_fit(bec_client_lib):
295295
"hexapod": {
296296
"deviceClass": "SynDeviceOPAAS",
297297
"deviceConfig": {},
298-
"deviceTags": {"user motors"},
298+
"deviceTags": ["user motors"],
299299
"readoutPriority": "baseline",
300300
"enabled": True,
301301
"readOnly": False,
@@ -304,7 +304,7 @@ def test_dap_fit(bec_client_lib):
304304
"deviceClass": "ophyd_devices.utils.bec_utils.DeviceClassInitError",
305305
"deviceConfig": {},
306306
"readoutPriority": "baseline",
307-
"deviceTags": {"user motors"},
307+
"deviceTags": ["user motors"],
308308
"enabled": True,
309309
"readOnly": False,
310310
},
@@ -318,7 +318,7 @@ def test_dap_fit(bec_client_lib):
318318
"hexapod": {
319319
"deviceClass": "SynDeviceOPAAS",
320320
"deviceConfig": {},
321-
"deviceTags": {"user motors"},
321+
"deviceTags": ["user motors"],
322322
"readoutPriority": "baseline",
323323
"enabled": True,
324324
"readOnly": False,
@@ -327,7 +327,7 @@ def test_dap_fit(bec_client_lib):
327327
"deviceClass": "ophyd_devices.WrongDeviceClass",
328328
"deviceConfig": {},
329329
"readoutPriority": "baseline",
330-
"deviceTags": {"user motors"},
330+
"deviceTags": ["user motors"],
331331
"enabled": True,
332332
"readOnly": False,
333333
},
@@ -383,7 +383,7 @@ def test_config_reload_with_describe_failure(bec_test_config_file_path, bec_clie
383383
"hexapod": {
384384
"deviceClass": "ophyd_devices.sim.sim_test_devices.SimPositionerWithDescribeFailure",
385385
"deviceConfig": {},
386-
"deviceTags": {"user motors"},
386+
"deviceTags": ["user motors"],
387387
"readoutPriority": "baseline",
388388
"enabled": True,
389389
"readOnly": False,
@@ -397,7 +397,7 @@ def test_config_reload_with_describe_failure(bec_test_config_file_path, bec_clie
397397
"update_frequency": 400,
398398
},
399399
"readoutPriority": "baseline",
400-
"deviceTags": {"user motors"},
400+
"deviceTags": ["user motors"],
401401
"enabled": True,
402402
"readOnly": False,
403403
},
@@ -445,7 +445,7 @@ def test_config_add_remove_device(bec_client_lib):
445445
"update_frequency": 400,
446446
},
447447
"readoutPriority": "baseline",
448-
"deviceTags": {"user motors"},
448+
"deviceTags": ["user motors"],
449449
"enabled": True,
450450
"readOnly": False,
451451
}

bec_lib/bec_lib/bec_serializable.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import numpy as np
12
from pydantic import BaseModel, ConfigDict, computed_field
23

34

@@ -21,3 +22,12 @@ class BECSerializable(BaseModel):
2122
@property
2223
def bec_codec(self) -> BecCodecInfo:
2324
return BecCodecInfo(type_name=self.__class__.__name__)
25+
26+
def __eq__(self, other):
27+
if type(other) is not type(self):
28+
return False
29+
try:
30+
np.testing.assert_equal(self.model_dump(), other.model_dump())
31+
return True
32+
except AssertionError:
33+
return False

bec_lib/bec_lib/bec_service.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,6 @@ def _update_existing_services(self) -> None:
259259
msgs = [
260260
self.connector.get(MessageEndpoints.service_status(service)) for service in services
261261
]
262-
print(msgs)
263262
self._services_info = {msg.content["name"]: msg for msg in msgs if msg is not None}
264263
msgs = [self.connector.get(MessageEndpoints.metrics(service)) for service in services]
265264
self._services_metric = {msg.content["name"]: msg for msg in msgs if msg is not None}

bec_lib/bec_lib/device.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ def _prepare_rpc_msg(
308308
client: BECClient = self.root.parent.parent
309309
msg = messages.ScanQueueMessage(
310310
scan_type="device_rpc",
311-
parameter=params,
311+
parameter=messages.sanitize_one_way_encodable(params),
312312
queue=client.queue.get_default_scan_queue(), # type: ignore
313313
metadata={"RID": request_id, "response": True},
314314
)
@@ -1115,8 +1115,8 @@ def limits(self):
11151115
if not limit_msg:
11161116
return [0, 0]
11171117
limits = [
1118-
limit_msg.content["signals"].get("low", {}).get("value", 0),
1119-
limit_msg.content["signals"].get("high", {}).get("value", 0),
1118+
limit_msg.signals.get("low", {}).get("value", 0),
1119+
limit_msg.signals.get("high", {}).get("value", 0),
11201120
]
11211121
return limits
11221122

0 commit comments

Comments
 (0)