Skip to main content

GymPN

GymPN is a Python library for creating and training reinforcement learning (RL) agents in environments based on Action-Evolution Petri Nets (A-E PN). It provides tools for defining simulation problems, environments, and agents, making it easier to experiment with RL algorithms on business processes and resource allocation problems modelled as Petri nets.

Features

  • Action-Evolution Petri Nets (A-E PN): Define and simulate A-E PN environments.
  • Customizable RL Agents: Train agents using Proximal Policy Optimization (PPO), with optional net-factored credit (NF-GAE) for nets with independent parts.
  • Graph Observations: Generate graph-based observations for RL agents using PyTorch Geometric.
  • Postponement: Let the agent wait, globally or per independent part of the net.
  • Integration with Gymnasium: The environment is a standard Gymnasium environment.
  • Flexible Simulation Framework: Define custom events, actions, guards and reward functions.

Installation

GymPN requires Python 3.10 or newer and is installed from PyPI:

pip install gympn

The core install pulls in torch, torch-geometric, gymnasium and simpn. PyTorch publishes CPU-only and CUDA-specific wheels on its own index; if pip picks a build you do not want, install PyTorch first by following https://pytorch.org/get-started/locally/ and then run pip install gympn.

Optional features are installed as extras:

Extra Adds Enables
gympn[tensorboard] tensorboard Training curves in TensorBoard (open_tensorboard=True)
gympn[wandb] wandb Weights & Biases logging (use_wandb=True)
gympn[viz] matplotlib, networkx Plotting the graph observations (plot_observations=True)
gympn[all] all of the above

Training and testing work without any extra installed; a missing extra is reported with the pip install command that adds it.

For development (tests, linting, docs), clone the repository and install it in editable mode with every extra:

git clone https://github.com/bpogroup/gympn.git
cd gympn
pip install -e ".[dev]"

Quick Start

The minimal example is a task assignment problem with two employees and two task types. Train a policy on it:

from simpn.simulator import SimToken
from gympn import GymProblem, RandomSolver

agency = GymProblem()

# Places: tasks arrive, wait, and are processed by an employee.
arrival = agency.add_var("arrival", var_attributes=["task_type"])
waiting = agency.add_var("waiting", var_attributes=["task_type"])
busy = agency.add_var("busy", var_attributes=["task_type", "resource_id"])
employee = agency.add_var("employee", var_attributes=["code_employee"])
arrival.put({"task_type": 0})
arrival.put({"task_type": 1})
employee.put({"code_employee": 0})
employee.put({"code_employee": 1})

# Events evolve the net on their own; actions are the agent's decisions.
agency.add_event([arrival], [arrival, waiting], name="arrive",
                 behavior=lambda a: [SimToken(a, delay=1), SimToken(a)])
agency.add_action([waiting, employee], [busy], name="start",
                  behavior=lambda c, r: [SimToken((c, r), delay=1 if c["task_type"] == r["code_employee"] else 2)])
agency.add_event([busy], [employee], lambda b: [SimToken(b[1])], name="complete",
                 reward_function=lambda x: 1)

# Train a PPO agent; checkpoints go to data/train/<run name>/.
agency.training_run(length=10, args_dict={"epochs": 20, "episodes": 10, "logdir": "data/train", "name": "run"})

# Compare against a random policy on a fresh copy of the net.
import copy
print("random policy reward:", copy.deepcopy(agency).testing_run(RandomSolver(), length=10))

The examples directory contains complete scripts, including this one with a hand-written heuristic and a trained-policy evaluation (example_minimal_task_assignment.py; set train = True at the top to train before testing).

Learn GymPN

  1. First time? → Read the Gentle Introduction
  2. Want a full example? → See the Complete Example
  3. Need quick answers? → Use the Documentation Overview
  4. Want to understand algorithms? → Read the Algorithms Guide
  5. Net with several independent parts? → Read Net-Factored Credit (NF-GAE)
  6. Agent needs to wait? → See Postponement
  7. Looking up a class? → Browse the API Reference

Other guides: Agents Guide, Advanced Features, Extending GymPN, Benchmarks, Troubleshooting.

Contributing

Contributions are welcome. See the Contributing Guide for the development setup, the test suite and the release process.

License

This project is licensed under the MIT License. See the LICENSE file for details.

Metadata

Release files for gympn 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for gympn 0.2.0
File Size Uploaded Provenance Actions
gympn-0.2.0.tar.gz 205.8 kB With provenance Details for gympn-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for gympn 0.2.0
File Interpreter ABI Platform Actions
gympn-0.2.0-py3-none-any.whl Python 3 none any Details for gympn-0.2.0-py3-none-any.whl

Total release size: 371.1 kB

Release files / gympn-0.2.0.tar.gz

Download URL gympn-0.2.0.tar.gz
Size 205.8 kB
Tags Source
SHA-256 checksum
How to use checksums
c45aadb99e395389e15062f3be8f92609345b2af59a2bd1b2ab993531e979428
BLAKE2b-256 checksum
How to use checksums
5598b49883e864d0cced65f23656b4ec8162a36db0c5d7cf3d094b5c0326a19a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 13, 2026.

Transparency log

Release files / gympn-0.2.0-py3-none-any.whl

Download URL gympn-0.2.0-py3-none-any.whl
Size 165.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
989b0324d6fc9db793553b79e1b6115887114efe5b651134b51b7ae20e3227b4
BLAKE2b-256 checksum
How to use checksums
d5d8f4ba02424a6478b6eb39c76243ce2d33688303d63c44805f9f1d9a282b94
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 13, 2026.

Transparency log

Security for gympn 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for gympn-0.2.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 13, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page