SimUI
SimUI is the Python-first local UI layer for Biosimulant. It mounts a prebuilt web frontend over a BioWorld, exposes run-control APIs, streams world events over SSE, and renders module visuals.
Quick start
import biosimulant as biosim
from biosimulant.simui import Interface, Number, Button, EventLog, VisualsPanel
class TimeSeriesModule(biosim.BioModule):
def __init__(self):
self._points = []
def advance_window(self, start: float, end: float) -> None:
self._points.append([end, len(self._points)])
def get_outputs(self):
return {}
def snapshot(self):
return {"points": list(self._points)}
def restore(self, snapshot):
self._points = list(snapshot.get("points", []))
def visualize(self):
return {
"render": "timeseries",
"data": {"series": [{"name": "step_count", "points": self._points}]},
}
world = biosim.BioWorld(communication_step=0.1)
world.add_biomodule("ts", TimeSeriesModule())
ui = Interface(
world,
title="Time Series Demo",
controls=[
Number("duration", 10.0, minimum=0.1, maximum=100.0, step=0.1),
Button("Run"),
],
outputs=[EventLog(limit=100), VisualsPanel()],
)
ui.launch(port=8080)Components
Controls:
Number(name, default, minimum=None, maximum=None, step=None, label=None)Button(label="Run")
Outputs:
EventLog(limit=200)VisualsPanel(refresh="auto", interval_ms=500)
If you omit controls or outputs, SimUI defaults to duration plus a Run button and to EventLog plus VisualsPanel.
Run API
SimUI’s local run endpoint accepts duration only:
curl -X POST http://localhost:8080/ui/api/run \
-H "Content-Type: application/json" \
-d '{"duration": 10.0}'The old external tick parameter is rejected.
Endpoints
| Endpoint | Method | Purpose |
|---|---|---|
/ui/api/spec | GET | Interface spec |
/ui/api/run | POST | Start a run |
/ui/api/status | GET | Current run status |
/ui/api/state | GET | Status plus last step and module names |
/ui/api/pause | POST | Pause at a communication boundary |
/ui/api/resume | POST | Resume a paused run |
/ui/api/events | GET | Event log buffer |
/ui/api/visuals | GET | Current visuals |
/ui/api/snapshot | GET | Status, visuals, and buffered events |
/ui/api/stream | GET | SSE stream |
/ui/api/reset | POST | Clear runner/event buffers |
/api/reset resets SimUI session state. It is not a kernel-level BioWorld.reset().
SSE message types
The stream emits:
snapshotstepeventheartbeat
step messages include status, visuals, and the underlying WorldEvent.STEP record.
Mounting into FastAPI
from fastapi import FastAPI
app = FastAPI()
ui.mount(app, "/simulation")