wei.experiment_client

Contains the Experiment class that manages WEI flows and helps annotate the experiment run

Classes

ExperimentClient([server_host, server_port, ...])

Methods for the running and logging of a WEI Experiment including running WEI workflows

class wei.experiment_client.ExperimentClient(server_host: str = 'localhost', server_port: str = '8000', experiment: ExperimentDesign | Experiment | str | None = None, campaign: CampaignDesign | Campaign | str | None = None, working_dir: str | Path | None = None, log_experiment_end_on_exit: bool = True, timeout=10)

Methods for the running and logging of a WEI Experiment including running WEI workflows

__del__()

Logs the end of the experiment when cleaning up the experiment, if log_experiment_end_on_exit is True

__enter__()

Creates the experiment application context

__exit__(exc_type, exc_val, exc_tb)

Logs the end of the experiment when exiting the experiment application context, if log_experiment_end_on_exit is True

__init__(server_host: str = 'localhost', server_port: str = '8000', experiment: ExperimentDesign | Experiment | str | None = None, campaign: CampaignDesign | Campaign | str | None = None, working_dir: str | Path | None = None, log_experiment_end_on_exit: bool = True, timeout=10) None

Initializes an Experiment, and creates its log files

Parameters:
  • server_host (str) – address for WEI server

  • server_port (str) – port for WEI server

  • experiment (Optional[Union[ExperimentDesign, Experiment, str]]) – A new experiment design, or an existing experiment or experiment_id to continue

  • campaign (Optional[Union[CampaignDesign, Campaign, str]]) – A new campaign design, or an existing campaign or campaign_id to associate with the experiment

  • working_dir (Optional[Union[str, Path]]) – The directory to resolve relative paths from. Defaults to the current working directory.

  • log_experiment_end_on_exit (bool) – Whether to log the end of the experiment when cleaning up the experiment

await_runs(run_ids: List[str | ULID]) Dict[str, WorkflowRun]

Waits for all provided runs to complete, then returns a dictionary of their results

check_in()

Checks in with the server to let it know the experiment is still running

create_datapoint(datapoint: DataPoint)

Creates a new datapoint attached to the experiment

experiment_started = False

Lifecycle Methods

get_datapoint_info(datapoint_id: str) DataPoint

Returns the metadata for the datapoint for the given id

Parameters:

datapoint_id (str) – The id of the datapoint to get

Returns:

response (DataPoint) – The metadata for the requested datapoint

get_datapoint_value(datapoint_id: str) Dict[str, Any] | bytes

Returns the value of the datapoint for the given id

Parameters:

datapoint_id (str) – The id of the datapoint to get

Returns:

response (Dict[str, Any] | bytes) – Either a json object (for Value Datapoints) or bytes object (for File Datapoints) containing the value of the requested datapoint

get_experiment_datapoints() Dict[str, DataPoint]

returns a dictionary of the datapoints for this experiment.

get_run(run_id: str | ULID) WorkflowRun

Checks on a workflow run using the id given

Parameters:

run_id (str) – The id returned by the run_job function for this run

Returns:

response (Dict) – The JSON portion of the response from the server

get_run_log(run_id: str) Dict[Any, Any]

Returns the log for this experiment as a string

Parameters:

None

Returns:

response (Dict) – The JSON portion of the response from the server with the experiment log

get_wf_result_file(run_id: str, filename: str, output_filepath: str) Any

Returns a file from the WEI experiment result directory

get_workcell_state() dict

Fetches the current state of the workcell from the server.

Returns:

dict – A dictionary containing the current state of the workcell

Raises:

requests.exceptions.RequestException – If there’s an error communicating with the server

list_wf_files(run_id: str) Any

Returns a list of files from the WEI experiment run directory

log_comment(comment: str) Event

Logs a comment in the experiment log

Parameters:

comment (str) – The comment to log

Returns:

Event – The event that was logged

log_decision(decision_name: str, decision_value: bool) Event

Logs a decision in the experiment log

Parameters:
  • decision_name (str) – The name of the decision

  • decision_value (bool) – The value of the decision

Returns:

Event – The event that was logged

log_event(event: Event) Event

Logs an event to the WEI event log

Parameters:

event (Event) – The event to log

Returns:

Event – The event that was logged

log_experiment_end() Event

Logs the end of the experiment in the experiment log

Parameters:

None

Returns:

Event – The event that was logged

log_gladier_flow(flow_name: str, flow_id: Any) Event

Logs a Gladier flow in the experiment log

log_globus_compute(function_name: str, args: List[Any] | None = None, kwargs: Dict[str, Any] | None = None, result: Any | None = None) Event

Logs a Globus computation in the experiment log

log_local_compute(function_name: str, args: List[Any] | None = None, kwargs: Dict[str, Any] | None = None, result: Any | None = None) Event

Logs a local computation in the experiment log

Parameters:
  • function_name (str) – The name of the function called

  • args (List[Any]) – The positional arguments passed to the function

  • kwargs (Dict[str, Any]) – The keyword arguments passed to the function

Returns:

Event – The event that was logged

log_loop_start(loop_name: str) Event

Logs the start of a loop in the experiment log

query_run(run_id: str | ULID) WorkflowRun

Checks on a workflow run using the id given

Parameters:

run_id (str) – The id returned by the run_job function for this run

Returns:

response (Dict) – The JSON portion of the response from the server

save_datapoint_value(datapoint_id: str, output_filepath: str) None

Saves the datapoint for the given id to the specified file

Parameters:
  • datapoint_id (str) – The id of the datapoint to save

  • output_filepath (str) – The path to save the datapoint to

Returns:

None

start_or_continue_experiment(experiment: ExperimentDesign | Experiment | str, campaign: CampaignDesign | Campaign | str | None = None)

Creates a new experiment, or continues an existing experiment

Parameters:
  • experiment (Union[ExperimentDesign, Experiment, str]) – A new experiment design, or an existing experiment or experiment_id to continue

  • campaign (Optional[Union[CampaignDesign, Campaign, str]]) – A new campaign design, or an existing campaign or campaign_id to associate with the experiment

Returns:

None

start_run(workflow: Workflow | str | Path, payload: Dict[str, Any] | None = None, parameters: Dict[str, Any] | None = {}, simulate: bool = False, blocking: bool = True, validate_only: bool = False, raise_on_failed: bool = True, raise_on_cancelled: bool = True) WorkflowRun

Submits a workflow file to the server to be executed, and logs it in the overall event log.

Parameters:
  • workflow (str) – A workflow definition, or path to a workflow definition file

  • payload (Optional[Dict[str, Any]]) – Arguments to the workflow

  • simulate (bool = False) – Whether or not to run the workflow purely simulated

  • blocking (bool = True) – Whether to wait for the workflow to complete before returning

  • validate_only (bool = False) – Whether to only validate the workflow without actually running it

  • raise_on_failed (bool = True) – Whether to raise an exception if the workflow fails.

  • raise_on_cancelled (bool = True) – Whether to raise an exception if the workflow is cancelled.

Returns:

WorkflowRun – Information about the run that was started

validate_workflow(workflow: Workflow | str | Path, payload: Dict[str, Any] | None = None)

Submits a workflow file to the server to be validated

Parameters:
  • workflow (Union[Workflow, PathLike]) – A workflow definition, or path to a workflow definition file

  • payload (Optional[Dict[str, Any]]) – Arguments to the workflow

wait_for_workflow(workflow: WorkflowRun | str | ULID, polling_interval: float = 1.0) WorkflowRun

Waits for a workflow to reach a terminal state (COMPLETED, FAILED, or CANCELLED).

Parameters:
  • workflow (Union[WorkflowRun, str, ULID]) – The workflow run object, run_id, or ULID to wait for.

  • polling_interval (float, optional) – The time in seconds to wait between status checks. Defaults to 1.0 second.

Returns:

WorkflowRun – The final state of the workflow run.

Raises:

ValueError – If the provided workflow is invalid.