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.
- ionpulse_sequence_generator/__init__.py +91 -0
- ionpulse_sequence_generator/base/__init__.py +0 -0
- ionpulse_sequence_generator/base/configuration.py +23 -0
- ionpulse_sequence_generator/base/header.py +90 -0
- ionpulse_sequence_generator/base/jsonexportable.py +264 -0
- ionpulse_sequence_generator/event/__init__.py +0 -0
- ionpulse_sequence_generator/event/ddspidstatechange.py +65 -0
- ionpulse_sequence_generator/event/dioevent.py +73 -0
- ionpulse_sequence_generator/event/event.py +84 -0
- ionpulse_sequence_generator/event/multitonerfevent.py +139 -0
- ionpulse_sequence_generator/event/qubitevent.py +66 -0
- ionpulse_sequence_generator/event/readout.py +239 -0
- ionpulse_sequence_generator/event/singletonerfevent.py +185 -0
- ionpulse_sequence_generator/event/wait.py +63 -0
- ionpulse_sequence_generator/event/waveform.py +54 -0
- ionpulse_sequence_generator/hardware/__init__.py +0 -0
- ionpulse_sequence_generator/hardware/channel.py +115 -0
- ionpulse_sequence_generator/hardware/device.py +184 -0
- ionpulse_sequence_generator/hardware/hardware.py +780 -0
- ionpulse_sequence_generator/hardware/readout.py +500 -0
- ionpulse_sequence_generator/hardware/system.py +213 -0
- ionpulse_sequence_generator/hardware/units.py +97 -0
- ionpulse_sequence_generator/parameter/__init__.py +0 -0
- ionpulse_sequence_generator/parameter/parameter.py +479 -0
- ionpulse_sequence_generator/parameter/pid_parameter.py +118 -0
- ionpulse_sequence_generator/parameter/spline_parameter.py +370 -0
- ionpulse_sequence_generator/py.typed +0 -0
- ionpulse_sequence_generator/sequence/__init__.py +0 -0
- ionpulse_sequence_generator/sequence/conditional.py +121 -0
- ionpulse_sequence_generator/sequence/loop.py +108 -0
- ionpulse_sequence_generator/sequence/sequence.py +882 -0
- ionpulse_sequence_generator/utils/__init__.py +0 -0
- ionpulse_sequence_generator/utils/logging.py +96 -0
- ionpulse_sequence_generator/utils/utils.py +38 -0
- ionpulse_sequence_generator-2.4.1.dist-info/METADATA +52 -0
- ionpulse_sequence_generator-2.4.1.dist-info/RECORD +37 -0
- ionpulse_sequence_generator-2.4.1.dist-info/WHEEL +4 -0
|
@@ -0,0 +1,479 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import logging
|
|
4
|
+
from enum import Enum
|
|
5
|
+
from typing import TYPE_CHECKING, ClassVar
|
|
6
|
+
|
|
7
|
+
import numpy as np
|
|
8
|
+
|
|
9
|
+
if TYPE_CHECKING:
|
|
10
|
+
from typing import Any
|
|
11
|
+
|
|
12
|
+
from ionpulse_sequence_generator.base.jsonexportable import JSONexportable
|
|
13
|
+
from ionpulse_sequence_generator.hardware.system import System
|
|
14
|
+
from ionpulse_sequence_generator.hardware.units import Unit, Units, UnitType
|
|
15
|
+
|
|
16
|
+
logger = logging.getLogger(__name__)
|
|
17
|
+
|
|
18
|
+
ParameterValueType = float | bool | int | str | Enum
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class Parameter:
|
|
22
|
+
def __init__(
|
|
23
|
+
self,
|
|
24
|
+
value: ParameterValueType | list[ParameterValueType] | np.ndarray,
|
|
25
|
+
unit: Unit,
|
|
26
|
+
name: str = "",
|
|
27
|
+
) -> None:
|
|
28
|
+
"""
|
|
29
|
+
Args:
|
|
30
|
+
value (np.ndarray): converted parameter values (looped)
|
|
31
|
+
unit (Unit): unit of the paramter value
|
|
32
|
+
name (str, optional): name for the parameter, exported in debug mode.
|
|
33
|
+
"""
|
|
34
|
+
self._name = name
|
|
35
|
+
self._value = value
|
|
36
|
+
self._unit = unit
|
|
37
|
+
|
|
38
|
+
def __str__(self) -> str:
|
|
39
|
+
return str(self.__repr__())
|
|
40
|
+
|
|
41
|
+
def value(self, unit: Unit | None = None):
|
|
42
|
+
return self._value
|
|
43
|
+
|
|
44
|
+
def __repr__(self) -> str:
|
|
45
|
+
return f"{self.value(self._unit)} {self._unit.name}"
|
|
46
|
+
|
|
47
|
+
def __add__(self, other):
|
|
48
|
+
if self._unit == other._unit:
|
|
49
|
+
return self.__class__(self._value + other._value, self._unit)
|
|
50
|
+
else:
|
|
51
|
+
raise ValueError("Can only add parameters with the same units!")
|
|
52
|
+
|
|
53
|
+
def __sub__(self, other):
|
|
54
|
+
if self._unit == other._unit:
|
|
55
|
+
return self.__class__(self._value - other._value, self._unit)
|
|
56
|
+
else:
|
|
57
|
+
raise ValueError("Can only subtract parameters with the same units!")
|
|
58
|
+
|
|
59
|
+
def __mul__(self, other):
|
|
60
|
+
if self._unit == other._unit:
|
|
61
|
+
return self.__class__(self._value * other._value, self._unit)
|
|
62
|
+
else:
|
|
63
|
+
raise ValueError("Can only multiply parameters with the same units!")
|
|
64
|
+
|
|
65
|
+
def __truediv__(self, other):
|
|
66
|
+
if self._unit == other._unit:
|
|
67
|
+
return self.__class__(self._value / other._value, self._unit)
|
|
68
|
+
else:
|
|
69
|
+
raise ValueError("Can only divide parameters with the same units!")
|
|
70
|
+
|
|
71
|
+
def __radd__(self, other):
|
|
72
|
+
return self.__add__(other)
|
|
73
|
+
|
|
74
|
+
def __rsub__(self, other):
|
|
75
|
+
return self.__sub__(other)
|
|
76
|
+
|
|
77
|
+
def __rmul__(self, other):
|
|
78
|
+
return self.__mul__(other)
|
|
79
|
+
|
|
80
|
+
def __rtruediv__(self, other):
|
|
81
|
+
return self.__truediv__(other)
|
|
82
|
+
|
|
83
|
+
def __lt__(self, other) -> bool:
|
|
84
|
+
if self._unit == other._unit:
|
|
85
|
+
return bool(self._value.__lt__(other._value)) # type: ignore
|
|
86
|
+
else:
|
|
87
|
+
raise ValueError("Can only divide parameters with the same units!")
|
|
88
|
+
|
|
89
|
+
def __le__(self, other) -> bool:
|
|
90
|
+
if self._unit == other._unit:
|
|
91
|
+
return bool(self._value.__le__(other._value)) # type: ignore
|
|
92
|
+
else:
|
|
93
|
+
raise ValueError("Can only divide parameters with the same units!")
|
|
94
|
+
|
|
95
|
+
def __eq__(self, other) -> bool:
|
|
96
|
+
if self._unit == other._unit:
|
|
97
|
+
return bool(self._value.__eq__(other._value)) # type: ignore
|
|
98
|
+
else:
|
|
99
|
+
raise ValueError("Can only divide parameters with the same units!")
|
|
100
|
+
|
|
101
|
+
def __ne__(self, other) -> bool:
|
|
102
|
+
if self._unit == other._unit:
|
|
103
|
+
return bool(self._value.__ne__(other._value)) # type: ignore
|
|
104
|
+
else:
|
|
105
|
+
raise ValueError("Can only divide parameters with the same units!")
|
|
106
|
+
|
|
107
|
+
def __ge__(self, other) -> bool:
|
|
108
|
+
if self._unit == other._unit:
|
|
109
|
+
return bool(self._value.__ge__(other._value)) # type: ignore
|
|
110
|
+
else:
|
|
111
|
+
raise ValueError("Can only divide parameters with the same units!")
|
|
112
|
+
|
|
113
|
+
def __gt__(self, other) -> bool:
|
|
114
|
+
if self._unit == other._unit:
|
|
115
|
+
return bool(self._value.__gt__(other._value)) # type: ignore
|
|
116
|
+
else:
|
|
117
|
+
raise ValueError("Can only divide parameters with the same units!")
|
|
118
|
+
|
|
119
|
+
def __bool__(self) -> bool:
|
|
120
|
+
return bool(self._value != 0)
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
class JSONexportableParameter(Parameter, JSONexportable):
|
|
124
|
+
"""
|
|
125
|
+
# Parameter
|
|
126
|
+
This abstract base class provides appropriate overrides for JSONexportable methods
|
|
127
|
+
for storing system parameters. Parameter values are provided as nd_array
|
|
128
|
+
(looped parameters, see LoopSequence) with a unit attached and converted using
|
|
129
|
+
conversion functions from a hardware.
|
|
130
|
+
|
|
131
|
+
## Parameter classes
|
|
132
|
+
should be defined as child classes with class variables, e.g.
|
|
133
|
+
class Length(Parameter):
|
|
134
|
+
instances = []
|
|
135
|
+
typename="Length"
|
|
136
|
+
for objects to register to (see JSONexportable).
|
|
137
|
+
"""
|
|
138
|
+
|
|
139
|
+
__slots__ = ("_unit", "_value")
|
|
140
|
+
|
|
141
|
+
def __init__(
|
|
142
|
+
self,
|
|
143
|
+
value: np.ndarray,
|
|
144
|
+
unit: Unit,
|
|
145
|
+
name: str = "",
|
|
146
|
+
) -> None:
|
|
147
|
+
"""
|
|
148
|
+
Args:
|
|
149
|
+
value (np.ndarray): converted parameter values (looped)
|
|
150
|
+
unit (Unit): unit of the paramter value
|
|
151
|
+
name (str, optional): name for the parameter, exported in debug mode.
|
|
152
|
+
"""
|
|
153
|
+
Parameter.__init__(self, value, unit, name)
|
|
154
|
+
JSONexportable.__init__(self, name)
|
|
155
|
+
|
|
156
|
+
def __hash__(self) -> int:
|
|
157
|
+
if self._value.shape == ():
|
|
158
|
+
return hash(float(self._value))
|
|
159
|
+
else:
|
|
160
|
+
return hash(self._value.tobytes())
|
|
161
|
+
|
|
162
|
+
def __str__(self) -> str:
|
|
163
|
+
return self.__repr__()
|
|
164
|
+
|
|
165
|
+
def content_v(self) -> tuple:
|
|
166
|
+
return (self._value,)
|
|
167
|
+
|
|
168
|
+
def content_k(self) -> tuple:
|
|
169
|
+
return ("value",)
|
|
170
|
+
|
|
171
|
+
def __add__(self, other):
|
|
172
|
+
if self.typename == other.typename:
|
|
173
|
+
o = self.__class__(np.array(0), self._unit)
|
|
174
|
+
o._value = self._value + other._value
|
|
175
|
+
return o
|
|
176
|
+
else:
|
|
177
|
+
raise ValueError("Can only add parameters of the same type!")
|
|
178
|
+
|
|
179
|
+
def __sub__(self, other):
|
|
180
|
+
if self.typename == other.typename:
|
|
181
|
+
o = self.__class__(np.array(0), self._unit)
|
|
182
|
+
o._value = self._value - other._value
|
|
183
|
+
return o
|
|
184
|
+
else:
|
|
185
|
+
raise ValueError("Can only subtract parameters of the same type!")
|
|
186
|
+
|
|
187
|
+
def __mul__(self, other):
|
|
188
|
+
if isinstance(other, float | int | np.number):
|
|
189
|
+
o = self.__class__(np.array(0), self._unit)
|
|
190
|
+
o._value = self._value * other
|
|
191
|
+
return o
|
|
192
|
+
else:
|
|
193
|
+
raise ValueError("Multiplication of paramters with non-number types is not supported!")
|
|
194
|
+
|
|
195
|
+
def __truediv__(self, other):
|
|
196
|
+
if self.typename == other.typename:
|
|
197
|
+
return self.__class__(self._value / other._value, self._unit)
|
|
198
|
+
else:
|
|
199
|
+
raise ValueError("Can only divide parameters of the same type!")
|
|
200
|
+
|
|
201
|
+
def __radd__(self, other):
|
|
202
|
+
return self.__add__(other)
|
|
203
|
+
|
|
204
|
+
def __rsub__(self, other):
|
|
205
|
+
return self.__sub__(other)
|
|
206
|
+
|
|
207
|
+
def __rmul__(self, other):
|
|
208
|
+
return self.__mul__(other)
|
|
209
|
+
|
|
210
|
+
def __rtruediv__(self, other):
|
|
211
|
+
return self.__truediv__(other)
|
|
212
|
+
|
|
213
|
+
def __lt__(self, other):
|
|
214
|
+
return self._value.__lt__(other._value) # type: ignore
|
|
215
|
+
|
|
216
|
+
def __le__(self, other):
|
|
217
|
+
return self._value.__le__(other._value) # type: ignore
|
|
218
|
+
|
|
219
|
+
def __eq__(self, other):
|
|
220
|
+
if self._value.shape != other._value.shape:
|
|
221
|
+
return False
|
|
222
|
+
elif self._value.shape == () and other._value.shape == ():
|
|
223
|
+
return self._value == other._value
|
|
224
|
+
else:
|
|
225
|
+
return np.array_equal(self._value, other._value)
|
|
226
|
+
|
|
227
|
+
def __ne__(self, other):
|
|
228
|
+
return self._value.__ne__(other._value) # type: ignore
|
|
229
|
+
|
|
230
|
+
def __ge__(self, other):
|
|
231
|
+
return self._value.__ge__(other._value) # type: ignore
|
|
232
|
+
|
|
233
|
+
def __gt__(self, other):
|
|
234
|
+
return self._value.__gt__(other._value) # type: ignore
|
|
235
|
+
|
|
236
|
+
|
|
237
|
+
class Freq(JSONexportableParameter):
|
|
238
|
+
"""
|
|
239
|
+
# Frequency
|
|
240
|
+
defines simple and looped frequency parameters used in DDS and Quench Hardware.
|
|
241
|
+
"""
|
|
242
|
+
|
|
243
|
+
__slots__ = []
|
|
244
|
+
_instances: dict[int, Any] = {}
|
|
245
|
+
"""All instances of the class, keeping track of existing objects."""
|
|
246
|
+
_instance_dict: ClassVar[dict] = {}
|
|
247
|
+
"""Lookup dict to enable register() to find existing objects."""
|
|
248
|
+
typename = "freq"
|
|
249
|
+
|
|
250
|
+
def __init__(
|
|
251
|
+
self,
|
|
252
|
+
value: float | list[float] | np.ndarray,
|
|
253
|
+
unit: Unit,
|
|
254
|
+
name="",
|
|
255
|
+
) -> None:
|
|
256
|
+
"""
|
|
257
|
+
Args:
|
|
258
|
+
value (float | list[float] | np.ndarray): Frequency value or array (looped time)
|
|
259
|
+
unit (Unit): Unit of the given value
|
|
260
|
+
name (str, optional): Name of the frequency, used for debugging. Defaults to "".
|
|
261
|
+
|
|
262
|
+
Raises:
|
|
263
|
+
ValueError: If the unit is not a frequency unit.
|
|
264
|
+
"""
|
|
265
|
+
if unit not in UnitType.frequency:
|
|
266
|
+
raise ValueError(f"Unknown frequency unit {unit}!")
|
|
267
|
+
super().__init__(System().get_parameter_conversion_hardware().to_freq(np.array(value), unit=unit), unit, name)
|
|
268
|
+
|
|
269
|
+
def value(self, unit: Unit | None = None) -> np.ndarray:
|
|
270
|
+
"""
|
|
271
|
+
Returns:
|
|
272
|
+
np.ndarray: Value in the given unit
|
|
273
|
+
"""
|
|
274
|
+
if unit is None:
|
|
275
|
+
unit = self._unit
|
|
276
|
+
return System().get_parameter_conversion_hardware().from_freq(self._value, unit)
|
|
277
|
+
|
|
278
|
+
|
|
279
|
+
class Phase(JSONexportableParameter):
|
|
280
|
+
"""
|
|
281
|
+
# Phase
|
|
282
|
+
defines simple and looped phase parameters used in DDS and Quench Hardware.
|
|
283
|
+
"""
|
|
284
|
+
|
|
285
|
+
__slots__ = []
|
|
286
|
+
_instances: dict[int, Any] = {}
|
|
287
|
+
"""All instances of the class, keeping track of existing objects."""
|
|
288
|
+
_instance_dict: ClassVar[dict] = {}
|
|
289
|
+
"""Lookup dict to enable register() to find existing objects."""
|
|
290
|
+
typename = "phase"
|
|
291
|
+
|
|
292
|
+
def __init__(
|
|
293
|
+
self,
|
|
294
|
+
value: float | list[float] | np.ndarray,
|
|
295
|
+
unit: Unit,
|
|
296
|
+
name="",
|
|
297
|
+
) -> None:
|
|
298
|
+
"""
|
|
299
|
+
Args:
|
|
300
|
+
value (float | list[float] | np.ndarray): Phase value or array (looped time)
|
|
301
|
+
unit (Unit): Unit of the given value
|
|
302
|
+
name (str, optional): Name of the phase, used for debugging. Defaults to "".
|
|
303
|
+
|
|
304
|
+
Raises:
|
|
305
|
+
ValueError: If the unit is not a phase unit.
|
|
306
|
+
"""
|
|
307
|
+
if unit not in UnitType.phase:
|
|
308
|
+
raise ValueError(f"Unknown phase unit {unit}!")
|
|
309
|
+
super().__init__(System().get_parameter_conversion_hardware().to_phase(np.array(value), unit=unit), unit, name)
|
|
310
|
+
|
|
311
|
+
def value(self, unit: Unit | None = None) -> np.ndarray:
|
|
312
|
+
"""
|
|
313
|
+
Returns:
|
|
314
|
+
np.ndarray: Value in the given unit
|
|
315
|
+
"""
|
|
316
|
+
if unit is None:
|
|
317
|
+
unit = self._unit
|
|
318
|
+
return System().get_parameter_conversion_hardware().from_phase(self._value, unit)
|
|
319
|
+
|
|
320
|
+
|
|
321
|
+
class Amp(JSONexportableParameter):
|
|
322
|
+
"""
|
|
323
|
+
# Amplitude
|
|
324
|
+
defines simple and looped amplitude parameters used in DDS and Quench Hardware.
|
|
325
|
+
"""
|
|
326
|
+
|
|
327
|
+
__slots__ = []
|
|
328
|
+
_instances: dict[int, Any] = {}
|
|
329
|
+
"""All instances of the class, keeping track of existing objects."""
|
|
330
|
+
_instance_dict: ClassVar[dict] = {}
|
|
331
|
+
"""Lookup dict to enable register() to find existing objects."""
|
|
332
|
+
typename = "amp"
|
|
333
|
+
|
|
334
|
+
def __init__(
|
|
335
|
+
self,
|
|
336
|
+
value: float | list[float] | np.ndarray,
|
|
337
|
+
unit: Unit,
|
|
338
|
+
name="",
|
|
339
|
+
) -> None:
|
|
340
|
+
"""
|
|
341
|
+
Args:
|
|
342
|
+
value (float | list[float] | np.ndarray): Amplitude value or array (looped amplitude)
|
|
343
|
+
unit (Unit): Unit of the given value
|
|
344
|
+
name (str, optional): Name of the amplitude, used for debugging. Defaults to "".
|
|
345
|
+
|
|
346
|
+
Raises:
|
|
347
|
+
ValueError: If the unit is not an amplitude unit.
|
|
348
|
+
"""
|
|
349
|
+
if unit not in UnitType.amplitude:
|
|
350
|
+
raise ValueError(f"Unknown amplitude unit {unit}!")
|
|
351
|
+
super().__init__(System().get_parameter_conversion_hardware().to_amp(np.array(value), unit=unit), unit, name)
|
|
352
|
+
|
|
353
|
+
def value(self, unit: Unit | None = None) -> np.ndarray:
|
|
354
|
+
"""
|
|
355
|
+
Returns:
|
|
356
|
+
np.ndarray: Value in the given unit
|
|
357
|
+
"""
|
|
358
|
+
if unit is None:
|
|
359
|
+
unit = self._unit
|
|
360
|
+
return System().get_parameter_conversion_hardware().from_amp(self._value, unit)
|
|
361
|
+
|
|
362
|
+
|
|
363
|
+
class Time(JSONexportableParameter):
|
|
364
|
+
"""
|
|
365
|
+
# Time
|
|
366
|
+
defines simple and looped time parameters.
|
|
367
|
+
"""
|
|
368
|
+
|
|
369
|
+
__slots__ = ()
|
|
370
|
+
_instances: dict[int, Any] = {}
|
|
371
|
+
"""All instances of the class, keeping track of existing objects."""
|
|
372
|
+
_instance_dict: ClassVar[dict] = {}
|
|
373
|
+
"""Lookup dict to enable register() to find existing objects."""
|
|
374
|
+
typename = "time"
|
|
375
|
+
|
|
376
|
+
def __init__(
|
|
377
|
+
self,
|
|
378
|
+
value: float | list[float] | np.ndarray,
|
|
379
|
+
unit: Unit,
|
|
380
|
+
name: str = "",
|
|
381
|
+
) -> None:
|
|
382
|
+
"""
|
|
383
|
+
Args:
|
|
384
|
+
value (list[float] | float | np.ndarray): Time value or array (looped time)
|
|
385
|
+
unit (Unit): Unit of the given value
|
|
386
|
+
name (str, optional): Name of the time, used for debugging. Defaults to "".
|
|
387
|
+
|
|
388
|
+
Raises:
|
|
389
|
+
ValueError: If the unit is not a time unit.
|
|
390
|
+
"""
|
|
391
|
+
if unit not in UnitType.time:
|
|
392
|
+
raise ValueError(f"Unknown time unit {unit}!")
|
|
393
|
+
super().__init__(
|
|
394
|
+
System().get_parameter_conversion_hardware().to_time(value=np.array(value), unit=unit),
|
|
395
|
+
unit=unit,
|
|
396
|
+
name=name,
|
|
397
|
+
)
|
|
398
|
+
|
|
399
|
+
@classmethod
|
|
400
|
+
def add_array(cls, t1: np.ndarray, t2: np.ndarray) -> np.ndarray:
|
|
401
|
+
"""
|
|
402
|
+
np.ndarray addition for time arrays of different shapes.
|
|
403
|
+
If the dimensions of the arrays do not match, the function will reshape the arrays
|
|
404
|
+
to match dimensions before adding them
|
|
405
|
+
|
|
406
|
+
Returns:
|
|
407
|
+
np.ndarray: t1 + t2 in the largest shape between t1 and t2
|
|
408
|
+
"""
|
|
409
|
+
|
|
410
|
+
try:
|
|
411
|
+
return t1 + t2
|
|
412
|
+
except ValueError:
|
|
413
|
+
t1shape = np.array(t1.shape)
|
|
414
|
+
t2shape = np.array(t2.shape)
|
|
415
|
+
|
|
416
|
+
if len(t2shape) > len(t1shape):
|
|
417
|
+
tlist = [t2, t1]
|
|
418
|
+
tshapes = [t2shape, t1shape]
|
|
419
|
+
elif len(t2shape) < len(t1shape):
|
|
420
|
+
tlist = [t1, t2]
|
|
421
|
+
tshapes = [t1shape, t2shape]
|
|
422
|
+
else:
|
|
423
|
+
# simplest case, dimensionality matches, let np figure out the rest
|
|
424
|
+
return t1 + t2
|
|
425
|
+
|
|
426
|
+
newshape = tuple(np.append(np.repeat(1, len(tshapes[0]) - len(tshapes[1])), tshapes[1].astype(int)))
|
|
427
|
+
return tlist[1].reshape(newshape) + tlist[0]
|
|
428
|
+
|
|
429
|
+
@classmethod
|
|
430
|
+
def maximum(cls, t1: Time, t2: Time) -> Time:
|
|
431
|
+
"""
|
|
432
|
+
Returns:
|
|
433
|
+
Element-wise maximum of t1/t2 as a new Time.
|
|
434
|
+
Raises:
|
|
435
|
+
ValueError: If the two times are not the same shape
|
|
436
|
+
"""
|
|
437
|
+
return Time(np.maximum(t1._value, t2._value), Units.ns)
|
|
438
|
+
|
|
439
|
+
def __add__(self, other) -> Time:
|
|
440
|
+
val = Time.add_array(self._value, other._value)
|
|
441
|
+
t = Time(0, self._unit)
|
|
442
|
+
# Bypass unit conversion (we are already dealing with integer nanoseconds here)
|
|
443
|
+
t._value = val
|
|
444
|
+
return t
|
|
445
|
+
|
|
446
|
+
def __sub__(self, other, ignore_channel_index=False) -> Time:
|
|
447
|
+
val = Time.add_array(self._value, -other._value)
|
|
448
|
+
t = Time(0, self._unit)
|
|
449
|
+
t._value = val
|
|
450
|
+
return t
|
|
451
|
+
|
|
452
|
+
def __mul__(self, other) -> Time:
|
|
453
|
+
if isinstance(other, float | int | np.number):
|
|
454
|
+
o = self.__class__(np.array(0), self._unit)
|
|
455
|
+
o._value = self._value * other
|
|
456
|
+
return o
|
|
457
|
+
else:
|
|
458
|
+
raise ValueError("Multiplication of paramters with non-number types is not supported!")
|
|
459
|
+
|
|
460
|
+
def __lt__(self, other) -> numpy.bool[builtins.bool]:
|
|
461
|
+
return np.any(self._value < other._value)
|
|
462
|
+
|
|
463
|
+
def __le__(self, other) -> numpy.bool[builtins.bool]:
|
|
464
|
+
return np.any(self._value <= other._value)
|
|
465
|
+
|
|
466
|
+
def __gt__(self, other) -> numpy.bool[builtins.bool]:
|
|
467
|
+
return np.any(self._value > other._value)
|
|
468
|
+
|
|
469
|
+
def __ge__(self, other) -> numpy.bool[builtins.bool]:
|
|
470
|
+
return np.any(self._value >= other._value)
|
|
471
|
+
|
|
472
|
+
def value(self, unit: Unit | None = None) -> np.ndarray:
|
|
473
|
+
"""
|
|
474
|
+
Returns:
|
|
475
|
+
np.ndarray: Value in the given unit
|
|
476
|
+
"""
|
|
477
|
+
if unit is None:
|
|
478
|
+
unit = self._unit
|
|
479
|
+
return System().get_parameter_conversion_hardware().from_time(self._value, unit)
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import logging
|
|
4
|
+
from typing import Any, ClassVar
|
|
5
|
+
|
|
6
|
+
import numpy as np
|
|
7
|
+
|
|
8
|
+
from ionpulse_sequence_generator.base.jsonexportable import JSONexportable
|
|
9
|
+
from ionpulse_sequence_generator.hardware.channel import ChannelMask
|
|
10
|
+
from ionpulse_sequence_generator.hardware.hardware import DDSHardware
|
|
11
|
+
from ionpulse_sequence_generator.hardware.system import System
|
|
12
|
+
|
|
13
|
+
logger = logging.getLogger(__name__)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class PIDParameter(JSONexportable):
|
|
17
|
+
"""
|
|
18
|
+
# PIDParameter
|
|
19
|
+
Collects parameters for initializing a PID channel connected to an RF channel.
|
|
20
|
+
Initializes a PID on a DDS channel for DDSEvent.set_pid_reference() to stabilize the RF amplitdude.
|
|
21
|
+
Latency between the ADC input and the RF output can be tuned by setting pid_delay_start and pid_delay_end.
|
|
22
|
+
"""
|
|
23
|
+
|
|
24
|
+
__slots__ = (
|
|
25
|
+
"_ch_mask",
|
|
26
|
+
"_d_gain",
|
|
27
|
+
"_i_gain",
|
|
28
|
+
"_lp_resp",
|
|
29
|
+
"_override_zero",
|
|
30
|
+
"_p_gain",
|
|
31
|
+
"_pid_ch_mask",
|
|
32
|
+
"_pid_delay_end",
|
|
33
|
+
"_pid_delay_start",
|
|
34
|
+
"_pid_start_value",
|
|
35
|
+
"_rf_ch_mask",
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
_instances: dict[int, Any] = {}
|
|
39
|
+
"""All instances of the class, keeping track of existing objects."""
|
|
40
|
+
_instance_dict: ClassVar[dict] = {}
|
|
41
|
+
"""Lookup dict to enable register() to find existing objects."""
|
|
42
|
+
typename = "dds_pid_parameter"
|
|
43
|
+
"""A string to name the class type."""
|
|
44
|
+
|
|
45
|
+
def __init__(
|
|
46
|
+
self,
|
|
47
|
+
name: str,
|
|
48
|
+
ch_mask: ChannelMask,
|
|
49
|
+
pid_ch_mask: np.uint8,
|
|
50
|
+
p_gain: np.uint16,
|
|
51
|
+
i_gain: np.uint16,
|
|
52
|
+
d_gain: np.uint16,
|
|
53
|
+
lp_resp: np.uint16,
|
|
54
|
+
pid_delay_start: np.uint16,
|
|
55
|
+
pid_delay_end: np.uint16,
|
|
56
|
+
pid_start_value: np.uint16,
|
|
57
|
+
override_zero: bool,
|
|
58
|
+
) -> None:
|
|
59
|
+
"""
|
|
60
|
+
Args:
|
|
61
|
+
name (str): _description_
|
|
62
|
+
ch_mask (ChannelMask): RF channels to apply the PID Parameter to
|
|
63
|
+
pid_ch_mask (np.uint8): PID channels within the RF Channel to apply this parameter to (currently unused)
|
|
64
|
+
p_gain (np.uint16): P-Gain of the PID (0-2**16)
|
|
65
|
+
i_gain (np.uint16): I-Gain of the PID (0-2**16)
|
|
66
|
+
d_gain (np.uint16): D-Gain of the PID (0-2**16)
|
|
67
|
+
lp_resp (np.uint16): Low Pass response 0 = fastest (no LP), 2**16 = slowest
|
|
68
|
+
pid_delay_start (np.uint16): Start Delay of the PID relative to the pulse
|
|
69
|
+
pid_delay_end (np.uint16): End Delay of the PID relative to the pulse
|
|
70
|
+
pid_start_value (np.uint16): Start value of the PID after a reset
|
|
71
|
+
override_zero (bool): If True, all gain values are set to 0
|
|
72
|
+
|
|
73
|
+
Raises:
|
|
74
|
+
ValueError: If the ch_mask contains a non-DDS channel.
|
|
75
|
+
"""
|
|
76
|
+
super().__init__(name)
|
|
77
|
+
if any(not isinstance(hw, DDSHardware) for hw in System().get_hw_from_ch_mask(ch_mask)):
|
|
78
|
+
raise ValueError("ch_mask needs to contain DDS channels")
|
|
79
|
+
self._ch_mask = ch_mask
|
|
80
|
+
self._pid_ch_mask = np.uint16(pid_ch_mask)
|
|
81
|
+
self._p_gain = np.uint16(p_gain)
|
|
82
|
+
self._i_gain = np.uint16(i_gain)
|
|
83
|
+
self._d_gain = np.uint16(d_gain)
|
|
84
|
+
self._lp_resp = np.uint16(lp_resp)
|
|
85
|
+
self._pid_delay_start = np.uint16(pid_delay_start)
|
|
86
|
+
self._pid_delay_end = np.uint16(pid_delay_end)
|
|
87
|
+
self._pid_start_value = np.uint16(pid_start_value)
|
|
88
|
+
self._override_zero = override_zero
|
|
89
|
+
self.register()
|
|
90
|
+
self.mark()
|
|
91
|
+
|
|
92
|
+
def content_v(self) -> tuple:
|
|
93
|
+
return (
|
|
94
|
+
self._ch_mask,
|
|
95
|
+
self._pid_ch_mask,
|
|
96
|
+
self._p_gain,
|
|
97
|
+
self._i_gain,
|
|
98
|
+
self._d_gain,
|
|
99
|
+
self._lp_resp,
|
|
100
|
+
self._pid_delay_start,
|
|
101
|
+
self._pid_delay_end,
|
|
102
|
+
self._pid_start_value,
|
|
103
|
+
self._override_zero,
|
|
104
|
+
)
|
|
105
|
+
|
|
106
|
+
def content_k(self) -> tuple:
|
|
107
|
+
return (
|
|
108
|
+
"ch_mask",
|
|
109
|
+
"pid_ch_mask",
|
|
110
|
+
"p_gain",
|
|
111
|
+
"i_gain",
|
|
112
|
+
"d_gain",
|
|
113
|
+
"lp_resp",
|
|
114
|
+
"pid_delay_start",
|
|
115
|
+
"pid_delay_end",
|
|
116
|
+
"pid_start_value",
|
|
117
|
+
"override_zero",
|
|
118
|
+
)
|