← Home
ddm petri-net ode theory

Declarative Differential Models (DDM)

A Petri net describes a system declaratively — places hold state, transitions change it, arcs define the rules. A DDM takes that description and encodes it directly as differential equations. We specify what the relationships are, not how to compute them. Conservation laws come along unchanged: the ODE is dM/dt = C·v(M), so any weighting of places y with y·C = 0 (a P-invariant) has d(y·M)/dt = y·C·v = 0, and the total it weighs stays fixed for the whole run. Capacity limits come along only when they are modeled as a place the transitions draw from, the way the knapsack's capacity is; a capacity declared on a place is not in the equations at all (more on that below).

From Petri Nets to ODEs

From Petri Net to ODE System

Each transition gets a flux from mass-action kinetics, and each place changes by the arc-weighted sum of the fluxes around it:

flux(T)  = k × M(P1) × M(P2) × ...        one factor per input place
dM(p)/dt = Σ w(T→p) × flux(T)  −  Σ w(p→T) × flux(T)

k is the transition's rate constant, M(P) the marking of an input place, w an arc weight. Each input place enters the flux once, to the first power, whatever its arc weight; the weight only scales how much is drained and produced. That is the law in go-pflow's solver/ode.go (buildVecODEFunction) and in pflow.xyz's browser solver, petri-solver.js, and both set a transition's flux to zero whenever one of its inputs is at or below zero. Textbook chemical mass action raises each concentration to its stoichiometric coefficient instead, so 2A → B would be quadratic in A; the two agree only when every input arc has weight 1, which is the case the figure draws. Tokens become concentrations, firing becomes flux.

Discrete vs Continuous

Discrete vs Continuous Simulation

Discrete Simulation ODE Simulation
Track individual events Track population-level dynamics
"Patient 1 arrives at 8:15" "Patients arrive at rate 10/hour"
Slow: must process every event Fast: solves continuous equations
Scales with event count Scales with equation count

The ODE has one equation per place, so its size doesn't depend on whether a place holds 10 tokens or 10,000. The equations are differentiable in the rate constants, and go-pflow uses that: its learn package carries forward sensitivities alongside the solve (learn/sensitivity.go) and fits rates to data by gradient (learn/gradopt.go). The tests check those sensitivities against the closed form on a one-place decay and the loss gradients against central finite differences on decay and SIR (learn/sensitivity_test.go). Equilibrium is found by integrating until the marking stops moving (SolveUntilEquilibrium in solver/equilibrium.go). We have no stability analysis to point to: nothing in go-pflow linearizes the ODE around its equilibrium.

In Practice

pflow.xyz runs DDM in the browser. Draw a net, set initial markings and rate constants, run ODE analysis, and watch token flows evolve. The model exports as JSON-LD.

Example: Knapsack Optimization

pflow

The knapsack model is the worked case. Each item is a place holding one token, a shared capacity place starts at 15, and each take transition consumes its item and w units of capacity and produces v units of value. Under the first-power rate law every item obeys the same equation, so the relaxation takes every item in one common fraction — 71.4% here, for a value of 35.71 against an integer optimum of 38. The ODE spreads capacity across items rather than choosing among them, and the knapsack post derives the closed form (15·V/W while the total weight W exceeds the capacity) that every one of its numbers follows. Those numbers come from go-pflow's examples/knapsack, which prints them; no test pins them.

Exclusion Analysis

Exclusion Analysis

Exclusion analysis disables one transition at a time — the knapsack example sets the item's token and rate to zero — and re-runs the ODE to see what the rest of the net does without it. On the knapsack that is five runs (none excluded, then each item), and read through the closed form the table ranks what's left by value density until a subset fits. On that instance it also points at the optimum: dropping item2 is the one exclusion that raises the value, and what's left is the answer. We have not shown that it does so in general. Single exclusions only look at subsets one item smaller, and the knapsack post lists a benchmark against branch-and-bound on larger instances as the worked case still owed.

When DDM Breaks Down

DDM models aggregate behavior — populations, not individuals. We can't track "Patient 47" through the system. Discrete conditionals ("if X then Y") have no continuous analog at all, because the ODE has no firing instant at which to test one: a read arc, an inhibitor, a declared capacity or a guard is simply ignored by the solver. go-pflow's continuous engine, stochastic.Forecast, therefore refuses a net that leans on any of them (a capacity counts only if some transition feeds that place) rather than plot an answer that leaves them out; Gating() in metamodel/firing.go names which ones a model leans on. Small populations are the other limit. On a net without those constructs the discrete engine's average follows the ODE as the population grows, and stochastic/consistency_test.go pins how closely: on an SIR epidemic the gap must stay under 5% of the population at 1,000 and 2% at 10,000, and shrink between the two. With a handful of tokens the average is the wrong question anyway; what you want is the spread across runs, and the ODE has none. Arc weights above 1 are a third limit: the discrete engine draws weight-many tokens combinatorially while the ODE stays first-order, so the two disagree by design, and the same test file has one (TestConsistencyPreconditionIsHonest) that requires them to.

Inside those limits the ODE is cheap to run and its structure comes straight from the incidence matrix.

This topic is covered in depth in Chapter 3: From Discrete to Continuous of Petri Nets as a Universal Abstraction.

What Changed

Revised 2026-11-24 against go-pflow's solver, learn and stochastic packages, pflow.xyz's petri-solver.js, the Knapsack Model as revised in October, and book Chapter 3. Nothing was re-run.

  1. Rate law. The post gave the flux as k × M(P1)^w1 × M(P2)^w2 × …, textbook chemical mass action. Neither go-pflow nor the browser solver does that: each input place enters once, to the first power, and the weight scales only consumption and production. The formula now matches the code.
  2. "For free." The post said stability, sensitivity and equilibrium analysis came for free. Sensitivities, gradient fitting and equilibrium detection exist in go-pflow and are linked above; stability analysis doesn't, so that claim is gone.
  3. Capacity limits. The intro said capacity limits live in the equations. A capacity declared on a place is ignored by the ODE, and go-pflow's continuous engine refuses the net when some transition feeds that place; only a capacity modeled as a place is in the equations.
  4. Exclusion analysis. "Replaces combinatorial search with targeted simulation" is now scoped to what the knapsack shows: one instance, five runs, no general result.
  5. Breakdown cases. "Discrete conditionals don't have a clean continuous analog" and "very small populations (1-2 entities)" now point at the code that enforces and measures them; the closing claim that the analysis "comes free" for everything else was cut.

Related: Knapsack Model · Sudoku Petri-Net Model · Coffee Shop Model · The Incidence Reduction · Comparing Nets by Their ODE Signatures

×

Follow on Mastodon