Core simulation library for Biosimulant
Project description
biosim
Composable simulation runtime + UI layer for orchestrating runnable biomodules.
Executive Summary & System Goals
Vision
Provide a small, stable composition layer for simulations: wire reusable components ("biomodules") into a BioWorld, run them with a single orchestration contract, and visualize/debug runs via a lightweight web UI (SimUI). Biomodules are self-contained Python packages that can wrap external simulators internally (SBML/NeuroML/CellML/etc.) without a separate adapter layer.
Core Mission
- Compose simulations from reusable, interoperable biomodules.
- Make "run + visualize + share a config" the default workflow (local-first; hosted later).
- Keep the runtime small and predictable while letting biomodules embed their own simulator/tooling.
Primary Users
- Developers and researchers who need composable simulation workflows and fast iteration.
- Near-term beachhead: neuroscience demos (single neuron + small E/I microcircuits) with strong visuals and reproducible configs.
Installation
Preferred (pinned GitHub ref):
pip install "biosim @ git+https://github.com/<org>/biosim.git@<ref>"
Alternative (package index):
pip install biosim
Publishing to PyPI
This repository publishes to PyPI using GitHub Trusted Publishing.
Release workflow:
- Update
src/biosim/__about__.pywith a new version (example:0.0.2). - Commit and push the version bump to
main. - Create and push a matching tag (
v0.0.2). - Verify GitHub Actions
Publish to PyPIfinishes successfully.
Manual commands:
git add src/biosim/__about__.py
git commit -m "Bump version to 0.0.2"
git push origin main
git tag v0.0.2
git push origin v0.0.2
Automation script:
bash scripts/release_pypi.sh
- This reads the version from
src/biosim/__about__.py, requires a clean git tree, pushesmain, then creates and pushesv<version>. - You can also pass an explicit version:
bash scripts/release_pypi.sh 0.0.2. - Use
--no-pushto only create the local tag:bash scripts/release_pypi.sh --no-push.
Examples
- See
examples/for quick-start scripts. Try:
pip install -e .
python examples/basic_usage.py
For advanced curated demos (neuro/ecology), wiring configs, and model-pack templates, see the companion repo:
Quick Start: BioWorld
Minimal usage:
import biosim
from biosim import BioSignal, SignalMetadata
class Counter(biosim.BioModule):
min_dt = 0.1
def __init__(self):
self.value = 0
def reset(self) -> None:
self.value = 0
def advance_to(self, t: float) -> None:
self.value += 1
def get_outputs(self):
source = getattr(self, "_world_name", "counter")
return {
"count": BioSignal(
source=source,
name="count",
value=self.value,
time=0.0,
metadata=SignalMetadata(units="1", description="tick counter"),
)
}
world = biosim.BioWorld()
world.add_biomodule("counter", Counter())
world.run(duration=1.0, tick_dt=0.1)
Visuals from Modules
Modules may optionally expose web-native visuals via visualize(), returning a dict or list of dicts with keys render and data. The world can collect them without any transport layer:
class MyModule(biosim.BioModule):
min_dt = 0.1
def advance_to(self, t: float) -> None:
return
def get_outputs(self):
return {}
def visualize(self):
return {
"render": "timeseries",
"data": {"series": [{"name": "s", "points": [[0.0, 1.0]]}]},
}
world = biosim.BioWorld()
world.add_biomodule("module", MyModule())
world.run(duration=0.1, tick_dt=0.1)
print(world.collect_visuals()) # [{"module": "module", "visuals": [...]}]
See examples/visuals_demo.py for a minimal end-to-end example.
SimUI (Python-Declared UI)
SimUI lets you build and launch a small web UI entirely from Python (similar to Gradio's ergonomics), backed by FastAPI and a prebuilt React SPA that renders visuals from JSON. The frontend uses Server-Sent Events (SSE) for real-time updates.
- User usage (no Node/npm required):
-
Install UI extras:
pip install -e '.[ui]' -
Try the demo:
python examples/ui_demo.pythen openhttp://127.0.0.1:7860/ui/. -
From your own code:
from biosim.simui import Interface, Number, Button, EventLog, VisualsPanel world = biosim.BioWorld() ui = Interface( world, controls=[Number("duration", 10), Number("tick_dt", 0.1), Button("Run")], outputs=[EventLog(), VisualsPanel()], ) ui.launch()
-
The UI provides endpoints under
/ui/api/...:GET /api/spec– UI layout (controls, outputs, modules)POST /api/run– Start a simulation runGET /api/status– Runner status (running/paused/error)GET /api/state– Full state (status + last step + modules)GET /api/events– Buffered world events (?since_id=&limit=)GET /api/visuals– Collected module visualsGET /api/snapshot– Full snapshot (status + visuals + events)GET /api/stream– SSE endpoint for real-time event streamingPOST /api/pause– Pause running simulationPOST /api/resume– Resume paused simulationPOST /api/reset– Stop, reset, and clear buffers- Editor sub-API (
/api/editor/...): visual config editor for loading, saving, validating, and applying YAML wiring configs as node graphs. Endpoints includemodules,current,config,apply,validate,layout,to-yaml,from-yaml, andfiles.
-
Per-run resets for clean visuals
-
On each
Run, the backend clears its event buffer and callsreset()on modules if they implement it. -
The frontend clears visuals/events before posting
/api/run. -
To avoid overlapping charts across runs, add
reset()to modules that accumulate history (e.g., time series points). -
Maintainer flow (building the frontend SPA):
- Edit the React/Vite app under
src/biosim/simui/_frontend/. - Build via Python:
python -m biosim.simui.build(requires Node/npm). This writessrc/biosim/simui/static/app.js. - Alternatively:
bash scripts/build_simui_frontend.sh. - Packaging includes
src/biosim/simui/static/**, so end users never need npm.
- Edit the React/Vite app under
-
CI packaging (recommended): run the frontend build before
python -m buildso wheels/sdists ship the bundled assets.
Troubleshooting:
- If you see
SimUI static bundle missing at .../static/app.js, build the frontend withpython -m biosim.simui.build(requires Node/npm) before launching. End users installing a release wheel won't see this.
SimUI Design Notes
- Transport: SSE (Server-Sent Events). The SPA connects to
/api/streamfor real-time updates. Polling endpoints (/api/status,/api/visuals,/api/events) remain available for fallback/debugging. - Events API:
/api/events?since_id=<int>&limit=<int>returns{ events, next_since_id }whereeventsare appended world events andnext_since_idis the cursor for subsequent calls. - VisualSpec types supported now:
timeseries:data = { "series": [{ "name": str, "points": [[x, y], ...] }, ...] }bar:data = { "items": [{ "label": str, "value": number }, ...] }table:data = { "columns": [..], "rows": [[..], ...] }ordata = { "items": [{...}, ...] }image:data = { "src": str, "alt"?: str, "width"?: number, "height"?: number }scatter: scatter plot dataheatmap: matrix/heatmap datagraph: placeholder renderer shows counts + JSON; richer graph lib can be added latercustom:<type>: custom renderer namespace for user-defined types- unknown types: rendered as JSON fallback
- VisualSpec may also include an optional
description(string) for hover text or captions.
Terminology
Understanding the core concepts is essential for working with biosim effectively.
| Term | Description |
|---|---|
| BioWorld | Runtime container that orchestrates multi-rate biomodules, routes signals, and publishes lifecycle events. |
| BioModule | Pluggable unit of behavior with local state. Implements the runnable contract (setup/reset/advance_to/...). |
| BioSignal | Typed, versioned data payload exchanged between modules via named ports. |
| WorldEvent | Runtime events emitted by the BioWorld (STARTED, TICK, FINISHED, etc.). |
| Wiring | Module connection graph. Defined programmatically, via WiringBuilder, or loaded from YAML/TOML configs. |
| VisualSpec | JSON structure returned by module.visualize() with render type and data payload. |
Event Lifecycle
Every simulation follows this sequence:
STARTED -> TICK (xN) -> FINISHED
PAUSED, RESUMED, STOPPED, and ERROR may also be emitted depending on runtime control flow.
License
MIT. See LICENSE.txt.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file biosim-0.0.1.tar.gz.
File metadata
- Download URL: biosim-0.0.1.tar.gz
- Upload date:
- Size: 260.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3ef1be3f39d68f4ae2af54c761072775fa8ea057250cdd631612c4ffe18a4d17
|
|
| MD5 |
0d0900b5abda272be93997fae3671dc3
|
|
| BLAKE2b-256 |
b484aff99ba0bd3c39fda242ec73f0b7600faffb7a4febded0988b3481bb4f4e
|
Provenance
The following attestation bundles were made for biosim-0.0.1.tar.gz:
Publisher:
publish-pypi.yml on Biosimulant/biosim
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
biosim-0.0.1.tar.gz -
Subject digest:
3ef1be3f39d68f4ae2af54c761072775fa8ea057250cdd631612c4ffe18a4d17 - Sigstore transparency entry: 972826844
- Sigstore integration time:
-
Permalink:
Biosimulant/biosim@3a9fc8addd3cca667ec23ae87d414579d72fe6bd -
Branch / Tag:
refs/tags/v0.0.1 - Owner: https://github.com/Biosimulant
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@3a9fc8addd3cca667ec23ae87d414579d72fe6bd -
Trigger Event:
push
-
Statement type:
File details
Details for the file biosim-0.0.1-py3-none-any.whl.
File metadata
- Download URL: biosim-0.0.1-py3-none-any.whl
- Upload date:
- Size: 248.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9f2b7ead571920ac98bf2352e4a4e44e166398d5e21d3cad203cf65aa3204690
|
|
| MD5 |
d5982ae6e428baa8b9e59b0ce55e677d
|
|
| BLAKE2b-256 |
1b06b6a56d37784cb73533fac07ed41afa99af34eb1a8a20752611ea8d63e137
|
Provenance
The following attestation bundles were made for biosim-0.0.1-py3-none-any.whl:
Publisher:
publish-pypi.yml on Biosimulant/biosim
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
biosim-0.0.1-py3-none-any.whl -
Subject digest:
9f2b7ead571920ac98bf2352e4a4e44e166398d5e21d3cad203cf65aa3204690 - Sigstore transparency entry: 972826850
- Sigstore integration time:
-
Permalink:
Biosimulant/biosim@3a9fc8addd3cca667ec23ae87d414579d72fe6bd -
Branch / Tag:
refs/tags/v0.0.1 - Owner: https://github.com/Biosimulant
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@3a9fc8addd3cca667ec23ae87d414579d72fe6bd -
Trigger Event:
push
-
Statement type: