This release is a pre-release and may not be stable for production use.
nonlineum-theo
The Python client for Theo, the wastewater treatment plant simulator by Nonlineum Labs. From a script or a Jupyter notebook you can:
- build a plant;
- set its parameters;
- run dynamic simulations;
- read the results.
This package is a client only. It drives a running Theo engine over Theo's WebSocket API, the same API the Theo desktop application uses. The engine comes with the Theo application, which is licensed separately.
Requirements
- Python 3.10 or newer.
- A Theo engine to connect to. Usually that is the one the Theo application starts, but it can also be an engine on another machine.
Installation
pip install --pre nonlineum-theo
--pre is needed while the current release is a release candidate. For
notebooks, the notebook extra adds the live message panel, tables and
plots:
pip install --pre "nonlineum-theo[notebook]"
Connecting
import nonlineum.theo connects to an engine straight away. It looks for
one in this order:
- the address in the
THEO_WSenvironment variable, e.g.ws://127.0.0.1:19140/theo; - the engines registered in
~/.theo/engines/:- first the session named by
THEO_SESSION; - then the Theo window you last brought to the front;
- then the newest engine;
- first the session named by
ws://127.0.0.1:19140/theo.
If no engine is running yet, the import still succeeds and the next command connects.
A first plant
import nonlineum.theo as theo
plant = theo.plant
plant.add_influent("Influent")
plant.add_cstr("Tank")
plant.add_effluent("Effluent")
plant.connect("Influent.outlet", "Tank.inlet")
plant.connect("Tank.outlet", "Effluent.inlet")
plant.Influent.Q = 1_000 # m³/d
plant.Tank.V = 2_000 # m³
plant.set_stoptime(10) # d
plant.start()
How values work:
- Reading. Every unit is an attribute of
plant, and so is every variable of a unit:plant.Tank.COD,plant.Tank.XTSS,plant.Tank.pH. In a notebook the client pulls the plant state when a run finishes.plant.pull()refreshes it at any time. - Writing. Assigning to a parameter sends it to the engine. A value the engine refuses, for example one outside the parameter's range, is printed with the engine's reason and not kept.
Units:
- Named helpers.
add_clarifier,add_primary,add_splitter,add_combiner,add_anaerobic_digester,add_thickener,add_dewatering,add_oxidation_ditchandadd_plug_flow_tankadd the common unit types. - Any other type.
plant.add_unit(type, name)adds any unit type the engine offers. The type names are inUNIT_TYPES(from nonlineum.theo.plant import UNIT_TYPES).
Scripts
To work on a plant built in the Theo application, open its project file, run it and read the results:
import time
import nonlineum.theo as theo
codes = []
theo.on_message(lambda text, level, category, code: codes.append(code))
theo.open_project("/path/to/plant.theo") # a path on the engine's machine
theo.plant.set_stoptime(30) # d
theo.plant.start()
while "MESSAGE_SIMULATION_FINISHED" not in codes:
if "ERROR_SIMULATION_TERMINATED_ABNORMALLY" in codes:
raise RuntimeError("the simulation aborted")
theo.client.send_sync_command("progress")
time.sleep(1)
theo.plant.pull()
print(theo.plant.Effluent.COD)
Why the loop sends progress: outside a notebook, the client takes in the
engine's messages only while a command is in flight, so the poll is what
lets the finish message arrive.
Two more helpers:
theo.save_project(path)writes the session back to a.theofile.theo.plant.history(units, variables)returns the recorded time series as a pandas DataFrame (pandas comes with thenotebookextra).
Notes
- Units. Values are in the engine's units: flows in m³/d, volumes in m³, times in days, concentrations in g/m³ (COD in gCOD/m³).
- Values that are not numbers. A value that is not a finite number
comes as the string
"NaN","Infinite"or"-Infinite". For example, the hydraulic residence time (HRT) of a tank with no inflow is"Infinite". Check the type before computing with a value. - Version.
nonlineum.theo.__version__is the package version.
License
The nonlineum-theo package is released under the MIT License; the full
text is in the LICENSE file that ships with it. The Theo engine and the
Theo desktop application are not covered by it; they are licensed
separately.
Metadata
Release files for nonlineum-theo 1.0.0rc3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| nonlineum_theo-1.0.0rc3.tar.gz | 48.6 kB | Without provenance | Details for nonlineum_theo-1.0.0rc3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| nonlineum_theo-1.0.0rc3-py3-none-any.whl | Python 3 | none | any | Details for nonlineum_theo-1.0.0rc3-py3-none-any.whl |
Total release size: 99.3 kB
Release files / nonlineum_theo-1.0.0rc3.tar.gz
| Download URL | nonlineum_theo-1.0.0rc3.tar.gz |
|---|---|
| Size | 48.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8018bef2bda3dcde8ac718258b27e00fd047faaf290f23639fd6e2d1812688dd
|
|
BLAKE2b-256 checksum How to use checksums |
84e5baa7cd8d85d6180fa4d6e4441c99ba0ce4bc55a3d35fcd5c63d24403e8f6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.7
|
Release files / nonlineum_theo-1.0.0rc3-py3-none-any.whl
| Download URL | nonlineum_theo-1.0.0rc3-py3-none-any.whl |
|---|---|
| Size | 50.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d9fbfbab0500cf7726f674a8eed52c15a01cf8f141c207cb01bc999ff255433c
|
|
BLAKE2b-256 checksum How to use checksums |
d52f3e30d6f39910cf8ca079f6c214552600ecde6ec0c9ecd369e6815c56023f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.7
|
Security for nonlineum-theo 1.0.0rc3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.