Skip to content
For the complete documentation index, see llms.txt. This page is also available as Markdown.

Running an interactive experiment

You can start a real-time connection to a Chamber to send instructions and collect data. This is particularly suited for situations that require interaction, e.g., to test active learning, experiment design, or control algorithms. For long-running experiments that require no interaction, we recommend using the experiment queue instead.

You will need API credentials to run interactive experiments. To get your credentials, please use the sign-up form.

Basic workflow

You can find a complete example below.

1

Log in to the Remote Lab

First, log in to the Remote Lab (see also Quickstart)

from causalchamber import lab

rlab = lab.login(credentials_file = 'path/to/file')

If you stored your credentials in the environment variables CAUSALCHAMBER_USER and CAUSALCHAMBER_PASSWORD

from causalchamber import lab

rlab = lab.login()
2

Start an interactive session with a chamber

This opens an exclusive connection to the Chamber of your choice. You must specify the chamber_id of the Chamber, and the hardware configuration you would like it to load (given by config). The chamber will reset and set all inputs and sensor parameters to their default values.

chamber = rlab.new_session(chamber_id, config, duration=123)

Above, the duration field specifies, in seconds, how long you want to hold the session; to allow for the Chamber hardware to reset, the minimum duration is 60 seconds. While your session is active, the Chamber answers only to you.

If you're using the shared chamber pool, the duration field also determines how many credits you're charged (see How credits work). If you stop the session early, we'll refund the difference. Thus, we recommend being conservative and requesting more than enough time.

Users who rent their own Chambers are not charged by usage and can simply set the maximum duration of one month, i.e., duration=30 * 24 * 3600.

3

Send instructions and receive data

You can now send instructions to the Chamber to manipulate the hardware and receive data from its sensors. There are three instruction types:

chamber.set(target, value)

This sets the variable target to the given value, returning when the hardware has made the change. The above call returns None.

Target variables can be physical quantities, such as a polarizer's position, or parameters that control a sensor behavior. See the Chambers documentation for a description of each Chamber and its variables.

data = chamber.measure(n, delay)

The Chamber returns n successive measurements of all variables, including images if it produces them. Setting delay (in milliseconds) adds an additional delay before each measurement, allowing you to change the measurement frequency.

If the Chamber produces images, data = (dataframe, images) is a tuple of a pandas dataframe and an image array; otherwise it is just a pandas dataframe.

chamber.wait(milliseconds)

The Chamber acts as a precise clock and waits the given milliseconds before executing the next instruction.

This is useful, for example, if you want to wait for the system to reach equilibrium before measuring after a SET instruction.

4

End the session

Sessions automatically expire after the given duration. However, if you want to stop the session early—triggering a refund for the unused time—you can call

chamber.stop()

You can also call rlab.dashboard() to see your current sessions, and stop them by calling rlab.stop_session('<session_id>').

Using a context manager

To make sure you always get a refund for unused time (and free up the chamber for other users), we recommend using a context manager that will close the session automatically after your code finishes or experiences an error:

with rlab.new_session(chamber_id, config, duration=123) as chamber:
    # Your code goes here
    # ...

See below for a complete example.

A complete example

Let's connect to a Light Tunnel Mk2 and collect some images.

from causalchamber import lab

# Log in to the Remote Lab
rlab = lab.login(credentials_file='path/to/file')

# Start a session
with rlab.new_session('lt-demo-ch4lu', config='camera_fast') as chamber:
    # Turn on the light source to red and take one image
    chamber.set('red', 255)
    df, images = chamber.measure(n=1)

Because the Chamber produces images for the given config (see the Light Tunnel configurations), the returned data consists of two parts: df is a pandas dataframe containing the sensor measurements, and images an array with the collected images (only one in this case).

Let's have a look at the resulting image.

Submitting multiple instructions at once

You can submit multiple instructions in a single batch. This saves you the round-trip to the chamber for each instruction and ensures consistent timing between instructions.

The data produced during the execution of the batch will be returned in batch.submit().

To plot the resulting images:

Last updated