Skip to content

Environment

gympn.environment.AEPN_Env

Bases: Env

Gym environment for training a Deep Reinforcement Learning agent on the AEPN simulator.

step

step(action: int, build_obs: bool = True)

Execute one step in the environment. Returns (observation, reward, terminated, truncated, info)

build_obs=False skips constructing the (expensive) HeteroData graph observation and returns None in its place. Building the graph is ~80% of a step's cost (profiled), so planners that only need the reward, the done flag and the updated pn.pn_actions — e.g. MCTS descent and rollout steps that continue with a cheap policy — pass False and build the graph on demand only where a network forward is actually required (node expansion).

reset

reset(seed: Optional[int] = None, options: Optional[Dict[str, Any]] = None)

Reset the environment to its initial state.

render

render()

Render the current state of the environment (not implemented).

fork

fork() -> AEPN_Env

Create a deep copy of the environment for parallel simulations. Prefer get_state()/set_state() for cheaper rollouts; fork() is a safe fallback.

get_state

get_state() -> Dict[str, Any]

Return a snapshot of the full simulator + RNG states. This allows cheap replication via set_state() without deep-copying the whole env repeatedly.

Returns:

Name Type Description
snapshot dict

{ 'pn': deepcopy(self.pn), 'run': deepcopy(self.run), 'i': self.i, 'active_model': self.active_model, 'rng': { 'python': random.getstate(), 'numpy': np.random.get_state(), 'torch_cpu': torch.get_rng_state(), 'torch_cuda': torch.cuda.get_rng_state_all() if torch.cuda.is_available() else None } }

set_state

set_state(snapshot: Dict[str, Any]) -> None

Restore a previously captured simulator + RNG state.

Parameters:

Name Type Description Default
snapshot dict

A dictionary produced by get_state().

required

set_seed

set_seed(seed: int, *, deterministic: bool = True) -> None

Seed all stochastic elements for a reproducible run: Python, NumPy, PyTorch (CPU/GPU), cuDNN, and the underlying Petri net if it exposes a seed hook. Delegates to :func:gympn.seed_everything so there is a single source of truth for seeding across the library.

Parameters:

Name Type Description Default
seed int

The seed to set.

required
deterministic bool

Request deterministic PyTorch kernels (see seed_everything).

True