petri_net_nn.adapter¶
adapter ¶
Config-driven adapter from external data into the framework.
Each scenario — BPMN process, biological cascade, network protocol, manufacturing line — needs roughly the same pipeline: load a Petri net, load traces, train, optionally extract rules, optionally score anomalies. The boilerplate is identical across scenarios, only the data differs.
This module reads a TOML config file describing the data sources and
training parameters, and returns a ScenarioContext that exposes
the standard pipeline as methods. A scenario then becomes one config
file plus a data file (BPMN or XES), with no per-scenario glue code.
Config schema (TOML):
[scenario]
name = "..."
description = "..."
# Net source — exactly one of:
[net]
source = "bpmn_file"
path = "process.bpmn"
# OR
[net]
source = "inline"
# then declare places/transitions/arcs as TOML tables below
[[net.places]]
id = "p_x"
tokens = 1 # optional, default 0
label = "..." # optional
[[net.transitions]]
id = "t_x"
label = "..."
[[net.arcs]]
src = "p_x"
dst = "t_x"
# Trace source — exactly one of:
[traces]
source = "xes_file"
path = "traces.xes"
# OR
[traces]
source = "inline"
# with [[traces.inline]] entries below
[[traces.inline]]
attributes = { signal_strength = "0.9" }
events = ["t_a", "t_b"]
# Map per-trace attribute (or constant) onto a place's input
# activation. Each key is a place id; each value is either
# { attribute = "name" } or { constant = 0.5 }.
[training.input_marking]
p_signal = { attribute = "signal_strength" }
[training]
steps = 1500
lr = 0.1
sharpness = 1.0
firing = "sigmoid" # or "ste"
routing = "independent" # or "softmax"
num_steps = 0
seed = 0
Missing optional sections fall back to library defaults.
ScenarioContext
dataclass
¶
ScenarioContext(name, description, net, traces, training, input_marking_spec, input_values_spec=dict(), config=dict(), config_dir=Path())
Self-contained, config-driven scenario.
Use compile() + train() for the standard pipeline, or
attribute_to_marking / anomaly_score if you want to mix in
your own scoring code. Carrying the original config dict lets
consumers read scenario-specific extras (e.g. anomaly-generator
settings) without re-parsing the file.
attribute_to_values ¶
Coloured-Petri-net analogue of attribute_to_marking:
returns the scalar value carried by the token at each source
place. Reads the same spec form ({attribute = "..."} or
{constant = ...}) from the
[training.input_values] TOML section.
Source code in petri_net_nn/adapter.py
load_scenario ¶
Read a TOML scenario config and produce a ScenarioContext.
Relative path entries inside the config are resolved against
the config file's directory, so configs can sit next to their
data files without absolute paths.