booldog.io.primes
Read/write PyBoolNet prime implicants (dict or JSON file).
Functions
|
Parse PyBoolNet prime implicants (from a dict or a JSON file) into |
|
Save a model's prime implicants as a formatted JSON file. |
Module Contents
- booldog.io.primes.read_primes(primes_input)
Parse PyBoolNet prime implicants (from a dict or a JSON file) into the data needed to construct a
BoolDogModel.The primes are converted to bnet format internally (via
pyboolnet.file_exchange.primes2bnet) to derive each node’s rule string; the parsed primes themselves are also kept and returned as-is.- Parameters:
primes_input (str or dict) – Dictionary of primes (PyBoolNet prime-implicant format), or a path to an existing file containing primes saved in JSON format (read via
pyboolnet.file_exchange.read_primes).- Returns:
data – Dictionary with keys
"nodes"(list ofBoolDogNode, one per key inprimes),"modelinfo"(BoolDogModelInfo, withsource_formatset to"primes"andsourceset toprimes_inputwhen it is a file path, elseNone), and"primes"(the parsed prime-implicant dict). Suitable forBoolDogModel(**data).- Return type:
dict
- Raises:
ValueError – If
primes_inputis neither a dict nor a path to an existing file.
- booldog.io.primes.write_primes(network, outfile)
Save a model’s prime implicants as a formatted JSON file.
Unlike
pyboolnet.file_exchange.write_primes, this always writes formatted (sort_keys=True, indent=2) JSON and does not support returning the JSON as a string;outfileis required.- Parameters:
network (BoolDogModel) – A BoolDog object representing a Boolean network; its
primesproperty is what gets written.outfile (str or Path) – File name/path to write primes to. Overwritten if it already exists.
- Return type:
None