Skip to content
| Marketplace
Sign in
Visual Studio Code>Visualization>CPN IDENew to Visual Studio Code? Get it now.
CPN IDE

CPN IDE

AleFire

|
67 installs
| (0) | Free
Edit, validate and simulate Coloured Petri Nets (CPN Tools .cpn models or plain-text .petri.json) with the bundled CPN IDE editor and simulator.
Installation
Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.
Copied to clipboard
More Info

CPN IDE for VS Code

ci

Draw, validate and simulate Coloured Petri Nets without leaving VS Code. The extension runs CPN IDE, the successor of CPN Tools, in an editor tab: open a .cpn model, click ▶, and you get the full CPN IDE canvas, declarations, type checker and simulator. You can also write a net as plain text (.petri.json + .sml) and watch it render as a diagram.

Nothing to install first: the CPN IDE backend, UI and simulator ship with the extension, and a Java 17 runtime is downloaded on first use if you don't already have one.

A Coloured Petri Net open in CPN IDE inside VS Code

Features

  • Edit .cpn models (CPN Tools / CPN IDE format) in a VS Code editor tab. Saving writes back to the workspace file.
  • Validate and simulate: type-check the model, fire transitions one at a time, or run many steps, with token markings shown on the diagram.
  • Text models: describe places, transitions and arcs in NAME.petri.json and the CPN ML declarations in NAME.sml. Opening the JSON shows the net graphically; edits in the canvas are saved back to the JSON.
  • Completion, hover and go-to-definition in .petri.json: arc endpoints, colour sets, subpage names, ports and fusion names are suggested; hovering a place type shows its colset declaration and F12 jumps to it in the .sml.
  • Net view: the CPN IDE sidebar has a Net section listing the pages, places, transitions (substitution transitions show their subpage) and arcs of the open .petri.json; click an entry to jump to it in the text.
  • CPN ML highlighting: .sml declaration files get syntax highlighting, bracket matching and comment toggling.
  • Live diagnostics: unknown nodes, bad references and type errors show up in the Problems panel as you edit.
  • Convert both ways: turn an existing .cpn into a text model, or export a text model to .cpn.
  • Headless runs: simulate a model for N steps without the UI and print the final marking.
  • Hierarchy: subpages, substitution transitions with port/socket assignments, and fusion places.
  • CPN IDE sidebar: an Activity Bar icon lists the models in your workspace (Models), the structure of the open one (Net) and the Analysis view. The backend controls (Start, Restart, Stop, Show Log, Docker) are in the status bar menu.

The CPN IDE sidebar with Models, Net and Analysis next to the canvas

Getting started

After installing, the Get Started with CPN IDE walkthrough opens on the Welcome page (also available via Help → Welcome or Welcome: Open Walkthrough). It opens an example, runs a simulation and creates your first net, step by step.

  1. Install CPN IDE from the Extensions view (search "CPN IDE").
  2. Open a folder that contains a .cpn or .petri.json file, or run CPN IDE: Open Example to copy one of the examples into cpn-examples/ in your workspace.
  3. Open the model:
    • a .petri.json opens straight in the CPN IDE canvas;
    • a .cpn opens as XML text: click ▶ in the editor title bar (or right-click it in the Explorer → CPN IDE: Open in CPN IDE).
  4. The first time, the extension starts its local backend (and downloads Java if needed). This takes a few seconds; the project console at the bottom of the canvas reports "Model is correct" once the model has been validated.

The CPN IDE icon in the Activity Bar opens a sidebar with three views:

  • Models: one row per net. NAME.cpn, NAME.petri.json and NAME.sml in the same folder are grouped; click the row to open the text model (or the .cpn) in the canvas, or expand it for the files, whose buttons run a headless simulation and convert (.cpn → text) or export (text → .cpn). The active model is selected as you switch tabs.

  • Net: the pages, places, transitions and arcs of the open text model (or of the .petri.json next to an open .cpn / .sml). Click one to jump to it in the JSON.

  • Analysis: Analyse (the play button in the view title) runs three steps on the open .cpn or .petri.json: Check Model validates it with the CPN IDE validator and lists the errors with their location (click one to open its source; if there are errors, the run stops there), then Structural Analysis, then Analyse State Space. The results accumulate in the one view. Save Report (next to it) writes them to a text file; Run Replications and Export Event Log are in the ... menu. The three steps are also separate commands in the Command Palette (CPN IDE: Check Model, Structural Analysis, Analyse State Space).

    Analysis results for the dining philosophers

    Run Replications runs N replications on the backend with a progress notification and opens the text replication_report.txt (a remote or Docker backend keeps it on its own machine, the notification says where). Export Event Log simulates the model while recording events and writes an XES or CSV event log to a play_out folder next to the model file; its case id (a variable bound on the net's transitions), start time, time unit and recorded events come from the cpnIde.eventLog.* settings. Structural Analysis needs no backend: it shows boundedness, deadlock freedom / liveness (Commoner and the state equation) and P/T-invariants in sections. Analyse State Space explores the reachable markings on the backend (cancellable; limits cpnIde.stateSpace.maxStates and cpnIde.stateSpace.timeoutSeconds) and shows bounds, dead markings and dead transitions, confirming or refuting the structural deadlock candidate. If the structural analysis finds a place whose bound is infinite, it first asks (modal, Explore anyway (capped)) before exploring. The search stops with a witness (the place and the firing path) as soon as a reached marking covers an earlier one on its path, i.e. a place keeps growing. A search cut short by the cap or the timeout reports Inconclusive instead of partial figures. Every row carries a badge: proved, up to N, candidate, inconclusive or approximate (the net has arcs whose token count is not fixed). "Unbounded" is only proved when every place has colour set UNIT; otherwise it is "Likely unbounded". Caveats: the state space is for untimed nets only; monitors are ignored; and the structural analysis counts tokens without their colours, so its results are approximate whenever an arc's token count is not fixed (the badge says so).

The backend controls are in the status bar menu (click the CPN IDE item): Start/Restart, Stop, Show Log, Settings, and the Docker actions (on macOS, when cpnIde.backendUrl is set, or after a failure). The settings are split into CPN IDE and CPN IDE: Advanced (cpnIde.debug, cpnIde.port, cpnIde.javaPath, cpnIde.backendUrl, cpnIde.simulation.stepDelayMs).

A .cpn that has a .petri.json twin next to it is hidden from the Models view; open the text model instead. A .cpn on its own shows as "CPN Tools model", with a Convert to Text Model button.

To start from scratch, run CPN IDE: New Net from the Command Palette (Ctrl+Shift+P / Cmd+Shift+P), or right-click a folder in the Explorer. It asks for a name, writes NAME.petri.json and NAME.sml with a small starter net, and opens it in the canvas.

Simulating a model

Click Start simulation in the CPN IDE toolbar. Enabled transitions are highlighted in green; click one to fire it, or use the Simulation panel on the left:

Action What it does
Single Step Fire the transition you click
Single Step Choose Binding Pick which binding of the variables to fire
Multi-Step (Animated) / (Fast Forward) Fire many steps, with or without the token animation
Rewind Go back to the initial marking
Replication Run the simulation several times and collect statistics

The current marking of each place is shown next to it (for example 1`2++1`4 means one token 2 and one token 4), and the project console logs every fired transition.

Simulating the producer/consumer example

Multi-step runs wait 100 ms between steps by default. Lower cpnIde.simulation.stepDelayMs, or turn off cpnIde.simulation.animate, to make them faster.

For a quick check without the UI, right-click a .cpn or .petri.json file and choose CPN IDE: Run Simulation (No UI). Enter the number of steps. The CPN IDE: Simulation output channel shows how many steps ran, the final marking of each place (as Page/Place) and any transitions still enabled:

Simulated 100 step(s) in 1301 ms
Final marking:
  MutualExclusion/Idle      1`1++ 1`2
  MutualExclusion/Lock      1`()
  MutualExclusion/Critical  empty
Still enabled: MutualExclusion/Enter

Text models

A net can be written by hand, versioned and diffed like any other source file. A model has two files next to each other:

  • NAME.petri.json: pages, places, transitions and arcs.
  • NAME.sml: CPN ML declarations (colour sets, variables, functions).
{
  "version": 1,
  "declarations": "mutex.sml",
  "pages": [
    {
      "name": "MutualExclusion",
      "places": [
        { "name": "Idle", "type": "INT", "init": "1`1++1`2" },
        { "name": "Lock", "type": "UNIT", "init": "1`()" },
        { "name": "Critical", "type": "INT" }
      ],
      "transitions": [{ "name": "Enter" }, { "name": "Leave" }],
      "arcs": [
        { "from": "Idle", "to": "Enter", "inscription": "p" },
        { "from": "Lock", "to": "Enter", "inscription": "()" },
        { "from": "Enter", "to": "Critical", "inscription": "p" },
        { "from": "Critical", "to": "Leave", "inscription": "p" },
        { "from": "Leave", "to": "Idle", "inscription": "p" },
        { "from": "Leave", "to": "Lock", "inscription": "()" }
      ]
    }
  ]
}
(* mutex.sml *)
var p: INT;
  • The standard declarations (UNIT, BOOL, INT, STRING, P_HIGH, ...) are added automatically. Declare the same name to override one.
  • Positions ("pos": [x, y]) are optional: nodes without one are laid out automatically.
  • Transitions can have a guard, time, priority and code; places can join a fusion set; a transition with a subpage becomes a substitution transition. The full format is in schema/petri.schema.json, and VS Code completes and validates .petri.json files against it.
  • (*! Block *) or (*! Outer / Inner *) in the .sml starts a named block in the declarations tree.
  • Snippets help you type models: in a .petri.json, petri inserts a whole model skeleton, and page, place, transition, arc and subpage insert one element each (Tab moves between the fields). In a .sml file (language CPN ML), colset, var, fun and block insert declarations.

Keep the JSON in one editor and the canvas in another (CPN IDE: Reopen as XML Text switches a canvas tab back to text). The canvas reloads when either file changes on disk.

A text model next to its diagram

Compile errors are reported while you type. When the backend is running and no CPN IDE tab is open, saved models are also type-checked by the simulator.

A compile error in the Problems panel

CPN IDE: Convert to Text Model turns an existing .cpn into .petri.json + .sml (graphics and monitors are dropped, with a warning). CPN IDE: Export .cpn writes the compiled model of a .petri.json as a .cpn file you can open in CPN Tools or CPN IDE.

Open .cpn in the canvas by default

The first time a .cpn opens as XML text, CPN IDE asks whether to always open .cpn files in the canvas. Yes adds "*.cpn": "cpnIde.editor" to workbench.editorAssociations; Not now asks again next session; Never stops asking. To undo, remove that entry from workbench.editorAssociations in your user settings. CPN IDE: Reopen as XML Text opens a file as text without prompting. Diff views (for example the Git diff) always stay text.

Commands

Command Where What it does
CPN IDE: Open Example Command Palette, walkthrough, sidebar Copy a bundled example into cpn-examples/ and open it
CPN IDE: Open in CPN IDE ▶ in the editor title, Explorer menu, sidebar Open a .cpn / .petri.json in the CPN IDE canvas
CPN IDE: Reopen as XML Text editor title Show the file as text again
CPN IDE: New Net Command Palette, Explorer folder menu, sidebar Create NAME.petri.json + NAME.sml with a starter net and open it
CPN IDE: Convert to Text Model .cpn editor title, Explorer menu Write .petri.json + .sml from a .cpn
CPN IDE: Export .cpn .petri.json editor title, Explorer menu Write a .cpn from a text model
CPN IDE: Run Simulation (No UI) Explorer menu, sidebar Simulate N steps and print the final marking
Simulate 100 steps (CodeLens) top of a .petri.json Run 100 headless steps and show each place's final marking inline until you edit the file; Clear results removes it. Also has Open in CPN IDE and Export .cpn lenses
CPN IDE: Analyse Analysis view title, Command Palette Check the model, run the structural analysis and explore the state space
CPN IDE: Check Model / Structural Analysis / Analyse State Space Command Palette Run one step of the analysis on its own
CPN IDE: Save Analysis Report Analysis view title, Command Palette Write the results in the Analysis view to a text file
CPN IDE: Run Replications Analysis view ... menu, Command Palette Run N replications and open the replication report
CPN IDE: Export Event Log (CSV/XES) Analysis view ... menu, Command Palette Simulate while recording events and write an event log to play_out
CPN IDE: Backend Status status bar, Command Palette Menu with Start/Restart, Stop, Show Log, Settings and the Docker actions
CPN IDE: Show Backend Log Command Palette, status bar menu Open the backend and simulator log
CPN IDE: Start / Restart / Stop Backend status bar menu Start the backend without opening a model, restart it and reload open CPN IDE tabs, or stop it and the simulator
CPN IDE: Start Docker Backend status bar menu, macOS walkthrough Run the Docker backend as container cpn-ide-backend, set cpnIde.backendUrl and reconnect open tabs
CPN IDE: Stop Docker Backend status bar menu Stop the cpn-ide-backend container

Start, Restart, Stop and the Docker commands are not in the Command Palette; use the status bar menu (CPN IDE: Backend Status).

Settings

Setting Default Description
cpnIde.simulation.animate true Animate tokens moving during simulation
cpnIde.theme auto auto makes the canvas, panels and toolbar follow a dark or high-contrast VS Code theme; light always keeps the UI's own light look. Applies when an editor is (re)opened
cpnIde.codeLens.enabled true Show the Simulate / Open in CPN IDE / Export .cpn CodeLenses at the top of .petri.json files
cpnIde.stateSpace.maxStates 100000 Analyse State Space stops after this many states and reports Inconclusive
cpnIde.stateSpace.timeoutSeconds 30 Analyse State Space stops after this many seconds and reports Inconclusive
cpnIde.eventLog.* Case id, start time, time unit and recorded events of Export Event Log

Under CPN IDE: Advanced:

Setting Default Description
cpnIde.simulation.stepDelayMs 100 Delay between steps of a multi-step run, in ms (CPN IDE itself uses 500)
cpnIde.javaPath Java 17+ executable. Empty: use JAVA_HOME, java on the PATH, or a downloaded runtime
cpnIde.backendUrl URL of an external backend, e.g. the Docker image below. Empty: use the bundled one
cpnIde.port 0 Port of the local backend (0 = any free port)
cpnIde.debug false Keep the UI's verbose console output in the webview developer tools

Simulation and debug settings apply when a CPN IDE tab is (re)opened.

Platform support

Platform Local simulator Notes
Windows x64 yes
Linux x64 yes needs 32-bit glibc: sudo apt install libc6:i386 (Debian/Ubuntu) or sudo dnf install glibc.i686 (Fedora)
macOS no the CPN simulator is a 32-bit binary; use Start Docker Backend in the status bar menu (see Docker backend)

Troubleshooting

The CPN IDE item in the status bar shows the backend state: ○ not running, spinning while it starts, ✓ ready, red when the backend or the simulator failed. Click it for the menu: show the log, restart or stop the backend, open the settings, or use the Docker backend.

  • "The CPN simulator needs 32-bit glibc" (Linux): the extension checks for /lib/ld-linux.so.2 before starting and shows the install command for your distribution, with Copy command and Use Docker backend buttons. Debian/Ubuntu: sudo dpkg --add-architecture i386 && sudo apt update && sudo apt install libc6:i386; Fedora: sudo dnf install glibc.i686; openSUSE: sudo zypper install glibc-32bit; Arch: sudo pacman -S lib32-glibc (needs multilib); Fedora Silverblue/Kinoite: rpm-ostree install glibc.i686, then reboot.
  • "The simulator could not start": on Linux, check the 32-bit glibc above. Otherwise click Show Log (or choose it in the status bar menu) to see why.
  • "Function not implemented" in cpnmld.log (VS Code inside a container, Docker 29 or later): the container's default seccomp profile blocks the 32-bit socket call the simulator uses. The Linux VSIX preloads a shim for this (resources/backend/shim); if you built the extension yourself, run scripts/build-sockshim.sh (needs gcc-multilib).
  • A simulator is already running on port 20001: the CPN simulator always uses this port, so only one can run per machine. A second VS Code window shares the first one's simulator. If a crashed window left one behind, the extension offers to stop it.
  • Validation never finishes: after 60 s the extension reports the hang. Choose Stop in the status bar menu and reopen the model.
  • Java download blocked (offline or behind a proxy): install a Java 17+ runtime yourself and set cpnIde.javaPath.

Examples

The examples/ folder has six small models, each as a text model and as a generated .cpn:

Model What it shows
01-simple-flow Three UNIT tokens move from Start to Done; the net stops after 3 steps
02-producer-consumer A counter produces items 1..5 into a buffer (guard [n <= 5]) and a consumer takes them out
03-mutual-exclusion Two processes share one lock, so at most one is ever in Critical
04-hierarchy A Worker subpage behind a substitution transition, with a fusion place shared by both pages
05-dining-philosophers Three philosophers take the left fork, then the right (uncoloured); the net can reach a dead marking
06-unbounded-producer A producer keeps adding tokens to a buffer; it is structurally unbounded, so a state space search hits its cap

How it works

The extension bundles CPN IDE 1.24.1031 (Java backend and Angular UI) and runs the UI in a VS Code webview. The backend listens on 127.0.0.1 only. It drives the CPN simulator daemon (cpnmld, fixed port 20001), which compiles and runs the model's SML code. The extension patches the daemon to listen on 127.0.0.1 only, runs it in a private per-user temp directory, and stops it, with its workers, when the backend stops or VS Code exits. Daemons left by a crashed VS Code are cleaned up on the next start. Requests that create a net go through a small local proxy that runs them one at a time, because two at once can hang the upstream backend.

Docker backend

On macOS, or to keep the simulator off your machine, choose Start Docker Backend in the status bar menu (or from the macOS walkthrough). It starts the image as the container cpn-ide-backend on a free local port, sets cpnIde.backendUrl (workspace or user) and reconnects open tabs. It offers once to stop the container when VS Code exits, and on macOS it is also offered the first time you open a model. Docker must be installed and running. Stop Docker Backend in the same menu stops the container.

Manually:

docker run -p 8080:8080 ghcr.io/alefire99/cpn-ide-backend:latest

Then set cpnIde.backendUrl to http://localhost:8080.

Contributing

Bug reports and ideas are welcome in the issue tracker. See CONTRIBUTING.md for the development setup. We use Git Flow: work on feature/* branches, open PRs into develop.

License

AGPL-3.0, same as upstream CPN IDE. See THIRD_PARTY_NOTICES.md.

  • Contact us
  • Jobs
  • Privacy
  • Manage cookies
  • Terms of use
  • Trademarks
  • Your Privacy Choices
  • Consumer Health Privacy
© 2026 Microsoft