stoner_measurement.plugins.state_sweep.base.StateSweepPlugin

class stoner_measurement.plugins.state_sweep.base.StateSweepPlugin(parent: QObject | None = None)[source]

Bases: StatePlugin

Base class for plugins that run a sub-sequence inside a continuous sweep loop.

A StateSweepPlugin drives a hardware sweep (e.g. a continuously ramping magnet, a time-based monitor) by iterating a BaseSweepGenerator and executing nested sub-steps at each sampled point.

In addition to the shared state and data-collection infrastructure inherited from StatePlugin, this class adds:

  • Sweep generator — sweep_generator provides an infinite (or finite) stream of (index, value, stage, meas_flag) tuples.

  • Sweep timeout — if the sweep generator can estimate its duration (via estimated_duration()), the allowed wall-clock time is estimated_duration × sweep_timeout_factor. When the deadline is exceeded state_error is emitted and the loop stops.

  • Safety limits — if a sampled value falls outside limits state_error is emitted and the loop stops.

  • Progress signals — state_changed is emitted at each sampled point; state_reached on normal completion.

Variables:
  • sweep_generator (BaseSweepGenerator) – Active sweep generator instance.

  • sweep_timeout_factor (float) – Multiplier applied to the sweep generator’s estimated duration to compute the sweep deadline. Defaults to default_sweep_timeout_factor, which concrete plugins may override. Has no effect when the generator returns inf for its estimated duration.

  • default_sweep_timeout_factor (float) – Plugin-type-specific default used to initialise sweep_timeout_factor.

  • sweep_generator_changed (pyqtSignal) – Emitted after sweep_generator is replaced.

Keyword Parameters:

parent (QObject | None) – Optional Qt parent object.

Examples

>>> from qtpy.QtWidgets import QApplication
>>> _ = QApplication.instance() or QApplication([])
>>> from stoner_measurement.plugins.state_sweep import SweepTimePlugin
>>> p = SweepTimePlugin()
>>> p.plugin_type
'state_sweep'
>>> p.sweep_timeout_factor
2.0
>>> import math
>>> math.isinf(p.sweep_timeout)
True
config_tabs(parent: QWidget | None = None) → list[tuple[str, QWidget]][source]

Return a fixed set of configuration tabs for this plugin.

Returns:

List of (tab_title, widget) pairs.

Return type:

(list[tuple[str, QWidget]])

declared_outputs() → PluginOutputs[source]

Declare state outputs with the current sweep segment.

default_measure_condition_step()[source]

Return an If command configured for this sweep’s measure flag.

property default_sweep_timeout_factor: float

Return the default timeout factor for this plugin type.

Returns:

Initial timeout multiplier applied to estimated sweep duration.

Return type:

(float)

effective_poll_period_seconds(configured_seconds: float) → float[source]

Return the minimum complete-loop period for the configured and engine rates.

execute_sequence(sub_steps: list) → None[source]

Connect, configure, and run sub_steps once per sweep point.

The sweep generator supplies (ix, value, stage, meas_flag) tuples. sub_steps are executed for every yielded point. meas_flag is retained on the plugin as point metadata for sub-steps and collection logic; it does not gate whether sub-steps run.

Parameters:

sub_steps (list) – Ordered list of zero-argument callables to run at each sweep point.

generate_action_code(indent: int, sub_steps: list, render_sub_step: Callable) → list[str][source]

Return action code lines for a while next(...) sweep loop.

Parameters:
  • indent (int) – Number of four-space indentation levels.

  • sub_steps (list) – Raw sub-step descriptors from the sequence tree.

  • render_sub_step (Callable) – Callback (step, indent) -> list[str] provided by the engine.

Returns:

Lines implementing the sweep loop with nested sub-step bodies.

Return type:

(list[str])

Examples

>>> from qtpy.QtWidgets import QApplication
>>> _ = QApplication.instance() or QApplication([])
>>> from stoner_measurement.plugins.state_sweep import SweepTimePlugin
>>> p = SweepTimePlugin()
>>> lines = p.generate_action_code(1, [], lambda s, i: [])
>>> any("while next(" in line for line in lines)
True
>>> p.clear_on_start = True
>>> lines2 = p.generate_action_code(1, [], lambda s, i: [])
>>> any(".clear_data()" in line for line in lines2)
True
>>> p.collect_data = True
>>> lines3 = p.generate_action_code(1, [], lambda s, i: [])
>>> any(".collect()" in line for line in lines3)
True
get_state() → float[source]

Read the current state value.

Returns:

Defaults to the most recently sampled value.

Return type:

(float)

is_at_target() → bool[source]

Return whether the target is reached (always True by default).

property plugin_type: str

Short tag identifying this plugin as a state-sweep plugin.

Returns:

Always "state_sweep".

Return type:

(str)

property segment: int

Return the current zero-based segment index for the active sweep point.

set_rate(value: float) → None[source]

Set the active sweep rate (NOP default).

set_state(value: float) → None[source]

Set the current state value (NOP default).

set_sweep_generator_class(cls: type[BaseSweepGenerator]) → None[source]

Replace the active sweep generator with a new instance of cls.

Parameters:

cls (type[BaseSweepGenerator]) – The sweep generator class to instantiate.

set_target(value: float) → None[source]

Set the active target value (NOP default).

abstract property state_name: str

Human-readable name for the swept state.

sweep_generator_changed

Qt signal.

pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL

types is normally a sequence of individual types.  Each type is either a
type object or a string that is the name of a C++ type.  Alternatively
each type could itself be a sequence of types each describing a different
overloaded signal.
name is the optional C++ name of the signal.  If it is not specified then
the name of the class attribute that is bound to the signal is used.
revision is the optional revision of the signal that is exported to QML.
If it is not specified then 0 is used.
arguments is the optional sequence of the names of the signal's arguments.
property sweep_rate_time_scale_seconds: float

Return the time-scale factor used to convert rate-based durations.

Returns:

Multiplicative factor converting distance / rate into seconds for this plugin’s rate units.

Return type:

(float)

Notes

Typical values are 60.0 for rate units expressed per minute and 1.0 for rate units expressed per second.

property sweep_timeout: float

Maximum allowed wall-clock sweep time in seconds.

Computed as sweep_generator.estimated_duration() * sweep_timeout_factor. Returns float("inf") when the generator cannot estimate its duration, effectively disabling the timeout.

Returns:

Timeout in seconds, or inf if not calculable.

Return type:

(float)

Examples

>>> from qtpy.QtWidgets import QApplication
>>> _ = QApplication.instance() or QApplication([])
>>> from stoner_measurement.sweep import MultiSegmentRampSweepGenerator
>>> from stoner_measurement.plugins.state_sweep import SweepTimePlugin
>>> p = SweepTimePlugin()
>>> p.sweep_generator = MultiSegmentRampSweepGenerator(
...     start=0.0, segments=[(2.0, 1.0, True)], state_sweep=p, parent=p
... )
>>> p.sweep_timeout_factor = 3.0
>>> p.sweep_timeout
540.3
to_json() → dict[str, Any][source]

Serialise this plugin’s configuration, including the sweep generator.

Extends to_json() with "sweep_generator" and "sweep_timeout_factor" keys.

Returns:

JSON-serialisable dictionary with all plugin keys.

Return type:

(dict[str, Any])

Examples

>>> from qtpy.QtWidgets import QApplication
>>> _ = QApplication.instance() or QApplication([])
>>> from stoner_measurement.plugins.state_sweep import SweepTimePlugin
>>> d = SweepTimePlugin().to_json()
>>> d["type"]
'state_sweep'
>>> "sweep_generator" in d
True
>>> d["sweep_timeout_factor"]
2.0
abstract property units: str

Physical units for the swept state.