mdadash.backend.widgets.base
Base Class for Widgets and Widget Manager
Classes
This is the base class for all widgets. |
|
This is the manager that manager all widgets. |
- class mdadash.backend.widgets.base.WidgetBase[source]
Bases:
ABCThis 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 ajoblib’sdelayedfunction 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 (likeprint) or direct plot outputs will not be captured by the widget run. They will have to be returned and handled inapply_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 anyAtomGroupselections 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 theon_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()ormdadash.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_sizeis the size of the buffer / batch (N) that can be used by the widget class to iterate the last N frames.
- class mdadash.backend.widgets.base.WidgetManager[source]
Bases:
objectThis is the manager that manager all widgets.
- 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