stoner_measurement.instruments.magnet_controller.MagnetController¶
- class stoner_measurement.instruments.magnet_controller.MagnetController(transport: BaseTransport, protocol: BaseProtocol)[source]¶
Bases:
BaseInstrumentAbstract base class for superconducting magnet power supply drivers.
Provides a uniform interface for controlling superconducting magnet power supplies such as the Oxford Instruments IPS120-10. All field values are in tesla and ramp rates in tesla per minute unless otherwise stated.
Subclasses must implement all abstract methods.
- Variables:
transport (BaseTransport) – Transport layer instance.
protocol (BaseProtocol) – Protocol layer instance.
Examples
>>> from stoner_measurement.instruments.transport import NullTransport >>> from stoner_measurement.instruments.protocol import OxfordProtocol >>> from stoner_measurement.instruments.magnet_controller import ( ... MagnetController, MagnetState, MagnetStatus, MagnetLimits, ... ) >>> class _MC(MagnetController): ... def get_model(self): return "TestMagnet" ... def get_firmware_version(self): return "1.0" ... @property ... def current(self): return 0.0 ... @property ... def field(self): return 0.0 ... @property ... def voltage(self): return 0.0 ... @property ... def status(self): ... return MagnetStatus( ... state=MagnetState.STANDBY, current=0.0, field=0.0, ... voltage=0.0, persistent=False, heater_on=False, ... at_target=True, ... ) ... @property ... def magnet_constant(self): return 0.1 ... @property ... def limits(self): return MagnetLimits(max_current=100.0) ... @property ... def heater(self): return False ... def set_target_current(self, current): pass ... def set_target_field(self, field): pass ... def set_ramp_rate_current(self, rate): pass ... def set_ramp_rate_field(self, rate): pass ... def set_magnet_constant(self, tesla_per_amp): pass ... def set_limits(self, limits): pass ... def ramp_to_target(self): pass ... def ramp_to_current(self, current, *, wait=False): pass ... def ramp_to_field(self, field, *, wait=False): pass ... def pause_ramp(self): pass ... def abort_ramp(self): pass ... def heater_on(self): pass ... def heater_off(self): pass >>> mc = _MC(NullTransport(), OxfordProtocol()) >>> mc.get_model() 'TestMagnet' >>> mc.status.state <MagnetState.STANDBY: 'standby'>
- abstractmethod abort_ramp() None[source]¶
Abort ramping immediately and hold the output at its current value.
- Raises:
ConnectionError – If the transport is not open.
- abstract property current: float¶
Return the current output in amps.
- Returns:
Instantaneous output current in amps.
- Return type:
(float)
- Raises:
ConnectionError – If the transport is not open.
- abstract property field: float¶
Return the magnetic field output in tesla.
- Returns:
Estimated magnetic field in tesla derived from the output current and the configured magnet constant.
- Return type:
(float)
- Raises:
ConnectionError – If the transport is not open.
- abstractmethod get_firmware_version() str[source]¶
Return the firmware version string.
- Returns:
Firmware version as reported by the device.
- Return type:
(str)
- Raises:
ConnectionError – If the transport is not open.
Examples
>>> mc.get_firmware_version() '1.0'
- abstractmethod get_model() str[source]¶
Return the instrument model identifier string.
- Returns:
Instrument model identifier as reported by the device.
- Return type:
(str)
- Raises:
ConnectionError – If the transport is not open.
Examples
>>> mc.get_model() 'TestMagnet'
- abstract property heater: bool¶
Return the persistent switch heater state.
- Returns:
Truewhen the persistent switch heater is energised,Falsewhen it is off.- Return type:
(bool)
- Raises:
ConnectionError – If the transport is not open.
- abstractmethod heater_off() None[source]¶
De-energise the persistent switch heater.
- Raises:
ConnectionError – If the transport is not open.
- abstractmethod heater_on() None[source]¶
Energise the persistent switch heater.
- Raises:
ConnectionError – If the transport is not open.
- abstract property limits: MagnetLimits¶
Return the configured operating limits.
- Returns:
Maximum permitted current, field, and ramp rate.
- Return type:
- Raises:
ConnectionError – If the transport is not open.
- abstract property magnet_constant: float¶
Return the magnet constant in tesla per amp.
- Returns:
Field-to-current conversion factor in T A⁻¹.
- Return type:
(float)
- Raises:
ConnectionError – If the transport is not open.
- abstractmethod pause_ramp() None[source]¶
Pause an active ramp, holding the output at its current value.
- Raises:
ConnectionError – If the transport is not open.
- property ramp_rate_current: float | None¶
Return the programmed current ramp rate in amps per minute when available.
Drivers that do not support direct ramp-rate readback return
None.
- property ramp_rate_field: float | None¶
Return the programmed field ramp rate in tesla per minute when available.
Drivers that do not support direct ramp-rate readback return
None.
- abstractmethod ramp_to_current(current: float, *, wait: bool = False) None[source]¶
Set a new target current and begin ramping.
- Parameters:
current (float) – Desired target current in amps.
- Keyword Parameters:
wait (bool) – If
True, block until the target is reached. Defaults toFalse.- Raises:
ConnectionError – If the transport is not open.
ValueError – If current exceeds the configured maximum.
- abstractmethod ramp_to_field(field: float, *, wait: bool = False) None[source]¶
Set a new target field and begin ramping.
- Parameters:
field (float) – Desired target field in tesla.
- Keyword Parameters:
wait (bool) – If
True, block until the target is reached. Defaults toFalse.- Raises:
ConnectionError – If the transport is not open.
ValueError – If field exceeds the configured maximum.
- abstractmethod ramp_to_target() None[source]¶
Start ramping the output towards the currently programmed target.
- Raises:
ConnectionError – If the transport is not open.
- refresh_magnet_constant() float[source]¶
Refresh and return the magnet constant from the controller.
Drivers whose magnet constant is effectively static or already cached may rely on the default implementation. Drivers that need an explicit hardware query should override this method.
- abstractmethod return_to_local() None[source]¶
Return the controller front panel to local/manual operation.
This is intended as a safety-oriented handoff from software control back to an in-person operator, for example during disconnect or after a quench condition has been detected.
Implementations should prefer a non-locked local or remote/local mode that leaves the instrument operable from the front panel. They should not place the controller into a remotely locked-out state.
- Raises:
ConnectionError – If the transport is not open.
- abstractmethod set_limits(limits: MagnetLimits) None[source]¶
Set operating limits for the controller.
- Parameters:
limits (MagnetLimits) – Maximum current, field, and ramp rate limits to apply.
- Raises:
ConnectionError – If the transport is not open.
- abstractmethod set_magnet_constant(tesla_per_amp: float) None[source]¶
Set the magnet constant used for field calculations.
- Parameters:
tesla_per_amp (float) – Field-to-current conversion factor in T A⁻¹.
- Raises:
ConnectionError – If the transport is not open.
ValueError – If tesla_per_amp is not positive.
- abstractmethod set_ramp_rate_current(rate: float) None[source]¶
Set the current ramp rate.
- Parameters:
rate (float) – Ramp rate in amps per minute.
- Raises:
ConnectionError – If the transport is not open.
ValueError – If rate exceeds the configured maximum or is negative.
- abstractmethod set_ramp_rate_field(rate: float) None[source]¶
Set the field ramp rate.
- Parameters:
rate (float) – Ramp rate in tesla per minute.
- Raises:
ConnectionError – If the transport is not open.
ValueError – If rate exceeds the configured maximum or is negative.
- abstractmethod set_target_current(current: float) None[source]¶
Set the target output current.
- Parameters:
current (float) – Desired target current in amps.
- Raises:
ConnectionError – If the transport is not open.
ValueError – If current exceeds the configured maximum.
- abstractmethod set_target_field(field: float) None[source]¶
Set the target magnetic field.
- Parameters:
field (float) – Desired target field in tesla.
- Raises:
ConnectionError – If the transport is not open.
ValueError – If field exceeds the configured maximum.
- abstract property status: MagnetStatus¶
Return a consolidated status snapshot.
- Returns:
Current operational state, output readings, and heater status.
- Return type:
- Raises:
ConnectionError – If the transport is not open.
- property target_current: float | None¶
Return the programmed current target in amps when available.
Drivers that do not support direct setpoint readback return
None.
- property target_field: float | None¶
Return the programmed field target in tesla when available.
Drivers that do not support direct setpoint readback return
None.
- abstract property voltage: float¶
Return the output voltage in volts.
- Returns:
Instantaneous output voltage in volts.
- Return type:
(float)
- Raises:
ConnectionError – If the transport is not open.