ionpulse_sequence_generator 2.4.1__py3-none-any.whl

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.

Potentially problematic release.


This version of ionpulse_sequence_generator might be problematic. Click here for more details.

Files changed (37) hide show
  1. ionpulse_sequence_generator/__init__.py +91 -0
  2. ionpulse_sequence_generator/base/__init__.py +0 -0
  3. ionpulse_sequence_generator/base/configuration.py +23 -0
  4. ionpulse_sequence_generator/base/header.py +90 -0
  5. ionpulse_sequence_generator/base/jsonexportable.py +264 -0
  6. ionpulse_sequence_generator/event/__init__.py +0 -0
  7. ionpulse_sequence_generator/event/ddspidstatechange.py +65 -0
  8. ionpulse_sequence_generator/event/dioevent.py +73 -0
  9. ionpulse_sequence_generator/event/event.py +84 -0
  10. ionpulse_sequence_generator/event/multitonerfevent.py +139 -0
  11. ionpulse_sequence_generator/event/qubitevent.py +66 -0
  12. ionpulse_sequence_generator/event/readout.py +239 -0
  13. ionpulse_sequence_generator/event/singletonerfevent.py +185 -0
  14. ionpulse_sequence_generator/event/wait.py +63 -0
  15. ionpulse_sequence_generator/event/waveform.py +54 -0
  16. ionpulse_sequence_generator/hardware/__init__.py +0 -0
  17. ionpulse_sequence_generator/hardware/channel.py +115 -0
  18. ionpulse_sequence_generator/hardware/device.py +184 -0
  19. ionpulse_sequence_generator/hardware/hardware.py +780 -0
  20. ionpulse_sequence_generator/hardware/readout.py +500 -0
  21. ionpulse_sequence_generator/hardware/system.py +213 -0
  22. ionpulse_sequence_generator/hardware/units.py +97 -0
  23. ionpulse_sequence_generator/parameter/__init__.py +0 -0
  24. ionpulse_sequence_generator/parameter/parameter.py +479 -0
  25. ionpulse_sequence_generator/parameter/pid_parameter.py +118 -0
  26. ionpulse_sequence_generator/parameter/spline_parameter.py +370 -0
  27. ionpulse_sequence_generator/py.typed +0 -0
  28. ionpulse_sequence_generator/sequence/__init__.py +0 -0
  29. ionpulse_sequence_generator/sequence/conditional.py +121 -0
  30. ionpulse_sequence_generator/sequence/loop.py +108 -0
  31. ionpulse_sequence_generator/sequence/sequence.py +882 -0
  32. ionpulse_sequence_generator/utils/__init__.py +0 -0
  33. ionpulse_sequence_generator/utils/logging.py +96 -0
  34. ionpulse_sequence_generator/utils/utils.py +38 -0
  35. ionpulse_sequence_generator-2.4.1.dist-info/METADATA +52 -0
  36. ionpulse_sequence_generator-2.4.1.dist-info/RECORD +37 -0
  37. ionpulse_sequence_generator-2.4.1.dist-info/WHEEL +4 -0
@@ -0,0 +1,780 @@
1
+ import logging
2
+ from enum import Enum
3
+ from typing import Any
4
+
5
+ import numpy as np
6
+
7
+ from ionpulse_sequence_generator.hardware.channel import DEFAULT_CHANNEL, ChannelMask
8
+ from ionpulse_sequence_generator.hardware.units import Unit, Units, UnitType, machine_units
9
+
10
+ logger = logging.getLogger(__name__)
11
+
12
+
13
+ class Domain(Enum):
14
+ """
15
+ # Domain
16
+ Defines a range of domains `Hardware` classes belong to.
17
+ """
18
+
19
+ READOUT = 0
20
+ DIGITAL = 1
21
+ DDS = 2
22
+ QUENCH = 3
23
+ QUBIT = 4
24
+ DDS_ADC = 5
25
+ QUENCH_ADC = 6
26
+ FASTINO = 7
27
+
28
+
29
+ class Hardware:
30
+ """
31
+ # Hardware
32
+ Base class offering the following properties:
33
+ - channel mapping
34
+ - parameter conversion (to_<>, from_<>)
35
+ - limit checking (check_<>())
36
+ Child classes with specific parameter resolutions, limits, and channel implementations
37
+ can be added to a `Device`.
38
+
39
+ ## Channel Mapping
40
+ Each Hardware class implements a mapping (`_channel_dict`) from a hardware specific key
41
+ to a ChannelMask. These ChannelMasks can then be retrieved by calling `channel(key)`.
42
+
43
+ ## Parameter Conversion
44
+ Parameter conversion logic is implemented in this base class, converting float values
45
+ with Units to hardware internal unsigned values (used inside the parameter class for conversion)
46
+ to_<unit>(value, unit)
47
+ takes a value with a unit and converts it to internal values
48
+ This function will generate a warning when rounding or trucation occurs.
49
+ from_<unit>(value, unit)
50
+ takes an internal value and converts it to a value with the given unit
51
+
52
+ i.e. such that the following holds:
53
+ from_time(to_time(10, us), us) -> 10
54
+
55
+ ## Limit Checking
56
+ Checks for value limits for parameters used with this hardware. As these checks are
57
+ Hardware implementation specific, child classes might want to overwrite them. A basic
58
+ min/max checking is implemented in this base class.
59
+ check_<unit>(value, unit, **kwargs)
60
+ checks if the boundaries of this value for a given unit are observed
61
+ This function will generate an error if the value is not within the set boundaries
62
+ """
63
+
64
+ _freq_res_steps: np.uint
65
+ """Frequency resoltion steps of this hardware for parameter conversion"""
66
+ _phase_res_steps: np.uint
67
+ """Phase resoltion steps of this hardware for parameter conversion"""
68
+ _amp_res_steps: np.uint
69
+ """Amplitude resoltion steps of this hardware for parameter conversion"""
70
+ _time_resolution_ns: np.uint
71
+ """Time resoltion in ns of this hardware for parameter conversion"""
72
+
73
+ _freq_max: tuple[np.ndarray[Any, np.dtype[np.float64]], Unit]
74
+ """Frequecy upper limit, used for checking Frequency parameters when used with this Hardware"""
75
+ _freq_min: tuple[np.ndarray[Any, np.dtype[np.float64]], Unit]
76
+ """Frequency lower limit, used for checking Frequency parameters when used with this Hardware"""
77
+ _amp_max: tuple[np.ndarray[Any, np.dtype[np.float64]], Unit]
78
+ """Amplitude upper limit, used for checking Amplitude parameters when used with this Hardware"""
79
+ _amp_min: tuple[np.ndarray[Any, np.dtype[np.float64]], Unit]
80
+ """Amplitude lower limit, used for checking Amplitude parameters when used with this Hardware"""
81
+
82
+ _time_min_edge_ns: np.uint
83
+ """Minimum wait time before an event can be executed"""
84
+
85
+ _channel_dict: dict[Any, ChannelMask]
86
+ """Mapping the internal channel identifier to a ChannelMask"""
87
+ _hardware_channel_dict: dict[Any, Any]
88
+ """Mapping the internal channel identifier to a hardware channel identifier"""
89
+ _channels: ChannelMask
90
+ """Channels belonging to this hardware"""
91
+ _id: int = None # type: ignore
92
+ """Hardware id within a device"""
93
+ domain: Domain
94
+ """Domain this hardware belongs to."""
95
+
96
+ def __init__(self):
97
+ """Initialize conversion cache for runtime caching without precomputation."""
98
+ self._conversion_cache = {}
99
+ self._max_cache_size = 100000
100
+
101
+ def _get_cache_key(self, func_name: str, value: np.ndarray, unit: Unit) -> tuple:
102
+ """Generate cache key for conversion functions"""
103
+ if value.shape == ():
104
+ return (func_name, float(value), unit.name, unit.value)
105
+ else:
106
+ array_hash = hash(value.tobytes())
107
+ return (func_name, array_hash, unit.name, unit.value)
108
+
109
+ def _cache_conversion(self, func_name: str, value: np.ndarray, unit: Unit, result: np.ndarray) -> np.ndarray:
110
+ """Cache conversion result with LRU eviction"""
111
+ if len(self._conversion_cache) < self._max_cache_size:
112
+ cache_key = self._get_cache_key(func_name, value, unit)
113
+ self._conversion_cache[cache_key] = result.copy()
114
+ elif len(self._conversion_cache) >= self._max_cache_size:
115
+ oldest_key = next(iter(self._conversion_cache))
116
+ del self._conversion_cache[oldest_key]
117
+ cache_key = self._get_cache_key(func_name, value, unit)
118
+ self._conversion_cache[cache_key] = result.copy()
119
+ return result
120
+
121
+ def _get_cached_conversion(self, func_name: str, value: np.ndarray, unit: Unit) -> np.ndarray | None:
122
+ """Get cached conversion result if available"""
123
+ cache_key = self._get_cache_key(func_name, value, unit)
124
+ if cache_key in self._conversion_cache:
125
+ result = self._conversion_cache.pop(cache_key)
126
+ self._conversion_cache[cache_key] = result
127
+ return result.copy()
128
+ else:
129
+ return None
130
+
131
+ def channel(self, **kwargs: Any) -> ChannelMask:
132
+ """
133
+ **kwargs: A key for one channel, depending on the specific hardware implementation
134
+
135
+ Returns:
136
+ ChannelMask: The requested channel
137
+ """
138
+ return ChannelMask()
139
+
140
+ def log_conversion(self, name: str, value: np.ndarray, converted_value: int, unit: Unit, func) -> None:
141
+ """
142
+ Internal function to log warnings for rounding during conversion.
143
+
144
+ Args:
145
+ name (str): Name of the parameter type
146
+ value (np.ndarray): value to be converted
147
+ converted_value (int): converted value (after to_<>)
148
+ unit (Unit): Unit of the given value
149
+ func (from_<>): conversion function from this class
150
+ """
151
+ if value.shape == ():
152
+ logger.debug(
153
+ "%s %s %s rounded to %s %s!",
154
+ name,
155
+ value,
156
+ unit.name,
157
+ func(converted_value, unit),
158
+ unit.name,
159
+ )
160
+ else:
161
+ logger.debug(
162
+ "%s \n%s\n %s rounded to \n%s\n %s!",
163
+ name,
164
+ value,
165
+ unit.name,
166
+ func(converted_value, unit),
167
+ unit.name,
168
+ )
169
+
170
+ def to_amp(self, value: np.ndarray[Any, np.dtype[np.float64]], unit: Unit) -> np.ndarray[Any, np.dtype[np.uint16]]:
171
+ cached_result = self._get_cached_conversion("to_amp", value, unit)
172
+ if cached_result is not None:
173
+ return cached_result.astype(np.uint16)
174
+
175
+ v = np.round(value * unit.value * self._amp_res_steps).astype(np.uint16)
176
+ if np.any(self.from_amp(v, unit) != value):
177
+ self.log_conversion("Amplitude", value, v, unit, self.from_amp)
178
+
179
+ return self._cache_conversion("to_amp", value, unit, v)
180
+
181
+ def to_freq(self, value: np.ndarray[Any, np.dtype[np.float64]], unit: Unit) -> np.ndarray[Any, np.dtype[np.int32]]:
182
+ cached_result = self._get_cached_conversion("to_freq", value, unit)
183
+ if cached_result is not None:
184
+ return cached_result.astype(np.int32)
185
+
186
+ v = np.round(value * unit.value * self._freq_res_steps).astype(np.int32)
187
+ if np.any(self.from_freq(v, unit) != value):
188
+ self.log_conversion("Frequency", value, v, unit, self.from_freq)
189
+
190
+ return self._cache_conversion("to_freq", value, unit, v)
191
+
192
+ def to_phase(
193
+ self, value: np.ndarray[Any, np.dtype[np.float64]], unit: Unit
194
+ ) -> np.ndarray[Any, np.dtype[np.uint16]]:
195
+ cached_result = self._get_cached_conversion("to_phase", value, unit)
196
+ if cached_result is not None:
197
+ return cached_result.astype(np.uint16)
198
+
199
+ v = np.round(value * unit.value * self._phase_res_steps).astype(np.uint16)
200
+ if np.any(self.from_phase(v, unit) != value):
201
+ self.log_conversion("Phase", value, v, unit, self.from_phase)
202
+
203
+ return self._cache_conversion("to_phase", value, unit, v)
204
+
205
+ def to_time(self, value: np.ndarray[Any, np.dtype[np.float64]], unit: Unit) -> np.ndarray[Any, np.dtype[np.uint64]]:
206
+ cached_result = self._get_cached_conversion("to_time", value, unit)
207
+ if cached_result is not None:
208
+ return cached_result
209
+
210
+ ticks = np.round(value * unit.value / self._time_resolution_ns).astype(np.uint64)
211
+ v = ticks * self._time_resolution_ns
212
+ if np.any(self.from_time(v, unit) != value):
213
+ self.log_conversion("Time", value, v, unit, self.from_time)
214
+
215
+ return self._cache_conversion("to_time", value, unit, v)
216
+
217
+ def from_amp(
218
+ self, value: np.ndarray[Any, np.dtype[np.float64]], unit: Unit
219
+ ) -> np.ndarray[Any, np.dtype[np.float64]]:
220
+ return value / unit.value / self._amp_res_steps
221
+
222
+ def from_freq(
223
+ self, value: np.ndarray[Any, np.dtype[np.float64]], unit: Unit
224
+ ) -> np.ndarray[Any, np.dtype[np.float64]]:
225
+ return value / unit.value / self._freq_res_steps
226
+
227
+ def from_phase(
228
+ self, value: np.ndarray[Any, np.dtype[np.float64]], unit: Unit
229
+ ) -> np.ndarray[Any, np.dtype[np.float64]]:
230
+ return value / unit.value / self._phase_res_steps
231
+
232
+ def from_time(self, value: np.ndarray, unit: Unit) -> np.ndarray[Any, np.dtype[np.float64]]:
233
+ return value / unit.value
234
+
235
+ def check_freq(self, value: np.ndarray[Any, np.dtype[np.float64]], unit: Unit) -> None:
236
+ if value.shape == ():
237
+ if value > self.to_freq(*self._freq_max) or value < self.to_freq(*self._freq_min):
238
+ raise ValueError(
239
+ f"Frequency {self.from_freq(value, unit)} {unit.name} is out of \
240
+ range ({self._freq_min[0]} {self._freq_min[1].name}, {self._freq_max[0]} {self._freq_max[1].name})"
241
+ )
242
+ elif np.any(value > self.to_freq(*self._freq_max)) or np.any(value < self.to_freq(*self._freq_min)):
243
+ raise ValueError(
244
+ f"Frequency {self.from_freq(value, unit)} {unit.name} is out of \
245
+ range ({self._freq_min[0]} {self._freq_min[1].name}, {self._freq_max[0]} {self._freq_max[1].name})"
246
+ )
247
+
248
+ def check_phase(self, degree: np.ndarray[Any, np.dtype[np.float64]], unit: Unit) -> None:
249
+ pass # can in principle always be rounded to 360, should we warn the user?
250
+
251
+ def check_amp(self, value: np.ndarray[Any, np.dtype[np.float64]], unit: Unit) -> None:
252
+ if value.shape == ():
253
+ if value > self.to_amp(*self._amp_max) or value < self.to_amp(*self._amp_min):
254
+ raise ValueError(
255
+ f"Amplitude {self.from_amp(value, unit)} {unit.name} is out of \
256
+ range ({self._amp_min[0]} {self._amp_min[1].name}, {self._amp_max[0]} {self._amp_max[1].name})"
257
+ )
258
+ elif np.any(value > self.to_amp(*self._amp_max)) or np.any(value < self.to_amp(*self._amp_min)):
259
+ raise ValueError(
260
+ f"Amplitude {self.from_amp(value, unit)} {unit.name} is out of \
261
+ range ({self._amp_min[0]} {self._amp_min[1].name}, {self._amp_max[0]} {self._amp_max[1].name})"
262
+ )
263
+
264
+ def check_time(
265
+ self, value: np.ndarray[Any, np.dtype[np.uint64]], unit: Unit, edge: bool = False, **kwargs: Any
266
+ ) -> None:
267
+ """
268
+ Checks if the given time (value, unit) complies with the requirements of this hardware
269
+
270
+ Args:
271
+ value (np.ndarray): Time value
272
+ unit (Unit): Unit of the given value
273
+ edge (bool): if True, the time will be checked for complience with edge timing of this hardware.
274
+
275
+ Raises:
276
+ ValueError: If the given time is smaller than the minimum time.
277
+ """
278
+
279
+ if value.shape == ():
280
+ if value < self._time_resolution_ns:
281
+ raise ValueError(
282
+ f"Time {self.from_time(value, unit)} {unit.name} can not be \
283
+ smaller than the time resolution {self._time_resolution_ns / unit.value}!"
284
+ )
285
+ elif np.any(value < self._time_resolution_ns):
286
+ raise ValueError(
287
+ f"Time {self.from_time(value, unit)} {unit.name} can not be \
288
+ smaller than the time resolution {self._time_resolution_ns / unit.value}!"
289
+ )
290
+ if edge and np.any(value < self._time_min_edge_ns):
291
+ raise ValueError(
292
+ f"Time {self.from_time(value, unit)} {unit.name} can not be \
293
+ smaller than the minimum edge time {self._time_min_edge_ns / unit.value}!"
294
+ )
295
+
296
+ def get_min_edge_time(self, unit: Unit) -> float:
297
+ """
298
+ Returns:
299
+ float: The value of the minimum edge time for this Hardware in the given unit.
300
+ """
301
+ return float(self._time_min_edge_ns / unit.value)
302
+
303
+ def get_time_resolution(self, unit: Unit) -> float:
304
+ """
305
+ Returns:
306
+ float: The value of the time resolution for this Hardware in the given unit.
307
+ """
308
+ return float(self._time_resolution_ns / unit.value)
309
+
310
+ def __repr__(self) -> str:
311
+ return f"{self.__class__.__name__}: {self._channels}"
312
+
313
+ def get_num_channels(self) -> int:
314
+ """
315
+ Returns:
316
+ int: The number of channels contained by this Hardware
317
+ """
318
+ return len(self._channel_dict)
319
+
320
+
321
+ class DDSHardware(Hardware):
322
+ """
323
+ # DDSHardware
324
+ Hardware for the TIQI DDS cards. One DDS Hardware manages multiple DDS Cards within
325
+ an MTCA Rack, and assumes 4 channels per card.
326
+ """
327
+
328
+ domain = Domain.DDS
329
+
330
+ _freq_res_steps = machine_units["1Ghz"]
331
+ _phase_res_steps = machine_units["2pi"]
332
+ _amp_res_steps = machine_units["100%"]
333
+ _time_resolution_ns = 1 / machine_units["1ns"]
334
+ _voltage_resolution_mV = 1 / machine_units["1mV"] # noqa: N815
335
+
336
+ _freq_max = (np.array(400.0), Units.MHz)
337
+ _freq_min = (np.array(10.0), Units.MHz)
338
+ _amp_max = (np.array(100.0), Units.percent)
339
+ _amp_min = (np.array(0.0), Units.percent)
340
+
341
+ _time_min_edge_ns = 162 * _time_resolution_ns
342
+
343
+ _channels_per_slot = 4
344
+ """Number of rf channels per card"""
345
+ _tones_per_channel = 1
346
+ """Number of tones per channel"""
347
+
348
+ def __init__(self, slots: list) -> None:
349
+ """
350
+ Hardware for the TIQI DDS cards.
351
+
352
+ Args:
353
+ slots (list): Populated slots in the MTCA Rack, starting from 0. May be a sparse list.
354
+ """
355
+ super().__init__()
356
+ self._channel_dict = {}
357
+ self._hardware_channel_dict = {}
358
+ self._channels = ChannelMask()
359
+ # pre-fill ChannelMasks, will be filled out later by System
360
+ for slot in slots:
361
+ for i in range(self._channels_per_slot):
362
+ self._channel_dict[(slot, i)] = ChannelMask()
363
+ self._hardware_channel_dict[(slot, i)] = i + slot * self._channels_per_slot
364
+
365
+ def channel(self, channel: int, slot: int | None = None) -> ChannelMask:
366
+ """
367
+ Args:
368
+ channel (int): Number of the channel on the card or rack if no slot is given, starting from 0
369
+ slot (int | None, optional): Slot of the card to be indexed. Defaults to None.
370
+
371
+ Raises:
372
+ AttributeError: If the hardware is not part of a system.
373
+ ValueError: If the requested channel invalid.
374
+
375
+ Returns:
376
+ ChannelMask: The requested channel
377
+ """
378
+ if self._id is None:
379
+ raise AttributeError("This hardware must be part of a built system before you can request channels!")
380
+ if slot is not None:
381
+ if channel >= self._channels_per_slot:
382
+ raise ValueError(f"Requested ChannelMask for channel {channel} outside the given slot!")
383
+ return self._channel_dict[(slot, channel)]
384
+ else:
385
+ slot = int(np.floor(channel / self._channels_per_slot))
386
+ return self._channel_dict[(slot, channel % self._channels_per_slot)]
387
+
388
+ class SlopeTime(Enum):
389
+ """
390
+ # SlopeTime
391
+ Default slope time options for shaped pulses using the VGA on the DDS cards.
392
+ """
393
+
394
+ SLOWEST = 0
395
+ SLOW = 1
396
+ MEDIUM = 2
397
+ FAST = 3
398
+
399
+ slope_time_max = (2**18 - 1) * _time_resolution_ns * Units.ns.value
400
+ """Maximum slope time for shaped pulses using the VGA"""
401
+ slope_time_min = 6 * _time_resolution_ns * Units.ns.value # > 5 clock cycles for VGA ramp
402
+ """Minimum slope time for shaped pulses using the VGA"""
403
+ slope_time_delay = 400 * Units.ns.value
404
+
405
+ @classmethod
406
+ def get_slope_time(cls, slope: SlopeTime, unit: Unit) -> float:
407
+ """
408
+ Args:
409
+ slope (SlopeTime): Default slope time option
410
+ unit (Unit): Unit of the returned value
411
+
412
+ Returns:
413
+ float: time value in the given unit
414
+ """
415
+ match slope:
416
+ case cls.SlopeTime.SLOWEST:
417
+ return cls.slope_time_max / unit.value
418
+ case cls.SlopeTime.SLOW:
419
+ return 3.0 * Units.us.value / unit.value
420
+ case cls.SlopeTime.MEDIUM:
421
+ return 1.2 * Units.us.value / unit.value
422
+ case cls.SlopeTime.FAST:
423
+ return cls.slope_time_min / unit.value
424
+
425
+ def check_time(self, value: np.ndarray[Any, np.dtype[np.uint64]], unit: Unit, **kwargs: Any) -> None:
426
+ """
427
+ Checks if the given time (value, unit) complies with the requirements of this hardware
428
+
429
+ Args:
430
+ value (np.ndarray): Time value
431
+ unit (Unit): Unit of the given value
432
+ edge (bool): if True, the time will be checked for complience with edge timing of this hardware.
433
+ slope_time (bool): if True, the time will be checked for complience with shaped edges of this hardware.
434
+
435
+ Raises:
436
+ ValueError: If the given time is smaller than the minimum time.
437
+ """
438
+ super().check_time(value, unit, **kwargs)
439
+ if (
440
+ kwargs.get("slope_time", False)
441
+ and np.any(value > self.slope_time_max)
442
+ and np.any(value < self.slope_time_min)
443
+ ):
444
+ raise ValueError(
445
+ f"SlopeTime {value / unit.value} is out of range \
446
+ {(self.slope_time_min / unit.value, self.slope_time_max / unit.value)}!"
447
+ )
448
+
449
+ class PIDStateChangeType(Enum):
450
+ NONE = 0
451
+ ACTIVATE = 1
452
+ RESET = 2
453
+ OVERRIDE = 3
454
+
455
+ reference_voltage_max = 300.0 * Units.mV.value
456
+
457
+ def to_refv(self, value: float, unit: Unit, pid_ch: int = 0, adc_ch: int = 0):
458
+ """
459
+ Args:
460
+ value (float): value of the reference voltage in the given Unit
461
+ unit (Unit): Unit of the reference voltage
462
+ pid_ch (int, optional): PID channel for this setting (0-7). Defaults to 0.
463
+ adc_ch (int, optional): ADC channel on the card (0-1). Defaults to 0.
464
+
465
+ Raises:
466
+ ValueError: If the given Unit is not a voltage unit
467
+ ValueError: If the given voltage is above the max. ADC voltage range
468
+
469
+ Returns:
470
+ int : reference voltage setting for the DDS card PID core
471
+ """
472
+ if unit not in UnitType.voltage:
473
+ raise ValueError(f"Unknown voltage unit {unit}!")
474
+ if value * unit.value > self.reference_voltage_max or value < 0:
475
+ raise ValueError(
476
+ f"Voltage {value} {unit.name} outside of ADC voltage"
477
+ f" range 0 - {self.reference_voltage_max} {Units.mV.name}!"
478
+ )
479
+ return (
480
+ ((pid_ch & 0x7) << 15)
481
+ | (np.uint32(adc_ch) << 14)
482
+ | (np.uint32(np.round(value * unit.value / self._voltage_resolution_mV)) & 0x3FFF)
483
+ )
484
+
485
+ def get_slot(self, channel: ChannelMask) -> int:
486
+ return list(self._channel_dict.keys())[list(self._channel_dict.values()).index(channel)][0]
487
+
488
+
489
+ class DIOHardware(Hardware):
490
+ """
491
+ # DIOHardware
492
+ Hardware for digital inputs and outputs. Currently only one IO channel with either
493
+ 32 bit (M-ACTION) or 16 bit (Quench RFSoC) width output and 2 bit width input (PMT)
494
+ is availiable
495
+ """
496
+
497
+ domain = Domain.DIGITAL
498
+
499
+ _time_resolution_ns = 1 / machine_units["1ns"]
500
+
501
+ _time_min_edge_ns = 10 * _time_resolution_ns
502
+
503
+ _n_cam_ions_max = 10
504
+
505
+ def __init__(self) -> None:
506
+ """
507
+ Hardware for digital inputs and outputs.
508
+ """
509
+ super().__init__()
510
+ self._channel_dict = {}
511
+ self._hardware_channel_dict = {}
512
+ self._channels = ChannelMask()
513
+ self._channel_dict[(0, 0)] = ChannelMask()
514
+ self._hardware_channel_dict[(0, 0)] = DEFAULT_CHANNEL
515
+
516
+ def channel(self) -> ChannelMask:
517
+ """
518
+ Raises:
519
+ AttributeError: If the Hardware is not part of a system.
520
+
521
+ Returns:
522
+ ChannelMask: The channel of the DIO hardware
523
+ """
524
+ if self._id is None:
525
+ raise AttributeError("This hardware must be part of a built system before you can request channels!")
526
+ return self._channel_dict[(0, 0)]
527
+
528
+
529
+ class QuenchHardware(Hardware):
530
+ """
531
+ # QuenchHardware
532
+ Hardware for Quench RFSoC (16 channels) and Quench MTCA (controlling multiple Quench
533
+ ACFK cards with 8 channels each).
534
+ """
535
+
536
+ domain = Domain.QUENCH
537
+
538
+ _freq_res_steps = machine_units["1Ghz"]
539
+ _phase_res_steps = machine_units["2pi"]
540
+ _amp_res_steps = machine_units["100%"]
541
+ _time_resolution_ns = (1 / machine_units["1ns"]) / 2 # 4 ns FIXME once DDS is gone
542
+
543
+ _freq_max = (np.array(400.0), Units.MHz)
544
+ _freq_min = (np.array(0.06), Units.MHz)
545
+ _amp_max = (np.array(100.0), Units.percent)
546
+ _amp_min = (np.array(0.0), Units.percent)
547
+
548
+ _time_min_edge_ns = np.uint(34 * _time_resolution_ns)
549
+ _time_min_shaping_ns = np.uint(34 * _time_resolution_ns)
550
+ _time_min_shaping_interval_ns = np.uint(10 * _time_resolution_ns)
551
+
552
+ _channels_per_slot = 8
553
+ """Number of channels per slot"""
554
+
555
+ _tones_per_channel = 4
556
+ """Number of tones per channel"""
557
+ _freq_interpolator_max_order = 2
558
+ _phase_interpolator_max_order = 1
559
+ _amp_interpolator_max_order = 3
560
+
561
+ def __init__(self, slots: list) -> None:
562
+ """
563
+ Hardware for the Quench RFSoC and Quench MTCA.
564
+
565
+ Args:
566
+ slots (list): [0, 1] for the RFSoC or populated slots in the MTCA Rack, starting from 0.
567
+ May be a sparse list.
568
+ """
569
+ super().__init__()
570
+ self._channel_dict = {}
571
+ self._hardware_channel_dict = {}
572
+ self._channels = ChannelMask()
573
+ # pre-fill ChannelMasks, will be filled out later by System
574
+ for slot in slots:
575
+ for i in range(self._channels_per_slot):
576
+ self._channel_dict[(slot, i)] = ChannelMask()
577
+ self._hardware_channel_dict[(slot, i)] = i + slot * self._channels_per_slot
578
+
579
+ def channel(self, channel: int, slot: int | None = None) -> ChannelMask:
580
+ """
581
+ Args:
582
+ channel (int): Number of the channel on the card or rack if no slot is given, starting from 0
583
+ slot (int | None, optional): Slot of the card to be indexed. Defaults to None.
584
+
585
+ Raises:
586
+ AttributeError: If the hardware is not part of a system.
587
+ ValueError: If the requested channel invalid.
588
+
589
+ Returns:
590
+ ChannelMask: The requested channel
591
+ """
592
+ if self._id is None:
593
+ raise AttributeError("This hardware must be part of a built system before you can request channels!")
594
+ if slot is not None:
595
+ if channel >= self._channels_per_slot:
596
+ raise ValueError("Requested ChannelMask for channels outside the given slot!")
597
+ return self._channel_dict[(slot, channel)]
598
+ else:
599
+ slot = np.floor(channel / self._channels_per_slot)
600
+ return self._channel_dict[(slot, channel % self._channels_per_slot)]
601
+
602
+ def check_time(self, value: np.ndarray, unit: Unit, **kwargs) -> None:
603
+ """
604
+ Checks if the given time (value, unit) complies with the requirements of this hardware
605
+
606
+ Args:
607
+ value (np.ndarray): Time value
608
+ unit (Unit): Unit of the given value
609
+ edge (bool): if True, the time will be checked for complience with edge timing of this hardware.
610
+ shaping (bool): if True, the time will be checked for complience with shaping of this hardware.
611
+
612
+ Raises:
613
+ ValueError: If the given time is smaller than the minimum time.
614
+ """
615
+ super().check_time(value, unit, **kwargs)
616
+ if kwargs.get("shaping", False) and np.any(value < self._time_min_shaping_ns):
617
+ raise ValueError(
618
+ f"Shaping time {value} can not be smaller than the minimum shaping time "
619
+ f"{self._time_min_shaping_ns / unit.value} {unit.name}!"
620
+ )
621
+
622
+
623
+ class DDSADCHardware(Hardware):
624
+ """
625
+ # DDSADCHardware
626
+ Hardware for the DDS ADCs (2 ADC channels per card)
627
+ """
628
+
629
+ domain = Domain.DDS_ADC
630
+
631
+ _channels_per_slot = 2
632
+ """Number of channels per slot"""
633
+
634
+ def __init__(self, slots: list) -> None:
635
+ """
636
+ Hardware for the Quench RFSoC and Quench MTCA.
637
+
638
+ Args:
639
+ slots (list): [0, 1] for the RFSoC or populated slots in the MTCA Rack, starting from 0.
640
+ May be a sparse list.
641
+ """
642
+ super().__init__()
643
+ self._channel_dict = {}
644
+ self._hardware_channel_dict = {}
645
+ self._channels = ChannelMask()
646
+ # pre-fill ChannelMasks, will be filled out later by System
647
+ for slot in slots:
648
+ for i in range(self._channels_per_slot):
649
+ self._channel_dict[(slot, i)] = ChannelMask()
650
+ self._hardware_channel_dict[(slot, i)] = i + slot * self._channels_per_slot
651
+
652
+ def channel(self, channel: int, slot: int | None = None) -> ChannelMask:
653
+ """
654
+ Args:
655
+ channel (int): Number of the channel on the card or rack if no slot is given, starting from 0
656
+ slot (int | None, optional): Slot of the card to be indexed. Defaults to None.
657
+
658
+ Raises:
659
+ AttributeError: If the hardware is not part of a system.
660
+ ValueError: If the requested channel invalid.
661
+
662
+ Returns:
663
+ ChannelMask: The requested channel
664
+ """
665
+ if self._id is None:
666
+ raise AttributeError("This hardware must be part of a built system before you can request channels!")
667
+ if slot is not None:
668
+ if channel >= self._channels_per_slot:
669
+ raise ValueError("Requested ChannelMask for channels outside the given slot!")
670
+ return self._channel_dict[(slot, channel)]
671
+ else:
672
+ slot = np.floor(channel / self._channels_per_slot)
673
+ return self._channel_dict[(slot, channel % self._channels_per_slot)]
674
+
675
+ def get_ADC_index(self, channel: ChannelMask) -> int: # noqa: N802
676
+ return list(self._channel_dict.keys())[list(self._channel_dict.values()).index(channel)][1]
677
+
678
+ def get_slot(self, channel: ChannelMask) -> int:
679
+ return list(self._channel_dict.keys())[list(self._channel_dict.values()).index(channel)][0]
680
+
681
+
682
+ class QuenchADCHardware(Hardware):
683
+ """
684
+ # DDSADCHardware
685
+ Hardware for the DDS ADCs (2 ADC channels per card)
686
+ """
687
+
688
+ domain = Domain.QUENCH_ADC
689
+
690
+ _channels_per_slot = 8
691
+ """Number of channels per slot"""
692
+
693
+ def __init__(self, slots: list) -> None:
694
+ """
695
+ Hardware for the Quench RFSoC and Quench MTCA.
696
+
697
+ Args:
698
+ slots (list): [0, 1] for the RFSoC or populated slots in the MTCA Rack, starting from 0.
699
+ May be a sparse list.
700
+ """
701
+ super().__init__()
702
+ self._channel_dict = {}
703
+ self._hardware_channel_dict = {}
704
+ self._channels = ChannelMask()
705
+ # pre-fill ChannelMasks, will be filled out later by System
706
+ for slot in slots:
707
+ for i in range(self._channels_per_slot):
708
+ self._channel_dict[(slot, i)] = ChannelMask()
709
+ self._hardware_channel_dict[(slot, i)] = i + slot * self._channels_per_slot
710
+
711
+ def channel(self, channel: int, slot: int | None = None) -> ChannelMask:
712
+ """
713
+ Args:
714
+ channel (int): Number of the channel on the card or rack if no slot is given, starting from 0
715
+ slot (int | None, optional): Slot of the card to be indexed. Defaults to None.
716
+
717
+ Raises:
718
+ AttributeError: If the hardware is not part of a system.
719
+ ValueError: If the requested channel invalid.
720
+
721
+ Returns:
722
+ ChannelMask: The requested channel
723
+ """
724
+ if self._id is None:
725
+ raise AttributeError("This hardware must be part of a built system before you can request channels!")
726
+ if slot is not None:
727
+ if channel >= self._channels_per_slot:
728
+ raise ValueError("Requested ChannelMask for channels outside the given slot!")
729
+ return self._channel_dict[(slot, channel)]
730
+ else:
731
+ slot = np.floor(channel / self._channels_per_slot)
732
+ return self._channel_dict[(slot, channel % self._channels_per_slot)]
733
+
734
+
735
+ class FastinoHardware(Hardware):
736
+ """
737
+ # FastinoHardware
738
+ Hardware for the Fastino AWG (32 channels per card)
739
+
740
+ CM: at the moment this hardware (and the corresponding Device) only has one single channel,
741
+ used for waveform sequencing.
742
+ """
743
+
744
+ domain = Domain.FASTINO
745
+ _time_resolution_ns = 392
746
+ _time_min_edge_ns = 392
747
+ _voltage_max = (np.array(10.0), Units.V)
748
+ _voltage_min = (np.array(-10.0), Units.V)
749
+
750
+ _channels_per_slot = 32
751
+ """Number of channels per slot"""
752
+
753
+ def __init__(self, n_cards: int) -> None:
754
+ """
755
+ Hardware for the TIQI DDS cards.
756
+
757
+ Args:
758
+ n_slots (int): Number of Fastino cards
759
+ """
760
+ self._n_cards = n_cards
761
+ self._channel_dict = {}
762
+ self._hardware_channel_dict = {}
763
+ self._channels = ChannelMask()
764
+ self._channel_dict[(0, 0)] = ChannelMask()
765
+ self._hardware_channel_dict[(0, 0)] = DEFAULT_CHANNEL
766
+
767
+ def channel(self) -> ChannelMask:
768
+ """
769
+ Raises:
770
+ AttributeError: If the Hardware is not part of a system.
771
+
772
+ Returns:
773
+ ChannelMask: The channel of the DIO hardware
774
+ """
775
+ if self._id is None:
776
+ raise AttributeError("This hardware must be part of a built system before you can request channels!")
777
+ return self._channel_dict[(0, 0)]
778
+
779
+ def get_num_channels(self):
780
+ return self._n_cards * self._channels_per_slot