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.

alert(message: str) None[source]

Create an alert

A timestamp based on the current timestep is automatically prepended to the message.

Parameters:

message (str) – The string message used for the alert

apply_parallel_results(values: Any) None[source]

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.

Any update to the Widget class state or output plot creation etc will have to happen in this handler.

Parameters:

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

get_parallel_job() Any[source]

This handler is called if the run mode is set to parallel (_run_mode='parallel') to retrieve the parallel job to run from the Widget class. The Widget class must return a joblib’s delayed function as the return value.

Returns:

job – A joblib’s delayed function

Return type:

Any

Note

As the parallel job executes in a separate process, everything needed by the Widget class must be explicitly returned by the job. See apply_parallel_results() on how these results are available back to the Widget class. Any console outputs (like print) or direct plot outputs will not be captured by the widget run. They will have to be returned and handled in apply_parallel_results().

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

This handler is called everytime a widget input changes from the dashboard UI.

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

Note

This handler is not invoked when a Widget inputs are set when it is duplicated or when it is recreated from the state file. Only changes from the UI trigger this handler.

on_post_connect() None[source]

This handler is called everytime after connecting to the simulation.

The Universe (self.u) will be available and any AtomGroup selections or MDAnalysis analysis class instances that depend on the Universe can be created here.

on_post_create() None[source]

This handler is called after the widget instance is created and after all the inputs are set (Widget create, duplicate, refresh and re-create from state cases).

Since the inputs are set by the time this handler is invoked, further initializations (that are not possible in __init__) can be handled here.

Note

The Universe (self.u) may or may not be available at this stage as that depends on the simulation connected state. Use the on_post_connect() handler if you need the Universe to exist.

on_post_disconnect() None[source]

This handler is called everytime after disconnect from the simulation.

on_post_pause() None[source]

This handler is called everytime after the simulation is paused.

The pause could have been triggered by user clickling on the ‘Pause’ button on the dashboard or by any other Widget triggering a pause using pause_simulation() or mdadash.backend.kernel.utils.pause_simulation().

on_pre_resume() None[source]

This handler is called before trajectory iteration is resumed.

The resume is usually triggered by user clicking on the ‘Resume’ button on the dashboard.

pause_simulation() None[source]

Pause simulation and add an alert that this Widget (name) triggered the pause.

run_batch() None[source]

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

self.u.trajectory.buffer_size is the size of the buffer / batch (N) that can be used by the widget class to iterate the last N frames.

run_every_frame() None[source]

This handler is called everytime after the trajectory iterates forward if the run frequency is set to every-frame (_run_frequency='every-frame'). The trajectory timestep in the handler will be the current timestep.

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

Bases: object

This is the manager that manager all widgets.

add_widget_instance(data: dict) dict[source]

Add widget instance based on registered widget name

duplicate_widget_instance(data: dict) None[source]

Duplicate widget instance based on instance uuid

execute_code(data: dict) None[source]

Execute code in the kernel

Parameters:

data (dict) – Dict that has the following keys:

code: str

The code to execute in the kernel

get_available_widgets(_data: dict) None[source]

Get available widgets

Sends a dict containing name and description of all available widgets to the client.

get_widget_inputs(data: dict) None[source]

Get inputs

Send a dict containing the inputs and notes for a given widget uuid.

Parameters:

data (dict) – Dict that has the following keys:

uuid: str

The uuid of the instance

recreate_instances(data: dict) None[source]

Recreate widget instances

Recreate widget instances with data from state file

Parameters:

data (dict) – Data of the instances that need to be recreated

classmethod register_class(widget_class: WidgetBase) None[source]

Register widget class

Parameters:

widget_class – A widget class that is derived from WidgetBase

remove_widget_instance(data: dict) None[source]

Remove widget instance

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

Parameters:

data (dict) – Dict that has the following keys:

uuid: str

The uuid of the instance

run_widgets(uid: int, batch_ready: bool) 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

set_widget_input(data: dict) None[source]

Set input

Parameters:

data (dict) – Dict that has the following keys:

uuid: str

The uuid of the instance

attribute: str

The input attribute to set

value: Any

The value to set for the attribute

update_n_jobs(data: dict) None[source]

Update n_jobs for joblib.Parallel

Parameters:

data (dict) – Dict that has the following keys:

n_jobs: int

The number of parallel jobs