next-asictest-client 0.1.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- next_asictest_client-0.1.2/PKG-INFO +426 -0
- next_asictest_client-0.1.2/README.md +151 -0
- next_asictest_client-0.1.2/api-reference.md +159 -0
- next_asictest_client-0.1.2/configuration.md +107 -0
- next_asictest_client-0.1.2/pyproject.toml +17 -0
- next_asictest_client-0.1.2/setup.cfg +4 -0
- next_asictest_client-0.1.2/src/asictest/__init__.py +17 -0
- next_asictest_client-0.1.2/src/asictest/client.py +342 -0
- next_asictest_client-0.1.2/src/asictest/configuration.py +285 -0
- next_asictest_client-0.1.2/src/next_asictest_client.egg-info/PKG-INFO +426 -0
- next_asictest_client-0.1.2/src/next_asictest_client.egg-info/SOURCES.txt +14 -0
- next_asictest_client-0.1.2/src/next_asictest_client.egg-info/dependency_links.txt +1 -0
- next_asictest_client-0.1.2/src/next_asictest_client.egg-info/top_level.txt +1 -0
- next_asictest_client-0.1.2/tests/test_client.py +159 -0
- next_asictest_client-0.1.2/tests/test_configuration.py +71 -0
- next_asictest_client-0.1.2/tests/test_simulator.py +196 -0
|
@@ -0,0 +1,426 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: next-asictest-client
|
|
3
|
+
Version: 0.1.2
|
|
4
|
+
Summary: Python client for the ASIC Test2 DAQ console API
|
|
5
|
+
Requires-Python: >=3.10
|
|
6
|
+
Description-Content-Type: text/markdown
|
|
7
|
+
|
|
8
|
+
# ASIC Test2 Python client
|
|
9
|
+
|
|
10
|
+
`next-asictest-client` uses the same HTTP and Connect JSON endpoints as the web
|
|
11
|
+
console. The DAQ still owns FPGA communication, workflow admission, and
|
|
12
|
+
recordings. The client supports Python 3.10 or later and has no runtime
|
|
13
|
+
dependencies outside the standard library.
|
|
14
|
+
|
|
15
|
+
Install from PyPI:
|
|
16
|
+
|
|
17
|
+
```sh
|
|
18
|
+
python -m pip install next-asictest-client
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
From a checkout, install from the repository root:
|
|
22
|
+
|
|
23
|
+
```sh
|
|
24
|
+
python -m pip install ./python
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Read Board status
|
|
28
|
+
|
|
29
|
+
Pass the origin of the console without a route or hash fragment. The same client
|
|
30
|
+
also works with the DAQ's HTTP listener when it is directly reachable.
|
|
31
|
+
|
|
32
|
+
```python
|
|
33
|
+
from asictest import Client, StatusRegister, decode_bytes, decode_json
|
|
34
|
+
|
|
35
|
+
daq = Client("http://127.0.0.1:5173")
|
|
36
|
+
# For a protected installation, call daq.login(username, password) first.
|
|
37
|
+
print(daq.get_firmware()["profile"])
|
|
38
|
+
observation = daq.observe_firmware(StatusRegister.BOARD)
|
|
39
|
+
print(observation["source"], decode_json(observation["decodedJson"]))
|
|
40
|
+
print(decode_bytes(observation["rawPacket"]).hex(" "))
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
`session()`, `login()`, and `logout()` use the console's cookie-based access
|
|
44
|
+
control. Reuse the client instance for the lifetime of a session.
|
|
45
|
+
|
|
46
|
+
## Submit and inspect workflows
|
|
47
|
+
|
|
48
|
+
These examples are intended for a simulator. Channel and board-wide settings
|
|
49
|
+
are separate, just as in the console.
|
|
50
|
+
|
|
51
|
+
```python
|
|
52
|
+
from uuid import uuid4
|
|
53
|
+
from asictest import (
|
|
54
|
+
AsicPower, DataClockDivider, GeneralSettings, Opcode, ReadoutMask, ResetLevel,
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
command = daq.send_command(
|
|
58
|
+
Opcode.READ_STATUS, register=StatusRegister.BOARD, request_id=str(uuid4()),
|
|
59
|
+
)["workflow"]
|
|
60
|
+
result = daq.wait_for_workflow(command["id"])
|
|
61
|
+
print(result["state"], result.get("steps", []))
|
|
62
|
+
|
|
63
|
+
# Set GENERAL and gate timing on the simulator before acquiring data.
|
|
64
|
+
settings = GeneralSettings(
|
|
65
|
+
reset=ResetLevel.LOW,
|
|
66
|
+
power=AsicPower.OFF,
|
|
67
|
+
divider=DataClockDivider.DIV_1,
|
|
68
|
+
readout=ReadoutMask.ALL,
|
|
69
|
+
gate_width_ns=40,
|
|
70
|
+
gate_period_ns=496,
|
|
71
|
+
)
|
|
72
|
+
setup = daq.write_general(settings, request_id=str(uuid4()))["workflow"]
|
|
73
|
+
if daq.wait_for_workflow(setup["id"])["state"] != "completed":
|
|
74
|
+
raise RuntimeError("GENERAL configuration failed")
|
|
75
|
+
|
|
76
|
+
draft = daq.configuration() # Applied channel draft, or the server's example.
|
|
77
|
+
run = daq.start_run(draft, counter_test=True, duration_ms=500,
|
|
78
|
+
request_id=str(uuid4()))["workflow"]
|
|
79
|
+
result = daq.wait_for_workflow(run["id"])
|
|
80
|
+
print(result["state"], result.get("error", ""))
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
Omit `duration_ms` to run until stopped, then submit `daq.stop_run(request_id=...)`.
|
|
84
|
+
Workflows can continue after the client exits. `wait_for_workflow` returns the
|
|
85
|
+
terminal record, including failures, and a polling timeout leaves the workflow
|
|
86
|
+
running on the DAQ. Save the request ID and original payload before submission.
|
|
87
|
+
If the HTTP connection fails during submission, use the same ID and payload to
|
|
88
|
+
recover the original workflow. The client does not automatically retry
|
|
89
|
+
state-changing operations.
|
|
90
|
+
|
|
91
|
+
`execute_firmware(kind, payload, request_id=...)` accepts a dictionary or exact
|
|
92
|
+
JSON text/bytes. This covers the console's full and single-group configuration
|
|
93
|
+
writes, throughput, reset, and device workflows. Available workflow kinds depend
|
|
94
|
+
on the daemon installation.
|
|
95
|
+
|
|
96
|
+
See **Configuration symbols** for the register map, clock
|
|
97
|
+
selectors, readout mask, mode codes, and examples for changing one register
|
|
98
|
+
group or writing the complete 17-register draft.
|
|
99
|
+
|
|
100
|
+
## Run data and other API calls
|
|
101
|
+
|
|
102
|
+
```python
|
|
103
|
+
import json
|
|
104
|
+
import shutil
|
|
105
|
+
|
|
106
|
+
runs = daq.get_firmware().get("runs", [])
|
|
107
|
+
if runs:
|
|
108
|
+
run_id = runs[0]["runNumber"]
|
|
109
|
+
with daq.open_artifact(run_id, "manifest") as stream:
|
|
110
|
+
manifest = json.load(stream)
|
|
111
|
+
print(manifest["state"])
|
|
112
|
+
|
|
113
|
+
rtl = manifest.get("rtl", {})
|
|
114
|
+
if rtl.get("decoded_state") == "ready":
|
|
115
|
+
artifact = "decoded.h5" if rtl.get("decoded_format") == "hdf5" else "decoded.csv"
|
|
116
|
+
with daq.open_artifact(run_id, artifact) as stream, open(artifact, "xb") as output:
|
|
117
|
+
shutil.copyfileobj(stream, output)
|
|
118
|
+
|
|
119
|
+
events = daq.get_decoded_run_page(run_id, list_events=True, page_number=1)
|
|
120
|
+
if events.get("events"):
|
|
121
|
+
event = events["events"][0]
|
|
122
|
+
raw = daq.get_decoded_run_page(
|
|
123
|
+
run_id, event_ref=event["ref"], list_packets=True, page_number=1,
|
|
124
|
+
)
|
|
125
|
+
print(raw.get("totalEntries"))
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
The client also provides `list_command_history`, `get_run_samples`, calibration,
|
|
129
|
+
I²C monitoring, and audit helpers. For any API method, use the service and method
|
|
130
|
+
names from [the protobuf definitions](https://github.com/next-exp/asic-test-daq/tree/dev/docker-simulator/proto/asictest/v1):
|
|
131
|
+
|
|
132
|
+
```python
|
|
133
|
+
telemetry = daq.rpc("MonitoringService", "GetMonitoring", {"severity": "warning"})
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
Requests accept protobuf JSON field names or their original snake-case names.
|
|
137
|
+
Python `bytes` are encoded for protobuf bytes fields. Responses preserve the
|
|
138
|
+
server's protobuf JSON representation. Convert quoted 64-bit fields with
|
|
139
|
+
`int(value)` as needed. `decode_bytes` and `decode_json` unpack bytes and
|
|
140
|
+
JSON-in-bytes fields. Optional or unavailable values may be omitted by the server.
|
|
141
|
+
The API surface depends on the deployed release, and unavailable routes return an
|
|
142
|
+
`ApiError`. `TransportError` indicates a failed HTTP exchange or invalid response.
|
|
143
|
+
|
|
144
|
+
The PyPI project description includes the **Python API reference** and **Configuration symbols** sections.
|
|
145
|
+
|
|
146
|
+
## Tests
|
|
147
|
+
|
|
148
|
+
From the repository root:
|
|
149
|
+
|
|
150
|
+
```sh
|
|
151
|
+
PYTHONPATH=python/src python -m unittest discover -s python/tests -v
|
|
152
|
+
ASIC_TEST_PYTHON_SIMULATOR=1 PYTHONPATH=python/src python -m unittest discover -s python/tests -v
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
The second command requires the native HDF5 and Blosc dependencies described
|
|
156
|
+
in the project README. It builds the pinned Go daemon and simulator and uses temporary
|
|
157
|
+
storage and loopback sockets. It covers status reads, durable replay, capture,
|
|
158
|
+
decoded and raw data, downloads, telemetry, and symbolic GENERAL and channel writes.
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
## Python API reference
|
|
162
|
+
|
|
163
|
+
Import the public API from `asictest`. Response objects use the server's
|
|
164
|
+
protobuf JSON field names, such as `selectedWorkflow` and `runNumber`.
|
|
165
|
+
Default-valued fields may be omitted. Protobuf 64-bit integers can arrive as
|
|
166
|
+
decimal strings and bytes as base64 strings. The DAQ version and its enabled
|
|
167
|
+
capabilities determine which operations and response fields are available.
|
|
168
|
+
|
|
169
|
+
### Connection and authentication
|
|
170
|
+
|
|
171
|
+
| Call | Arguments and result |
|
|
172
|
+
|---|---|
|
|
173
|
+
| `Client(base_url="http://127.0.0.1:5173", *, timeout=10)` | Creates a synchronous client against an HTTP or HTTPS origin. The timeout is in seconds. One instance retains cookies for subsequent calls. |
|
|
174
|
+
| `session()` | Returns the current session and access state. |
|
|
175
|
+
| `login(username, password)` | Signs in and returns the resulting session state. |
|
|
176
|
+
| `logout()` | Ends the session and clears the client's cookies. Returns `None`. |
|
|
177
|
+
| `rpc(service, method, request=None, *, timeout=None)` | Calls a unary `asictest.v1` RPC. Use unqualified names such as `FirmwareService` and `GetFirmware`. Pass a request mapping or omit it to send an empty object. A per-call timeout overrides the client timeout. Python `bytes` values are base64-encoded. Returns the response object. |
|
|
178
|
+
|
|
179
|
+
`ApiError` exposes `status`, `code`, `message` and `details` from a failed HTTP or
|
|
180
|
+
Connect response. `TransportError` reports a failed HTTP exchange or an invalid
|
|
181
|
+
response. Local argument validation can raise `ValueError`.
|
|
182
|
+
|
|
183
|
+
### Board status and command history
|
|
184
|
+
|
|
185
|
+
| Call | Arguments and result |
|
|
186
|
+
|---|---|
|
|
187
|
+
| `get_firmware(*, workflow_id="", run_id="", run_before=0)` | Returns the workspace, including capabilities, recent workflows, and runs. Set `workflow_id` or `run_id` for `selectedWorkflow` or `selectedRun`. Pass the previous response's `nextRunBefore` as `run_before` to continue paging through runs. |
|
|
188
|
+
| `observe_firmware(address=StatusRegister.BOARD)` | Requests a register observation. Pass an unflagged numeric address or `StatusRegister` member. Inspect `source`, `rawPacket`, and `decodedJson` when present. |
|
|
189
|
+
| `check_firmware_system()` | Requests the daemon's firmware system checks and returns their response. |
|
|
190
|
+
| `list_command_history(**fields)` | Returns `commands` and an optional `nextBeforeId`. Filter with `opcode`, `register`, `state`, or `query`. `page_size` defaults to 10 and is capped at 25. Supply `nextBeforeId` as `before_id` for older matches. |
|
|
191
|
+
|
|
192
|
+
### Workflows, configuration, and acquisition
|
|
193
|
+
|
|
194
|
+
Submission helpers return an object containing `workflow`. Use its `id` to
|
|
195
|
+
inspect progress. Persist a unique `request_id` and the original request before
|
|
196
|
+
submitting a workflow. To recover after an ambiguous network failure, send the
|
|
197
|
+
same ID and payload. The client makes each submission once per call.
|
|
198
|
+
|
|
199
|
+
| Call | Arguments and result |
|
|
200
|
+
|---|---|
|
|
201
|
+
| `execute_firmware(kind, payload, *, request_id)` | Submits a workflow by its DAQ kind. Pass a JSON-serializable value, a JSON string, or the exact JSON bytes. The latter two forms preserve the supplied JSON. |
|
|
202
|
+
| `send_command(opcode, *, request_id, register=None, payload=())` | Submits a Command Builder workflow. Use an `Opcode`, an address appropriate to the opcode, and a list or tuple of payload words. The DAQ adds the status request flag for reads. |
|
|
203
|
+
| `configuration()` | Returns JSON text for the applied channel draft when available, otherwise the DAQ's example. Use `json.loads` to edit it. |
|
|
204
|
+
| `read_general()` | Observes GENERAL and returns a `GeneralReadback` with exact `general_word` and `timing_word` and typed `settings`. |
|
|
205
|
+
| `write_general(settings, *, request_id)` | Builds and submits a board-wide GENERAL write from a `GeneralSettings` instance. |
|
|
206
|
+
| `write_configuration(configuration, *, request_id, chain=None)` | Submits a complete draft as a mapping or JSON text. With `chain` set to a `Chain` member, writes only that group using the supplied complete draft. |
|
|
207
|
+
| `start_run(configuration, *, request_id, counter_test, duration_ms=None)` | Starts capture using the channel draft. Set `counter_test` to select counter test data. Supply a duration in milliseconds for a timed run or leave it unset for a run stopped by command. |
|
|
208
|
+
| `pause_run(run_id, *, request_id)` | Stops the active open-ended HDF5 subrun, checks the final delimiter and keeps the parent file open. |
|
|
209
|
+
| `resume_run(run_id, configuration, *, request_id, counter_test)` | Starts the next subrun in the paused parent with a fresh configuration snapshot. Preserve the parent's counter source. |
|
|
210
|
+
| `stop_run(*, request_id)` | Ends an active capture or finalizes the paused parent. |
|
|
211
|
+
| `cancel_firmware(workflow_id)` | Requests cancellation of the selected firmware workflow. |
|
|
212
|
+
| `wait_for_workflow(workflow_id, *, timeout=30, interval=0.25)` | Polls until the workflow is `completed`, `failed`, `cancelled`, `uncertain`, or `interrupted`. Returns the workflow record in any of those states. Both times are positive seconds. Raises `TimeoutError` if the wait expires. The server workflow can continue after the wait ends. |
|
|
213
|
+
|
|
214
|
+
### Read and edit GENERAL settings
|
|
215
|
+
|
|
216
|
+
```python
|
|
217
|
+
from dataclasses import replace
|
|
218
|
+
from uuid import uuid4
|
|
219
|
+
|
|
220
|
+
from asictest import DataClockDivider, ReadoutMask
|
|
221
|
+
|
|
222
|
+
readback = client.read_general()
|
|
223
|
+
print(readback.settings.gate_period_ns)
|
|
224
|
+
print(f"{readback.general_word:04X} {readback.timing_word:04X}")
|
|
225
|
+
|
|
226
|
+
updated = replace(
|
|
227
|
+
readback.settings,
|
|
228
|
+
divider=DataClockDivider.MHZ_25,
|
|
229
|
+
readout=ReadoutMask.L0 | ReadoutMask.R0,
|
|
230
|
+
gate_period_ns=500,
|
|
231
|
+
)
|
|
232
|
+
workflow = client.write_general(updated, request_id=str(uuid4()))["workflow"]
|
|
233
|
+
result = client.wait_for_workflow(workflow["id"])
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
The settings use symbols for reset level, ASIC power, clock selector, and
|
|
237
|
+
channel mask. Gate durations are expressed in nanoseconds. A clock selector
|
|
238
|
+
of zero is readable as `DataClockDivider.RESERVED` and rejected for writes.
|
|
239
|
+
|
|
240
|
+
### Subrun workflow
|
|
241
|
+
|
|
242
|
+
1. Enable `decoded_hdf5_enabled` and call `start_run(..., duration_ms=None)`.
|
|
243
|
+
Wait until acquisition is running. The initial workflow's `recording` step
|
|
244
|
+
in state `prepared` contains the parent `run_id` in its decoded `evidenceJson`.
|
|
245
|
+
2. Call `pause_run(run_id, request_id=...)` and wait for its workflow to complete.
|
|
246
|
+
3. Submit `write_configuration` and/or `write_general` for the settings you
|
|
247
|
+
want to change. Check their workflow results before resuming.
|
|
248
|
+
4. Call `resume_run(run_id, new_draft, request_id=..., counter_test=...)` with
|
|
249
|
+
the same counter-source selection as Start. Resume stores the supplied draft
|
|
250
|
+
and a fresh GENERAL observation. Use the configuration workflows in the
|
|
251
|
+
previous step to send changes to the board.
|
|
252
|
+
5. Call `stop_run(request_id=...)` to finalize the parent. Once finalized, use
|
|
253
|
+
`open_artifact(run_id, "decoded.h5")` for the shared file or
|
|
254
|
+
`get_decoded_run_page(run_id, subrun=1, list_events=True)` for the second
|
|
255
|
+
subrun's events.
|
|
256
|
+
|
|
257
|
+
Start, Pause, Resume, configuration writes and Stop each take their own
|
|
258
|
+
request ID. To retry a submission, reuse its ID and original arguments.
|
|
259
|
+
The capture or resume workflow reaches a terminal state at the end of its
|
|
260
|
+
subrun. The run manifest remains `paused` until the next Resume or Stop.
|
|
261
|
+
|
|
262
|
+
### Run data and files
|
|
263
|
+
|
|
264
|
+
With HDF5 enabled, both methods below work during acquisition and while the parent
|
|
265
|
+
is paused. The count covers indexed event starts in the committed prefix. The
|
|
266
|
+
latest event can still be receiving data. Every subrun starts at event reference
|
|
267
|
+
1. The FPGA event ID is a separate header field, and packet numbers continue
|
|
268
|
+
across the parent.
|
|
269
|
+
|
|
270
|
+
```python
|
|
271
|
+
count = client.get_subrun_event_count(run_id, subrun=1)
|
|
272
|
+
if count:
|
|
273
|
+
page = client.get_subrun_event_page(
|
|
274
|
+
run_id, 1, first_event=1, last_event=count, page_number=1,
|
|
275
|
+
)
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
Bounds are inclusive. An upper bound beyond the committed prefix is clipped.
|
|
279
|
+
A page contains at most 100 rows or event headers when `list_events=True`.
|
|
280
|
+
Keep the same bounds and advance `page_number` while `hasMore` is true. Read
|
|
281
|
+
completed subruns for stable pagination. Word pages include an `event_ref`
|
|
282
|
+
column. Zero identifies an unassigned diagnostic row between events.
|
|
283
|
+
|
|
284
|
+
| Call | Arguments and result |
|
|
285
|
+
|---|---|
|
|
286
|
+
| `get_subrun_event_count(run_id, subrun=0)` | Returns the number of indexed events in the committed HDF5 prefix as an integer. |
|
|
287
|
+
| `get_subrun_event_page(run_id, subrun, *, first_event, last_event, page_number=1, list_events=False)` | Reads one page of decoded rows or event headers within the selected HDF5 subrun. |
|
|
288
|
+
| `get_decoded_run_page(run_id, **fields)` | Returns decoding status, event summaries, decoded rows or raw packets for the requested run. Use `status_only=True` for status, `list_events=True` for summaries, or an `event_ref` from a summary for event words. Add `list_packets=True` with `event_ref` for raw event packets. Use `page_number` starting at 1, or `cursor` with `nextCursor` and `hasMore` where supported. On deployments supporting packet selection, pass `packet` with a numbered event word page to select one recorded datagram. |
|
|
289
|
+
| `get_run_samples(run_id="", **fields)` | Returns `state`, `counterTest`, `points`, and `totalEvents` when available. Each point may include channel, word, ADC, flips, and event. Filter with `first_event` and `last_event`. An empty run ID selects the daemon's current or most recent capture. |
|
|
290
|
+
| `open_artifact(run_id, artifact)` | Context manager yielding a binary response stream. Use a server-allowed artifact name such as `manifest`, `decoded.h5` or `decoded.csv`, depending on the recording. The stream closes on exit. |
|
|
291
|
+
|
|
292
|
+
### Calibration, I²C monitoring, and audit
|
|
293
|
+
|
|
294
|
+
| Call | Arguments and result |
|
|
295
|
+
|---|---|
|
|
296
|
+
| `get_calibration_log(session_id="")` | Lists calibration sessions, or returns the selected `session` and its entries when an ID is supplied. |
|
|
297
|
+
| `save_calibration_step(**fields)` | Returns the resulting calibration `session`. Request fields are `session_id`, `action`, `expected_entries`, `entry`, `conditions`, `gate_ns` and `channels`. The chosen action determines which fields the DAQ requires. |
|
|
298
|
+
| `get_i2c_monitor()` | Returns the current I²C monitor status and readings available on the daemon. |
|
|
299
|
+
| `set_i2c_monitor(enabled)` | Enables or disables I²C monitoring and returns the resulting monitor state. |
|
|
300
|
+
| `get_monitoring(**fields)` | Returns telemetry, alarms, and audit events. Request fields include `query`, `severity`, `category`, and `run_id`. For incremental reads, send `epoch` and `after` using the previous response's `epoch` and `next`. Check `gap` when tracking continuity. |
|
|
301
|
+
| `acknowledge_alarm(key)` | Acknowledges the alarm selected by its key and returns the updated `alarm`. |
|
|
302
|
+
| `export_audit(run_id)` | Returns the run's audit export as JSON bytes. Pass the result to `json.loads` or write it to a binary file. |
|
|
303
|
+
|
|
304
|
+
### Configuration and decoding helpers
|
|
305
|
+
|
|
306
|
+
| Call or symbol | Meaning |
|
|
307
|
+
|---|---|
|
|
308
|
+
| `decode_bytes(value)` | Decodes a protobuf JSON base64 string to bytes. |
|
|
309
|
+
| `decode_json(value)` | Decodes a protobuf JSON base64 string containing JSON and returns the parsed Python value. |
|
|
310
|
+
| `GeneralSettings(reset, power, divider, readout, gate_width_ns, gate_period_ns)` | Collects board-wide settings. `payload()` validates them and returns the GENERAL workflow payload. |
|
|
311
|
+
| `channel_draft(words, clocks)` | Builds the canonical draft from one ten-digit hex word per `Channel` and one `ChainClock` per `Chain`. |
|
|
312
|
+
| `read_channel_fields(raw_hex)` | Returns a mapping from `ChannelField` to integer for the 40-bit channel word. |
|
|
313
|
+
| `write_channel_fields(raw_hex, fields)` | Returns a ten-digit hex word with the selected fields updated. Supply a mapping from `ChannelField` to integer or a named mode. Invalid words and out-of-range values raise `ValueError`. |
|
|
314
|
+
| `Channel.register`, `Chain.channels`, `ChannelField.maximum` | Expose the register address, ordered channel membership, and largest field value. |
|
|
315
|
+
| `RTL_PROFILE`, `SCHEMA_VERSION` | Identify the channel draft format used by `channel_draft`. |
|
|
316
|
+
|
|
317
|
+
The configuration symbols below give the named opcodes, register addresses,
|
|
318
|
+
clock selectors, bit masks and channel field values used by these helpers.
|
|
319
|
+
|
|
320
|
+
## Configuration symbols
|
|
321
|
+
|
|
322
|
+
The current ConnectRPC requests carry workflow payloads as JSON bytes. The
|
|
323
|
+
protobuf messages define the transport fields. The ASIC Test2 register addresses,
|
|
324
|
+
group order and GENERAL layout come from the Go backend. The Python symbols
|
|
325
|
+
preserve those values in the request JSON. The installed DAQ validates the request
|
|
326
|
+
and determines which workflows are available.
|
|
327
|
+
[ConnectRPC definition](https://github.com/next-exp/asic-test-daq/blob/dev/docker-simulator/proto/asictest/v1/firmware.proto) ·
|
|
328
|
+
[Go register codec](https://github.com/next-exp/asic-test-daq/blob/dev/docker-simulator/backend/internal/fpga/codec.go) ·
|
|
329
|
+
[Go configuration schema](https://github.com/next-exp/asic-test-daq/blob/dev/docker-simulator/backend/internal/fpga/plan.go)
|
|
330
|
+
|
|
331
|
+
### Commands and registers
|
|
332
|
+
|
|
333
|
+
| Symbol | API value |
|
|
334
|
+
|---|---:|
|
|
335
|
+
| `Opcode.CONTROL` | 0 |
|
|
336
|
+
| `Opcode.WRITE_REGISTER` | 2 |
|
|
337
|
+
| `Opcode.READ_STATUS` | 4 |
|
|
338
|
+
| `StatusRegister.BOARD` | `0x0000` |
|
|
339
|
+
| `StatusRegister.MONITOR_BYTE` | `0x0001` |
|
|
340
|
+
| `StatusRegister.POTENTIOMETER_BYTE` | `0x0002` |
|
|
341
|
+
| `StatusRegister.GENERAL`, `WriteRegister.GENERAL` | `0x0003` |
|
|
342
|
+
| `WriteRegister.THROUGHPUT` | `0x0000` |
|
|
343
|
+
| `WriteRegister.I2C_COMMAND_FIFO` | `0x0001` |
|
|
344
|
+
| `Channel.R0.register` through `Channel.SZJ.register` | `0x0004`–`0x0014` |
|
|
345
|
+
|
|
346
|
+
Use `StatusRegister` for reads and `WriteRegister` for writes. The DAQ adds the
|
|
347
|
+
status-request bit when sending `Opcode.READ_STATUS`. To acquire, use
|
|
348
|
+
`start_run()` and `stop_run()` so the DAQ owns recording and finalization.
|
|
349
|
+
|
|
350
|
+
### Board-wide GENERAL settings
|
|
351
|
+
|
|
352
|
+
`GeneralSettings` builds the configuration and gate-timing words for
|
|
353
|
+
`Client.write_general()`. Its fields use the same meanings as the console.
|
|
354
|
+
|
|
355
|
+
| Field | Symbols or range |
|
|
356
|
+
|---|---|
|
|
357
|
+
| `reset` | `ResetLevel.LOW` (0) or `HIGH` (1), the raw bit level |
|
|
358
|
+
| `power` | `AsicPower.ON` (0) or `OFF` (1), the active-low EN bit |
|
|
359
|
+
| `divider` | `DataClockDivider.DIV_1` through `DIV_7` |
|
|
360
|
+
| `readout` | `ReadoutMask.L0`, `L6`, `L7`, `R0`, `R6`, `R7`, in bit order 0–5. Combine with `|`. `NONE` is 0 and `ALL` is 63. |
|
|
361
|
+
| `gate_width_ns` | 16–40 ns, in steps of 8 ns |
|
|
362
|
+
| `gate_period_ns` | 256–1000 ns, in steps of 8 ns |
|
|
363
|
+
|
|
364
|
+
See the example under **Submit and inspect workflows** for a simulator
|
|
365
|
+
GENERAL write. The divider is the raw data-clock code. The chain shift clock
|
|
366
|
+
below is a separate setting.
|
|
367
|
+
|
|
368
|
+
### Channel configuration drafts
|
|
369
|
+
|
|
370
|
+
`Channel` contains `R0`–`R7`, `L0`–`L7`, and `SZJ`. `Chain` exposes the
|
|
371
|
+
canonical groups as `R0`, `R1_R7`, `L0_L7`, and `SZJ`.
|
|
372
|
+
`ChainClock` and `DataClockDivider` expose `MHZ_100`, `MHZ_50`,
|
|
373
|
+
`MHZ_33_33`, `MHZ_25`, `MHZ_12_5`, `MHZ_10`, and `MHZ_5` for codes 1–7.
|
|
374
|
+
Legacy enum names retain their numeric values.
|
|
375
|
+
`GeneralSettings` accepts exact 5 ns steps and packs the width and period
|
|
376
|
+
into six and ten bits respectively. A 40 ns width and 500 ns period produce
|
|
377
|
+
timing word `0x2064`.
|
|
378
|
+
|
|
379
|
+
This example starts from the DAQ's channel draft, edits a single field, then
|
|
380
|
+
writes the R1–R7 group using the full draft.
|
|
381
|
+
|
|
382
|
+
```python
|
|
383
|
+
import json
|
|
384
|
+
from uuid import uuid4
|
|
385
|
+
|
|
386
|
+
from asictest import Channel, Chain, ChannelField, Client, write_channel_fields
|
|
387
|
+
|
|
388
|
+
daq = Client()
|
|
389
|
+
draft = json.loads(daq.configuration())
|
|
390
|
+
group = next(group for group in draft["chains"] if group["name"] == Chain.R1_R7)
|
|
391
|
+
channel = next(channel for channel in group["channels"] if channel["name"] == Channel.R3)
|
|
392
|
+
channel["raw_hex"] = write_channel_fields(
|
|
393
|
+
channel["raw_hex"], {ChannelField.FAST_THRESHOLD: 42},
|
|
394
|
+
)
|
|
395
|
+
accepted = daq.write_configuration(
|
|
396
|
+
draft, chain=Chain.R1_R7, request_id=str(uuid4()),
|
|
397
|
+
)["workflow"]
|
|
398
|
+
print(daq.wait_for_workflow(accepted["id"])["state"])
|
|
399
|
+
```
|
|
400
|
+
|
|
401
|
+
Omit `chain` to write all 17 channel registers. To construct a draft from scratch,
|
|
402
|
+
pass a complete `Channel`-to-hex-word mapping and a complete `Chain`-to-`ChainClock`
|
|
403
|
+
mapping to `channel_draft(words, clocks)`. It uses the backend schema version
|
|
404
|
+
and profile, with groups and channels in canonical order.
|
|
405
|
+
|
|
406
|
+
#### Channel word fields
|
|
407
|
+
|
|
408
|
+
The DAQ accepts a ten-digit `raw_hex` word for each channel. These helpers use
|
|
409
|
+
the TRISK-J Table 5 bit positions displayed by the web editor. Physical field
|
|
410
|
+
mapping remains unverified. `read_channel_fields()` returns the raw integers and
|
|
411
|
+
`write_channel_fields()` preserves fields omitted from the update.
|
|
412
|
+
[Web editor field definitions](https://github.com/next-exp/asic-test-daq/blob/dev/docker-simulator/frontend/src/components/channel-word.ts)
|
|
413
|
+
|
|
414
|
+
| `ChannelField` | Bits | Values |
|
|
415
|
+
|---|---|---|
|
|
416
|
+
| `PREAMP_CONF` | 39–38 | `PreamplifierMode.PF_60_TO_320` (0), `PF_320` (1), `PF_500` (2), `PF_900_TO_NF_5_12` (3) |
|
|
417
|
+
| `PREAMP_OFFSET` | 37–33 | 0–31 |
|
|
418
|
+
| `INTEGRATOR_CALIB` | 32–30 | `IntegratorCalibration.NORMAL` (0), `B_LOW_THRESHOLD` (2), `B_HIGH_THRESHOLD` (3), `A_LOW_THRESHOLD` (4), `A_HIGH_THRESHOLD` (5) |
|
|
419
|
+
| `FAST_GEARBOX` | 29–26 | 0–15 |
|
|
420
|
+
| `FAST_THRESHOLD` | 25–18 | 0–255 |
|
|
421
|
+
| `TOT_THRESHOLD` | 17–12 | 0–63 |
|
|
422
|
+
| `SZJ_CALIB` | 11–9 | `SzjCalibration.MODE_B_GEARBOX` (2), `MODE_C_MAT_THRESHOLD` (5), `MODE_A_THR_TOT_THRESHOLD` (6), `NORMAL` (7) |
|
|
423
|
+
| `MAT_THRESHOLD` | 8–0 | 0–511 |
|
|
424
|
+
|
|
425
|
+
Raw integers are accepted for every field, including codes whose mode is
|
|
426
|
+
unspecified in the editor. Named modes use the same codes as the editor.
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
# ASIC Test2 Python client
|
|
2
|
+
|
|
3
|
+
`next-asictest-client` uses the same HTTP and Connect JSON endpoints as the web
|
|
4
|
+
console. The DAQ still owns FPGA communication, workflow admission, and
|
|
5
|
+
recordings. The client supports Python 3.10 or later and has no runtime
|
|
6
|
+
dependencies outside the standard library.
|
|
7
|
+
|
|
8
|
+
Install from PyPI:
|
|
9
|
+
|
|
10
|
+
```sh
|
|
11
|
+
python -m pip install next-asictest-client
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
From a checkout, install from the repository root:
|
|
15
|
+
|
|
16
|
+
```sh
|
|
17
|
+
python -m pip install ./python
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Read Board status
|
|
21
|
+
|
|
22
|
+
Pass the origin of the console without a route or hash fragment. The same client
|
|
23
|
+
also works with the DAQ's HTTP listener when it is directly reachable.
|
|
24
|
+
|
|
25
|
+
```python
|
|
26
|
+
from asictest import Client, StatusRegister, decode_bytes, decode_json
|
|
27
|
+
|
|
28
|
+
daq = Client("http://127.0.0.1:5173")
|
|
29
|
+
# For a protected installation, call daq.login(username, password) first.
|
|
30
|
+
print(daq.get_firmware()["profile"])
|
|
31
|
+
observation = daq.observe_firmware(StatusRegister.BOARD)
|
|
32
|
+
print(observation["source"], decode_json(observation["decodedJson"]))
|
|
33
|
+
print(decode_bytes(observation["rawPacket"]).hex(" "))
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
`session()`, `login()`, and `logout()` use the console's cookie-based access
|
|
37
|
+
control. Reuse the client instance for the lifetime of a session.
|
|
38
|
+
|
|
39
|
+
## Submit and inspect workflows
|
|
40
|
+
|
|
41
|
+
These examples are intended for a simulator. Channel and board-wide settings
|
|
42
|
+
are separate, just as in the console.
|
|
43
|
+
|
|
44
|
+
```python
|
|
45
|
+
from uuid import uuid4
|
|
46
|
+
from asictest import (
|
|
47
|
+
AsicPower, DataClockDivider, GeneralSettings, Opcode, ReadoutMask, ResetLevel,
|
|
48
|
+
)
|
|
49
|
+
|
|
50
|
+
command = daq.send_command(
|
|
51
|
+
Opcode.READ_STATUS, register=StatusRegister.BOARD, request_id=str(uuid4()),
|
|
52
|
+
)["workflow"]
|
|
53
|
+
result = daq.wait_for_workflow(command["id"])
|
|
54
|
+
print(result["state"], result.get("steps", []))
|
|
55
|
+
|
|
56
|
+
# Set GENERAL and gate timing on the simulator before acquiring data.
|
|
57
|
+
settings = GeneralSettings(
|
|
58
|
+
reset=ResetLevel.LOW,
|
|
59
|
+
power=AsicPower.OFF,
|
|
60
|
+
divider=DataClockDivider.DIV_1,
|
|
61
|
+
readout=ReadoutMask.ALL,
|
|
62
|
+
gate_width_ns=40,
|
|
63
|
+
gate_period_ns=496,
|
|
64
|
+
)
|
|
65
|
+
setup = daq.write_general(settings, request_id=str(uuid4()))["workflow"]
|
|
66
|
+
if daq.wait_for_workflow(setup["id"])["state"] != "completed":
|
|
67
|
+
raise RuntimeError("GENERAL configuration failed")
|
|
68
|
+
|
|
69
|
+
draft = daq.configuration() # Applied channel draft, or the server's example.
|
|
70
|
+
run = daq.start_run(draft, counter_test=True, duration_ms=500,
|
|
71
|
+
request_id=str(uuid4()))["workflow"]
|
|
72
|
+
result = daq.wait_for_workflow(run["id"])
|
|
73
|
+
print(result["state"], result.get("error", ""))
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
Omit `duration_ms` to run until stopped, then submit `daq.stop_run(request_id=...)`.
|
|
77
|
+
Workflows can continue after the client exits. `wait_for_workflow` returns the
|
|
78
|
+
terminal record, including failures, and a polling timeout leaves the workflow
|
|
79
|
+
running on the DAQ. Save the request ID and original payload before submission.
|
|
80
|
+
If the HTTP connection fails during submission, use the same ID and payload to
|
|
81
|
+
recover the original workflow. The client does not automatically retry
|
|
82
|
+
state-changing operations.
|
|
83
|
+
|
|
84
|
+
`execute_firmware(kind, payload, request_id=...)` accepts a dictionary or exact
|
|
85
|
+
JSON text/bytes. This covers the console's full and single-group configuration
|
|
86
|
+
writes, throughput, reset, and device workflows. Available workflow kinds depend
|
|
87
|
+
on the daemon installation.
|
|
88
|
+
|
|
89
|
+
See **Configuration symbols** for the register map, clock
|
|
90
|
+
selectors, readout mask, mode codes, and examples for changing one register
|
|
91
|
+
group or writing the complete 17-register draft.
|
|
92
|
+
|
|
93
|
+
## Run data and other API calls
|
|
94
|
+
|
|
95
|
+
```python
|
|
96
|
+
import json
|
|
97
|
+
import shutil
|
|
98
|
+
|
|
99
|
+
runs = daq.get_firmware().get("runs", [])
|
|
100
|
+
if runs:
|
|
101
|
+
run_id = runs[0]["runNumber"]
|
|
102
|
+
with daq.open_artifact(run_id, "manifest") as stream:
|
|
103
|
+
manifest = json.load(stream)
|
|
104
|
+
print(manifest["state"])
|
|
105
|
+
|
|
106
|
+
rtl = manifest.get("rtl", {})
|
|
107
|
+
if rtl.get("decoded_state") == "ready":
|
|
108
|
+
artifact = "decoded.h5" if rtl.get("decoded_format") == "hdf5" else "decoded.csv"
|
|
109
|
+
with daq.open_artifact(run_id, artifact) as stream, open(artifact, "xb") as output:
|
|
110
|
+
shutil.copyfileobj(stream, output)
|
|
111
|
+
|
|
112
|
+
events = daq.get_decoded_run_page(run_id, list_events=True, page_number=1)
|
|
113
|
+
if events.get("events"):
|
|
114
|
+
event = events["events"][0]
|
|
115
|
+
raw = daq.get_decoded_run_page(
|
|
116
|
+
run_id, event_ref=event["ref"], list_packets=True, page_number=1,
|
|
117
|
+
)
|
|
118
|
+
print(raw.get("totalEntries"))
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
The client also provides `list_command_history`, `get_run_samples`, calibration,
|
|
122
|
+
I²C monitoring, and audit helpers. For any API method, use the service and method
|
|
123
|
+
names from [the protobuf definitions](https://github.com/next-exp/asic-test-daq/tree/dev/docker-simulator/proto/asictest/v1):
|
|
124
|
+
|
|
125
|
+
```python
|
|
126
|
+
telemetry = daq.rpc("MonitoringService", "GetMonitoring", {"severity": "warning"})
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
Requests accept protobuf JSON field names or their original snake-case names.
|
|
130
|
+
Python `bytes` are encoded for protobuf bytes fields. Responses preserve the
|
|
131
|
+
server's protobuf JSON representation. Convert quoted 64-bit fields with
|
|
132
|
+
`int(value)` as needed. `decode_bytes` and `decode_json` unpack bytes and
|
|
133
|
+
JSON-in-bytes fields. Optional or unavailable values may be omitted by the server.
|
|
134
|
+
The API surface depends on the deployed release, and unavailable routes return an
|
|
135
|
+
`ApiError`. `TransportError` indicates a failed HTTP exchange or invalid response.
|
|
136
|
+
|
|
137
|
+
The PyPI project description includes the **Python API reference** and **Configuration symbols** sections.
|
|
138
|
+
|
|
139
|
+
## Tests
|
|
140
|
+
|
|
141
|
+
From the repository root:
|
|
142
|
+
|
|
143
|
+
```sh
|
|
144
|
+
PYTHONPATH=python/src python -m unittest discover -s python/tests -v
|
|
145
|
+
ASIC_TEST_PYTHON_SIMULATOR=1 PYTHONPATH=python/src python -m unittest discover -s python/tests -v
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
The second command requires the native HDF5 and Blosc dependencies described
|
|
149
|
+
in the project README. It builds the pinned Go daemon and simulator and uses temporary
|
|
150
|
+
storage and loopback sockets. It covers status reads, durable replay, capture,
|
|
151
|
+
decoded and raw data, downloads, telemetry, and symbolic GENERAL and channel writes.
|