Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Conducting Automated/Autonomous Experiments with MADSci

This notebook teaches you how to run interactive experiments using the MADSci ExperimentNotebook class, which is designed for cell-by-cell execution in Jupyter notebooks.

Goals

After completing this notebook, you should understand how to:

  • Use ExperimentNotebook for interactive, cell-by-cell experiment execution

  • Interact with MADSci manager services (workcell, resource, location, data) through the built-in clients

  • Track experiment lifecycle with start/end semantics

For a simpler, script-based approach see examples/example_experiment.py, which demonstrates ExperimentScript for run-once experiments.

What is an Experiment Application?

The MADSci software architecture uses a number of modular components, called managers, to organize the workflows, resources and datapoints that we will use to actually do science. In order to interface with the manager, we provide clients with predefined functions that make the manager functionality easy to understand and use.

MADSci provides several experiment modalities depending on your use case:

  • ExperimentNotebook: For interactive Jupyter notebook experiments with cell-by-cell execution (used in this tutorial)

  • ExperimentScript: For simple run-once experiments (see examples/example_experiment.py)

  • ExperimentTUI: For interactive terminal UI experiments

  • ExperimentNode: For experiments that operate as REST server nodes

All modalities inherit from ExperimentBase, which uses MadsciClientMixin for automatic client management. This means:

  • Lightweight composition-based design (no REST server overhead)

  • Automatic client initialization from lab context

  • All manager clients available as properties

Built-in Client Access

Through the MadsciClientMixin, all experiment classes provide automatic access to:

  • experiment_client: Experiment management and lifecycle

  • workcell_client: Workflow coordination and scheduling

  • resource_client: Resource and inventory tracking

  • data_client: Data capture, storage, and querying

  • location_client: Location management and positioning

  • event_client: Distributed event logging (also available as logger)

  • lab_client: Lab configuration and context

This demo will assume that you have the Example Lab found in the MADSci repo installed and running on your local machine. If this is not the case, follow the instructions found in the top level MADSci readme, including running just up

Setup

Below is an example class inheriting from the ExperimentNotebook class. This modality is designed for interactive, cell-by-cell execution in Jupyter notebooks with rich display output.

Unlike ExperimentScript (which uses a single run() call), ExperimentNotebook uses a start()/end() pattern that maps naturally to notebook cells.

An experiment class contains an ExperimentDesign object. This can be as simple as the name and description of the experiment, but can also contain checks to ensure that the resources of the lab are in the correct state to begin a run of the experiment, though this functionality is still being tested and refined.

Starting the Experiment

With ExperimentNotebook, you explicitly call start() to begin the experiment. This registers the experiment with the Experiment Manager and displays a status panel. You can then run experiment steps in subsequent cells, and call end() when finished.

What can we get from an Experiment application?

Clients! The experiment class automatically inherits client management from MadsciClientMixin. When you create an ExperimentNotebook instance:

  1. It gets the lab configuration from the Lab server

  2. It automatically initializes clients for all MADSci managers

  3. All clients are configured with the proper connection details

  4. Clients are available as properties (e.g., self.workcell_client)

This eliminates the need to manually create and configure each client - they’re all ready to use!

ExperimentNotebook also provides notebook-friendly features like:

  • display(data, title): Rich-formatted output in notebook cells

  • start()/end(): Cell-by-cell lifecycle management

  • Context manager: with experiment: for single-cell experiments

Workcell Client

The Workcell Client interacts with the workcell manager, and can be used to send and monitor workflows, add nodes to the workcell and request state information about the workcell and its nodes. Below are some examples of this functionality.

Resource Client

The workflow above failed because there was no plate in the location the robot arm was trying to pick up from. In order to fix this, we make use of the Resource Client. This client is automatically available through the MadsciClientMixin and allows us to:

  • Create plate assets imported from the provided MADSci resource types

  • Place resources into location slots where devices can access them

  • Track resource inventory and usage throughout experiments

Location Client

The Location Client also comes pre-configured and ready to use. It handles:

  • Saving robot positioning information for the workcell

  • Retrieving location definitions and their associated resources

  • Managing the spatial organization of your lab setup

Both clients work together seamlessly since they’re part of the integrated MADSci ecosystem.

Data Client

The Data Client is automatically configured and used to send and retrieve data using different databases to store datapoints. Datapoints can be either files or JSON data. For file datapoints, they must be saved locally and reopened to be used, while JSON datapoints can be worked with directly.

The workcell manager has an internal data client that it uses to save the results of workflows, which can be retrieved using the experiment’s data_client property - no manual configuration needed!

We can also use experiment.display() to render results with Rich formatting in the notebook.

Complete Experiment Loop

Now we can put it all together, and combine the tools for a complete experiment loop. Since we already called experiment.start() earlier, the experiment is already being tracked by the Experiment Manager. We can use the built-in event_client (also available as logger) to log progress.

Note: For a standalone script version of this same pattern, see examples/example_experiment.py which wraps this logic in an ExperimentScript.run_experiment() method with automatic lifecycle management.

Summary

ExperimentNotebook vs ExperimentScript

FeatureExperimentNotebookExperimentScript
Use CaseInteractive Jupyter notebooksRun-once scripts
ExecutionCell-by-cell with start()/end()Single run() call
DisplayRich formatting with display()Standard print output
LifecycleManual start()/end() or context managerAutomatic via manage_experiment()
OverrideUse clients directly between start()/end()Override run_experiment()

Benefits of Built-in Client Management

The MadsciClientMixin integration (shared by all experiment modalities) provides:

  1. Automatic Configuration: All clients are pre-configured with proper connection details

  2. No Manual Setup: No need to manually create and configure individual clients

  3. Consistent Interface: All manager services are accessed through a unified client pattern

  4. Error Handling: Built-in connection management and error handling

  5. Context Aware: Clients automatically use the current MADSci lab context

  6. Lazy Initialization: Clients are only created when first accessed, improving startup performance

Next Steps

  • See examples/example_experiment.py for a standalone script-based experiment

  • See the MADSci CLI reference (docs/guides/cli_reference.md) for managing experiments from the command line

  • Explore the template catalog (docs/guides/template_catalog.md) for scaffolding new experiment projects