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,91 @@
|
|
|
1
|
+
from .base.header import Header
|
|
2
|
+
from .event.ddspidstatechange import DDSPIDStateChange
|
|
3
|
+
from .event.dioevent import DIOEvent
|
|
4
|
+
from .event.event import Event
|
|
5
|
+
from .event.multitonerfevent import MultiToneRFEvent
|
|
6
|
+
from .event.readout import Discriminator, DiscriminatorType, PopCameraFIFO, PopPMTFIFO
|
|
7
|
+
from .event.singletonerfevent import SingleToneRFEvent
|
|
8
|
+
from .event.wait import Wait
|
|
9
|
+
from .event.waveform import WaveformEvent
|
|
10
|
+
from .hardware.channel import ChannelMask
|
|
11
|
+
from .hardware.device import DeviceRole, FastinoRack, MACTIONRack, QuenchRFSoC
|
|
12
|
+
from .hardware.hardware import (
|
|
13
|
+
DDSADCHardware,
|
|
14
|
+
DDSHardware,
|
|
15
|
+
DIOHardware,
|
|
16
|
+
Domain,
|
|
17
|
+
FastinoHardware,
|
|
18
|
+
QuenchADCHardware,
|
|
19
|
+
QuenchHardware,
|
|
20
|
+
)
|
|
21
|
+
from .hardware.readout import (
|
|
22
|
+
CameraChannel,
|
|
23
|
+
PlotWindow,
|
|
24
|
+
PMTChannel,
|
|
25
|
+
Readout,
|
|
26
|
+
ReadoutChannel,
|
|
27
|
+
ReadoutPostprocessingMethod,
|
|
28
|
+
ShotChannel,
|
|
29
|
+
VectorChannel,
|
|
30
|
+
)
|
|
31
|
+
from .hardware.system import System
|
|
32
|
+
from .hardware.units import Unit, Units
|
|
33
|
+
from .parameter.parameter import Amp, Freq, Phase, Time
|
|
34
|
+
from .parameter.pid_parameter import PIDParameter
|
|
35
|
+
from .parameter.spline_parameter import AmpSpline, FreqSpline, PhaseSpline
|
|
36
|
+
from .sequence.conditional import ConditionalSequence
|
|
37
|
+
from .sequence.loop import LoopSequence
|
|
38
|
+
from .sequence.sequence import LinearSequence, Sequence
|
|
39
|
+
from .utils.logging import setup_logging
|
|
40
|
+
|
|
41
|
+
__all__ = [
|
|
42
|
+
"Amp",
|
|
43
|
+
"AmpSpline",
|
|
44
|
+
"CameraChannel",
|
|
45
|
+
"ChannelMask",
|
|
46
|
+
"ConditionalSequence",
|
|
47
|
+
"DDSADCHardware",
|
|
48
|
+
"DDSHardware",
|
|
49
|
+
"DDSPIDStateChange",
|
|
50
|
+
"DIOEvent",
|
|
51
|
+
"DIOHardware",
|
|
52
|
+
"DeviceRole",
|
|
53
|
+
"Discriminator",
|
|
54
|
+
"DiscriminatorType",
|
|
55
|
+
"Domain",
|
|
56
|
+
"Event",
|
|
57
|
+
"FastinoHardware",
|
|
58
|
+
"FastinoRack",
|
|
59
|
+
"Freq",
|
|
60
|
+
"FreqSpline",
|
|
61
|
+
"Header",
|
|
62
|
+
"LinearSequence",
|
|
63
|
+
"LoopSequence",
|
|
64
|
+
"MACTIONRack",
|
|
65
|
+
"MultiToneRFEvent",
|
|
66
|
+
"PIDParameter",
|
|
67
|
+
"PMTChannel",
|
|
68
|
+
"Phase",
|
|
69
|
+
"PhaseSpline",
|
|
70
|
+
"PlotWindow",
|
|
71
|
+
"PopCameraFIFO",
|
|
72
|
+
"PopPMTFIFO",
|
|
73
|
+
"QuenchADCHardware",
|
|
74
|
+
"QuenchHardware",
|
|
75
|
+
"QuenchRFSoC",
|
|
76
|
+
"Readout",
|
|
77
|
+
"ReadoutChannel",
|
|
78
|
+
"ReadoutPostprocessingMethod",
|
|
79
|
+
"Sequence",
|
|
80
|
+
"ShotChannel",
|
|
81
|
+
"SingleToneRFEvent",
|
|
82
|
+
"System",
|
|
83
|
+
"Time",
|
|
84
|
+
"Unit",
|
|
85
|
+
"Units",
|
|
86
|
+
"VectorChannel",
|
|
87
|
+
"Wait",
|
|
88
|
+
"WaveformEvent",
|
|
89
|
+
]
|
|
90
|
+
|
|
91
|
+
setup_logging()
|
|
File without changes
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
|
|
3
|
+
from ionpulse_sequence_generator.utils.utils import singleton
|
|
4
|
+
|
|
5
|
+
logger = logging.getLogger(__name__)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
@singleton
|
|
9
|
+
class Configuration:
|
|
10
|
+
"""Configuration options for the Ionpulse Sequence Generator"""
|
|
11
|
+
|
|
12
|
+
def __init__(self) -> None:
|
|
13
|
+
self.check_post_time = True
|
|
14
|
+
"""Activates the post time check for events which require a minimum time for the next event,
|
|
15
|
+
such as e.g. MultitoneRFEvents with ShapedParameters.
|
|
16
|
+
Deactivating this option will increase performance but remove _post_time from events and sequences,
|
|
17
|
+
which is used by sync() to generate appropriately long padding times when syncing sequences.
|
|
18
|
+
Deactivate at your own peril.
|
|
19
|
+
"""
|
|
20
|
+
self.debuglog_register_messages = False
|
|
21
|
+
"""Activates the logging of DEBUG messages when objects get registered in
|
|
22
|
+
JSONExportable.register()
|
|
23
|
+
"""
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
from importlib.metadata import distribution
|
|
3
|
+
from typing import Any
|
|
4
|
+
|
|
5
|
+
from ionpulse_sequence_generator.hardware.system import System
|
|
6
|
+
|
|
7
|
+
logger = logging.getLogger(__name__)
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class Header:
|
|
11
|
+
"""
|
|
12
|
+
# Header
|
|
13
|
+
This class creates a header for serialized sequence instructions, providing additional
|
|
14
|
+
parameters to the system.
|
|
15
|
+
|
|
16
|
+
## User Variables
|
|
17
|
+
self.debug_level
|
|
18
|
+
Debug level for the JSON parser to determine printout when sequence is parsed and run.
|
|
19
|
+
https://docs.python.org/3/library/logging.html#logging-levels
|
|
20
|
+
Logging Level
|
|
21
|
+
40 logging.ERROR
|
|
22
|
+
no printing, unless an error occurs
|
|
23
|
+
30 logging.WARNING
|
|
24
|
+
minimal printout, warnings
|
|
25
|
+
20 logging.INFO
|
|
26
|
+
useful info
|
|
27
|
+
10 logging.DEBUG
|
|
28
|
+
full debug info including parser messages, can be slow
|
|
29
|
+
|
|
30
|
+
## Internal Variables
|
|
31
|
+
self._version
|
|
32
|
+
Version of the sequence generator to check compatibility in the JSON parser
|
|
33
|
+
|
|
34
|
+
self._user_content: dict[str, Any]
|
|
35
|
+
User content added to the header. Will be ignored by the parser.
|
|
36
|
+
"""
|
|
37
|
+
|
|
38
|
+
typename = "header"
|
|
39
|
+
|
|
40
|
+
def __init__(self, debug_level: int = logging.WARNING) -> None:
|
|
41
|
+
self._version = distribution("ionpulse-sequence-generator").version
|
|
42
|
+
self.debug_level = debug_level
|
|
43
|
+
self._system_features: list[str] = []
|
|
44
|
+
self._shots = 0
|
|
45
|
+
|
|
46
|
+
# user content added using add_field
|
|
47
|
+
self._user_content = {}
|
|
48
|
+
|
|
49
|
+
def add_field(self, name: str, value: Any) -> None:
|
|
50
|
+
"""
|
|
51
|
+
Adds a custom entry to the parameter `user_content` with key `name` and
|
|
52
|
+
value `value`.
|
|
53
|
+
"""
|
|
54
|
+
|
|
55
|
+
self._user_content[name] = value
|
|
56
|
+
|
|
57
|
+
def set_shots(self, shots: int):
|
|
58
|
+
"""
|
|
59
|
+
Sets the number of repetitions per datapoint for the sequence.
|
|
60
|
+
|
|
61
|
+
Args:
|
|
62
|
+
shots (int): Number of repetitions.
|
|
63
|
+
"""
|
|
64
|
+
self._shots = shots
|
|
65
|
+
|
|
66
|
+
def to_json(self) -> dict[str, Any]:
|
|
67
|
+
"""
|
|
68
|
+
JSON representation of the object.
|
|
69
|
+
|
|
70
|
+
Returns:
|
|
71
|
+
dict[str, Any] : A dict for unique variables in this instance, including the
|
|
72
|
+
name if the loglevel is `DEBUG` or below is enabled.
|
|
73
|
+
"""
|
|
74
|
+
sys = System()
|
|
75
|
+
return {
|
|
76
|
+
"version": self._version,
|
|
77
|
+
"debug_level": self.debug_level,
|
|
78
|
+
"shots": self._shots,
|
|
79
|
+
"shot_channel_names": sys.readout._shot_channel_names,
|
|
80
|
+
"readout_channel_names": sys.readout._readout_channel_names,
|
|
81
|
+
"readout_postprocessing_method": sys.readout._readout_postprocessing_method,
|
|
82
|
+
"vector_channel_names": sys.readout._vector_channel_names,
|
|
83
|
+
"shot_channel_plot_index": sys.readout._shot_channel_plot_index,
|
|
84
|
+
"readout_channel_plot_index": sys.readout._readout_channel_plot_index,
|
|
85
|
+
"vector_channel_plot_index": sys.readout._vector_channel_plot_index,
|
|
86
|
+
"timestamp_channel_mask": sys.readout._timestamp_channel_mask,
|
|
87
|
+
"system_features": sys._features,
|
|
88
|
+
"channel_idx_to_hw": sys._idx_to_ch,
|
|
89
|
+
**self._user_content,
|
|
90
|
+
}
|
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
#!/usr/bin/python3
|
|
2
|
+
|
|
3
|
+
import logging
|
|
4
|
+
from typing import Any, ClassVar
|
|
5
|
+
|
|
6
|
+
from ionpulse_sequence_generator.base.configuration import Configuration
|
|
7
|
+
|
|
8
|
+
logger = logging.getLogger(__name__)
|
|
9
|
+
configuration = Configuration()
|
|
10
|
+
|
|
11
|
+
json_indent = 4
|
|
12
|
+
"""Indent of the exported JSON string"""
|
|
13
|
+
garbage_collection_warning_threshold = 100
|
|
14
|
+
"""Threshold for printing a warning message when instances are deleted."""
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def to_tuple(d: list[Any] | tuple[Any] | dict[Any, Any], use_idx: bool = True) -> tuple[Any, ...]:
|
|
18
|
+
"""Converts a dict or list d to a tuple.
|
|
19
|
+
|
|
20
|
+
dicts will be sorted by keys, lists will remain in the given order.
|
|
21
|
+
Nested dicts or list are treated by recursive calls.
|
|
22
|
+
|
|
23
|
+
use_idx will replace nested JSONexportable objects with their index,
|
|
24
|
+
if obj.idx>=0.
|
|
25
|
+
|
|
26
|
+
Returns
|
|
27
|
+
The input object recursively converted into a tuple
|
|
28
|
+
"""
|
|
29
|
+
if d is None:
|
|
30
|
+
return (None,)
|
|
31
|
+
|
|
32
|
+
contentlist = []
|
|
33
|
+
if isinstance(d, dict):
|
|
34
|
+
for item in d.items():
|
|
35
|
+
if isinstance(item[1], dict | list | tuple):
|
|
36
|
+
contentlist.append((item[0], to_tuple(item[1])))
|
|
37
|
+
elif isinstance(item[1], JSONexportable) and item[1]._idx >= 0:
|
|
38
|
+
# the typename is added to make objects stored in
|
|
39
|
+
# different class variables arrays uniqe
|
|
40
|
+
contentlist.append((item[0], item[1].typename, item[1]._idx))
|
|
41
|
+
else:
|
|
42
|
+
contentlist.append(item)
|
|
43
|
+
return tuple(sorted(contentlist, key=lambda tup: tup[0]))
|
|
44
|
+
elif isinstance(d, list | tuple):
|
|
45
|
+
for item in d:
|
|
46
|
+
if isinstance(item, dict | list | tuple):
|
|
47
|
+
contentlist.append(to_tuple(item))
|
|
48
|
+
elif isinstance(item, JSONexportable) and item._idx >= 0:
|
|
49
|
+
# the typename is added to make objects stored in
|
|
50
|
+
# different class variables arrays uniqe
|
|
51
|
+
# contentlist.append((item.typename, item._idx)
|
|
52
|
+
contentlist.append(item._idx)
|
|
53
|
+
else:
|
|
54
|
+
contentlist.append(item)
|
|
55
|
+
return tuple(contentlist)
|
|
56
|
+
else:
|
|
57
|
+
raise TypeError(f"Type must be either list or dict but is {type(d)}")
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
class JSONexportable:
|
|
61
|
+
"""
|
|
62
|
+
# JSONexportable.
|
|
63
|
+
This abstract base class unfies the following properties
|
|
64
|
+
- serializable (`content_v()`, `content_k()` and `get_content()`)
|
|
65
|
+
Used for exporting this object with to_json and to_json_member
|
|
66
|
+
- hashable (`to_tuple()`, `__hash__()`, `__eq__()`)
|
|
67
|
+
This object can be used as a dict key
|
|
68
|
+
- markable (`mark()`)
|
|
69
|
+
Allows garbage collection (see below)
|
|
70
|
+
- registerable (hashable, register)
|
|
71
|
+
Allows the (child) object instance to be registered to a parent object
|
|
72
|
+
|
|
73
|
+
## Serializable / JSON Export
|
|
74
|
+
JSONexportable instancess can be exported as a dict using `to_json()`, which will
|
|
75
|
+
export the full dict of properties given by `get_content()`. To optimize the exported
|
|
76
|
+
JSON, nested objects can be exported using `to_json_member()` using the index obtained
|
|
77
|
+
from register (see below).
|
|
78
|
+
|
|
79
|
+
## Registerable & Hashable
|
|
80
|
+
For later reference and exporting, instances of child classes will be kept in a
|
|
81
|
+
registry (`_instances`). These dicts should be class variables
|
|
82
|
+
of any child class with a `typename`. Each instance is uniquely identifyable with
|
|
83
|
+
an `_idx`. The hashable properties are used for faster comparisons between objects
|
|
84
|
+
using the `_instance_dict` (mapping instance -> idx). After exporting `clear()` can
|
|
85
|
+
be called to delete all instances.
|
|
86
|
+
|
|
87
|
+
## Markable / Garbage collection
|
|
88
|
+
To be able to identify "unused" objects, i.e. objects which will not be referenced
|
|
89
|
+
when calling from a root object, objects can be marked using `mark()`, and must
|
|
90
|
+
also call `mark()` on any of their JSONexportable member objects. Garbage collection
|
|
91
|
+
can then delete any non-marked instances from the instance list and re-index the
|
|
92
|
+
remaining instances.
|
|
93
|
+
"""
|
|
94
|
+
|
|
95
|
+
__slots__ = ("_idx", "_marked", "_name", "_hash_cache", "_content_cache")
|
|
96
|
+
_instances: dict[int, Any]
|
|
97
|
+
"""Contains all instances of the class, as a map from global index to the object."""
|
|
98
|
+
_instance_dict: dict[Any, int]
|
|
99
|
+
"""Used for fast hash comparisons of existing instances of this class."""
|
|
100
|
+
typename: str = ""
|
|
101
|
+
"""Typename of the base class, """
|
|
102
|
+
_global_instance_counter: ClassVar[int] = 0
|
|
103
|
+
|
|
104
|
+
def __init__(self, name: str | None) -> None:
|
|
105
|
+
"""
|
|
106
|
+
Args:
|
|
107
|
+
name (str | None): Name of the instance, exported in debug mode.
|
|
108
|
+
"""
|
|
109
|
+
self._name = name
|
|
110
|
+
self._idx = -1
|
|
111
|
+
self._marked = False
|
|
112
|
+
self._hash_cache = None
|
|
113
|
+
self._content_cache = None
|
|
114
|
+
|
|
115
|
+
def content_v(self) -> tuple:
|
|
116
|
+
"""
|
|
117
|
+
Returns:
|
|
118
|
+
tuple : A tuple of content values of the class for serialization.
|
|
119
|
+
"""
|
|
120
|
+
return ()
|
|
121
|
+
|
|
122
|
+
def content_k(self) -> tuple:
|
|
123
|
+
"""
|
|
124
|
+
Returns:
|
|
125
|
+
tuple : A tuple of content keys of the class for serialization.
|
|
126
|
+
"""
|
|
127
|
+
return ()
|
|
128
|
+
|
|
129
|
+
def get_content(self) -> dict[str, Any]:
|
|
130
|
+
"""
|
|
131
|
+
Used for serialization of the object.
|
|
132
|
+
Returns:
|
|
133
|
+
dict[keys, values] : A dict for unique variables in this instance
|
|
134
|
+
"""
|
|
135
|
+
return dict(zip(self.content_k(), self.content_v()))
|
|
136
|
+
|
|
137
|
+
def to_json(self) -> dict[str, Any]:
|
|
138
|
+
"""
|
|
139
|
+
JSON representation of the object.
|
|
140
|
+
|
|
141
|
+
Returns:
|
|
142
|
+
dict[str, Any] : A dict for unique variables in this instance, including the
|
|
143
|
+
name if the loglevel is `DEBUG` or below is enabled.
|
|
144
|
+
"""
|
|
145
|
+
if logger.level <= logging.DEBUG:
|
|
146
|
+
return {"name": f"[{self._idx}] {self._name}", **self.get_content()}
|
|
147
|
+
else:
|
|
148
|
+
return self.get_content()
|
|
149
|
+
|
|
150
|
+
def to_json_member(self):
|
|
151
|
+
"""JSON representation of the object as a member of another object
|
|
152
|
+
|
|
153
|
+
Returns:
|
|
154
|
+
Either a tuple(index, name) or an int (index) of the object.
|
|
155
|
+
"""
|
|
156
|
+
if logger.level <= logging.DEBUG:
|
|
157
|
+
return self._idx, self._name
|
|
158
|
+
else:
|
|
159
|
+
return self._idx
|
|
160
|
+
|
|
161
|
+
# NOTE: If __eq__ is overwritten by a child class, __hash__ will be implicitely set to None
|
|
162
|
+
def __eq__(self, other):
|
|
163
|
+
"""Equal is checked by comparing indices if the type strictly matches,
|
|
164
|
+
unless the object has not been registered yet, then the content is compared.
|
|
165
|
+
|
|
166
|
+
Note: This equal function is slow and should not be called.
|
|
167
|
+
Use primitive comparison in the specific child classes instead.
|
|
168
|
+
"""
|
|
169
|
+
return self.__hash__() == other.__hash__() and self.content_v() == other.content_v()
|
|
170
|
+
|
|
171
|
+
def to_tuple(self) -> tuple:
|
|
172
|
+
"""JSONexportable._content as a tuple, see base.to_tuple()
|
|
173
|
+
Returns:
|
|
174
|
+
tuple: The content of this object converted to a nested tuple.
|
|
175
|
+
"""
|
|
176
|
+
return to_tuple(self.get_content(), True)
|
|
177
|
+
|
|
178
|
+
def __hash__(self) -> int:
|
|
179
|
+
if self._hash_cache is not None:
|
|
180
|
+
return self._hash_cache
|
|
181
|
+
|
|
182
|
+
try:
|
|
183
|
+
content = self.content_v()
|
|
184
|
+
self._hash_cache = hash(content)
|
|
185
|
+
except TypeError:
|
|
186
|
+
if self._content_cache is None:
|
|
187
|
+
self._content_cache = to_tuple(self.content_v())
|
|
188
|
+
self._hash_cache = hash(self._content_cache)
|
|
189
|
+
|
|
190
|
+
return self._hash_cache
|
|
191
|
+
|
|
192
|
+
@classmethod
|
|
193
|
+
def clear(cls) -> None:
|
|
194
|
+
"""Removes all items from the instance registry."""
|
|
195
|
+
cls._instances.clear()
|
|
196
|
+
cls._instance_dict.clear()
|
|
197
|
+
|
|
198
|
+
def mark(self) -> None:
|
|
199
|
+
"""
|
|
200
|
+
Marks this instance and all JSONexportable instances contained by it.
|
|
201
|
+
Used for garbage collection, which will delete unmarked instances.
|
|
202
|
+
"""
|
|
203
|
+
self._marked = True
|
|
204
|
+
|
|
205
|
+
# NOTE: about ChannelMasks in Events and Sequences:
|
|
206
|
+
# Generally, ChannelMasks should be mutable for "register()" to work as intended, i.e.
|
|
207
|
+
# that it allows the same object to be extended over multiple channels.
|
|
208
|
+
# However this conflicts with the "Quench" syncing strategy, as it is implemented now.
|
|
209
|
+
# This strategy saves all sequences/events in one array in the order they have been added,
|
|
210
|
+
# Which requires ChannelMasks to be immutable. Hence the ChannelMask has to be added to
|
|
211
|
+
# content_v() and content_k() for events. If the ChannelMask object could be extended
|
|
212
|
+
# to account for later sequences using the "same" event, suddenly an event will appear
|
|
213
|
+
# in the sequence on channels which were not previously part of the sequence.
|
|
214
|
+
# The "Channelsequence" strategy of syncing avoids this, by indexing an array or sequence
|
|
215
|
+
# with the channels it has been added to, before calling register() to create a unified object.
|
|
216
|
+
# The second part of this problem are Parameters. While generally ChannelMasks can be expanded,
|
|
217
|
+
# if we convert Parameters for different domains with different resolutions, these parameters
|
|
218
|
+
# have to be unique to one domain, or rather are incompatible with domains with higher resolutions.
|
|
219
|
+
def register(self):
|
|
220
|
+
"""Add an instance to the instances registry.
|
|
221
|
+
Returns
|
|
222
|
+
JSONexportable: This instance or an already existing instance from the registry.
|
|
223
|
+
"""
|
|
224
|
+
if self._idx >= 0:
|
|
225
|
+
if configuration.debuglog_register_messages:
|
|
226
|
+
logger.debug(
|
|
227
|
+
"%s %s already registered with id %d at idx %d.",
|
|
228
|
+
self.typename,
|
|
229
|
+
self._name,
|
|
230
|
+
id(self),
|
|
231
|
+
self._idx,
|
|
232
|
+
)
|
|
233
|
+
return self
|
|
234
|
+
|
|
235
|
+
idx = self.__class__._instance_dict.get(self, -1)
|
|
236
|
+
if idx >= 0:
|
|
237
|
+
other = self.__class__._instances[idx]
|
|
238
|
+
if configuration.debuglog_register_messages:
|
|
239
|
+
logger.debug(
|
|
240
|
+
"%s %s already registered as %s with id %d at idx %d.",
|
|
241
|
+
self.typename,
|
|
242
|
+
self._name,
|
|
243
|
+
other._name,
|
|
244
|
+
id(other),
|
|
245
|
+
idx,
|
|
246
|
+
)
|
|
247
|
+
return other
|
|
248
|
+
else:
|
|
249
|
+
JSONexportable._global_instance_counter += 1
|
|
250
|
+
self._idx = JSONexportable._global_instance_counter
|
|
251
|
+
self.__class__._instances[self._idx] = self
|
|
252
|
+
self.__class__._instance_dict[self] = self._idx
|
|
253
|
+
if configuration.debuglog_register_messages:
|
|
254
|
+
logger.debug(
|
|
255
|
+
"Registering %s %s with id %d at idx %d",
|
|
256
|
+
self.typename,
|
|
257
|
+
self._name,
|
|
258
|
+
id(self),
|
|
259
|
+
self._idx,
|
|
260
|
+
)
|
|
261
|
+
return self
|
|
262
|
+
|
|
263
|
+
def __repr__(self) -> str:
|
|
264
|
+
return f"{self.get_content()}"
|
|
File without changes
|
|
@@ -0,0 +1,65 @@
|
|
|
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.hardware import DDSHardware
|
|
7
|
+
from ionpulse_sequence_generator.hardware.system import System
|
|
8
|
+
from ionpulse_sequence_generator.parameter.parameter import Time
|
|
9
|
+
|
|
10
|
+
from .wait import Wait
|
|
11
|
+
|
|
12
|
+
logger = logging.getLogger(__name__)
|
|
13
|
+
system = System()
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class DDSPIDStateChange(Wait):
|
|
17
|
+
"""
|
|
18
|
+
# Wait
|
|
19
|
+
This event will idle a single channel for the given wait time.
|
|
20
|
+
|
|
21
|
+
This is used for padding and syncing multiple channels:
|
|
22
|
+
```
|
|
23
|
+
RFEdge RFEdge RFEdge |
|
|
24
|
+
CH1: <-time->|action| <-time->|action| <-time->|action| | CH1 and
|
|
25
|
+
RFEdge RFEdge RFWait |
|
|
26
|
+
CH2: <-time->|action| <-time->|action| <-time-> | CH2 synced
|
|
27
|
+
```
|
|
28
|
+
"""
|
|
29
|
+
|
|
30
|
+
__slots__ = "_dds_pid_state_change"
|
|
31
|
+
|
|
32
|
+
def __init__(
|
|
33
|
+
self,
|
|
34
|
+
name: str,
|
|
35
|
+
ch_idx: ChannelMask,
|
|
36
|
+
time: Time,
|
|
37
|
+
state: DDSHardware.PIDStateChangeType,
|
|
38
|
+
wait_for_trigger=False,
|
|
39
|
+
) -> None:
|
|
40
|
+
"""
|
|
41
|
+
Args:
|
|
42
|
+
name (str): name, exported to the JSON for debugging
|
|
43
|
+
ch_mask (ChannelMask): channel this event is defined on
|
|
44
|
+
time (Time | None): wait time
|
|
45
|
+
wait_for_trigger (bool, optional): If True, the decoder will stall until a re-trigger event.
|
|
46
|
+
Defaults to False.
|
|
47
|
+
"""
|
|
48
|
+
super().__init__(name, ch_idx, time, wait_for_trigger)
|
|
49
|
+
self._dds_pid_state_change = state
|
|
50
|
+
|
|
51
|
+
def content_v(self) -> tuple:
|
|
52
|
+
return (
|
|
53
|
+
self._type,
|
|
54
|
+
self._ch_mask,
|
|
55
|
+
self._time._idx,
|
|
56
|
+
self._dds_pid_state_change,
|
|
57
|
+
)
|
|
58
|
+
|
|
59
|
+
def content_k(self) -> tuple:
|
|
60
|
+
return (
|
|
61
|
+
"type",
|
|
62
|
+
ChannelMask.typename,
|
|
63
|
+
Time.typename,
|
|
64
|
+
"dds_pid_state_change",
|
|
65
|
+
)
|
|
@@ -0,0 +1,73 @@
|
|
|
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 DIOEvent(Event):
|
|
16
|
+
"""
|
|
17
|
+
# DIOEvent
|
|
18
|
+
This Event is used for digital inputs (8 bit) and outputs (32 bit) managed by Pulseway.
|
|
19
|
+
"""
|
|
20
|
+
|
|
21
|
+
__slots__ = ("_input_gate_mask", "_input_gate_state", "_output_mask", "_output_state")
|
|
22
|
+
|
|
23
|
+
def __init__(
|
|
24
|
+
self,
|
|
25
|
+
name: str,
|
|
26
|
+
ch_idx: ChannelMask,
|
|
27
|
+
time: Time,
|
|
28
|
+
output_state: int,
|
|
29
|
+
output_mask: int = 0xFFFFFFFF,
|
|
30
|
+
input_gate_state: int = 0x0,
|
|
31
|
+
input_gate_mask: int = 0xFF,
|
|
32
|
+
) -> None:
|
|
33
|
+
"""
|
|
34
|
+
Args:
|
|
35
|
+
name (str): name, exported to the JSON for debugging
|
|
36
|
+
ch_mask (ChannelMask): channel this event is defined on
|
|
37
|
+
time (Time | None): wait time until the output and input_gate is applied
|
|
38
|
+
output_state (int): output_state after the event
|
|
39
|
+
output_mask (int, optional): mask for the output state (only bits with 1s in the mask
|
|
40
|
+
will be changed in the state). Defaults to 0xFFFFFFFF.
|
|
41
|
+
input_gate_state (int, optional): activating inputs for edge detection. Defaults to 0x0.
|
|
42
|
+
input_gate_mask (int, optional): mask for the input (only 1s in the mask will be
|
|
43
|
+
changed in the state). Defaults to 0xFF.
|
|
44
|
+
"""
|
|
45
|
+
for hw in system.get_hw_from_ch_mask(ch_idx):
|
|
46
|
+
hw.check_time(time._value, time._unit, edge=True)
|
|
47
|
+
super().__init__(name, ch_idx, time)
|
|
48
|
+
self._output_state = output_state
|
|
49
|
+
self._output_mask = output_mask
|
|
50
|
+
self._input_gate_state = input_gate_state
|
|
51
|
+
self._input_gate_mask = input_gate_mask
|
|
52
|
+
|
|
53
|
+
def content_v(self) -> tuple:
|
|
54
|
+
return (
|
|
55
|
+
self._type,
|
|
56
|
+
self._time._idx,
|
|
57
|
+
self._ch_mask,
|
|
58
|
+
self._output_state,
|
|
59
|
+
self._output_mask,
|
|
60
|
+
self._input_gate_state,
|
|
61
|
+
self._input_gate_mask,
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
def content_k(self) -> tuple:
|
|
65
|
+
return (
|
|
66
|
+
"type",
|
|
67
|
+
Time.typename,
|
|
68
|
+
ChannelMask.typename,
|
|
69
|
+
"output_state",
|
|
70
|
+
"output_mask",
|
|
71
|
+
"input_gate_state",
|
|
72
|
+
"input_gate_mask",
|
|
73
|
+
)
|