bnediction / bonesis

Synthesis and Reprogramming of Most Permissive Boolean Networks
https://bnediction.github.io/bonesis/
Other
11 stars 1 forks source link

Bug when a partially-specifed function is a constant #6

Closed kyuhyongpark closed 1 hour ago

kyuhyongpark commented 1 day ago

Good afternoon,

I've been trying to run bonesis on a partially-specified Boolean network using AEON format. It seems to me that there is a small bug when one of the specifed functions is a constant. I tried making a temporary fix by using older version of AEON.py and rewriting some of the scripts in colomoto/minibn.py, but unsure if this is appropriate. Please let me know what you think.

I was trying to run the following script. I tried 3 different ways of specifying that T is a constant, $T:true or $T:1 or $T:T | !T \n T -? T, but I got the same error.

import bonesis
import bonesis.aeon

fp = open("aeon_test.aeon", "w")

fp.write(
"""#name:aeon_test
$A:A & T
A -> A
T -> A
A ->? B
$T:true
"""
)

fp.close()

data = {}

dom = bonesis.aeon.AEONDomain.from_aeon_file("aeon_test.aeon")

bo = bonesis.BoNesis(dom, data)

print(bo.is_satisfiable())

for bn in bo.boolean_networks(limit=10):
    print("-"*20)
    print(bn)
    for att in list(bn.attractors()):
        print(att)

I used Windows 10 with python 3.11.4 and a new virtual enviroment.

pip install bonesis
pip install biodivine_aeon==0.3.0

Package          Version
---------------- -----------
beautifulsoup4   4.12.3
biodivine_aeon   0.3.0
bonesis          0.6.6
boolean.py       4.0
cffi             1.17.1
clingo           5.7.1
colomoto-jupyter 0.8.8
colorama         0.4.6
mpbn             3.8
networkx         3.4.2
numpy            2.1.2
pandas           2.2.3
pip              23.1.2
pycparser        2.22
pydot            3.0.2
pyeda            0.29.0
pyparsing        3.2.0
python-dateutil  2.9.0.post0
pytz             2024.2
scipy            1.14.1
setuptools       65.5.0
six              1.16.0
soupsieve        2.6
tqdm             4.66.5
tzdata           2024.2

I had to install older version of AEON.py, since the latest version installed with pip install biodivine_aeon would give following error when running the script:

Traceback (most recent call last):
  File ".\aeon_test.py", line 20, in <module>
    dom = bonesis.aeon.AEONDomain.from_aeon_file("aeon_test.aeon")
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".\.venv\Lib\site-packages\bonesis\aeon.py", line 227, in from_aeon_file
    return celf(am, **opts)
           ^^^^^^^^^^^^^^^^
  File ".\.venv\Lib\site-packages\bonesis\aeon.py", line 170, in __init__
    self.rg = self.am.graph()
              ^^^^^^^^^^^^^
AttributeError: 'biodivine_aeon.BooleanNetwork' object has no attribute 'graph'

With biodivine_aeon==0.3.0, I get below error when running the script:

Traceback (most recent call last):
  File ".\aeon_test.py", line 20, in <module>
    dom = bonesis.aeon.AEONDomain.from_aeon_file("aeon_test.aeon")
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".\.venv\Lib\site-packages\bonesis\aeon.py", line 227, in from_aeon_file
    return celf(am, **opts)
           ^^^^^^^^^^^^^^^^
  File ".\.venv\Lib\site-packages\bonesis\aeon.py", line 181, in __init__      
    self[name] = func
    ~~~~^^^^^^
  File ".\.venv\Lib\site-packages\bonesis\aeon.py", line 208, in __setitem__   
    s = struct_of_dnf(self.ba, f, list, sort=True)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".\.venv\Lib\site-packages\colomoto\minibn.py", line 266, in struct_of_dnf
    return container(sorted(clauses) if sort else clauses)
                     ^^^^^^^^^^^^^^^
  File ".\.venv\Lib\site-packages\colomoto\minibn.py", line 256, in make_clause
    return container(sorted(lits) if sort else lits)
                     ^^^^^^^^^^^^
  File ".\.venv\Lib\site-packages\colomoto\minibn.py", line 249, in make_lit
    return (l.obj, True)
            ^^^^^
AttributeError: '_TRUE' object has no attribute 'obj'

I replaced line 257-260 in colomoto/minibn.py from

    if f is ba.TRUE:
        return True
    elif f is ba.FALSE:
        return False

to

    if f is ba.TRUE or isinstance(f,_TRUE):
        return container((True,))
    elif f is ba.FALSE or isinstance(f,_FALSE):
        return container((False,))

which I believe fixes the bug. Running the script returns:

True
Grounding...done in 0.0s
--------------------
A <- A&T
B <- A
T <- 1

{'A': 1, 'B': 1, 'T': 1}
{'A': 0, 'B': 0, 'T': 1}
--------------------
A <- A&T
B <- 1
T <- 1

{'A': 1, 'B': 1, 'T': 1}
{'A': 0, 'B': 1, 'T': 1}
--------------------
A <- A&T
B <- 0
T <- 1

{'A': 1, 'B': 0, 'T': 1}
{'A': 0, 'B': 0, 'T': 1}

Thanks,

Kyu Hyong Park

pauleve commented 5 hours ago

Many thanks for your bug report. The AEON interface was indeed quite outdated! Can you confirm that upgrading to colomoto-jupyer 0.8.9 and using the current master branch of bonesis fixes the issue?

EDIT: and latest biodivine_aeon (1.1.1)

kyuhyongpark commented 3 hours ago

Thank you so much for addressing the bug so promptly. The issue is fixed. I really appreciate your quick response!

Installed packages for reference:

pip install git+https://github.com/bnediction/bonesis
pip install biodivine_aeon

Package          Version
---------------- -----------
beautifulsoup4   4.12.3
biodivine_aeon   1.1.1
bonesis          9999
boolean.py       4.0
cffi             1.17.1
clingo           5.7.1
colomoto_jupyter 0.8.9
colorama         0.4.6
mpbn             3.8
networkx         3.4.2
numpy            2.1.2
pandas           2.2.3
pip              24.2
pycparser        2.22
pydot            3.0.2
pyeda            0.29.0
pyparsing        3.2.0
python-dateutil  2.9.0.post0
pytz             2024.2
scipy            1.14.1
setuptools       65.5.0
six              1.16.0
soupsieve        2.6
tqdm             4.66.5
tzdata           2024.2