chemistrylab.lab package

class chemistrylab.lab.shelf.Shelf(vessels, n_working=1)[source]

Bases: object

The shelf class holds vessels from experiments.

pop, __getitem__, __delitem__, and append are implemented so shelves can be used similar to a list of vessels

append(vessel: Vessel)[source]
get_vessels()[source]
get_working_vessels()[source]

Returns a tuple of the ‘working’ vessels used for observations and rewards.

insert(index, vessel)[source]
load_vessel(path: str)[source]

TODO: Implement this Args: - path (str): the path to the vessel that is to be loaded

pop(index=-1)[source]
reset(target=None)[source]

TODO: Update this along with __init__ Resets the shelf to it’s initial state

restock(target=None)[source]
class chemistrylab.lab.shelf.VariableShelf(variable_vessels: list, fixed_vessels: list, n_working=1)[source]

Bases: Shelf

Shelf which is given a set of fixed and variable vessels. On reset the original vessels are deepcopied into new vessel objects

reset(target=None)[source]

TODO: Update this along with __init__ Resets the shelf to it’s initial state

restock(target=None)[source]
class chemistrylab.lab.manager.Manager(config_filename: str)[source]

Bases: Env

build_actions(actions: Tuple[ManagerAction])[source]

Construct the list of actions (different for each bench)

Parameters:

actions (Tuple[ManagerAction]) – A list of actions the bench can perform

characterize(observation_list)[source]

Provide an observation of the vessel in the manager’s hand using a characterization bench

Parameters:

observation_list (Tuple[str]) – A list of observations to make about the vessel

create_vessel(label='')[source]

Creates an empty vessel and places it in the manager’s hand (as long as the hand is empty)

Parameters:

label (str) – A name for the vessel

dispose_vessel()[source]

Removes and deletes the vessel in the manager’s hand

encode_bench()[source]
Returns:

A vector containing a one-hot encoding of which bench is selected, as well as some information about the contents of the benches shelf.

Return type:

np.ndarray

end_experiment()[source]

After calling this, the next call to step() will result in a terminal state.

get_observation()[source]

Creates an observation of the manager’s state

TODO: Give info about the manager’s shelf

Returns:

The observation

Return type:

np.ndarray

get_target()[source]
Returns:

The smiles code of the manager’s target

Return type:

str

insert_vessel(bench_idx, vessel_idx)[source]

Inserts the vessel in the manager’s hand into the benches shelf

Parameters:
  • bench_idx (int) – The index of the bench you want to modify the shelf of (set to -1 for the manager’s shelf).

  • vessel_idx (int) – The insertion index. (works the same as list.insert)

reset(*args, seed=None, options=None)[source]

Resets the environment to an initial internal state, returning an initial observation and info.

This method generates a new starting state often with some randomness to ensure that the agent explores the state space and learns a generalised policy about the environment. This randomness can be controlled with the seed parameter otherwise if the environment already has a random number generator and reset() is called with seed=None, the RNG is not reset.

Therefore, reset() should (in the typical use case) be called with a seed right after initialization and then never again.

For Custom environments, the first line of reset() should be super().reset(seed=seed) which implements the seeding correctly.

Changed in version v0.25: The return_info parameter was removed and now info is expected to be returned.

Parameters:
  • seed (optional int) – The seed that is used to initialize the environment’s PRNG (np_random). If the environment does not already have a PRNG and seed=None (the default option) is passed, a seed will be chosen from some source of entropy (e.g. timestamp or /dev/urandom). However, if the environment already has a PRNG and seed=None is passed, the PRNG will not be reset. If you pass an integer, the PRNG will be reset even if it already exists. Usually, you want to pass an integer right after the environment has been initialized and then never again. Please refer to the minimal example above to see this paradigm in action.

  • options (optional dict) – Additional information to specify how the environment is reset (optional, depending on the specific environment)

Returns:

Observation of the initial state. This will be an element of observation_space

(typically a numpy array) and is analogous to the observation returned by step().

info (dictionary): This dictionary contains auxiliary information complementing observation. It should be analogous to

the info returned by step().

Return type:

observation (ObsType)

reset_with_target(target: str)[source]

Resets the bench with a specific target material.

Parameters:

target (str) – The target material

restock_bench(bench_idx)[source]

Restocks the shelf of a specified bench.

NOTE: I may modify this later

run_bench(bench_idx, policy_idx)[source]

Wraps use_bench

Parameters:
  • bench_idx (GenBench) – The index of the bench to run

  • policy_idx (Policy) – The index of the policy to use for the bench

set_bench_target(bench_idx, target_idx)[source]

Sets a benches target

Parameters:
  • bench_idx (int) – The index of the bench you want to set the target in.

  • target_idx (int) – The target to set (corresponds to the managers list of targets).

set_cur_bench(idx)[source]

Sets the bench the manager is currently focused on.

Parameters:

idx (int) – The bench index

set_target(target)[source]

Sets the manager’s target material

Parameters:

target (str) – The smiles code of the target material

setup(benches: Tuple[GenBench], bench_names: Tuple[str], bench_agents: Tuple, targets: Tuple[str], actions: list = [])[source]
Parameters:
  • benches (Tuple[GenBench]) – The benches available to this manager

  • bench_names (Tuple[str]) – A name for each bench.

  • bench_agents (Tuple) – A Tuple of (name, Policy) pairs.

  • targets (Tuple[str]) – A list of targets yo give to benches.

  • actions (Tuple[ManagerAction]) – A list of actions the bench can perform

step(action: int)[source]

Run one timestep of the environment’s dynamics using the agent actions.

When the end of an episode is reached (terminated or truncated), it is necessary to call reset() to reset this environment’s state for the next episode.

Changed in version 0.26: The Step API was changed removing done in favor of terminated and truncated to make it clearer to users when the environment had terminated or truncated which is critical for reinforcement learning bootstrapping algorithms.

Parameters:

action (ActType) – an action provided by the agent to update the environment state.

Returns:

An element of the environment’s observation_space as the next observation due to the agent actions.

An example is a numpy array containing the positions and velocities of the pole in CartPole.

reward (SupportsFloat): The reward as a result of taking the action. terminated (bool): Whether the agent reaches the terminal state (as defined under the MDP of the task)

which can be positive or negative. An example is reaching the goal state or moving into the lava from the Sutton and Barton, Gridworld. If true, the user needs to call reset().

truncated (bool): Whether the truncation condition outside the scope of the MDP is satisfied.

Typically, this is a timelimit, but could also be used to indicate an agent physically going out of bounds. Can be used to end the episode prematurely before a terminal state is reached. If true, the user needs to call reset().

info (dict): Contains auxiliary diagnostic information (helpful for debugging, learning, and logging).

This might, for instance, contain: metrics that describe the agent’s performance state, variables that are hidden from observations, or individual reward terms that are combined to produce the total reward. In OpenAI Gym <v26, it contains “TimeLimit.truncated” to distinguish truncation and termination, however this is deprecated in favour of returning terminated and truncated variables.

done (bool): (Deprecated) A boolean value for if the episode has ended, in which case further step() calls will

return undefined results. This was removed in OpenAI Gym v26 in favor of terminated and truncated attributes. A done signal may be emitted for different reasons: Maybe the task underlying the environment was solved successfully, a certain timelimit was exceeded, or the physics simulation has entered an invalid state.

Return type:

observation (ObsType)

swap_vessels(bench_idx, vessel_idx)[source]

Swaps the vessel in hand with the a vessel in the shelf of one of the benches (or the lab manager’s shelf). Note: This can add or remove vessels from a shelf depending on what is in the shelf / hand.

Parameters:
  • bench_idx (int) – The index of the bench you want to modify the shelf of (set to -1 for the manager’s shelf).

  • vessel_idx (int) – The shelf index you want to swap your vessel with.

use_bench(bench, policy)[source]

Runs a bench with a given policy. (This will likely be modified in the future)

Parameters:
  • bench (GenBench) – The bench to run

  • policy (Policy) – The Policy to use for the bench

Returns:

0 if the bench ran successfully and -1 otherwise.

class chemistrylab.lab.manager.ManagerAction(name, args, cost, bench)[source]

Bases: NamedTuple

args: dict

Alias for field number 1

bench: int | None

Alias for field number 3

cost: float

Alias for field number 2

name: str

Alias for field number 0

chemistrylab.lab.manager.Manager_v0()

Action Index

Required Bench

Function Call

0

None

set_cur_bench(idx = 0)

1

None

set_cur_bench(idx = 1)

2

None

set_cur_bench(idx = 2)

3

None

end_experiment()

4

None

swap_vessels(bench_idx = -1, vessel_idx = 0)

5

None

swap_vessels(bench_idx = -1, vessel_idx = 1)

6

None

swap_vessels(bench_idx = -1, vessel_idx = 2)

7

None

characterize(observation_list = [‘PVT’])

8

Reaction

run_bench(bench_idx = 0, policy_idx = 0)

9

Reaction

swap_vessels(bench_idx = 0, vessel_idx = 0)

8

Distillation

run_bench(bench_idx = 1, policy_idx = 0)

9

Distillation

swap_vessels(bench_idx = 1, vessel_idx = 0)

8

Extraction

run_bench(bench_idx = 2, policy_idx = 0)

9

Extraction

swap_vessels(bench_idx = 2, vessel_idx = 0)