booldog.io.circuit

Function to transform booldog:Network to DiGraph

Attributes

logger

PAREN_RE

Classes

BooleanOperators

A simple class to define the Boolean operators as class attributes. This

BooleanDiGraph

Simple helper class to track logic nodes

Functions

clean_line(line)

Makes sure line is a Boolean rule, and not a header or comment

booldog2circuit(model)

Export a BoolDog Boolean model to Networkx DiGraph

resolve_rule(rule, processor)

Parse a Boolean rule and replace it with "logical" nodes and edges in the

resolve_factor(factor, processor)

Parse a single factor of a Boolean rule.

Module Contents

booldog.io.circuit.logger
booldog.io.circuit.PAREN_RE
booldog.io.circuit.clean_line(line)

Makes sure line is a Boolean rule, and not a header or comment

class booldog.io.circuit.BooleanOperators

A simple class to define the Boolean operators as class attributes. This is used to make the code more readable and maintainable.

AND = '&'
OR = '|'
NOT = '!'
class booldog.io.circuit.BooleanDiGraph

Bases: networkx.DiGraph

Simple helper class to track logic nodes

and_count = 0
or_count = 0
not_count = 0
add_and()

Add a AND node to the graph.

add_or()

Add a OR node to the graph.

add_not()

Add a NOT node to the graph.

booldog.io.circuit.booldog2circuit(model)

Export a BoolDog Boolean model to Networkx DiGraph

Parameters:

model (booldog:BoolDogModel) – A BoolDog object representing a Boolean network.

Returns:

graph – A networkx.DiGraph with the same nodes as the input network. Boolean rules are represented as additional “logical” nodes (and, or, not) and edges.

Return type:

BooleanDiGraph

booldog.io.circuit.resolve_rule(rule, processor)

Parse a Boolean rule and replace it with “logical” nodes and edges in the graph.

The rule can be nested with brackets, which are resolved first.

Parameters:
  • rule (str) – A Boolean rule (e.g. “A & B | C”)

  • processor (function) – A function that takes a list of nodes and an operator, processes them as needed. The operator can be “AND”, “OR”, or “NOT”. The function should return the new node representing the result of applying the operator to the nodes.

Returns:

new_s – Replacement string (the final node)

Return type:

str

booldog.io.circuit.resolve_factor(factor, processor)

Parse a single factor of a Boolean rule.

The factor can be a list of nodes connected by ‘&’, ‘|’, and ‘!’ operators. The factor does not contain brackets.

Parameters:
  • factor (str) – A Boolean factor e.g. “A & B | C”

  • processor (function) – A function that takes a list of nodes and an operator, processes them as needed. The operator can be “AND”, “OR”, or “NOT”. The function should return the new node representing the result of applying the operator to the nodes.

Returns:

s – Replacement string (the final node representing this factor)

Return type:

str