stoner_measurement.plugins.state_sweep.base.StateSweepPlugin¶
- class stoner_measurement.plugins.state_sweep.base.StateSweepPlugin(parent: QObject | None = None)[source]¶
Bases:
StatePluginBase class for plugins that run a sub-sequence inside a continuous sweep loop.
A
StateSweepPlugindrives a hardware sweep (e.g. a continuously ramping magnet, a time-based monitor) by iterating aBaseSweepGeneratorand 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_generatorprovides 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 isestimated_duration × sweep_timeout_factor. When the deadline is exceededstate_erroris emitted and the loop stops.Safety limits — if a sampled value falls outside
limitsstate_erroris emitted and the loop stops.Progress signals —
state_changedis emitted at each sampled point;state_reachedon 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 returnsinffor 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_generatoris 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.
- declared_outputs() PluginOutputs[source]¶
Declare state outputs with the current sweep segment.
- default_measure_condition_step()[source]¶
Return an
Ifcommand 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_stepsare executed for every yielded point.meas_flagis 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:
- Returns:
Lines implementing the sweep loop with nested sub-step bodies.
- Return type:
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)
- property plugin_type: str¶
Short tag identifying this plugin as a state-sweep plugin.
- Returns:
Always
"state_sweep".- Return type:
(str)
- 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.
- 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 / rateinto seconds for this plugin’s rate units.- Return type:
(float)
Notes
Typical values are
60.0for rate units expressed per minute and1.0for 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. Returnsfloat("inf")when the generator cannot estimate its duration, effectively disabling the timeout.- Returns:
Timeout in seconds, or
infif 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.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