Visualization¶
Introspect a running net or export it to Graphviz DOT.
cpnx.snapshot
¶
Capture a JSON-serialisable snapshot of a PetriNet's current marking.
Acquires the net's internal lock while reading, so the snapshot reflects a
consistent point-in-time view. For each place, records each token's id,
payload (as a plain dict), created_at, and color. For a
SinkPlace, the place's entry is instead a dict with a
"tokens" list (from its ring buffer, if any) and an "absorbed" count
(the cumulative number of tokens ever absorbed).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
net
|
PetriNet
|
The |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
A dict with two keys: |
dict[str, Any]
|
list of token dicts, or (for sink places) a dict with |
dict[str, Any]
|
|
dict[str, Any]
|
mid-firing. |
Source code in src/cpnx/visualization.py
cpnx.to_dot
¶
Render a PetriNet's structure and current token counts as Graphviz DOT.
Acquires the net's internal lock while reading. Places are drawn as circles
labelled with their name and current token count (or, for
SinkPlaces, the cumulative absorbed count). Transitions
are drawn as boxes. Each input arc is drawn as an edge from its place to the
transition, labelled with its count and, when applicable, consume_all
and/or settle=<settle_secs>s. Each output arc is drawn as an edge from the
transition to its place, labelled with its count.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
net
|
PetriNet
|
The |
required |
Returns:
| Type | Description |
|---|---|
str
|
A string containing the full |
str
|
suitable for rendering with Graphviz (e.g. |