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

Parameters:

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

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() 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.

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

on_post_connect() None[source]

on_post_connect handler

This handler is called after connecting to the simulation

on_post_create() None[source]

on_post_create handler

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

on_post_disconnect() None[source]

on_post_disconnect handler

This handler is called after disconnection from simulation

on_post_pause() None[source]

on_post_pause handler

This handler is called after user pauses trajectory iteration

on_pre_resume() None[source]

on_pre_resume handler

This handler is called after user resumes trajectory iteration

pause_simulation() None[source]

Pause the simulation

run_batch() 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’).

self.u.trajectory.buffer_size is the size of the buffer / batch that can be used by the widget class.

run_every_frame() None[source]

run_every_frame handler

This handler is called during every trajectory iteration if the run frequency is set to every-frame (_run_frequency=’every-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(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