def check_espresso_responds(): cmd = find_command("espresso") cmd = [cmd, "--help"] log.info(f"espresso command = {' '.join(cmd)}") proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) out, err = proc.communicate() out = out.decode() if "Espresso" not in out: log.error(f"espresso output does not contain 'Espresso': out={out}") return log.info(f"espresso works")
def check_eqntott_responds(): cmd = find_command("eqntott") cmd = [cmd, "--help"] log.info(f"eqntott command = {' '.join(cmd)}") proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) out, err = proc.communicate() err = err.decode() if "usage" not in err: log.error(f"eqntott output does not contain 'usage': out={out}") return log.info(f"eqntott works")
def check_nusmv_responds(): cmd = find_command("nusmv") cmd = [cmd] log.info(f"clasp command = {' '.join(cmd)}") proc = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) out, err = proc.communicate(input="MODULE main".encode()) out = out.decode() if "NuSMV" not in out: log.error(f"NuSMV output does not contain 'NuSMV': out={out}") return log.info("NuSMV works")
def check_imagemagick_responds(): cmd = find_command("convert") cmd = [cmd, "-help"] log.info(f"imagemagick command = {' '.join(cmd)}") proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) out, err = proc.communicate() out = out.decode() if "ImageMagick" not in out: log.error( f"imagemagick output does not contain 'ImageMagick': out={out}") return log.info(f"imagemagick works")
def check_clasp_responds(): cmd = find_command("clasp") cmd = [cmd, "--help"] log.info(f"clasp command = {' '.join(cmd)}") proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) out, err = proc.communicate() out = out.decode() if not proc.returncode == 0: log.error( f"clasp did not respond with return code 0: return_code={proc.returncode}" ) return if "clasp version" not in out: log.error(f"clasp output does not contain 'clasp version': out={out}") return log.info("clasp works")
def check_gringo_responds(): cmd = find_command("gringo") cmd = [cmd, "--help"] log.info(f"gringo command = {' '.join(cmd)}") proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) out, err = proc.communicate() out = out.decode() if not proc.returncode == 0: log.error( f"gringo did not respond with return code 0: return_code={proc.returncode}" ) return if "Gringo" not in out: log.error(f"gringo output does not contain 'Gringo': out={out}") return log.info("gringo works")
def check_layout_engines(): for name in GRAPHVIZ_LAYOUT_ENGINES: cmd = find_command(name) log.info(f"{name} command = {cmd}") proc = subprocess.Popen([cmd, "-V"], stdout=subprocess.PIPE, stderr=subprocess.PIPE) out, err = proc.communicate() err = err.decode() # for some reason graphviz" reports on stderr if not proc.returncode == 0: log.error( f"{name} did not respond with return code 0: return_code={proc.returncode}" ) return if "graphviz" not in err: log.error(f"{name} output does not contain 'graphviz': out={err}") return log.info(f"{name} works")
def check_bnet2primes_responds(): cmd = find_command("bnet2prime") cmd = [cmd, "--ver"] log.info(f"bnet2prime command = {' '.join(cmd)}") proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) out, err = proc.communicate() out = out.decode() if not proc.returncode == 0: log.error( f"bnet2prime did not respond with return code 0: return_code={proc.returncode}" ) return if "BNetToPrime" not in out: log.error( f"bnet2prime output does not contain 'BNetToPrime': out={out}") return log.info("BNetToPrime works")
from typing import Optional import networkx from pyboolnet import find_command from pyboolnet.digraphs import convert_nodes_to_anonymous_strings, digraph2image from pyboolnet.digraphs import digraph2condensationgraph from pyboolnet.digraphs import digraph2dot from pyboolnet.digraphs import has_edge, has_path, find_successors, digraph2sccgraph from pyboolnet.helpers import divide_list_into_similar_length_lists from pyboolnet.state_space import hamming_distance, list_states_in_subspace from pyboolnet.state_space import subspace2dict, subspace2str, state2dict, state2str, random_state from pyboolnet.trap_spaces import compute_trap_spaces from pyboolnet.trap_spaces import compute_trapspaces_that_contain_state CMD_DOT = find_command("dot") UPDATE_STRATEGIES = ["asynchronous", "synchronous", "mixed"] log = logging.getLogger(__name__) def energy(primes: dict, state) -> int: """ This integer valued energy function E for Boolean networks is decreasing with transitions. That is, E(x) >= E(y) holds for any transition x -> y. It is based on the number of free variables in the smallest trapspace that contains *state*. The energy is therefore n >= E(x) >= 0 and E(x)=0 for steady states holds. **arguments**: * *primes*: prime implicants * *state*: a state
import logging import os import subprocess from typing import Union, List, Optional, Set import networkx from pyboolnet import find_command from pyboolnet.digraphs import _primes2signed_digraph from pyboolnet.digraphs import add_style_subgraphs as digraphs_add_style_subgraphs from pyboolnet.digraphs import digraph2dot, digraph2image, digraph2condensationgraph from pyboolnet.state_space import subspace2dict, states2dict, state2dict from pyboolnet.state_transition_graphs import successor_synchronous CMD_DOT = find_command("dot") CMD_CONVERT = find_command("convert") STYLES_SET = {"interactionsigns", "inputs", "outputs", "constants", "sccs", "anonymous"} log = logging.getLogger(__name__) def create_empty_igraph(primes: dict) -> networkx.DiGraph: """ creates an empty igraph with default attributes """ factor = 0.2 width = factor * sum(len(x) for x in primes) / len(primes) igraph = networkx.DiGraph()
import logging import subprocess from datetime import datetime from typing import Optional, List from pyboolnet import find_command from pyboolnet.state_space import subspace2str TRAP_SPACE_TYPES = ["max", "min", "all", "percolated", "circuits"] CMD_GRINGO = find_command("gringo") CMD_CLASP = find_command("clasp") log = logging.getLogger(__name__) def potassco_handle(primes: dict, type_: str, bounds: tuple, project: List[str], max_output: int, fname_asp: str, representation: str, extra_lines=None): """ Returns a list of trap spaces using the Potassco_ ASP solver :ref:`[Gebser2011]<Gebser2011>`. """ if type_ not in TRAP_SPACE_TYPES: log.error(f"unknown trap space type: type={type_}") raise Exception
import itertools import logging import os import subprocess from typing import Optional, List, Union, Iterable import networkx from pyboolnet import find_command LAYOUT_ENGINES = { name: find_command(name) for name in ["dot", "neato", "fdp", "sfdp", "circo", "twopi"] } log = logging.getLogger(__name__) def _primes2signed_digraph(primes: dict) -> networkx.DiGraph: """ Creates a signed interaction graph for primes. The method is in this module to avoid circular imports between the modules prime_implicants and interaction_graphs. """ digraph = networkx.DiGraph() edges = {} for name in primes: digraph.add_node(name) for term in primes[name][1]: for k, v in term.items():
import ast import logging import os from typing import Optional from pyboolnet import find_command from pyboolnet.external.bnet2primes import bnet_file2primes, bnet_text2primes from pyboolnet.boolean_normal_forms import primes2mindnf, get_dnf from pyboolnet.digraphs import find_outdag from pyboolnet.interaction_graphs import primes2igraph from pyboolnet.prime_implicants import CONSTANT_ON, CONSTANT_OFF from pyboolnet.prime_implicants import find_constants, find_inputs CMD_BNET2PRIMES = find_command("bnet2prime") log = logging.getLogger(__name__) def bnet2primes(bnet: str, fname_primes: Optional[str] = None) -> dict: """ Generates and returns the prime implicants of a Boolean network in **boolnet** format. The primes are saved as a *json* file if *fname_primes* is given. The argument *bnet* may be either the name of a *bnet* file or a string containing the file contents. Use the function `read_primes` to open a previously saved *json* file. .. example of boolnet format:: Erk, Erk & Mek | Mek & Raf Mek, Erk | Mek & Raf Raf, !Erk | !Raf
import datetime import logging import os import subprocess import sys import tempfile from typing import Tuple, Optional from pyboolnet import find_command, NUSMV_KEYWORDS from pyboolnet.helpers import get_env_with_libreadline6_on_ld_library_path from pyboolnet.prime_implicants import CONSTANT_ON, CONSTANT_OFF from pyboolnet.state_space import VAN_HAM_EXTENSIONS, find_vanham_variables from pyboolnet.state_transition_graphs import UPDATE_STRATEGIES from pyboolnet.temporal_logic import subspace2proposition CMD_NUSMV = find_command("nusmv") log = logging.getLogger(__file__) def print_warning_accepting_states_bug(primes: dict, ctl_spec: str): """ This bug occurs when the Specification is equivalent to TRUE or FALSE. """ if all(x not in ctl_spec for x in primes): log.warning( "accepting states bug might affect this result, see http://github.com/hklarner/PyBoolNet/issues/14" )
import logging import os import re import subprocess from typing import Optional, List from pyboolnet import find_command from pyboolnet.helpers import os_is_windows EQNTOTT_CMD = find_command("eqntott") ESPRESSO_CMD = find_command("espresso") FORBIDDEN_SYMBOLS = [ "False", "FALSE", "True", "TRUE", "Zero", "ZERO", "One", "ONE" ] log = logging.getLogger(__name__) def are_mutually_exclusive(this: str, other: str) -> bool: """ uses minimize_espresso to compute whether A and B are mutually exclusive """ return minimize_espresso(f"({this}) & ({other})") == "0" def implies(this: str, other: str) -> bool: """ uses minimize_espresso to compute whether *this* implies *other*. """