Skip to content

Commit e9950a7

Browse files
committed
follow AEON API changes (bug #6)
1 parent 67f34b0 commit e9950a7

File tree

3 files changed

+48
-11
lines changed

3 files changed

+48
-11
lines changed

.github/workflows/tests.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
strategy:
1010
max-parallel: 4
1111
matrix:
12-
python-version: ['3.9', '3.10', '3.11']
12+
python-version: ['3.10', '3.11', '3.12']
1313
clingo-version: ['5.6']
1414

1515
steps:
@@ -20,6 +20,7 @@ jobs:
2020
- name: Install dependencies
2121
run: |
2222
python -m pip install "clingo==${{ matrix.clingo-version }}.*"
23+
python -m pip install biodivine_aeon
2324
python -m pip install .
2425
- name: Test with pytest
2526
run: |

bonesis/aeon.py

+12-10
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def __repr__(self):
6666

6767

6868
def asp_of_AEONReg(dom, boenc, n, acting_n=None, regs=None, ns=""):
69-
regs = dom.rg.regulators(n) if regs is None else regs
69+
regs = dom.am.predecessors(n) if regs is None else regs
7070
acting_n = n if acting_n is None else acting_n
7171
d = len(regs)
7272
boenc.load_template_domain(ns=ns, allow_externals=ns)
@@ -76,24 +76,27 @@ def asp_of_AEONReg(dom, boenc, n, acting_n=None, regs=None, ns=""):
7676
nbc = dom.get_maxclause(d)
7777
rules.append(clingo.Function(f"{ns}maxC", symbols(n, nbc)))
7878
for m in regs:
79-
reg = dom.rg.find_regulation(m, acting_n)
80-
m = dom.rg.get_variable_name(m)
79+
reg = dom.am.find_regulation(m, acting_n)
80+
m = dom.am.get_variable_name(m)
8181
args = symbols(m, n)
82-
monotonicity = reg.get("monotonicity")
83-
if monotonicity == "activation":
82+
monotonicity = reg.get("sign")
83+
if monotonicity in [True, "positive", "+"]:
8484
sign = 1
85-
elif monotonicity == "inhibition":
85+
elif monotonicity in [False, "negative", "-"]:
8686
sign = -1
8787
else:
8888
sign = "(-1;1)"
8989
rules.append("{}in({},{},{})".format(ns, *args, sign))
90-
if reg["observable"]:
90+
if reg.get("essential"):
9191
boenc.load_template_edge(ns=ns)
9292
rules.append(":- not {}edge({},{},_)".format(ns, *args))
9393
return rules
9494

9595
def asp_of_AEONFunction(dom, n, func):
9696
rules = []
97+
if isinstance(func.struct, bool):
98+
rules.append(clingo.Function("constant", symbols(n, s2v(func.struct))))
99+
return rules
97100
for cid, c in enumerate(func.struct):
98101
if isinstance(c, bool):
99102
rules.append(clingo.Function("constant", symbols(n, s2v(c))))
@@ -167,7 +170,6 @@ class AEONDomain(BonesisDomain, dict):
167170
def __init__(self, aeon_model, maxclause=None, canonic=True):
168171
super().__init__()
169172
self.am = aeon_model
170-
self.rg = self.am.graph()
171173
self.ba = boolean.BooleanAlgebra(NOT_class=NOT)
172174
self.maxclause = maxclause
173175
self.canonic = canonic # canonicty is ensured only for parameters and free functions
@@ -176,7 +178,7 @@ def __init__(self, aeon_model, maxclause=None, canonic=True):
176178
self._f = bonesis.BooleanNetwork({})
177179

178180
for i in self.am.variables():
179-
name = self.rg.get_variable_name(i)
181+
name = self.am.get_variable_name(i)
180182
func = self.am.get_update_function(i)
181183
self[name] = func
182184

@@ -201,7 +203,7 @@ def register_parameter(g):
201203
else:
202204
assert self.params[name] == args
203205
return name
204-
func = func.to_string(self.am) if not isinstance(func, str) else func
206+
func = str(func) if not isinstance(func, str) else func
205207
f = self.ba.parse(RE_PARAMETER.sub(register_parameter, func))
206208
self._f[node] = f
207209
f = self._f[node]

tests/test_aeon.py

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import unittest
2+
3+
import os
4+
import tempfile
5+
import shutil
6+
7+
import bonesis
8+
import bonesis.aeon
9+
10+
class TestAEONImport(unittest.TestCase):
11+
def setUp(self):
12+
self.test_dir = tempfile.mkdtemp()
13+
14+
def tearDown(self):
15+
shutil.rmtree(self.test_dir)
16+
17+
18+
def test_import_with_constant(self):
19+
"""
20+
Source: https://github.com/bnediction/bonesis/issues/6
21+
"""
22+
fpath = os.path.join(self.test_dir, "test1.aeon")
23+
with open(fpath, "w") as fp:
24+
fp.write("""#name:aeon_test
25+
$A:A & T
26+
A -> A
27+
T -> A
28+
A ->? B
29+
$T:true
30+
""")
31+
32+
dom = bonesis.aeon.AEONDomain.from_aeon_file(fpath)
33+
bo = bonesis.BoNesis(dom)
34+
self.assertEqual(bo.boolean_networks().count(), 3)

0 commit comments

Comments
 (0)