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,185 @@
1
+ from __future__ import annotations
2
+
3
+ import logging
4
+
5
+ import numpy as np
6
+
7
+ from ionpulse_sequence_generator.hardware.channel import ChannelMask
8
+ from ionpulse_sequence_generator.hardware.hardware import DDSHardware, Domain
9
+ from ionpulse_sequence_generator.hardware.system import System
10
+ from ionpulse_sequence_generator.hardware.units import Unit, Units, UnitType
11
+ from ionpulse_sequence_generator.parameter.parameter import Amp, Freq, Phase, Time
12
+
13
+ from .event import Event
14
+
15
+ logger = logging.getLogger(__name__)
16
+ system = System()
17
+
18
+
19
+ class SingleToneRFEvent(Event):
20
+ """
21
+ # DDSEvent
22
+ This Event is used to set an Amplitude, Frequency and Phase of a DDS or Quench channel.
23
+
24
+ Additionally, on a DDS Channel pulse shaping (`set_slope_time`) and
25
+ PID stabilization (`set_pid_reference`, with a `PID_Parameter` for this channel) can be used.
26
+ """
27
+
28
+ __slots__ = (
29
+ "_amp",
30
+ "_flags",
31
+ "_freq",
32
+ "_phase",
33
+ "_pid_ref",
34
+ "_slope_end_delay",
35
+ "_slope_start_delay",
36
+ "_slope_time",
37
+ )
38
+
39
+ def __init__(
40
+ self,
41
+ name: str,
42
+ ch_idx: ChannelMask,
43
+ freq: Freq,
44
+ phase: Phase,
45
+ amp: Amp,
46
+ time: Time,
47
+ flags: int = 0,
48
+ ) -> None:
49
+ """
50
+ Args:
51
+ name (str): name, exported to the JSON for debugging
52
+ ch_mask (ChannelMask): channel this event is defined on
53
+ freq (Freq): Frequency to set on the channel
54
+ phase (Phase): Phase to set on the channel
55
+ amp (Amp): Amplitude to set on the channel
56
+ time (Time): Time until the parameters are applied
57
+ flags (int, optional): flags for the DDS Cards, unused. Defaults to 0.
58
+ """
59
+ super().__init__(name, ch_idx, time)
60
+
61
+ self._pid_ref = None
62
+ self._slope_time = None
63
+ self._slope_start_delay = None
64
+ self._slope_end_delay = None
65
+ self._flags = flags
66
+
67
+ hw_list = system.get_hw_from_ch_mask(ch_idx)
68
+ amp_is_active = np.any(amp._value > 0)
69
+
70
+ for hw in hw_list:
71
+ hw.check_time(time._value, time._unit, edge=True)
72
+ hw.check_amp(amp._value, amp._unit)
73
+ if amp_is_active:
74
+ hw.check_freq(freq._value, freq._unit)
75
+ hw.check_phase(phase._value, phase._unit)
76
+
77
+ self._amp = amp.register()
78
+ self._freq = freq.register()
79
+ self._phase = phase.register()
80
+
81
+ def content_v(self) -> tuple:
82
+ return (
83
+ self._type,
84
+ self._time._idx,
85
+ self._ch_mask,
86
+ self._flags,
87
+ self._freq._idx,
88
+ self._phase._idx,
89
+ self._amp._idx,
90
+ self._pid_ref,
91
+ self._slope_time,
92
+ self._slope_start_delay,
93
+ self._slope_end_delay,
94
+ )
95
+
96
+ def content_k(self) -> tuple:
97
+ return (
98
+ "type",
99
+ Time.typename,
100
+ ChannelMask.typename,
101
+ "flags",
102
+ Freq.typename,
103
+ Phase.typename,
104
+ Amp.typename,
105
+ "pid_ref",
106
+ "slope_time",
107
+ "slope_start_delay",
108
+ "slope_end_delay",
109
+ )
110
+
111
+ def mark(self) -> None:
112
+ super().mark()
113
+ self._freq.mark()
114
+ self._phase.mark()
115
+ self._amp.mark()
116
+ if self._slope_time is not None:
117
+ self._slope_time.mark()
118
+ self._slope_start_delay.mark()
119
+ self._slope_end_delay.mark()
120
+
121
+ def set_slope_time(self, slope_time: Time) -> SingleToneRFEvent:
122
+ """
123
+ WARNING: Shaped pulses will not align with a normal pulse due to additional delays!
124
+
125
+ Args:
126
+ slope_time (Time): Rise time of the slope.
127
+ Different shapes can be programmed on the DDS Card using ionpulse.
128
+
129
+ Raises:
130
+ AttributeError: If the Event is not defined on a DDS channel
131
+
132
+ Returns:
133
+ DDSEvent: this event
134
+ """
135
+ for hw in system.get_hw_from_ch_mask(self._ch_mask):
136
+ hw.check_time(slope_time._value, slope_time._unit, slope_time=True)
137
+ if hw.domain != Domain.DDS:
138
+ raise AttributeError("Slope time can only be used on DDS Hardware!")
139
+ self._slope_start_delay = Time(DDSHardware.slope_time_delay, Units.ns).register()
140
+ self._slope_time = slope_time.register()
141
+ self._slope_end_delay = Time(DDSHardware.slope_time_delay, Units.ns).register()
142
+ return self
143
+
144
+ def get_time(self) -> Time:
145
+ """
146
+ Returns:
147
+ Time: wait time until the action is performed
148
+
149
+ Note: Shaped pulses include an additional delay of 800ns
150
+ dds_delay (1.296 us)
151
+ dds_to_vga_delay (400 ns)
152
+ vga_ramping_delay (shape time)
153
+ hard coded short wait (400 ns) that resets the VGA
154
+ """
155
+ if self._slope_time is not None:
156
+ return self._time + self._slope_start_delay + self._slope_time + self._slope_end_delay
157
+ return self._time
158
+
159
+ def set_pid_reference(self, pid_ch: int, adc_ch: ChannelMask, ref_v: float, unit: Unit) -> SingleToneRFEvent:
160
+ """
161
+ Args:
162
+ pid_ch (int): PID channel within the DDS channel to be used (0-7)
163
+ adc_ch (int): ADC channel on the DDS card used for stabilization (0-1)
164
+ ref_v (float): Reference voltage to stabilize to (ideally ~100 - ~200 mV, max. 300 mV)
165
+ unit (Unit):
166
+
167
+ Raises:
168
+ ValueError: If the unit does
169
+ AttributeError: _description_
170
+
171
+ Returns:
172
+ DDSEvent: _description_
173
+ """
174
+ if unit not in UnitType.voltage:
175
+ raise ValueError(f"Unknown voltage unit {unit}!")
176
+ hw = system.get_hw_from_ch_mask(self._ch_mask)[0]
177
+ if hw.domain != Domain.DDS:
178
+ raise AttributeError("PID can only be used on DDS Hardware!")
179
+ adc_hw = system.get_hw_from_ch_mask(adc_ch)[0]
180
+ if adc_hw.domain != Domain.DDS_ADC:
181
+ raise AttributeError("PID can only be used on DDS Hardware!")
182
+ if hw.get_slot(self._ch_mask) != adc_hw.get_slot(adc_ch): # type: ignore
183
+ raise AttributeError("ADC Channel and DDS Channel must be on the same card!")
184
+ self._pid_ref = hw.to_refv(ref_v, unit=unit, pid_ch=pid_ch, adc_ch=adc_hw.get_ADC_index(adc_ch)) # type: ignore
185
+ return self
@@ -0,0 +1,63 @@
1
+ from __future__ import annotations
2
+
3
+ import logging
4
+
5
+ from ionpulse_sequence_generator.hardware.channel import ChannelMask
6
+ from ionpulse_sequence_generator.hardware.system import System
7
+ from ionpulse_sequence_generator.parameter.parameter import Time
8
+
9
+ from .event import Event
10
+
11
+ logger = logging.getLogger(__name__)
12
+ system = System()
13
+
14
+
15
+ class Wait(Event):
16
+ """
17
+ # Wait
18
+ This event will idle a single channel for the given wait time.
19
+
20
+ This is used for padding and syncing multiple channels:
21
+ ```
22
+ RFEdge RFEdge RFEdge |
23
+ CH1: <-time->|action| <-time->|action| <-time->|action| | CH1 and
24
+ RFEdge RFEdge RFWait |
25
+ CH2: <-time->|action| <-time->|action| <-time-> | CH2 synced
26
+ ```
27
+ """
28
+
29
+ __slots__ = ("_wait_for_trigger",)
30
+
31
+ def __init__(
32
+ self,
33
+ name: str,
34
+ ch_idx: ChannelMask,
35
+ time: Time,
36
+ wait_for_trigger=False,
37
+ ) -> None:
38
+ """
39
+ Args:
40
+ name (str): name, exported to the JSON for debugging
41
+ ch_mask (ChannelMask): channel this event is defined on
42
+ time (Time): wait time
43
+ wait_for_trigger (bool, optional): If True, the decoder will stall until a re-trigger event.
44
+ Defaults to False.
45
+ """
46
+ super().__init__(name, ch_idx, time)
47
+ for hw in system.get_hw_from_ch_mask(ch_idx):
48
+ hw.check_time(time._value, time._unit, edge=True)
49
+ self._wait_for_trigger = wait_for_trigger
50
+
51
+ def content_v(self) -> tuple:
52
+ return (
53
+ self._type,
54
+ self._ch_mask,
55
+ self._time._idx,
56
+ )
57
+
58
+ def content_k(self) -> tuple:
59
+ return (
60
+ "type",
61
+ ChannelMask.typename,
62
+ Time.typename,
63
+ )
@@ -0,0 +1,54 @@
1
+ import logging
2
+
3
+ from ionpulse_sequence_generator.hardware.channel import ChannelMask
4
+ from ionpulse_sequence_generator.parameter.parameter import Time
5
+
6
+ from .event import Event
7
+
8
+ logger = logging.getLogger(__name__)
9
+
10
+
11
+ class WaveformEvent(Event):
12
+ """
13
+ # WaveformEvent
14
+ This Event is used to trigger a waveform on a Fastino device.
15
+ """
16
+
17
+ __slots__ = ("_reverse", "_slowdown", "_waveform_id")
18
+
19
+ def __init__(
20
+ self, name: str, ch_mask: ChannelMask, time: Time, waveform_id: str | int, reverse: bool, slowdown: int
21
+ ) -> None:
22
+ """
23
+ Args:
24
+ name (str): Name of the event
25
+ ch_mask (ChannelMask): Channel mask representing the waveform sequencing channel.
26
+ time (Time): Time parameter representing the duration of the waveform.
27
+ waveform_id (str | int): Unique identifier of the waveform.
28
+ reverse (bool): Whether to play the waveform in reverse.
29
+ slowdown (int): Slowdown factor for the waveform.
30
+ """
31
+ super().__init__(name, ch_mask, time)
32
+ self._waveform_id = waveform_id
33
+ self._reverse = reverse
34
+ self._slowdown = slowdown
35
+
36
+ def content_v(self) -> tuple:
37
+ return (
38
+ self._type,
39
+ self._time._idx,
40
+ self._ch_mask,
41
+ self._waveform_id,
42
+ self._reverse,
43
+ self._slowdown,
44
+ )
45
+
46
+ def content_k(self) -> tuple:
47
+ return (
48
+ "type",
49
+ Time.typename,
50
+ ChannelMask.typename,
51
+ "waveform_id",
52
+ "reverse",
53
+ "slowdown",
54
+ )
File without changes
@@ -0,0 +1,115 @@
1
+ from __future__ import annotations
2
+
3
+ DEFAULT_CHANNEL = 0
4
+ """Default channel number for hardware without channel indexing."""
5
+
6
+
7
+ class ChannelMask:
8
+ """
9
+ # ChannelMask
10
+ This class is used to identify one or multiple channels over multiple `Hardware`s.
11
+ Instances of this class should only be constructed from `Hardware` instances connected
12
+ to a `System`.
13
+ """
14
+
15
+ typename = "ch_mask"
16
+
17
+ __slots__ = ("_channels",)
18
+
19
+ def __init__(self, channels: set[int] | list[int] = []) -> None:
20
+ """
21
+ Args:
22
+ channels (set[int] | list[int], optional): A set of uinique indices for Channels. Defaults to [].
23
+ """
24
+ self._channels = set(channels)
25
+
26
+ def __hash__(self) -> int:
27
+ return hash(frozenset(self._channels))
28
+
29
+ def to_idx_list(self) -> list[int]:
30
+ """
31
+ Returns:
32
+ list[int] : A sorted list of indices, ensuring reproducability between runs.
33
+ """
34
+ ret = list(self._channels)
35
+ ret.sort()
36
+ return ret
37
+
38
+ def is_single_channel(self) -> bool:
39
+ """
40
+ Returns:
41
+ bool : True if the ChannelMask only contains a single index.
42
+ """
43
+ return len(self._channels) == 1
44
+
45
+ def contains(self, other: ChannelMask) -> bool:
46
+ """
47
+ Returns:
48
+ bool : True if other is contained in self, False otherwise.
49
+ """
50
+ return other._channels.issubset(self._channels)
51
+
52
+ def __or__(self, other: ChannelMask) -> ChannelMask:
53
+ """
54
+ Returns:
55
+ ChannelMask: A new ChannelMask instance containing all channels that are present in
56
+ `self` or `other`.
57
+ """
58
+ return ChannelMask(self._channels | other._channels)
59
+
60
+ def __eq__(self, other: ChannelMask) -> bool:
61
+ if not isinstance(other, ChannelMask):
62
+ return False
63
+ return other._channels == self._channels
64
+
65
+ def __sub__(self, other: ChannelMask) -> ChannelMask:
66
+ """
67
+ Returns:
68
+ ChannelMask : A new ChannelMask instance containing all channels that are present in
69
+ `self` but not in `other`.
70
+ """
71
+ return ChannelMask(self._channels - other._channels)
72
+
73
+ def __len__(self) -> int:
74
+ """
75
+ Returns:
76
+ int : Number of channels inside the ChannelMask.
77
+ """
78
+ return len(self._channels)
79
+
80
+ def is_empty(self) -> bool:
81
+ return len(self._channels) == 0
82
+
83
+ def __and__(self, other: ChannelMask) -> ChannelMask:
84
+ """
85
+ Returns:
86
+ ChannelMask : A new ChannelMask instance containing all channels that are present in
87
+ both `self` and `other`.
88
+ """
89
+ return ChannelMask(self._channels & other._channels)
90
+
91
+ def to_json_member(self) -> tuple:
92
+ """JSON representation of the object as a member of another object
93
+
94
+ Returns:
95
+ tuple: The channel indices for this object as a tuple.
96
+ """
97
+ return tuple(self._channels)
98
+
99
+ def __str__(self) -> str:
100
+ # todo: create proper representation from system with (dev.id, hw.id, slot, ch)
101
+ return str(self._channels)
102
+
103
+ def __bool__(self) -> bool:
104
+ """
105
+ Returns:
106
+ bool : True if the ChannelMask contains any channels, False otherwise.
107
+ """
108
+ return len(self._channels) > 0
109
+
110
+ def __repr__(self) -> str:
111
+ return self.__str__()
112
+
113
+ def __iter__(self):
114
+ for idx in self.to_idx_list():
115
+ yield ChannelMask([idx])
@@ -0,0 +1,184 @@
1
+ import logging
2
+ from enum import Enum
3
+
4
+ from ionpulse_sequence_generator.hardware.channel import ChannelMask
5
+ from ionpulse_sequence_generator.hardware.hardware import (
6
+ DDSADCHardware,
7
+ DDSHardware,
8
+ DIOHardware,
9
+ FastinoHardware,
10
+ Hardware,
11
+ QuenchADCHardware,
12
+ QuenchHardware,
13
+ )
14
+
15
+ logger = logging.getLogger(__name__)
16
+
17
+
18
+ class DeviceRole(Enum):
19
+ """
20
+ # DeviceRole
21
+ Role of a `Device` within a `System`, either `MAIN` or `SUBORDINATE`, where the MAIN
22
+ device contains the readout channel and is expected to trigger all subordinates.
23
+ """
24
+
25
+ MAIN = 0
26
+ SUBORDINATE = 1
27
+
28
+
29
+ class Device:
30
+ """
31
+ # Device
32
+ Base class for creating specific devices containing Hardware.
33
+
34
+ """
35
+
36
+ __slots__ = (
37
+ "_channels",
38
+ "_hardware",
39
+ "_id",
40
+ "_is_async",
41
+ "_name",
42
+ "_role",
43
+ )
44
+
45
+ def __init__(self, name: str, role: DeviceRole, is_async: bool = False) -> None:
46
+ """
47
+ Args:
48
+ name (str): Name of the device
49
+ role (DeviceRole): Role of the device within a system.
50
+ is_async (bool): Whether the device operates asynchronously.
51
+ """
52
+ self._name: str = name
53
+ self._role: DeviceRole = role
54
+ self._id: int | None = None
55
+ self._is_async: bool = is_async
56
+ self._hardware: list[Hardware] = []
57
+ self._channels: ChannelMask = ChannelMask()
58
+
59
+ def __getitem__(self, hardware_type: type[Hardware]) -> Hardware:
60
+ """
61
+ Args:
62
+ hardware_type (type[Hardware]): Hardware type to retrieve from the device.
63
+
64
+ Raises:
65
+ AttributeError: If the device is not part of a system, Hardware can not be accessed.
66
+
67
+ Returns:
68
+ Hardware: The hardware of the requested type within this system.
69
+ """
70
+ if self._id is None:
71
+ raise AttributeError("This device must be part of a built system before you can request hardware!")
72
+ return next(v for v in self._hardware if isinstance(v, hardware_type))
73
+
74
+ def __repr__(self) -> str:
75
+ return f"{self._name}: {self._hardware}"
76
+
77
+ def get_num_channels(self) -> int:
78
+ """
79
+ Returns:
80
+ int: Number of channels attached to `Hardware` contained by this device.
81
+ """
82
+ return sum([hw.get_num_channels() for hw in self._hardware])
83
+
84
+ def build(self) -> None:
85
+ """
86
+ Called from system.build(), prepare step for building hardware into this device.
87
+ """
88
+
89
+ def clear(self) -> None:
90
+ """
91
+ Called from system.clear(), removing all hardware in this device
92
+ """
93
+
94
+
95
+ class MACTIONRack(Device):
96
+ """
97
+ # MACTIONRack
98
+
99
+ """
100
+
101
+ def __init__(self, name: str, role: DeviceRole, is_async: bool = False) -> None:
102
+ """
103
+ Args:
104
+ name (str): Name of the device
105
+ role (DeviceRole): Role of the device within a system.
106
+ is_async (bool): Whether the device operates asynchronously.
107
+ """
108
+ super().__init__(name, role, is_async)
109
+ self._hardware: list[Hardware] = [DIOHardware()]
110
+ self._dds_slots: list[int] = []
111
+ self._quench_slots: list[int] = []
112
+
113
+ def add_dds_cards(self, slots: list[int]) -> None:
114
+ self._dds_slots.extend(slots)
115
+
116
+ def add_quench_cards(self, slots: list[int]) -> None:
117
+ self._quench_slots.extend(slots)
118
+
119
+ def build(self) -> None:
120
+ if self._dds_slots:
121
+ self._hardware.append(DDSHardware(slots=self._dds_slots))
122
+ self._hardware.append(DDSADCHardware(slots=self._dds_slots))
123
+ if self._quench_slots:
124
+ self._hardware.append(QuenchHardware(slots=self._quench_slots))
125
+ for i, hw in enumerate(self._hardware):
126
+ hw._id = i
127
+
128
+ def clear(self) -> None:
129
+ self._hardware = [DIOHardware()]
130
+ self._channels = ChannelMask()
131
+ self._id = None
132
+
133
+
134
+ class QuenchRFSoC(Device):
135
+ """
136
+ # QuenchRFSoC
137
+ """
138
+
139
+ def __init__(self, name: str, role: DeviceRole, is_async: bool = False) -> None:
140
+ """
141
+ Args:
142
+ name (str): Name of the device
143
+ role (DeviceRole): Role of the device within a system.
144
+ is_async (bool): Whether the device operates asynchronously.
145
+ """
146
+ super().__init__(name, role, is_async)
147
+ self._hardware: list[Hardware] = [DIOHardware(), QuenchHardware(slots=[0, 1]), QuenchADCHardware(slots=[0, 1])]
148
+
149
+ def build(self) -> None:
150
+ for i, hw in enumerate(self._hardware):
151
+ hw._id = i
152
+
153
+ def clear(self) -> None:
154
+ self._hardware = [DIOHardware(), QuenchHardware(slots=[0, 1]), QuenchADCHardware(slots=[0, 1])]
155
+ self._channels = ChannelMask()
156
+ self._id = None
157
+
158
+
159
+ class FastinoRack(Device):
160
+ """
161
+ # FastinoRack
162
+
163
+ """
164
+
165
+ def __init__(self, name: str, n_cards: int, role: DeviceRole, is_async: bool = False) -> None:
166
+ """
167
+ Args:
168
+ name (str): Name of the device
169
+ role (DeviceRole): Role of the device within a system.
170
+ n_cards (int): Number of Fastino cards to add.
171
+ is_async (bool): Whether the device operates asynchronously.
172
+ """
173
+ super().__init__(name, role, is_async)
174
+ self._n_cards = n_cards
175
+ self._hardware: list[Hardware] = [FastinoHardware(n_cards)]
176
+
177
+ def build(self) -> None:
178
+ for i, hw in enumerate(self._hardware):
179
+ hw._id = i
180
+
181
+ def clear(self) -> None:
182
+ self._hardware = [FastinoHardware(self._n_cards)]
183
+ self._channels = ChannelMask()
184
+ self._id = None