from typing import Any
from qcodes.instrument import Instrument, InstrumentChannel, InstrumentModule
from qcodes.instrument.channel import ChannelList
from qcodes.parameters import ManualParameter
from qm import QuantumMachinesManager
[docs]
class OPXChannel(InstrumentChannel):
def __init__(
self,
parent: InstrumentModule,
name: str,
channel_number: int,
direction: str,
**kwargs: Any,
) -> None:
super().__init__(parent, name, **kwargs)
self.channel_number = channel_number
self.direction = direction
self.add_parameter(
"enabled",
parameter_class=ManualParameter,
initial_value=True,
vals=None,
)
def __repr__(self) -> str:
return (
f"<{self.__class__.__name__}: {self.short_name} "
f"({self.direction} {self.channel_number})>"
)
[docs]
class OPXOutputChannel(OPXChannel):
def __init__(self, parent, name: str, channel_number: int, **kwargs):
super().__init__(
parent,
name,
channel_number=channel_number,
direction="output",
**kwargs,
)
[docs]
class FEMModule(InstrumentModule):
def __init__(
self,
parent: Instrument,
name: str,
slot: int,
module_type: str,
n_outputs: int,
n_inputs: int,
**kwargs: Any,
) -> None:
super().__init__(parent, name, **kwargs)
self.slot = slot
self.module_type = module_type
self.add_submodule(
"outputs",
ChannelList(self, "outputs", OPXOutputChannel, snapshotable=True),
)
for i in range(1, n_outputs + 1):
ch = OPXOutputChannel(self, f"out{i}", channel_number=i)
self.add_submodule(f"out{i}", ch)
self.outputs.append(ch)
self.outputs.lock()
self.add_submodule(
"inputs",
ChannelList(self, "inputs", OPXInputChannel, snapshotable=True),
)
for i in range(1, n_inputs + 1):
ch = OPXInputChannel(self, f"in{i}", channel_number=i)
self.add_submodule(f"in{i}", ch)
self.inputs.append(ch)
self.inputs.lock()
def __repr__(self) -> str:
return (
f"<{self.__class__.__name__}: {self.short_name} "
f"type={self.module_type} slot={self.slot}>"
)
[docs]
class OPX1000(Instrument):
def __init__(
self,
name: str,
ip_address: str,
port: int,
modules: dict[str, dict[str, Any]],
**kwargs: Any,
) -> None:
super().__init__(name, metadata={}, label="opx1000", **kwargs)
self.qmm = QuantumMachinesManager(
host=ip_address,
port=port,
)
self.add_submodule(
"modules",
ChannelList(self, "modules", FEMModule, snapshotable=True),
)
for module_name, module_config in modules.items():
self.add_module(module_name, **module_config)
self.modules.lock()
[docs]
def add_module(
self,
module_name: str,
**kwargs: Any,
) -> None:
module = FEMModule(
parent=self,
name=module_name,
**kwargs,
)
self.add_submodule(module_name, module)
self.modules.append(module)
[docs]
def get_idn(self) -> dict[str, str | None]:
"""
Override Instrument.get_idn so QCoDeS never calls self.ask('*IDN?').
"""
return {
"vendor": "Quantum Machines",
"model": self.name,
"serial": None,
"firmware": None,
}