How to Add a SimUI Interface
SimUI gives a local BioWorld a browser UI with controls, status, streamed events, and rendered visuals.
Install
pip install "biosimulant[ui]"Create an interface
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(p) for p in 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",
description="Interactive local demo built with SimUI",
controls=[
Number("duration", 50.0, minimum=1.0, maximum=200.0, step=1.0, label="Duration"),
Button("Run"),
],
outputs=[EventLog(limit=50), VisualsPanel()],
)
ui.launch(port=8080, open_browser=True)Current run contract
/api/runacceptsduration- the old external tick parameter is rejected
- SSE messages include
snapshot,step,event, andheartbeat /api/resetclears SimUI runner and event buffers; it does not introduce a kernel-level reset API
Mount into an existing FastAPI app
from fastapi import FastAPI
app = FastAPI()
ui.mount(app, "/simulation")Runnable examples already exist in examples/ui_demo.py and examples/multi_module_ui_demo.py.