ReferencesBiosimulant LibrarySimUI

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

EndpointMethodPurpose
/ui/api/specGETInterface spec
/ui/api/runPOSTStart a run
/ui/api/statusGETCurrent run status
/ui/api/stateGETStatus plus last step and module names
/ui/api/pausePOSTPause at a communication boundary
/ui/api/resumePOSTResume a paused run
/ui/api/eventsGETEvent log buffer
/ui/api/visualsGETCurrent visuals
/ui/api/snapshotGETStatus, visuals, and buffered events
/ui/api/streamGETSSE stream
/ui/api/resetPOSTClear runner/event buffers

/api/reset resets SimUI session state. It is not a kernel-level BioWorld.reset().

SSE message types

The stream emits:

  • snapshot
  • step
  • event
  • heartbeat

step messages include status, visuals, and the underlying WorldEvent.STEP record.

Mounting into FastAPI

from fastapi import FastAPI
 
app = FastAPI()
ui.mount(app, "/simulation")

See Also