A Go library for Petri net modeling, ODE simulation, process mining, and zero-knowledge proofs.
go-pflow is not an AI/ML library. It implements structural, dynamical computation based on Petri nets and differential equations. See Why Petri Nets? for the motivation.
For comprehensive documentation, see the book.
Installation
go get github.com/pflow-xyz/go-pflow
Quick Start
// Build a Petri net and simulate with ODE solver net, rates := petri.Build(). Place("S", 999).Place("I", 1).Place("R", 0). Transition("infect").Transition("recover"). Arc("S", "infect", 1).Arc("I", "infect", 1).Arc("infect", "I", 2). Arc("I", "recover", 1).Arc("recover", "R", 1). WithCustomRates(map[string]float64{"infect": 0.3, "recover": 0.1}) prob := solver.NewProblem(net, net.SetState(nil), [2]float64{0, 100}, rates) sol := solver.Solve(prob, solver.Tsit5(), solver.DefaultOptions()) fmt.Println("Final state:", sol.GetFinalState())
See The go-pflow Library for the full API guide.
Packages
| Package | Purpose | Book Chapter |
|---|---|---|
petri |
Core types, fluent Builder API | Ch 1: Why Petri Nets? |
solver |
ODE solvers (Tsit5, RK45, implicit) | Ch 3: Discrete to Continuous |
stateutil |
State map utilities | Ch 18: go-pflow Library |
hypothesis |
Move evaluation for game AI | Ch 6: Game Mechanics |
sensitivity |
Parameter sensitivity analysis | Ch 18: go-pflow Library |
cache |
Simulation memoization | Ch 18: go-pflow Library |
reachability |
Deadlock/liveness analysis | Ch 2: Mathematics of Flow |
workflow |
Task dependencies, SLA tracking | Ch 10: Complex State Machines |
statemachine |
Hierarchical state machines | Ch 18: go-pflow Library |
actor |
Message-passing actor model | Ch 18: go-pflow Library |
eventlog |
Event log parsing | Ch 11: Process Mining |
mining |
Process discovery, rate learning | Ch 11: Process Mining |
monitoring |
Real-time prediction, SLA alerts | Ch 11: Process Mining |
learn |
Neural ODE-ish parameter fitting | Ch 18: go-pflow Library |
tokenmodel |
Token model schemas, DSL | Ch 4: Token Language |
codegen/solidity |
Solidity smart contract generation | Ch 17: Code Generation |
prover |
Groth16 ZK proofs with gnark | Ch 12: Zero-Knowledge Proofs |
visualization |
SVG rendering | Ch 18: go-pflow Library |
plotter |
Time series SVG plots | Ch 18: go-pflow Library |
Examples
Each example maps to a book chapter demonstrating the modeling pattern:
| Example | Domain | Book Chapter | Run |
|---|---|---|---|
| basic | Token flow fundamentals | Ch 1 | cd examples/basic && go run main.go |
| coffeeshop | Resource modeling | Ch 5 | cd examples/coffeeshop/cmd && go run main.go |
| tictactoe | Game AI, move evaluation | Ch 6 | cd examples/tictactoe && go run ./cmd |
| sudoku | Constraint satisfaction | Ch 7 | cd examples/sudoku/cmd && go run *.go |
| knapsack | Combinatorial optimization | Ch 8 | cd examples/knapsack/cmd && go run *.go |
| poker | Complex state machines | Ch 10 | cd examples/poker && go run ./cmd |
| monitoring_demo | Process mining, SLA prediction | Ch 11 | cd examples/monitoring_demo && go run main.go |
| erc | Token standards, Solidity codegen | Ch 4 | go run ./examples/erc |
| connect4 | Pattern recognition | Ch 6 | cd examples/connect4 && go run ./cmd |
| nim | Optimal strategy | Ch 6 | cd examples/nim && go run ./cmd |
| chess | N-Queens, Knight's Tour | Ch 7 | cd examples/chess/cmd && go run *.go |
| neural | Parameter learning | Ch 3 | cd examples/neural && go run main.go |
| visualization_demo | SVG generation | Ch 16 | make run-visualization |
See examples/README.md for more details.
The Book
book.pflow.xyz covers everything from foundations to advanced topics:
Part I: Foundations — Why Petri Nets, Mathematics of Flow, Discrete to Continuous, Token Language
Part II: Applications — Resource Modeling, Game Mechanics, Constraint Satisfaction, Optimization, Enzyme Kinetics, Complex State Machines
Part III: Advanced — Process Mining, Zero-Knowledge Proofs, Topology-Driven Verification, Declarative Infrastructure
Part IV: Building — Visual Editor, Code Generation, go-pflow Library, Dual Implementation
Testing
CLI
The pflow CLI provides simulation, analysis, and plotting from the command line. See cmd/pflow/README.md.
Compatibility
- Go 1.23+
- JSON format compatible with pflow.xyz
License
MIT License - see LICENSE for details.
Related
- book.pflow.xyz — Technical book
- pflow.xyz — Visual editor and JavaScript implementation
- RESEARCH_PAPER_OUTLINE.md — Research paper draft