REDAC User Programs (Hybridalgorithms)

class pybrid.base.hybrid.programs.BaseProgram(controller: BaseController, run: BaseRun, output: Optional[IO] = None)

Base class for user programs.

DAQ_CONFIG: BaseDAQConfig = None

Shortcut to set BaseRun.daq_config if not None.

RUN_CONFIG: BaseRunConfig = None

Shortcut to set BaseRun.config if not None.

computer: Optional[AnalogComputer]

Underlying computer abstraction.

controller: BaseController

Underlying controller used by this program.

async entrypoint()

Entrypoint of all user programs.

This is either called automatically by the user-program command of the command line, or needs to be called when initialising a user program by hand.

get_run_kwargs() dict

Collects shortcut RUN_CONFIG and DAQ_CONFIG used when creating new runs.

logger: Logger

Logger instance.

output: Optional[IO]

Output stream to write data to. Used to redirect to file or similar.

print(*args, **kwargs)

Convenience wrapper around print() which redirects it to output.

run: BaseRun

Initial or current run.

abstract async start()

Abstract start method called by entrypoint(), to be overwritten.

class pybrid.base.hybrid.programs.SimpleRun(controller: BaseController, run: BaseRun, output: Optional[IO] = None)

SimpleRun Abstraction

This class implements a user-extendable version of a single analog computation. Users should inherit this class and overwrite the following function to inject their specific code.

ignore_run_errors: ClassVar[bool] = False

Whether to ignore errors during a run by default

run: Optional[BaseRun]

Initial or current run.

run_done(run)

User-supplied function to consume the result of a run.

Refer to the analog computer specific run class implementation for all available information. Use run.data to access the data captured during computation.

run_error(run: BaseRun, error: Exception)

Error handling function.

Is called on any exception raised during a computation.

set_configuration(run: BaseRun, computer: AnalogComputer)

User-supplied function to set the configuration of the analog computer before the run is started.

To configure the analog computer, change any configuration parameter of the computer argument or any of its sub-entities (clusters, blocks and functions). See REDAC Blocks and Configurations for all possible configurations.

The configuration is automatically applied by the underlying program logic.

async start()

Pre-implemented specialization of BaseProgram.start().

When the SimpleRun user program is used, this function calls the user-supplied set_configuration() function, then applies the configuration to the analog computer, starts a computation and then calls the user-supplied run_done() function.

class pybrid.base.hybrid.programs.RunEvaluateReconfigureLoop(*args, **kwargs)

Run-Evaluate-Reconfigure-Loop Abstraction

This class implements the typical process flow of a run-evaluate-reconfigure-loop. Users should inherit this class and overwrite the following function to inject their specific code.

computer: Optional[AnalogComputer]

Underlying computer abstraction.

controller: BaseController

Underlying controller used by this program.

ignore_run_errors: ClassVar[bool] = False

Whether to ignore errors during a run by default

initial_configuration(run: BaseRun, computer: AnalogComputer)

User-supplied function called before the first run.

Use this function to set the configurations for the first run. Run configuration parameters (e.g. OP time or DAQ config) will be kept to future runs.

Parameters:
  • run – First run that is about to be started

  • computer – A representation of the specific analog computer

Returns:

None

logger: logging.Logger

Logger instance.

loop_done(runs: List[BaseRun])

User-supplied function called after the loop exits.

Use this to close any open resources (like files) and to do evaluation across multiple runs.

Parameters:

runs – List of all executed runs.

Returns:

None

next_configuration(run: BaseRun, computer: AnalogComputer, previous_runs: List[BaseRun])

User-supplied function called before each run except the first.

Use this function to set the configurations for the upcoming run. You can either modify the passed modules or access modules you ‘remembered’ in init_loop.

Parameters:
  • run – Run that is about to be started

  • computer – A representation of the specific analog computer

  • previous_runs – List of previous runs

Returns:

None

output: Optional[IO]

Output stream to write data to. Used to redirect to file or similar.

run: BaseRun

Initial or current run.

run_done(run: BaseRun) bool

User-supplied function called after a run is completed.

Use this function to evaluate the results of the latest run. If the loop should be stopped after this run, return True.

Parameters:

run – The just completed run

Returns:

False if loop should be stopped, True to continue

run_error(run: BaseRun, error: Exception)

Error handling function.

Is called on any exception raised during a computation.

set_user_variables(computer: AnalogComputer)

User-supplied function called before the loop is started.

Use this function to set user variables and constant computer configuration values. Acquire any necessary resources (like opening files).

Parameters:

computer – A representation of the specific analog computer

Returns:

None

async start()

Entrypoint for starting the Run-Evaluate-Reconfigure-Loop

This function is called automatically by the pybrid command line tool. You should not need to call it unless you manually start a loop.

Returns:

None