Skip to content

Commit 236edc8

Browse files
committed
fix: change port and fem entries from str to int
1 parent ea5b21b commit 236edc8

File tree

2 files changed

+18
-29
lines changed

2 files changed

+18
-29
lines changed

src/qibolab/_core/instruments/qm/config/devices.py

+17-25
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from dataclasses import dataclass, field
2-
from typing import Generic, Literal, TypeVar, Union
2+
from typing import Literal, Union
33

44
from qibolab._core.components import OscillatorConfig
55

@@ -22,19 +22,6 @@
2222
"Controllers",
2323
]
2424

25-
V = TypeVar("V")
26-
27-
28-
class PortDict(Generic[V], dict[str, V]):
29-
"""Dictionary that automatically converts keys to strings.
30-
31-
Used to register input and output ports to controllers and Octaves
32-
in the QUA config.
33-
"""
34-
35-
def __setitem__(self, key: Union[str, int], value: V):
36-
super().__setitem__(str(key), value)
37-
3825

3926
@dataclass(frozen=True)
4027
class AnalogInput:
@@ -67,8 +54,12 @@ def update(self, config: MwFemOscillatorConfig):
6754
assert self.band == config.band
6855
assert self.sampling_rate == config.sampling_rate
6956
assert self.full_scale_power_dbm == config.power
70-
assert config.upconverter not in self.upconverters
71-
self.upconverters[config.upconverter] = {"frequency": config.frequency}
57+
if config.upconverter not in self.upconverters:
58+
self.upconverters[config.upconverter] = {"frequency": config.frequency}
59+
else:
60+
assert (
61+
config.frequency == self.upconverters[config.upconverter]["frequency"]
62+
)
7263

7364

7465
@dataclass(frozen=True)
@@ -116,10 +107,10 @@ class OctaveInput:
116107
class Controller:
117108
type: ModuleTypes = "opx1"
118109
"""https://docs.quantum-machines.co/latest/docs/Introduction/config/?h=opx10#controllers"""
119-
analog_outputs: PortDict[dict[str, dict]] = field(default_factory=PortDict)
120-
digital_outputs: PortDict[dict[str, dict]] = field(default_factory=PortDict)
121-
analog_inputs: PortDict[dict[str, Union[AnalogInput, MwFemInput]]] = field(
122-
default_factory=PortDict
110+
analog_outputs: dict[int, dict] = field(default_factory=dict)
111+
digital_outputs: dict[int, dict] = field(default_factory=dict)
112+
analog_inputs: dict[int, Union[AnalogInput, MwFemInput]] = field(
113+
default_factory=dict
123114
)
124115

125116
def _set_default_inputs(self):
@@ -150,14 +141,14 @@ def add_octave_input(self, port: int, config: QmAcquisitionConfig):
150141
@dataclass
151142
class Opx1000:
152143
type: Literal["opx1000"] = "opx1000"
153-
fems: dict[str, Controller] = field(default_factory=PortDict)
144+
fems: dict[int, Controller] = field(default_factory=dict)
154145

155146

156147
@dataclass
157148
class Octave:
158149
connectivity: Union[str, tuple[str, int]]
159-
RF_outputs: PortDict[dict[str, OctaveOutput]] = field(default_factory=PortDict)
160-
RF_inputs: PortDict[dict[str, OctaveInput]] = field(default_factory=PortDict)
150+
RF_outputs: dict[int, OctaveOutput] = field(default_factory=dict)
151+
RF_inputs: dict[int, OctaveInput] = field(default_factory=dict)
161152

162153
def __post_init__(self):
163154
if "/" in self.connectivity:
@@ -179,9 +170,10 @@ def process_controller_id(id: ControllerId):
179170
"""
180171
if isinstance(id, tuple):
181172
con, fem = id
182-
return con, str(fem)
173+
return con, fem
183174
if "/" in id:
184-
return id.split("/")
175+
con, fem = id.split("/")
176+
return con, int(fem)
185177
return id, None
186178

187179

src/qibolab/_core/instruments/qm/controller.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -536,10 +536,7 @@ def play(
536536
experiment = program(args, options, sweepers, offsets)
537537

538538
if self.script_file_name is not None:
539-
script_config = (
540-
{"version": 1} if self.manager is None else asdict(self.config)
541-
)
542-
script = generate_qua_script(experiment, script_config)
539+
script = generate_qua_script(experiment, asdict(self.config))
543540
with open(self.script_file_name, "w") as file:
544541
file.write(script)
545542

0 commit comments

Comments
 (0)