petri_net_nn.pnml¶
pnml ¶
PNML (Petri Net Markup Language) import and export.
PNML is the ISO/IEC 15909-2 interchange format for Petri nets. Adding import / export here connects PETRA to the established Petri-net tool ecosystem — CPN Tools, GreatSPN, TINA, Snoopy, ProM, and many others all emit or consume PNML.
This module supports the P/T net subset of PNML 2009:
- one or more
<net>elements (the first net is parsed; others are ignored on import); - places, transitions, arcs nested under
<page>elements (the parser flattens all pages into a single net, which is the standard interpretation when no page-level semantics are needed); - names (via
<name><text>...</text></name>); - initial markings (
<initialMarking><text>N</text></initialMarking>); - arc inscriptions for arc weights
(
<inscription><text>N</text></inscription>); - inhibitor arcs via the common
<arctype><text>inhibitor</text></arctype>extension recognised by Snoopy, GreatSPN and others.
PETRA-specific extensions that have no standard PNML representation — transition durations, firing rates, guards, arc output values — are dropped on export and ignored on import. The structural net (places, transitions, flow, weights, initial marking, inhibitor arcs) round-trips cleanly.
parse_pnml ¶
Parse a PNML document into a PETRA PetriNet.
The first <net> element in the document is used; additional
nets (PNML allows multiple) are ignored. All pages within that
net are flattened — places, transitions, and arcs are collected
regardless of which page they live on. Anything PETRA doesn't
understand (graphics, tool-specific extensions, colour
declarations) is silently dropped.
Source code in petri_net_nn/pnml.py
to_pnml ¶
Serialise a PETRA PetriNet as a PNML 2009 P/T net document.
Includes places, transitions, arcs, arc weights (as PNML
inscriptions), initial markings, place / transition names, and
inhibitor arcs (via the de-facto <arctype>inhibitor</arctype>
extension). PETRA-specific extensions without a standard PNML
representation — transition durations, firing rates, guards,
arc output values — are dropped. The export is a string of
UTF-8 XML, suitable for writing to a .pnml file or piping
into any PNML-aware tool.