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,213 @@
1
+ import logging
2
+ from typing import Any, TypedDict
3
+
4
+ from ionpulse_sequence_generator.hardware.channel import DEFAULT_CHANNEL, ChannelMask
5
+ from ionpulse_sequence_generator.hardware.device import Device, DeviceRole
6
+ from ionpulse_sequence_generator.hardware.hardware import DDSHardware, Hardware
7
+ from ionpulse_sequence_generator.hardware.readout import Readout
8
+ from ionpulse_sequence_generator.hardware.units import Unit
9
+ from ionpulse_sequence_generator.utils.utils import singleton
10
+
11
+ logger = logging.getLogger(__name__)
12
+
13
+
14
+ class HardwareChannelDescription(TypedDict):
15
+ device: str
16
+ hardware: str
17
+ channel: int
18
+
19
+
20
+ @singleton
21
+ class System:
22
+ """
23
+ # System
24
+ Singleton class to which `Devices` can be added. Once all devices have been added,
25
+ `build()` has to be called in order to assing channel indexing and allow requesting
26
+ of ChannelMasks.
27
+ """
28
+
29
+ __slots__ = (
30
+ "_async_channels",
31
+ "_built",
32
+ "_ch_to_idx_map",
33
+ "_channels",
34
+ "_devices",
35
+ "_features",
36
+ "_hw_cache",
37
+ "_idx_to_ch",
38
+ "_name",
39
+ "_parameter_conv_hw",
40
+ "_timing_cache",
41
+ "readout",
42
+ )
43
+
44
+ def __init__(self) -> None:
45
+ self._devices: dict[str, Device] = {}
46
+ self._features: dict[str, Any] = {}
47
+ self._ch_to_idx_map: dict[ChannelMask, int] = {}
48
+ self._idx_to_ch: list[HardwareChannelDescription] = []
49
+ self._channels = ChannelMask()
50
+ self.readout = Readout()
51
+ self._built = False
52
+ self._async_channels = ChannelMask()
53
+ self._hw_cache = {}
54
+ self._timing_cache = {}
55
+ # TODO: return to individual conversions for each hardware and adapt by system
56
+ self._parameter_conv_hw = DDSHardware(slots=[])
57
+
58
+ def add_device(self, device: Device) -> None:
59
+ """
60
+ Args:
61
+ device (Device): Device to be added to the system, note that the name of
62
+ the device should be unique.
63
+
64
+ Raises:
65
+ AttributeError: If the system has already be built.
66
+ ValueError: If the first added device is not the MAIN device.
67
+ """
68
+ if self._built:
69
+ raise AttributeError("System has already been built, you can't add devices after that.")
70
+ # assign device ID
71
+ # device ID 0 is the main device and has the readout
72
+ if device._role is not DeviceRole.MAIN and len(self._devices) == 0:
73
+ raise ValueError("First Device added to the system must be the main device.")
74
+ # There can only be one main device
75
+ if device._role is DeviceRole.MAIN and len(self._devices) > 0:
76
+ raise ValueError("There can only be one main device in a system.")
77
+ device._id = len(self._devices)
78
+ self._devices[device._name] = device
79
+
80
+ def get_hw_by_type(self, hw_type: type[Hardware]) -> list[Hardware]:
81
+ """
82
+ Returns:
83
+ list[Hardware]: A list of all `Hardware` of the given `hw_type` within the system.
84
+ """
85
+ hws = []
86
+ for device in self._devices.values(): # Fix PERF401
87
+ hws.extend([hw for hw in device._hardware if isinstance(hw, hw_type)])
88
+ return hws
89
+
90
+ def get_hw_from_ch_mask(self, ch_mask: ChannelMask) -> list[Hardware]:
91
+ """
92
+ Returns:
93
+ list[Hardware]: A list of all `Hardware` within the given `ch_mask`.
94
+ """
95
+ cache_key = tuple(sorted(ch_mask._channels))
96
+
97
+ if cache_key in self._hw_cache:
98
+ return self._hw_cache[cache_key]
99
+
100
+ hws = []
101
+ for device in self._devices.values():
102
+ if device._channels & ch_mask:
103
+ hws.extend([hw for hw in device._hardware if hw._channels & ch_mask])
104
+
105
+ self._hw_cache[cache_key] = hws
106
+
107
+ return hws
108
+
109
+ def get_timing_constraints_from_ch_mask(self, ch_mask: ChannelMask, unit: Unit):
110
+ """
111
+ Returns:
112
+ min_edge_time (float): minimum edge time for a given ch_mask
113
+ time_resolution (float): minimum time resolution for a given ch_mask
114
+ """
115
+ cache_key = (tuple(sorted(ch_mask._channels)), unit)
116
+
117
+ if cache_key in self._timing_cache:
118
+ return self._timing_cache[cache_key]
119
+
120
+ hws = self.get_hw_from_ch_mask(ch_mask)
121
+ time_min_edge = 0
122
+ time_resolution = 0
123
+
124
+ for hw in hws:
125
+ time_min_edge = max(hw.get_min_edge_time(unit), time_min_edge)
126
+ time_resolution = max(hw.get_time_resolution(unit), time_resolution)
127
+
128
+ result = (time_min_edge, time_resolution)
129
+ self._timing_cache[cache_key] = result
130
+
131
+ return result
132
+
133
+ def get_parameter_conversion_hardware(self) -> Hardware:
134
+ """
135
+ Returns:
136
+ Hardware : Hardware used for converting parameters for sequences on this system,
137
+ defining the global resolution and conversion functions.
138
+ """
139
+ return self._parameter_conv_hw
140
+
141
+ def __getitem__(self, device_name: str) -> Device:
142
+ if not self._built:
143
+ raise AttributeError("This System must built before you can request devices!")
144
+ return self._devices[device_name]
145
+
146
+ def __repr__(self) -> str:
147
+ return f"{self.__class__.__name__}: {list(self._devices.keys())}"
148
+
149
+ def build(self) -> None:
150
+ """
151
+ Builds the system, assigning channel indices and allows the requesting of
152
+ ChannelMasks from the Hardware.
153
+ """
154
+ # assign readout channel first
155
+ idx = 0
156
+ self.readout._ch_mask = ChannelMask([idx])
157
+ self._ch_to_idx_map[self.readout._ch_mask] = idx
158
+ self._idx_to_ch += [
159
+ {
160
+ "device": "",
161
+ "hardware": str(self.readout.__class__.__name__),
162
+ "channel": DEFAULT_CHANNEL,
163
+ }
164
+ ]
165
+ self._async_channels |= self.readout._ch_mask
166
+ # then assign masks for the rest of the hardware
167
+ idx = 1
168
+ for device in self._devices.values():
169
+ device.build()
170
+ for hw in device._hardware:
171
+ if device._role == DeviceRole.MAIN:
172
+ self._idx_to_ch[0]["device"] = str(device._name)
173
+ for ch in hw._channel_dict:
174
+ hw._channel_dict[ch] = ChannelMask([idx])
175
+ hw._channels |= hw._channel_dict[ch]
176
+ self._ch_to_idx_map[hw._channel_dict[ch]] = idx
177
+ self._idx_to_ch += [
178
+ {
179
+ "device": str(device._name),
180
+ "hardware": str(hw.__class__.__name__),
181
+ "channel": hw._hardware_channel_dict[ch],
182
+ }
183
+ ]
184
+ idx += 1
185
+ device._channels |= hw._channels
186
+ if device._is_async:
187
+ self._async_channels |= device._channels
188
+ else:
189
+ self._channels |= device._channels
190
+ self._built = True
191
+
192
+ def is_built(self) -> bool:
193
+ """
194
+ Returns:
195
+ bool: True if the build() has been called, False otherwise
196
+ """
197
+ return self._built
198
+
199
+ def clear(self) -> None:
200
+ self._devices = {}
201
+ self._ch_to_idx_map = {}
202
+ self._idx_to_ch = []
203
+ self._channels = ChannelMask()
204
+ self._async_channels = ChannelMask()
205
+ self.readout = Readout()
206
+ self._built = False
207
+
208
+ def clear_readout(self) -> None:
209
+ ch_mask = self.readout._ch_mask
210
+ pmt_channels = self.readout.pmt_channels
211
+ self.readout = Readout()
212
+ self.readout._ch_mask = ch_mask
213
+ self.readout.pmt_channels = pmt_channels
@@ -0,0 +1,97 @@
1
+ from typing import Any
2
+
3
+ import numpy as np
4
+
5
+ # NOTE: Using different resolutions between channels requires a ChannelMask to be defined for each parameter
6
+ # before creation. While this is not a problem in itself, it is inconvenient for the user
7
+ # to create parameters assigned to a channel, when the channel already is assigned in the Event
8
+ # Secondly, different resolutions (especially timing) lead to issues with syncing. The user would expect that
9
+ # a time of "x us" is always rounded to a certain precision. When using different resolutions this will not be true.
10
+ # More severe, even if the same Time object reference is used to construct an Event, the actual value will differ.
11
+ # This could be mitigated using a "post-sync" strategy, i.e. syncing the sequence when the main sequence is generated.
12
+ # Times (and other parameters) can be registered during runtime using their float representations expanding the
13
+ # ChannelMask. Then, when the main sequence is generated, all channels for a certain Parameter are known and
14
+ # the Parameter can be rounded to the lowest precision. One issue here is that we have to implement virtual syncing
15
+ # (add no waits, but sync later) to detect sync issues while the user is building the sequence.
16
+ # Furthermore it removes the usability of "get_time", i.e. give the user the ability to request a Time
17
+ # representing the runtime of a certain sequence. This could still be done by keeping references to all
18
+ # Times encompassed in the sequence (i.e. allow times to be a sum of multiple other times), but becomes
19
+ # cumbersome and complicated quite quickly.
20
+ # Because of these issues, for now we use global resolutions for parameters:
21
+
22
+ machine_units = {}
23
+ """machine_units defines global unit resolutions for the hardware."""
24
+ machine_units["1Ghz"] = np.uint64(2**32) # 32 bit frequencies / 1 GHz
25
+ machine_units["2pi"] = np.uint32(2**16) # 16 bit phases / 1 rad
26
+ machine_units["100%"] = np.uint32(2**14 - 1) # 14 bit amplitudes / 100%
27
+ machine_units["1ns"] = 1 / 8 # 8 ns time resolution, 36 bit times
28
+ machine_units["1mV"] = 25
29
+ round_decimals = 7
30
+
31
+
32
+ class Unit:
33
+ """
34
+ # Unit
35
+ Unit class to define units for physical parameters.
36
+ """
37
+
38
+ name: str
39
+ value: Any
40
+
41
+ def __init__(self, name: str, value: Any) -> None:
42
+ self.name = name
43
+ self.value = value
44
+
45
+ def __eq__(self, other):
46
+ return self.name == other.name and self.value == other.value
47
+
48
+ def __hash__(self):
49
+ return hash((self.name, self.value))
50
+
51
+
52
+ class Units:
53
+ """
54
+ # Units
55
+ provides a simple unit system for the sequence generator and pycrystal without
56
+ the overhead of a full unit package.
57
+
58
+ It uses the 'standard' approach for units, where
59
+
60
+ `value1 * unit = value2 * base_unit`
61
+
62
+ where `base_unit = 1`, such that
63
+
64
+ `value1 * unit1 + value2 * unit2 = value3 * unit3`
65
+
66
+ where conversion between units, i.e. from `unit1 -> unit2` is given by
67
+
68
+ `value1 * unit1/unit2 = value2`
69
+ """
70
+
71
+ ns = Unit("ns", 1)
72
+ us = Unit("us", 1e3)
73
+ ms = Unit("ms", 1e6)
74
+ s = Unit("s", 1e9)
75
+ GHz = Unit("GHz", 1)
76
+ MHz = Unit("MHz", 1e-3)
77
+ kHz = Unit("kHz", 1e-6) # noqa: N815
78
+ Hz = Unit("Hz", 1e-9)
79
+ percent = Unit("%", 0.01)
80
+ rad = Unit("rad", 1 / (2 * np.pi))
81
+ degree = Unit("°", 1 / 360)
82
+ mV = Unit("mV", 1) # noqa: N815
83
+ V = Unit("V", 1e3)
84
+ none = Unit("", None)
85
+
86
+
87
+ class UnitType:
88
+ """
89
+ # UnitType
90
+ to check if the correct type of unit is passed to a parameter
91
+ """
92
+
93
+ frequency = (Units.GHz, Units.MHz, Units.kHz, Units.Hz)
94
+ phase = (Units.degree, Units.rad)
95
+ amplitude = (Units.percent,)
96
+ time = (Units.ns, Units.us, Units.ms, Units.s)
97
+ voltage = (Units.V, Units.mV)
File without changes