Skip to content

Commit

Permalink
update docs to remove references to controllers
Browse files Browse the repository at this point in the history
  • Loading branch information
CamDavidsonPilon committed Jul 18, 2024
1 parent 52921de commit b7ee4f3
Show file tree
Hide file tree
Showing 10 changed files with 69 additions and 170 deletions.
29 changes: 0 additions & 29 deletions developer-guide/04-Automations/01-intro-automations.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,3 @@ slug: /intro-automations
Automations are specialized [background jobs](/developer-guide/intro-background-jobs) with a simplified interface for controlling some part of the Pioreactor. Whereas there is really only one way to control stirring in the Pioreactor (on, off, and constant), there are many ways to modify dosing to get different microbiological outcomes. Similarly with LEDs: there are many ways researchers want to control LEDs to change microorganisms. Same with temperature. For that reason, we've built an automation interface to make developing automations easier. You'll see an example of this simplified design when we build one in the next page.


### Controllers

Because we often want to change automations during an experiment, there is a `Controller` object (a background job) that initializes and teardowns automations during an experiment. For each automation type: dosing, temperature, and LED, there is a corresponding controller: `DosingController`, `TemperatureController`, and `LEDController`, respectively. Running these looks like:


```python
from pioreactor.background_jobs.dosing_control import DosingController

dc = DosingController(
dosing_automation="turbidostat", # name of the automation, see next page
duration=30, # how often `execute` runs, in minutes
target_od=2.0, # kwarg that the turbidostat automation needs
volume=0.5, # kwarg that the turbidostat automation needs
)
```

The controller will start the automation (and publish information about to MQTT via `published_settings`), and if requested, will stop the automation and start a new one. Using the controllers is the preferred way to start and stop automations, rather than invoking the automations directly.

Since the automation in the controller is part of `published_settings`, you can change the automation over MQTT by publishing to a MQTT topic. For example, if you wish to change the dosing automation from `turbidostat` to `chemostat`, publish the following JSON payload to `pioreactor/<unit>/<experiment>/dosing_control/automation/set`

```
{
"automation_name":"chemostat",
"args": {
"volume: 1,
"duration": 20
}
}
```
2 changes: 1 addition & 1 deletion developer-guide/04-Automations/02-writing-automations-1.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class NaiveTurbidostat(DosingAutomationJobContrib):

```

Run the script with `pio run dosing_control --automation-name naive_turbidostat --target-od 0.5`. This will start the job. After a moment, you may notice that warnings are thrown - that's because there's no optical density measurements being produced! You can use crtl-c to stop the job.
Run the script with `pio run dosing_atomation --automation-name naive_turbidostat --target-od 0.5`. This will start the job. After a moment, you may notice that warnings are thrown - that's because there's no optical density measurements being produced! You can use crtl-c to stop the job.

#### Editing attributes over MQTT (optional)

Expand Down
2 changes: 1 addition & 1 deletion developer-guide/04-Automations/03-writing-automations-2.md
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ Let's save this file to our Pioreactor plugin folder, by accessing the Pioreacto

You can test the automation from the Pioreactor's command line by executing:
```
pio run led_control --automation-name light_dark_cycle --light_intensity 45 --light_duration_hours 16 --dark_duration_hours 8
pio run led_automation --automation-name light_dark_cycle --light_intensity 45 --light_duration_hours 16 --dark_duration_hours 8
```


Expand Down
31 changes: 0 additions & 31 deletions developer-guide/05-Scripts/01-writing-scripts.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,37 +33,6 @@ What is `get_unit_name` and `get_latest_experiment_name`? These are helper funct
:::


#### Automations

Using automations requires you to invoke them with a `Controller`. For example, below we start a chemostat with some specific parameters, and set the target temperature to 30C.

```python
from pioreactor.background_jobs.dosing_control import DosingController
from pioreactor.background_jobs.temperature_control import TemperatureController
from pioreactor.whoami import get_latest_experiment_name

unit = get_unit_name()
experiment = get_latest_experiment_name()

dc = DosingController(
"chemostat", # automation name
duration=1, # every minute,
volume=1, # dose 1mL
unit=unit,
experiment=experiment,
)

tc = TemperatureController(
"thermostat",
target_temperature=30,
unit=unit,
experiment=experiment
)

dc.block_until_disconnected()
```


### Starting a long-running script

On the command line, you can run your script with
Expand Down
6 changes: 3 additions & 3 deletions developer-guide/07-Plugins/01-intro-plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ import click
from pioreactor.background_jobs.stirring import start_stirring
from pioreactor.background_jobs.od_reading import start_od_reading
from pioreactor.actions.led_intensity import led_intensity
from pioreactor.background_jobs.temperature_control import start_temperature_control
from pioreactor.background_jobs.temperature_automation import start_temperature_automation


__plugin_summary__ = "My example script to control stirring, OD and temperature"
Expand All @@ -124,7 +124,7 @@ def click_my_script():

stirrer = start_stirring(target_rpm=400)
od_reader = start_od_reading("90", "REF")
temp_controller = start_temperature_control("thermostat", target_temperature=32)
temp_automation = start_temperature_automation("thermostat", target_temperature=32)

time.sleep(10)
stirrer.set_target_rpm(300)
Expand Down Expand Up @@ -172,7 +172,7 @@ class DemoAutomation(DosingAutomationContrib):

You should be able to execute the following from the command line now:
```
pio run dosing_control --automation-name demo --volume 10
pio run dosing_automation --automation-name demo --volume 10
```


Expand Down
4 changes: 2 additions & 2 deletions developer-guide/20-User interface/03-example-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ curl -H "Content-Type: application/json" \
# START THERMOSTAT AT 35C
curl -H "Content-Type: application/json" \
--data '{"options": {"automation_name": "thermostat", "target_temperature": 35}}' \
-X PATCH "http://leader.local/api/workers/worker02/experiments/Demo%20experiment%206/jobs/temperature_control/run"
-X PATCH "http://leader.local/api/workers/worker02/experiments/Demo%20experiment%206/jobs/temperature_automation/run"

# CHANGE TARGET TEMP TO 32C
curl -H "Content-Type: application/json" \
--data '{"settings": {"target_temperature": 32}}' \
-X PATCH "http://leader.local/api/workers/worker02/experiments/Demo%20experiment%206/jobs/temperature_automation/update"

# STOP THERMOSTAT
curl -X PATCH "http://leader.local/api/workers/worker02/experiments/Demo%20experiment%206/jobs/temperature_control/stop"
curl -X PATCH "http://leader.local/api/workers/worker02/experiments/Demo%20experiment%206/jobs/temperature_automation/stop"

```

Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ This Inventory tab will display metadata pertaining to each of your Pioreactors.

### Active and inactive

Workers can be *active* (available for running activities and cultures), or inactive. Inactive Pioreactors can still be assigned to experiments, but won't response to commands to run activities or participate in experiment profiles.
Workers can be *active* (available for running activities), or inactive. Inactive Pioreactors can still be assigned to experiments, but won't respond to commands to run activities or participate in experiment profiles. Inactive is a useful tool for taking a Pioreactor temporarily out of an experiment or cluster.

Turning a worker to inactive will halt all it's activities.
Turning a worker to inactive will halt all its activities.


### Possible cluster topologies
Expand Down Expand Up @@ -75,4 +75,4 @@ Yes, so long as that worker isn't the leader. Note: this doesn't change historic

#### Can I change the name of a _leader_?

This is more difficult, and our suggestion is to restart the cluster.
This is more difficult, and our suggestion is to restart the cluster.
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,57 @@ Experiment profiles can be managed in the UI at http://pioreactor.local/experime
<iframe width="560" height="315" src="https://www.youtube.com/embed/yxxj0ncTxws?si=42eGY8yIt5D84qUA" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen></iframe>


### On the command line
#### Alternatively: On the command line

All profiles are stored on the leader's disk under `~/.pioreactor/experiment_profiles/`. You can create and edit profiles in this directory, as well.
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.


## Tips to writing profiles
## 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
Expand Down Expand Up @@ -72,11 +117,11 @@ will check, after 6 hours, if the `target_rpm` is above 500, and if true, will u
You can also compare against strings. For example, to stop a job if the temperature automation running is equal to `thermostat`, use:

```yaml
temperature_control:
temperature_automation:
...
- type: stop
hours_elapsed: 6.0
if: pio1:temperature_control:automation_name == thermostat
if: pio1:temperature_automation:automation_name == thermostat


```
Expand All @@ -90,7 +135,7 @@ Some published settings have are actually nested json blobs, but we need either
...
- type: update
hours_elapsed: 6.0
if: pio1:temperature_control:temperature.temperature <= 30
if: pio1:temperature_automation:temperature.temperature <= 30
options:
target_temperature: 32
```
Expand Down Expand Up @@ -207,7 +252,7 @@ common:
od_reading:
actions:
- type: start
dosing_control:
dosing_automation:
actions:
- type: when
condition: ${{::od_reading:od1.od > 2.0}}
Expand Down Expand Up @@ -283,92 +328,6 @@ Finally, there is more control using the other optional fields:
volume: 1.5
```

### Start/stop controllers instead of automations

A common task is to start the thermostat, and you may want to do something like:


```yaml
# wrong, this won't work ❌
common:
jobs:
thermostat:
actions:
- type: start
hours_elapsed: 0.0
options:
target_temperature: 30
```


However, to start (and stop) automations (which the `thermostat` is), you actually need to use the controllers:

```yaml
# correct ✅
common:
jobs:
temperature_control:
actions:
- type: start
hours_elapsed: 0.0
options:
automation_name: thermostat
target_temperature: 30
```


Likewise, to _stop_ a automation, you need to stop the controller:


```yaml
# correct ✅
common:
jobs:
temperature_control:
actions:
- type: start
hours_elapsed: 0.0
options:
automation_name: thermostat
target_temperature: 30
- type: stop
hours_elapsed: 12.0
```

How do you update `target_temperature`, see below.

### Update automations instead of controllers

A setting like `target_temperature` or `volume` is attached to the automation, not a controller, so you need to update the automation:

```yaml
# correct ✅
common:
jobs:
temperature_control:
actions:
- type: start
hours_elapsed: 0.0
options:
automation_name: thermostat
target_temperature: 30
- type: stop
hours_elapsed: 12.0
temperature_automation: # this is thermostat
- type: update
hours_elapsed: 1.0
options:
target_temperature: 32
- type: update
hours_elapsed: 2.0
options:
target_temperature: 34
```


### YAML syntax check, and indentation problems

Expand All @@ -379,7 +338,7 @@ common:
# correct ✅
common:
jobs:
temperature_control:
temperature_automation:
actions:
- type: start
hours_elapsed: 0.0
Expand All @@ -394,7 +353,7 @@ common:
# wrong ❌
common:
jobs:
temperature_control:
temperature_automation:
actions:
- type: start
hours_elapsed: 0.0
Expand All @@ -412,7 +371,7 @@ This is likely because you are using `-` where you shouldn't:
# wrong ❌
common:
jobs:
temperature_control:
temperature_automation:
actions:
- type: start
hours_elapsed: 0.0
Expand All @@ -425,7 +384,7 @@ common:
# correct ✅
common:
jobs:
temperature_control:
temperature_automation:
actions:
- type: start
hours_elapsed: 0.0
Expand Down
2 changes: 1 addition & 1 deletion user-guide/30-Advanced/01-cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ The leader also has their own unique set of `pio` commands (these commands do no

The leader computer interacts with the worker computers using the `pios` command. Unless otherwise noted, the `pios` will target all worker computers. Available `pios` commands on the leader computer are the following:

* `pios kill --name <job>` terminate the job `<job>` on the workers. Ex: `pios kill --name dosing_control`.
* `pios kill --name <job>` terminate the job `<job>` on the workers. Ex: `pios kill --name dosing_automation`.
* `pios run <job>` on each worker, run the job `<job>` in the background. Job specific arguments can be specified after. Ex: `pios run add_media --ml 1`. Use `-y` to skip confirmation.
* `pios update` install the latest PioreactorApp code on each worker.
* `pios sync-configs` deploy the config.ini files to workers.
Expand Down
4 changes: 2 additions & 2 deletions user-guide/30-Advanced/15-intro-python-scripting.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,13 @@ import time
from pioreactor.background_jobs.stirring import start_stirring
from pioreactor.background_jobs.od_reading import start_od_reading
from pioreactor.actions.led_intensity import led_intensity
from pioreactor.background_jobs.temperature_control import start_temperature_control
from pioreactor.background_jobs.temperature_automation import start_temperature_automation

led_intensity({'B': 50})

stirrer = start_stirring(target_rpm=400)
od_reader = start_od_reading("90", "REF")
temp_controller = start_temperature_control("thermostat", target_temperature=32)
thermostat = start_temperature_automation("thermostat", target_temperature=32)

time.sleep(10)
stirrer.set_target_rpm(300)
Expand Down

0 comments on commit b7ee4f3

Please sign in to comment.