Skip to main content
Introspection is a first-class feature. There are four views, each serializable with JSON.stringify, and together they hold everything a frontend needs to draw a circuit and animate its signals.

Topology

describe() returns a ComponentDescription tree rooted at "root":
Each node has an id (its hierarchical path), its name, the parent id, the definition name, its kind, its ports, child components and internal connections. Primitives have empty components and connections. See ComponentDescription.

Wires

A wire is one driver plus every port connected to it. The driver is either one of the circuit’s inputs or a gate’s output. Connections add no delay, so every port on a wire always has the same value. A wire is named after its driver. In AND, the wire leaving the inner NAND is called root.nand.outputs.out, and it also reaches root.not.inputs.a and both inputs of the NOT’s gate. That’s why the trace and the netlist talk about wires, while signals lists every port separately.

Netlist

elaborate() returns the flattened graph that the simulator actually runs:
Each wire lists its driver, every port on it, and the gates that read it. That’s useful for highlighting a whole wire when one port is hovered.

State

inspect() turns a simulation state into plain data:
  • signals has an entry for every port in the hierarchy, in hierarchical order, so any port in a diagram can be colored directly.
  • wires groups those ports by wire, so you can see that a value really is the same wire.
The state itself is immutable, and each snapshot is a fresh plain object.

Trace

Enable tracing with simulate(definition, { trace: true }). It’s off by default to save memory.
  • Entries are ordered by tick, and by wire id within a tick, so traces are deterministic.
  • trace() returns everything from tick 0 up to the state you call it on. Branches each have their own trace, and they share their common history.
  • Each state also has changes: just the entries added by the step that produced it. That’s handy when stepping with step().
Traces are the raw material for timing diagrams and waveform views.