Creating and editing experiment profiles
Using the UI
Experiment profiles can be managed in the UI at http://pioreactor.local/experiment-profiles. See video below for a demonstration.
Alternatively: On the command line
All profiles are stored on the leader's disk under ~/.pioreactor/experiment_profiles/
, allowing you can create and edit profiles in this directory, as well.
Writing profiles
Adding a name, author, and description
It's a good idea to give your profile a descriptive and unique name. This way it will be easier to find later. Also providing a detailed description will help your colleagues (and future self!) understand what the profile accomplishes.
common
and pioreactors
blocks
Any tasks in the common
block will execute that task for all workers assigned to the current experiment. The pioreactors
block is where you can write tasks for specific Pioreactors. For example, you may want the stirring to be on for all Pioreactors, but you want the temperature to be different for your two workers:
experiment_profile_name: stirring with different temperatures
metadata:
author: Cameron DP
description: turn on stirring for all workers, but set the temperature to be different between them.
common:
jobs:
stirring:
actions:
- type: start
hours_elapsed: 0
pioreactors:
pio001:
jobs:
temperature_automation:
actions:
- type: start
hours_elapsed: 0.0
options:
automation_name: thermostat
target_temperature: 35
pio002:
jobs:
temperature_automation:
actions:
- type: start
hours_elapsed: 0.0
options:
automation_name: thermostat
target_temperature: 32
hours_elapsed
refers to the profile start time
When writing a profile, note that the hours_elapsed
field refers to when the experiment profile started, and not when the experiment started.
Conditionals and expressions
How the if
directive works
The if
directive can be included in any action to conditionally execute it or not. The if
statement is evaluated when the action is to be executed (i.e., when elapsed_hours
has passed).
The if
directive is a general boolean expression, and to common operators can be used:
and
or
not
True
andFalse
(
and)
Also included are numbers (floats), and strings (examples later). The comparison operators are:
==
>=
and<=
>
and<
The operators addition +
, subtraction -
, multiplication *
, and division /
are allowed on floats, as well.
The power of if
comes when you combine it with expressions, see the next section.
How expressions work
Expressions are our way to fetch dynamic data, provided from jobs, during execution of profiles. For example, the following:
pio1:stirring:target_rpm >= 500
will fetch the target_rpm
from pio1
's stirring
job at the time the action is to be executed, compare it to 500
, and return true or false. To use this in an example:
stirring:
...
- type: update
hours_elapsed: 6.0
if: pio1:stirring:target_rpm >= 500
options:
target_rpm: 400
will check, after 6 hours, if the target_rpm
is above 500, and if true, will update the target RPM to 400.
You can also compare against strings. For example, to stop a job if the temperature automation running is equal to thermostat
, use:
temperature_automation:
...
- type: stop
hours_elapsed: 6.0
if: pio1:temperature_automation:automation_name == thermostat
Where do these dynamic values come from? Each job has published_settings
that can be referenced (refer to the job's source code to all published_settings
for a job, or they are published in MQTT).
Some published settings have are actually nested json blobs, but we need either numbers or strings to compare in our boolean expression. You can index these json blobs in the boolean expression using .
, for example:
temperature_automation:
...
- type: update
hours_elapsed: 6.0
if: pio1:temperature_automation:temperature.temperature <= 30
options:
target_temperature: 32
We use temperature.temperature
because the temperature
published setting is a json blob that looks like the following, and we wish to reference the "temperature" field in the blob:
{
"temperature": <float>,
"timestamp": <ISO 8601 timestamp>
}
Expressions in options
Similar to an if
directive using dynamic data, options can also have dynamic data (see notes above for syntax, too). However, to distinguish between a string and an expression, an expression must be wrapped in ${{ ... }}
. For example, consider the following update
action:
pioreactors:
worker1:
jobs:
stirring:
actions:
- type: start
hours_elapsed: 0
options:
target_rpm: 500
- type: update
hours_elapsed: 12
options:
target_rpm: ${{ worker1:stirring:target_rpm + 50 }}
This will update the value of target_rpm
to whatever its current value is (after 1 hour), and add 50 to it.
You can use any pioreactor and any job in an expression - you aren't limited to the job
your editing. For example, the update
below will dynamically set the target_rpm
to a function of optical density.
pioreactors:
worker1:
jobs:
stirring:
actions:
- type: start
hours_elapsed: 0
options:
target_rpm: 500
- type: update
hours_elapsed: 12
options:
target_rpm: ${{ worker1:stirring:target_rpm + worker1:od_reading:od1.od * 10 }}
Expressions in the common
block
Expressions can reference individual Pioreactors, for example worker1:stirring:target_rpm
, but what if you want to specify all Pioreactors in an expression? This is useful for using expressions in the common
block. The syntax for this is to use the following
::<job_name>:setting
For example, to conditionally change the stirring RPM in all Pioreactors, and to update it:
common:
jobs:
stirring:
actions:
- type: update
hours_elapsed: 6
if: ${{ ::stirring:target_rpm <= 500 }}
options:
target_rpm: 500
You can also use this syntax in options
:
common:
jobs:
stirring:
actions:
- type: update
hours_elapsed: 6
if: ${{ ::stirring:target_rpm <= 500 }}
options:
target_rpm: ${{ ::stirring:target_rpm + 10 * ::od_reading:od1.od }}
Built-in functions in expressions
There's also some built-in functions you can use in expressions:
random()
produces a random number between 0 and 1.unit()
returns the unit the expression is evaluated for.job_name()
returns the job name the expression is evaluated for.experiment()
returns the experiment the expression is evaluated for.