You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: AGENTS.md
+97-28Lines changed: 97 additions & 28 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,25 +5,57 @@ This repository contains the **executable code for the Pioreactor project**. It
5
5
1.`core/` — backend / worker code that runs jobs. Important files:
6
6
-`core/pioreactor/background_jobs/base.py` is the super class for background jobs (like stirring, od_reading, automations, etc)
7
7
2.`core/pioreactor/web/` — Flask-based web API. Important files:
8
-
-`core/pioreactor/web/api.py`handles the leader-only (and frontend) api. This is the main entry point most often. It sends requests to the`unit_api.py` too.
9
-
-`core/pioreactor/web/unit_api.py` is the pioreactor-specific api for controlling individual actions on a Pioreactor.
10
-
-`core/pioreactor/web/tasks.py` lists the Huey (background) tasks spawned by the web apis.
8
+
-`core/pioreactor/web/api.py` handles the leader-only (and frontend) API. This is the main entry point most often. It sends requests to `unit_api.py` too.
9
+
-`core/pioreactor/web/unit_api.py` is the pioreactor-specific API for controlling individual actions on a Pioreactor.
10
+
-`core/pioreactor/web/tasks.py` lists the Huey (background) tasks spawned by the web APIs.
11
11
3.`frontend/` — React-based web UI
12
12
13
13
---
14
14
15
-
## Running the System
15
+
## Key components
16
+
17
+
***Background Jobs**
18
+
Long-running tasks inherit from `BackgroundJob` in `core/pioreactor/background_jobs/base.py`. Examples include stirring control (`stirring.py`), optical density readings (`od_reading.py`), temperature automation, dosing automation.
19
+
20
+
***Automations**
21
+
Higher-level automation logic derives from `AutomationJob` in `core/pioreactor/automations/base.py`. Dosing, temperature, and LED automations are implemented under `core/pioreactor/automations/`.
22
+
23
+
***Command-Line Interface**
24
+
The `pio` CLI in `core/pioreactor/cli/pio.py` provides commands to run jobs, adjust settings, view logs, and update software. It checks for first-boot success and ensures the user is not running as root.
25
+
26
+
***Configuration System**
27
+
Configuration is loaded through `get_config()` in `core/pioreactor/config.py`, which merges global and unit-specific files and creates additional sections like `PWM_reverse`. A sample development config is provided in `config.dev.ini` with settings for PWM channels, stirring parameters, OD reading, MQTT broker, UI options, and more.
28
+
29
+
***Hardware Utilities**
30
+
`core/pioreactor/hardware.py` defines GPIO pin mappings and I2C addresses depending on hardware version. Modules in `core/pioreactor/utils/` implement PWM control, ADC/DAC access, temperature sensors, and network helpers.
31
+
32
+
***Data Structures and Messaging**
33
+
Typed message structures for MQTT communication—such as `ODReadings`, `DosingEvent`, and `CalibrationBase`—are defined in `core/pioreactor/structs.py`.
34
+
35
+
***Version and Device Info**
36
+
Software version and hardware detection logic reside in `pioreactor/version.py`, exposing `__version__` and helper functions like `get_hardware_version()`.
37
+
38
+
***Plugin System**
39
+
Additional functionality can be loaded via Python entry points or drop-in `.py` files under `~/.pioreactor/plugins`. Plugins are discovered and registered in `pioreactor/plugin_management/__init__.py`.
40
+
41
+
***Web API and UI**
42
+
The `core/pioreactor/web/` directory includes our APIs and built frontend React projects.
43
+
44
+
---
45
+
46
+
## Running the system
16
47
17
48
ALWAYS use the project virtualenv for any Python or pytest commands:
18
49
19
50
```bash
20
51
source .venv/bin/activate
21
52
```
22
53
54
+
We use Python 3.13.
55
+
23
56
**Startup order (recommended):**
24
57
25
58
0. Before starting anything, run `make dev-status` to see whether the Huey consumer, Flask API (4999), or frontend dev server (3000) are already up. Only launch what's listed under "Need to start".
26
-
27
59
1. Start the Huey consumer:
28
60
29
61
```bash
@@ -43,20 +75,22 @@ source .venv/bin/activate
43
75
44
76
```bash
45
77
pio run XYZ
78
+
pio kill --job-name XYZ
46
79
```
47
80
81
+
Some jobs might be blocking and long-running, so use the background feature of your harness to not block.
82
+
48
83
---
49
84
50
-
## Tools & Commands
85
+
## Tools & commands
51
86
52
87
Available commands are listed in the `Makefile`. Key ones:
53
88
54
89
```bash
55
90
make dev-status # Summarizes which dev servers are already running vs need to be started
56
-
make tail-log # Show last 10 lines of the merged pioreactor log (override with LINES=200)
57
-
make huey-dev # Run Huey consumer with dev flags
58
-
make web-dev # Run Flask API on 127.0.0.1:4999
59
-
make frontend-dev # Run React dev server on 127.0.0.1:3000
91
+
make huey-dev # Run Huey consumer with dev flags
92
+
make web-dev # Run Flask API on 127.0.0.1:4999
93
+
make frontend-dev # Run React dev server on 127.0.0.1:3000
60
94
```
61
95
62
96
`make dev-status` either reports "All dev services appear to be running" with brief details, or prints a "Need to start" list with only the missing services. Start only those listed; everything else is already running.
@@ -65,7 +99,7 @@ make frontend-dev # Run React dev server on 127.0.0.1:3000
65
99
66
100
## Testing
67
101
68
-
* Use **pytest** for Python tests. However, all the tests take in excess of 30 minutes, so don't run the entire test suite. Instead run specific files or tests using pytest options.
102
+
* Use **pytest** for Python tests. All tests take in excess of 30 minutes, so don't run the entire test suite. Instead run specific files or tests using pytest options.
69
103
70
104
```bash
71
105
.venv/bin/pytest core/tests/test_cli.py
@@ -76,37 +110,72 @@ make frontend-dev # Run React dev server on 127.0.0.1:3000
76
110
## Logging
77
111
78
112
* All logs are written to **`pioreactor.log`**.
79
-
* To view logs:
113
+
* To view recent logs:
80
114
81
115
```bash
82
-
make tail-log
116
+
pio logs -n 10
83
117
```
84
118
85
119
---
86
120
87
-
## Search & Navigation
121
+
## MQTT
88
122
89
-
When searching the repo:
123
+
We make use a mosquitto MQTT. Try `pio mqtt` to get a feed, or subset with `pio mqtt -t "your topic"`.
90
124
91
-
***Exclude** these directories:
125
+
---
92
126
93
-
*`core/tests/data/`
94
-
*`core/update_scripts/`
127
+
## Search & navigation
95
128
96
-
***Exclude** all `CHANGELOG.md` files.
129
+
When searching the repo, exclude these directories:
97
130
98
-
## CI
131
+
*`core/tests/data/`
132
+
*`core/update_scripts/`
133
+
*`migration_scripts/`
134
+
*`tests/data`
135
+
*`update_scripts/`
136
+
*`experiments/`
137
+
*`jupyer_notebooks/`
99
138
100
-
We run github actions for our CI, located in `.github/workflows/ci.yaml`
139
+
Also exclude all `CHANGELOG.md` files.
140
+
141
+
---
142
+
143
+
## CI
144
+
145
+
We run GitHub Actions for CI, located in `.github/workflows/ci.yaml`.
146
+
147
+
---
148
+
149
+
## Important filesystem locations
150
+
151
+
-`.pioreactor/config.ini` contains development configuration parameters.
152
+
-`.pioreactor/plugins/` is where Python plugin files (`*.py`) can be added.
153
+
-`.pioreactor/experiment_profiles/` stores experiment profiles in YAML format.
154
+
-`.pioreactor/storage/` holds the main database, backups, and caches.
Make sure to consider the following when editing and reviewing code.
105
163
106
-
- One of the Raspberry Pi's is assigned as the "leader", and this hosts most of the services: web server, MQTT broker, database, etc. It also sends commands to any "workers". The leader can also be a worker. Together, the leader and all the workers are called a "cluster". A cluster can be a small as a single leader+worker. Pioreactors are assigned to be a leader, worker, or both based on the custom image they install.
107
-
- Different jobs, like stirring, OD reading, dosing, etc. are controlled by separate Python objects. Some jobs will passively listen for events from other jobs, and change their behavior in response, for example, dosing automations listen to OD readings, and may respond by dosing or not dosing.
108
-
- The main "control plane" for the Pioreactor software is the command line interface, pio. For example, when the user starts a activity from the UI, the web server will run `pio run X ...`, which launches a Python process that will instantiate the object the controls the activity.
109
-
- Because each activity is a separate Python process, we can modify an activity before running it by changing files on the filesystem.
110
-
- The Raspberry Pis / Pioreactors communicate through the local network (in more advanced cases, this network is hosted on the leader). Users control the Pioreactor cluster while being on the same network, and accessing the web UI or the command line of the Pioreactors.
111
-
- Leaders talk to Pioreactors via http requests between their respective web servers (using lighttpd + Flask, on port 80 by default). Workers send experiment data back to the leader via MQTT (see below). We expect users to control the leader only (using the web interface or CLI), and let the leader control the workers (there are exceptions).
112
-
- The Pioreactor UI also connects to MQTT, and uses it to push and pull live data from the activities in each Pioreactor (states of activities, settings, graphs, etc).
164
+
- One of the Raspberry Pi's is assigned as the "leader", and this hosts most of the services: web server, MQTT broker, database, etc. It also sends commands to any "workers". The leader can also be a worker. Together, the leader and all the workers are called a "cluster". A cluster can be a small as a single leader+worker. Pioreactors are assigned to be a leader, worker, or both based on the custom image they install.
165
+
- Different jobs, like stirring, OD reading, dosing, etc. are controlled by separate Python objects. Some jobs will passively listen for events from other jobs, and change their behavior in response, for example, dosing automations listen to OD readings, and may respond by dosing or not dosing.
166
+
- The main "control plane" for the Pioreactor software is the command line interface, pio. For example, when the user starts a activity from the UI, the web server will run `pio run X ...`, which launches a Python process that will instantiate the object the controls the activity.
167
+
- Because each activity is a separate Python process, we can modify an activity before running it by changing files on the filesystem.
168
+
- The Raspberry Pis / Pioreactors communicate through the local network (in more advanced cases, this network is hosted on the leader). Users control the Pioreactor cluster while being on the same network, and accessing the web UI or the command line of the Pioreactors.
169
+
- Leaders talk to Pioreactors via HTTP requests between their respective web servers (using lighttpd + Flask, on port 80 by default). Workers send experiment data back to the leader via MQTT (see below). We expect users to control the leader only (using the web interface or CLI), and let the leader control the workers (there are exceptions).
170
+
- The Pioreactor UI also connects to MQTT, and uses it to push and pull live data from the activities in each Pioreactor (states of activities, settings, graphs, etc).
171
+
172
+
---
173
+
174
+
## Purpose and usage
175
+
176
+
The Pioreactor software enables users to control and monitor small-scale bioreactors. It supports features such as:
177
+
178
+
* Running stirring, optical density measurement, and dosing automatically.
179
+
* Managing a cluster of Pioreactors via MQTT and HTTP APIs.
180
+
* Applying calibrations for pumps, stirring, and OD readings.
181
+
* Scheduling complex experiment profiles that coordinate multiple jobs across workers.
Copy file name to clipboardExpand all lines: core/pioreactor/web/AGENTS.md
-2Lines changed: 0 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -17,8 +17,6 @@ Key modules:
17
17
***`utils.py`** – Helper utilities for caching responses, rate limiting, and validating filenames.
18
18
19
19
20
-
21
-
22
20
The repository also includes a compiled frontend in the `static/` directory and startup scripts (`fcgi.py`).
23
21
24
22
Overall, the project provides a REST API and task queue framework to manage Pioreactor clusters, interact with hardware via CLI commands, and expose data/logs to a web UI.
0 commit comments