stanza.routines

Module Contents

Classes

NameDescription
RoutineContextContext object passed to routine functions containing resources and results.
RoutineRunnerSimple runner that executes decorated routine functions with resources and configs.

Functions

NameDescription
routineDecorator to register a function as a routine.
get_registered_routinesGet all registered routines.
clear_routine_registryClear all registred routines

Data

logger _routine_registry

API

1stanza.routines.logger

Value: getLogger(...)

1stanza.routines._routine_registry: dict[str, collections.abc.Callable[..., typing.Any]]

Value: None

1class stanza.routines.RoutineContext(resources: stanza.registry.ResourceRegistry, results: stanza.registry.ResultsRegistry)

Context object passed to routine functions containing resources and results.

Initialization

Initialize context with resource and results registries.

1stanza.routines.routine(
2 func: collections.abc.Callable[..., typing.Any] | None = None,
3 *,
4 name: str | None = None
5) -> collections.abc.Callable[..., typing.Any]

Decorator to register a function as a routine.

The decorated function receives:

  • ctx: RoutineContext with ctx.resources and ctx.results
  • **params: Merged config and user parameters

Usage: @routine def my_sweep(ctx, gate, voltages, measure_contact): device = ctx.resources.device return device.sweep_1d(gate, voltages, measure_contact)

@routine(name=“custom_name”) def analyze_sweep(ctx, **params):

Access previous sweep data

sweep_data = ctx.results.get(“my_sweep”) if sweep_data: voltages, currents = sweep_data

Do analysis…

return analysis_result

1stanza.routines.get_registered_routines() -> dict[str, collections.abc.Callable[..., typing.Any]]

Get all registered routines.

1stanza.routines.clear_routine_registry() -> None

Clear all registred routines

1class stanza.routines.RoutineRunner(resources: list[typing.Any] | None = None, configs: list[typing.Any] | None = None)

Simple runner that executes decorated routine functions with resources and configs.

Resources can be provided in two ways:

  1. Pass initialized resources directly via resources parameter
  2. Pass configuration objects via configs parameter (runner instantiates resources)

When using the configs parameter, a DataLogger is automatically created and registered with name=“logger” for convenient logging within routines.

Examples:

With initialized resources

device = Device(name=“device”, …) logger = DataLogger(name=“logger”, …) runner = RoutineRunner(resources=[device, logger])

With configs (runner creates device + logger automatically)

device_config = DeviceConfig(…) runner = RoutineRunner(configs=[device_config])

Now ctx.resources.device and ctx.resources.logger are available

Initialization

Initialize runner with resources or configs.

Parameters:

Parameters:

  • resources: List of resource objects with .name attribute (Device, DataLogger, etc.)
  • configs: List of configuration objects (DeviceConfig, etc.) to instantiate resources from

Raises:

ValueError: If neither resources nor configs provided, or if both provided

1_build_resources_from_configs(configs: list[typing.Any]) -> list[stanza.logger.data_logger.DataLogger | typing.Any]

Instantiate resources from configuration objects.

Parameters:

configs
list[typing.Any]

List of configuration objects (e.g., DeviceConfig)

Returns:

List of instantiated resource objects

1_extract_routine_configs(configs: list[typing.Any]) -> dict[str, dict[str, typing.Any]]

Extract routine parameters from configuration objects (recursive).

Parameters:

configs
list[typing.Any]

List of configuration objects (e.g., DeviceConfig)

Returns:

Dictionary mapping routine names to their parameters

1_extract_from_routine_config(
2 routine_config: typing.Any, routine_configs: dict[str, dict[str, typing.Any]]
3) -> None

Recursively extract parameters from routine config and its nested routines.

Parameters:

routine_config
typing.Any

The routine configuration to extract from

routine_configs
dict[str, dict[str, typing.Any]]

Dictionary to store extracted parameters

1run(
2 routine_name: str, **params: typing.Any
3) -> typing.Any

Execute a registered routine.

Parameters:

routine_name
str

Name of the routine to run

Returns:

Result of the routine

1run_all(parent_routine: str | None = None) -> dict[str, typing.Any]

Execute all routines from config in order.

Parameters:

parent_routine
str | None

If specified, run only nested routines under this parent.

Returns:

Dictionary mapping routine names to their results

1_run_routine_tree(
2 routine_config: typing.Any, results: dict[str, typing.Any]
3) -> None

Recursively run a routine and its nested routines.

Parameters:

routine_config
typing.Any

The routine configuration to execute

results
dict[str, typing.Any]

Dictionary to store results

1get_result(routine_name: str) -> typing.Any

Get stored result from a routine.

1list_routines() -> list[str]

List all registered routines.

1list_results() -> list[str]

List all stored results.