Skip to main content

bigraph-viz2

A lightweight, interactive, read-only renderer for process-bigraph composites. Drop-in replacement for bigraph-viz's static PNG output in HTML reports — no graphviz dependency, pan / zoom / click-to-inspect / double-click-to-collapse / Alt-drag-to-rearrange in the browser, and the entire renderer inlines into a self-contained ~40 KB snippet.

bigraph-viz2 rendering a multi-cell tissue composite

The example above shows a two-cell tissue with nested substores (membrane, cytoplasm, nucleus), processes living inside each, and wires reaching across container boundaries. Orange = input port, teal = output port.

Install

pip install bigraph-viz2

No graphviz. No node. No browser at install time. The JS bundle is vendored inside the Python package; consumers need only Python ≥ 3.10.

Use

The Python API has one main function and a Jupyter wrapper.

from bigraph_viz2 import emit_html

# one-shot: a self-contained HTML fragment you can paste anywhere
snippet = emit_html(composite_state, height="600px")
report_html = report_html.replace("{{BIGRAPH}}", snippet)

In a Jupyter notebook:

from bigraph_viz2 import BigraphViz
BigraphViz(composite_state)   # auto-displays via _repr_html_

Composite expansion + schema validation

A raw .pbg document references stores by wire path that may not exist until process_bigraph.Composite materializes them. To render the expanded structure (so all wire targets resolve and the spec is also type-checked), pass expand=True:

from bigraph_viz2 import emit_html
html = emit_html(spec, expand=True)

This mirrors what bigraph-viz did: it calls core.realize(schema, state) under the hood. Requires the expand extra:

pip install "bigraph-viz2[expand]"

For composites referencing custom process addresses (e.g. local:MyProcess), build a core with those registered and pass it:

from process_bigraph import allocate_core
import my_pkg                       # side-effect: registers process types
core = allocate_core()
html = emit_html(spec, expand=True, core=core)

There's also a stand-alone validator that returns a list of issues without rendering:

from bigraph_viz2 import validate_state
issues = validate_state(spec)       # [] if clean

Multi-instance pages

For pages with multiple viz instances, inline the bundle once and dedupe the rest:

snippets = [emit_html(specs[0], dedupe=False)]
for spec in specs[1:]:
    snippets.append(emit_html(spec, dedupe=True))

API

emit_html(state, *,
          height="500px",
          width="100%",
          inspector=True,         # show the right-side inspector panel
          theme="light",          # only "light" supported in v0.1
          dedupe=False,           # set True after the first call on a page
          id=None,                # explicit DOM id (auto-generated otherwise)
          max_row_width=480       # auto-wrap threshold inside each container
          ) -> str

Returns a self-contained HTML fragment.

Interactions

gesture effect
drag (anywhere) pan
wheel zoom centered on cursor (0.25× – 4×)
hover a port tooltip with port name
click a node populate the inspector
double-click a node collapse / expand subtree
Alt + drag a node reorder siblings; drop into row / new row
Esc (while dragging) cancel the drag

Collapse state persists in the URL hash and survives reload.

Concepts

bigraph-viz2 renders compositional bigraph schemas with three primitive shapes:

shape meaning
circle a variable — a leaf in the place graph
rounded rectangle a store — a container nesting substores, processes, variables
sharp rectangle a process — reads from / writes to its declared ports

A composite is a tree of stores; processes live anywhere inside that tree. Each process declares ports, which connect by wire to variables — possibly across multiple container boundaries. Ports render as small triangles on the edge of the process rectangle:

  • orange ▶ — input port (variable feeds the process)
  • teal ▶ — output port (process writes to the variable)
  • gray · — undirected (direction not declared in the spec)

Port direction is read from the spec's inputs: / outputs: blocks (preferred), or from a single ports: block (treated as undirected for back-compat with existing bigraph-viz specs).

Example spec

spec = {
    "name": "cell",
    "stores": {
        "membrane": {
            "v":        {"_type": "variable", "value": -70},
            "channels": {"_type": "variable", "value": []},
        },
        "cytoplasm": {
            "M":   {"_type": "variable", "value": 1.0},
            "ATP": {"_type": "variable", "value": 2.0},
            "metabolism": {
                "_type": "process",
                "address": "fba.CobraStep",
                "config": {"model": "iJO1366"},
                "inputs":  {"substrate": ["M"]},
                "outputs": {"atp":       ["ATP"]},
            },
        },
        "diffusion": {
            "_type": "process",
            "address": "ode.IonFlux",
            "config": {},
            "inputs":  {"voltage":  ["membrane", "v"]},
            "outputs": {"channels": ["membrane", "channels"]},
        },
    },
}

from bigraph_viz2 import emit_html
html = emit_html(spec, height="500px")

Wire paths are relative to the process's enclosing store (["M"] = the sibling named M; ["..", "membrane", "v"] = up to the enclosing store, then into membrane.v).

Development

git clone https://github.com/vivarium-collective/bigraph-viz2
cd bigraph-viz2

# build the JS bundle and vendor it into py/
bash scripts/vendor.sh

# JS tests + typecheck
cd js && npm test && npm run typecheck

# JS end-to-end smoke (real browser)
cd js && npm run test:e2e

# Python tests (includes a Playwright round-trip)
cd py && pip install -e ".[test]" && pytest

Status

v0.1 — initial release.

License

Apache-2.0.

Metadata

Release files for bigraph-viz2 0.3.16

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for bigraph-viz2 0.3.16
File Size Uploaded Provenance Actions
bigraph_viz2-0.3.16.tar.gz 21.2 kB Without provenance Details for bigraph_viz2-0.3.16.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for bigraph-viz2 0.3.16
File Interpreter ABI Platform Actions
bigraph_viz2-0.3.16-py3-none-any.whl Python 3 none any Details for bigraph_viz2-0.3.16-py3-none-any.whl

Total release size: 39.0 kB

Release files / bigraph_viz2-0.3.16.tar.gz

Download URL bigraph_viz2-0.3.16.tar.gz
Size 21.2 kB
Tags Source
SHA-256 checksum
How to use checksums
a4e2a0486b1a7b42d443880c6cb1ed5fe2e081f13aa52a94648a9850048c05b5
BLAKE2b-256 checksum
How to use checksums
297d71d39488060dfc6f64238f86dfc5e9893b92bcf1845100153e11db0eb74e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.3

Release files / bigraph_viz2-0.3.16-py3-none-any.whl

Download URL bigraph_viz2-0.3.16-py3-none-any.whl
Size 17.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e8fc98a51300f23323e8f76a293894e6f93d6e8681879355eb4e2b3dc0d5c82c
BLAKE2b-256 checksum
How to use checksums
3962ee294ef72527e01bd73fd71b999f030a8f0af3ec41ff8ddddd9d302030d3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.3

Security for bigraph-viz2 0.3.16

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page