mdadash.backend.widgets.base

Base Class for Widgets and Widget Manager

Classes

WidgetBase()

This is the base class for all widgets.

WidgetManager()

This is the manager that manager all widgets.

class mdadash.backend.widgets.base.WidgetBase[source]

Bases: ABC

This is the base class for all widgets.

apply_parallel_results(values: Any) None[source]

apply_parallel_results handler

This handler is called with the results of the parallel job execution. This is invoked when the run mode is set to parallel (_run_mode=’parallel’) after the parallel job completes.

Parameters:

values (Any) – The results returned by the parallel job run

get_parallel_job(batch_size: int) Any[source]

get_parallel_job handler

This handler is called if the run mode is set to parallel (_run_mode=’parallel’) to get the parallel job to run.

Parameters:

batch_size (int) – The configured batch size to use in the parallel jobs if their run frequency is batch

Returns:

job – A joblib’s delayed function

Return type:

Any

on_input_change(attribute: str, old_value: Any, new_value: Any) None[source]

on_input_change handler

This handler is called after a widget input has changed. Validations can be performed in this handler and any exceptions raised with messages will show up as errors in the UI

Parameters:
  • attribute (str) – The input attribute that changed

  • old_value (Any) – The previous value held by this attribute

  • new_value (Any) – The current value of this attribute

post_connect() None[source]

post_connect handler

This handler is called after connecting to the simulation

post_disconnect() None[source]

post_disconnect handler

This handler is called after disconnection from simulation

post_pause() None[source]

post_pause handler

This handler is called after user pauses trajectory iteration

pre_resume() None[source]

pre_resume handler

This handler is called after user resumes trajectory iteration

run_batch(batch_size: int) None[source]

run_batch handler

This handler is called every time a new batch of timesteps is full and ready to be run if the run frequency is set to batch (_run_frequency=’batch’).

Parameters:

batch_size (int) – The batch size, which indicates the number of buffered timesteps available in the buffer is passed

run_per_frame() None[source]

run_per_frame handler

This handler is called during every trajectory iteration if the run frequency is set to per-frame (_run_frequency=’per-frame’). The trajectory timestep is the current frame.

class mdadash.backend.widgets.base.WidgetManager[source]

Bases: object

This is the manager that manager all widgets.

add_widget_instance(uid: int, widget_name: str) str | None[source]

Add widget instance

Add a widget instance based on the widget name already registered with the manager.

Parameters:
  • uid (int) – Universe ID (index into universes array)

  • widget_name (str) – Name of the widget class registered

Return type:

uuid of instance added or None

property classes

Dictionary of registered widget classes keyed by widget name

delete_widget_instance(uuid: str) str | None[source]

Remove widget instance

Remove widget instance based on uuid returned during the instance creation using add_widget_instance()

Parameters:

uuid (str) – The uuid of the instance to be removed

Return type:

uuid of instance deleted or None

duplicate_widget_instance(uid: int, uuid: str) str | None[source]

Duplicate widget instance

Duplicate widget instance based on existing instance uuid

Parameters:
  • uid (int) – Universe ID (index into universes array)

  • uuid (str) – The uuid of the instance to be duplicated

Return type:

uuid of new instance created

get_inputs(uuid: str) list[source]

Get inputs for widget instance

Parameters:

uuid (str) – The uuid of the widget instance

Returns:

response – List of input dicts

Return type:

list

property instances

Dictionary of widget instances keyed by widget uuid

classmethod register_class(widget_class: WidgetBase) None[source]

Register widget class

Parameters:

widget_class – A widget class that is derived from WidgetBase

run_widgets(uid: int, batch_ready: bool, batch_size: int) None[source]

Run widget instances

Parameters:
  • uid (int) – Universe ID (index into universes array)

  • batch_ready (bool) – Flag indicating if a batch of timesteps is full

  • batch_size (int) – Size of the batch

set_input(uuid: str, attribute: str, value: Any) bool[source]

Set input for a widget instance attribute

Parameters:
  • uuid (str) – The uuid of the widget instance

  • attribute (str) – The input attribute to set

  • value (Any) – The value to set for the attribute

Returns:

response – True or False to indicate if input validation succeeded

Return type:

bool

update_n_jobs(data: dict) None[source]

Update n_jobs for joblib.Parallel