Ejemplo n.º 1
0
def test_compute_attractors_tarjan():
    bnet = "\n".join(["x, !x&y | z", "y, !x | !z", "z, x&!y"])
    primes = bnet2primes(bnet)
    stg = primes2stg(primes, "asynchronous")
    steady_states, cyclic = compute_attractors_tarjan(stg)

    assert steady_states == ["101"]
    assert cyclic == [{"010", "110"}]
Ejemplo n.º 2
0
def test_completeness():
    bnet = "\n".join([
        "v0,   v0", "v1,   v2", "v2,   v1", "v3,   v1&v0", "v4,   v2",
        "v5,   v3&!v6", "v6,   v4&v5"
    ])
    primes = bnet2primes(bnet)

    assert completeness(primes, "asynchronous")
    assert not completeness(primes, "synchronous")

    answer, example = completeness_with_counterexample(primes, "synchronous")
    example = state2str(example)
    stg = primes2stg(primes, "synchronous")

    for x in compute_trap_spaces(primes, "min"):
        x = subspace2str(primes, x)

        states = list_states_in_subspace(primes, x)
        states = [state2str(x) for x in states]

        assert not has_path(stg, example, states)

    bnet = "\n".join([
        "v1, !v1&v2&v3 | v1&!v2&!v3", "v2, !v1&!v2 | v1&v3",
        "v3, !v1&v3 | v1&v2", "v4, 1", "v5, v4"
    ])
    primes = bnet2primes(bnet)

    assert not completeness(primes, "asynchronous")

    answer, example = completeness_with_counterexample(primes, "asynchronous")

    assert len(example) == len(primes)
    assert completeness(primes, "synchronous")

    bnet = "\n".join(
        ["v1, !v1&v2&v3 | v1&!v2&!v3", "v2, !v1&!v2 | v1&v3", "v3, v2 | v3"])
    primes = bnet2primes(bnet)

    assert completeness(primes, "asynchronous")
    assert completeness(primes, "synchronous")

    bnet = "\n".join([
        "v1,   !v2", "v2,   v1", "v3,   v1", "v4,   v2", "v5,   v6",
        "v6,   v4&v5", "v7,   v2", "v8,   v5", "v9,   v6&v10", "v10,  v9&v7"
    ])
    primes = bnet2primes(bnet)

    assert completeness(primes, "synchronous")
def test_stg2image():
    fname_in = get_tests_path_in(fname="irma.primes")
    fname_out1 = get_tests_path_out(fname="irma_stg_async.pdf")
    fname_out2 = get_tests_path_out(fname="irma_stg_tendencies_async.pdf")
    fname_out3 = get_tests_path_out(fname="irma_stg_sccs_async.pdf")

    primes = read_primes(fname_json=fname_in)
    stg = primes2stg(primes=primes, update="asynchronous")
    stg2image(stg, fname_out1)

    add_style_tendencies(stg)
    stg2image(stg, fname_out2)

    stg = primes2stg(primes=primes, update="asynchronous")
    add_style_sccs(stg)
    stg2image(stg, fname_out3)

    fname_out1 = get_tests_path_out(fname="irma_stg_sync.pdf")
    fname_out2 = get_tests_path_out(fname="irma_stg_tendencies_sync.pdf")
    fname_out3 = get_tests_path_out(fname="irma_stg_sccs_sync.pdf")
    fname_out4 = get_tests_path_out(fname="irma_stg_path.pdf")

    primes = read_primes(fname_json=fname_in)
    stg = primes2stg(primes=primes, update="synchronous")
    stg2image(stg, fname_out1)

    stg = primes2stg(primes=primes, update="asynchronous")
    add_style_tendencies(stg)
    stg2image(stg, fname_out2)

    stg = primes2stg(primes=primes, update="synchronous")
    add_style_sccs(stg)
    stg2image(stg, fname_out3)

    init = random_state(primes=primes)
    walk = random_walk(primes=primes,
                       update="asynchronous",
                       initial_state=init,
                       length=5)
    stg = primes2stg(primes=primes, update="asynchronous")
    add_style_path(stg, walk, "red")
    init = pyboolnet.state_space.random_state(primes=primes)
    walk = random_walk(primes=primes,
                       update="asynchronous",
                       initial_state=init,
                       length=5)
    add_style_path(stg, walk, "blue")
    stg2image(stg, fname_out4)
def test_primes2stg():
    primes = read_primes(fname_json=get_tests_path_in(fname="irma.primes"))

    def init(x):
        return x["Cbf1"] + x["Ash1"] + x["Gal80"] == 1

    primes2stg(primes=primes, update="asynchronous")
    primes2stg(primes=primes, update="synchronous")
    primes2stg(primes=primes, update="mixed")
    primes2stg(primes=primes, update="asynchronous", initial_states=init)
    primes2stg(primes=primes, update="synchronous", initial_states=init)
    primes2stg(primes=primes, update="mixed", initial_states=init)

    init = []
    stg = primes2stg(primes=primes, update="synchronous", initial_states=init)
    answer = sorted(stg.nodes())
    expected = []

    assert answer == expected

    init = ["000010"]
    stg = primes2stg(primes=primes, update="synchronous", initial_states=init)
    answer = sorted(stg.nodes())

    assert answer == ["000010", "000110"]

    init = [{"Cbf1": 0, "Gal4": 1, "Gal80": 0, "gal": 1, "Swi5": 0, "Ash1": 1}]
    stg = primes2stg(primes=primes, update="synchronous", initial_states=init)
    answer = sorted(stg.nodes())

    assert answer == ["010001", "010011", "100011", "101001"]
def test_stg2htg():
    fname_out = get_tests_path_out(fname="raf_htg.pdf")
    primes = get_primes("raf")
    stg = primes2stg(primes, "asynchronous")
    htg = stg2htg(stg)
    htg2image(htg, fname_out)
def test_stg2condensationgraph():
    fname_out = get_tests_path_out(fname="raf_cgraph.pdf")
    primes = get_primes("raf")
    stg = primes2stg(primes, "asynchronous")
    cgraph = stg2condensationgraph(stg)
    condensationgraph2image(cgraph, fname_out)
def test_stg2sccgraph():
    fname_out = get_tests_path_out(fname="raf_sccgraph.pdf")
    primes = get_primes("raf")
    stg = primes2stg(primes, "asynchronous")
    scc_graph = stg2sccgraph(stg)
    sccgraph2image(scc_graph, fname_out)
def test_stg2dot():
    fname_in = get_tests_path_in(fname="irma.primes")
    fname_out = get_tests_path_out(fname="irma_stg.dot")
    primes = read_primes(fname_json=fname_in)
    stg = primes2stg(primes=primes, update="asynchronous")
    stg2dot(stg, fname_out)
    create_stg_image(primes,
                     "asynchronous",
                     "stg2.pdf",
                     initial_states={
                         "x4": 0,
                         "x5": 0
                     },
                     styles=["anonymous", "tendencies", "mintrapspaces"])

    # drawing paths

    path = random_walk(primes,
                       "asynchronous",
                       initial_state="--00---",
                       length=4)
    stg = primes2stg(primes, "asynchronous", initial_states={"x4": 0, "x5": 0})
    add_style_path(stg, path, color="red")
    add_style_anonymous(stg)
    stg2image(stg, "stg3.pdf")

    # drawing factor graphs

    primes = get_primes("randomnet_n7k3")
    stg = primes2stg(primes, "asynchronous")
    scc_graph = stg2sccgraph(stg)
    sccgraph2image(scc_graph, "scc_graph.pdf")

    cograph = stg2condensationgraph(stg)
    sccgraph2image(cograph, "cograph.pdf")

    htg = stg2condensationgraph(stg)
Ejemplo n.º 10
0
from pyboolnet.repository import get_primes
from pyboolnet.state_transition_graphs import primes2stg
from pyboolnet.attractors import compute_attractors_tarjan, compute_attractors, find_attractor_state_by_randomwalk_and_ctl

if __name__ == "__main__":
    # attractor computation with Tarjan

    primes = get_primes("tournier_apoptosis")

    stg = primes2stg(primes, "asynchronous")
    steady, cyclic = compute_attractors_tarjan(stg)
    print(steady)
    print(cyclic)

    # random walk attractor detection

    state = find_attractor_state_by_randomwalk_and_ctl(primes, "asynchronous")
    print(state)

    # model checking based attractor detection

    attrs = compute_attractors(primes, "asynchronous", fname_json="attrs.json")

    print(attrs["is_complete"])
    for x in attrs["attractors"]:
        print(x["is_steady"])
        print(x["state"]["str"])