booldog.io.primes

Read/write PyBoolNet prime implicants (dict or JSON file).

Functions

read_primes(primes_input)

Parse PyBoolNet prime implicants (from a dict or a JSON file) into

write_primes(network, outfile)

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 of BoolDogNode, one per key in primes), "modelinfo" (BoolDogModelInfo, with source_format set to "primes" and source set to primes_input when it is a file path, else None), and "primes" (the parsed prime-implicant dict). Suitable for BoolDogModel(**data).

Return type:

dict

Raises:

ValueError – If primes_input is 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; outfile is required.

Parameters:
  • network (BoolDogModel) – A BoolDog object representing a Boolean network; its primes property is what gets written.

  • outfile (str or Path) – File name/path to write primes to. Overwritten if it already exists.

Return type:

None