cohesivm.experiment

This module contains the Experiment class which is responsible for packaging the multiple components of an experiment together. Further, it handles the worker process which executes the measurements in the background.

class ExperimentState(value)[source]

Bases: Enum

An Enumeration of the different states an Experiment can be in.

INITIAL = 1
READY = 2
RUNNING = 3
FINISHED = 4
ABORTED = 5
class Experiment(database: Database, device: Device, measurement: Measurement, interface: Interface, sample_id: str, selected_contacts: List[str] | None = None, data_stream: Queue | None = None)[source]

Bases: object

A statemachine which packages the components of an experiment (Device, Interface and Measurement), checks their compatibility, executes the measurements in a separate process and keeps track of the progress. Creates during initialization a new multiprocessing.Value which holds the current state of the experiment.

Parameters:
  • database – The database where the data is stored.

  • device – The measurement device which is used to run the experiment.

  • interface – The contacting hardware which establishes the electronic connection on the sample.

  • measurement – The routine which is run for each contact on the interface.

  • sample_id – The string identifier of the sample which should be unique in the database.

  • selected_contacts – List of selected contact ids which should be measured. The default are all available contacts on the interface.

  • data_stream – A multiprocessing.Queue-like object where the measurement results can be sent to, e.g., for real-time plotting of the measurement.

Raises:

CompatibilityError – If the provided components are not compatible with each other.

property state: ExperimentState

The current state of the experiment stored in a multiprocessing.Value.

property database: Database

The database where the data is stored.

property device: Device

The measurement device which is used to run the experiment.

property measurement: Measurement

The routine which is run for each contact on the interface.

property interface: Interface

The contacting hardware which establishes the electronic connection on the sample.

property sample_id: str

The string identifier of the sample which should be unique in the database.

property selected_contacts: List[str]

List of selected contact ids which should be measured. The default is all available contacts on the interface.

property current_contact_idx: int | None

List index of the currently measured contact from the selected_contacts. Stored as multiprocessing.Value while the state is RUNNING.

property data_stream: Queue

A multiprocessing.Queue-like object where the measurement results can be sent to, e.g., for real-time plotting of the measurement.

property dataset: str

The dataset path in the database which should be obtained from the dataset initialization.

property process: Process

The process which runs the measurements in the background.

preview(contact_id: str) None[source]

Starts a preview measurement on the specified contact which is executed by a separate worker process. Sends the data to the data_stream but does not store it in the database.

Changes the state property to RUNNING. Resets the state to the previous one if completed.

Parameters:

contact_id – The id of the contact for which the preview measurement should be run.

Raises:

StateError – If the state is RUNNING.

setup() None[source]

Generates the Metadata object and initializes the dataset in the database. Populates the dataset.

Changes the state to READY.

Raises:

StateError – If the state is none of INITIAL, FINISHED or ABORTED.

start() None[source]

Starts the experiment which is executed by a separate worker process. Selects the contact on the interface, generates/updates the current_contact_idx which is a multiprocessing.Value, runs the measurement and stores the result in the database.

Changes the state to RUNNING while running. Changes the state to FINISHED after completion.

Raises:

StateError – If the state is not READY.

quickstart() None[source]

Executes the setup() and start() to directly run the experiment.

Raises:

StateError – If the state is none of INITIAL, FINISHED or ABORTED.

abort() None[source]

If the experiment is not running but setup, the dataset is deleted from the database and the state is changed to INITIAL. Otherwise, terminates the multiprocessing.Process and changes the state to ABORTED.

Raises:

StateError – If the state is neither of READY nor RUNNING.