Source code for mjolnir.instruments.physical_instruments

from math import floor, log10, pi, sqrt
from typing import Any, Mapping

from qcodes import validators
from qcodes.instrument import Instrument, InstrumentBase, InstrumentChannel, ChannelTuple
from qcodes.parameters import ManualParameter, DelegateParameter

MERCURY_Z_CYLINDER_HEIGHT = 6
MERCURY_Z_CYLINDER_RADIUS = 0.262
MERCURY_BALL_RADIUS = 3.001


[docs] def mercury_ips_limits(x, y, z): rho_z = (x**2 + y**2) ** 0.5 r = sqrt(x**2 + y**2 + z**2) inside_cylinder_z = (rho_z <= MERCURY_Z_CYLINDER_RADIUS and -MERCURY_Z_CYLINDER_HEIGHT <= z <= MERCURY_Z_CYLINDER_HEIGHT) inside_ball = r <= MERCURY_BALL_RADIUS return inside_cylinder_z or inside_ball
[docs] class BreakoutBoxChannel(InstrumentChannel): """A single channel of the breakout box.""" SI_PREFIXES = {prefix: 10**exponent for prefix, exponent in zip(('u', 'm', '', 'k', 'M', 'G'), range(-6, 12, 3))} SI_PREFIXES_INVERTED = {power: prefix for prefix, power in SI_PREFIXES.items()} def __init__(self, parent: InstrumentBase, number: int, **kwargs: Any) -> None: super().__init__(parent, f'ch{number:02d}', **kwargs) self.number = number self.setting: ManualParameter = self.add_parameter( 'setting', parameter_class=ManualParameter, vals=validators.Enum('GND', '1:1', '1:1 1k', '1:1 17', '1:6', '1:6 1k', '1:6 17') ) """Filter setting.""" self.filter_RC: DelegateParameter = self.add_parameter( 'filter_RC', parameter_class=DelegateParameter, source=self.setting, get_parser=self._RC_from_str, set_parser=self._str_from_RC, unit='s' ) """RC constant of the filter.""" def _RC_from_str(self, s: str | None) -> float | None: if s is None: return None *connection, setting = s.split(' ') if not len(connection): return 0.0 if setting[-1].isalpha(): prefactor = int(setting[:-1]) prefix = setting[-1:] else: prefactor = int(setting) prefix = '' return 1 / (2 * pi * prefactor * self.SI_PREFIXES[prefix]) def _str_from_RC(self, RC: float | None) -> str | None: if RC is None: return None fcut = 1 / (2 * pi * RC) *connection, setting = self.setting.get().split(' ') if not len(connection): raise ValueError('Cannot infer connection type. Please set setting parameter instead.') prefix = self.SI_PREFIXES_INVERTED[10**floor(round(log10(fcut), 10))] prefactor = str(int(fcut // self.SI_PREFIXES[prefix])) return ' '.join(connection + [prefactor + prefix])
[docs] class BreakoutBox(Instrument): """Metadata-only instrument representing the state of the BoB.""" def __init__(self, name: str, num_channels: int = 96, metadata: Mapping[Any, Any] | None = None, label: str | None = None) -> None: super().__init__(name, metadata=metadata, label=label) channels = [] for ch in range(1, num_channels + 1): channel = BreakoutBoxChannel(self, ch) channels.append(channel) self.add_submodule(channel.name, channel) self.add_submodule( 'channels', ChannelTuple(self, 'channels', BreakoutBoxChannel, channels, snapshotable=False) )