alab_management.lab_view module#

Each task process will have a LabView instance, through which it can request the lab resources (devices and sample positions).

It can also update the position of a sample in the lab.

exception DeviceRunningException[source]#

Bases: Exception

Raise when a task try to release a device that is still running.

class LabView(task_id)[source]#

Bases: object

LabView is a wrapper over device view and sample view. A task can get access to that to request resources, query sample and update sample positions.

get_locked_sample_positions()[source]#

Get a list of sample positions that are occupied by this task.

Return type:

list[str]

get_sample(sample)[source]#

Get a sample by either an ObjectId corresponding to sample_id, or as a string corresponding to the sample’s name within the experiment., see also get_sample.

Return type:

Sample

get_sample_position_parent_device(position)[source]#

Get the name of the device that owns the sample position.

Return type:

str | None

move_sample(sample, position)[source]#

Move a sample to a new position. sample can be given as either an ObjectId corresponding to sample_id, or as a string corresponding to the sample’s name within the experiment.

See also

move_sample

property priority: int#

Get the priority of the task.

request_cleanup()[source]#

Request cleanup of the task. This function will block until the task is cleaned up.

request_resources(resource_request, priority=None, timeout=None)[source]#

Request devices and sample positions. This function is a context manager, which should be used in a with statement to ensure all the devices are released when the task is done.

resource_request format is: {device: {position: number, …}, …} device can be a name of a specific device (str), a type of device, or None. If device is a type, the resource request will look for any available device of that type. If device is None, the resource request will look for sample positions that do not belong to a device. position is the name of a sample position that should be reserved on the device, and number is the number of such positions that should be reserved. If the device is required but no positions are required, this can be left as an empty dictionary.

Examples ——– {TubeFurnace: {“tray”: 4}, “arm1”: {}} will find the first available TubeFurnace device, then reserve 4 sample positions of “{tubefurnacename}/tray/{tray_index}” on that device. It will also find the device named “arm1”.

The priority of the request can optionally be specified as a positive integer, which should probably be in the range of 0-40. 20 is the default “NORMAL” priority level. Higher number = higher priority. Numbers >= 100 are reserved for urgent/error correcting requests.

request_user_input(prompt, options)[source]#

Request user input from the user. This function will block until the user inputs something.

Parameters:
  • prompt (str) – The prompt to display to the user.

  • options (list[str]) – A list of options to display to the user.

Return type:

str

Returns:

response (str): The value returned by the user (from the buttons).

request_user_input_with_note(prompt, options)[source]#

Request user input from the user. This function will block until the user inputs something.

Parameters:
  • prompt (str) – The prompt to display to the user.

  • options (list[str]) – A list of options to display to the user.

Return type:

tuple[str, str]

Returns:

response (str): The value returned by the user (from the buttons). note (str): The note returned by the user.

run_subtask(task, samples, **kwargs)[source]#

Run a task as a subtask within the task. basically fills in task_id and lab_view for you. this command blocks until the subtask is completed.

Parameters:
  • task (Type[BaseTask]) – The type/class of the Task to run.

  • samples (List[Union[ObjectId, str]]) – List of sample IDs or names.

  • **kwargs – will be passed to the Task method via the parameters entry in the task collection.

property task_id: ObjectId#

Get the task id of the current task.

update_result(name, value)[source]#

Update a result of the task. This result will be saved in the task collection under results.name and can be retrieved later.

Args: name (str): name of the result (ie “diffraction pattern”). This will be used as the key in the results dictionary. value (Any): value of the result. This can be a numpy array, a set, or any other bson-serializable object (most standard Python types).

update_sample_metadata(sample, metadata)[source]#

Update the metadata of a sample. sample can be given as either an ObjectId corresponding to sample_id, or as a string corresponding to the sample’s name within the experiment.