The PywrJSONParser
class
- class pywrparser.parsers.PywrJSONParser(json_src, ruleset=None)
- __init__(json_src, ruleset=None)
Creates an instance of a parser in which the specified json_src is validated against the specified ruleset.
- Parameters
json_src (str) – A JSON encoded representation of a Pywr network
ruleset (str) – The key of a ruleset whose rules are to be applied
- set_parser_ruleset(ruleset)
Applies the specified ruleset to the parser.
- Parameters
ruleset (str) – The key of a ruleset whose rules are to be applied
- parse(raise_on_error=False, raise_on_warning=False, ignore_warnings=False, allow_duplicate_edges=True)
Parse the Pywr model definition that was passed to the parser on instantiation. Following this action, the
parser.errors
andparser.warnings
attributes are defined.- Parameters
raise_on_parser_error (bool) – Specifies whether parsing errors should be raised immediately as exceptions or collected in the errors return value.
raise_on_parser_warning (bool) – Specifies whether warnings encountered during parsing should be raised immediately as exceptions or collected in the warnings return value.
allow_duplicate_edges (bool) – Specifies whether duplicate edges are considered as errors or are permitted in a valid networks.
- property has_errors
Indicates the presence of errors in the parsed input.
- Returns
bool –
True
if errors are present
- property has_warnings
Indicates that warnings were generated by parsing the input.
- Returns
bool –
True
if warnings are present
- property has_duplicate_edges
Indicates the presence of duplicate edges in the parsed input.
- Returns
bool –
True
if duplicate edges are present
- property duplicate_edges
Return a dict of “duplicate” edges, that is edges of length n comprised of the same n nodes in the same order which are defined more than once. This is permitted by Pywr but may indicate a malformed network in some enviroments.
- Returns
duplicate_edges (Dict[PywrEdge, Int]) – A mapping from each duplicate edge to its multiplicity in the network