Skip to content

Commit ef550cd

Browse files
authored
Merge pull request #130 from jcrozum/daemontus/feat/no-autoexpand
Add option to avoid source node auto expansion
2 parents 7a84f76 + e2e3ca1 commit ef550cd

File tree

8 files changed

+55
-13
lines changed

8 files changed

+55
-13
lines changed

.github/workflows/test.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,10 @@ jobs:
2222
python -m pip install flake8 black mypy
2323
python -m pip install -r requirements.txt
2424
- name: Lint with Black
25-
uses: rickstaa/action-black@v1
25+
uses: psf/black@stable
2626
with:
27-
black_args: ". --check --diff"
27+
options: "--check --diff"
28+
version: "25.1.0" # If you change this, also update requirements-dev.txt
2829
- name: Check types
2930
run: |
3031
mypy biobalm

biobalm/succession_diagram.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ def default_config() -> SuccessionDiagramConfiguration:
185185
"attractor_candidates_limit": 100_000,
186186
"retained_set_optimization_threshold": 1_000,
187187
"minimum_simulation_budget": 1_000,
188+
"auto_expand_source_nodes": True,
188189
}
189190

190191
@staticmethod
@@ -1545,7 +1546,7 @@ def _expand_one_node(self, node_id: int):
15451546
# The SD created from the restricted Petri net is technically correct, but can
15461547
# propagate some of the input values further and yields a smaller SD.
15471548
source_nodes = []
1548-
if node_id == self.root():
1549+
if node_id == self.root() and self.config["auto_expand_source_nodes"]:
15491550
source_nodes = extract_source_variables(self.petri_net)
15501551

15511552
sub_spaces: list[BooleanSpace]

biobalm/types.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,8 @@ class SuccessionDiagramConfiguration(TypedDict):
229229
intersect negative cycles to find an NFVS subset. Typically,
230230
for smaller networks, the trade-off is in favor of
231231
computing a smaller NFVS.
232+
233+
[Default: 2_000]
232234
"""
233235

234236
pint_goal_size_limit: int
@@ -242,19 +244,25 @@ class SuccessionDiagramConfiguration(TypedDict):
242244
The default value was empirically tested as safe on Debian linux, but other operating
243245
systems may need a different limit to stay safe. Nevertheless, this should not be
244246
an issue on smaller/simpler networks.
247+
248+
[Default: 8_192]
245249
"""
246250

247251
attractor_candidates_limit: int
248252
"""
249253
If more than `attractor_candidates_limit` states are produced during the
250254
attractor detection process, then the process fails with a `RuntimeError`.
251255
This is mainly to avoid out-of-memory errors or crashing `clingo`.
256+
257+
[Default: 100_000]
252258
"""
253259

254260
retained_set_optimization_threshold: int
255261
"""
256262
If there are more than this amount of attractor candidates, the attractor
257263
detection process will try to optimize the retained set using ASP (if enabled).
264+
265+
[Default: 1_000]
258266
"""
259267

260268
minimum_simulation_budget: int
@@ -269,4 +277,16 @@ class SuccessionDiagramConfiguration(TypedDict):
269277
However, this budget only applies when simulation has not been able to make progress
270278
in the recent round. That is, if simulation has actively eliminated some candidates in
271279
the recent round, it will still continue regardless of the budget limit.
280+
281+
[Default: 1_000]
282+
"""
283+
284+
auto_expand_source_nodes: bool
285+
"""
286+
When `biobalm` detects that the network has source nodes, it expands them all simultaneously,
287+
instead of expanding them one by one. This is useful for networks with many source nodes,
288+
because it produces a much smaller succession diagram without losing any "interesting" behavior.
289+
However, this setting needs to be disabled if only specific source nodes are to be expanded.
290+
291+
[Default: True]
272292
"""

example/attractors.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@
1818
# Prepare a config which will print progress.
1919
config = SuccessionDiagram.default_config()
2020
config["debug"] = True # Print progress.
21-
config[
22-
"max_motifs_per_node"
23-
] = 1_000_000 # Maximum number of outgoing edges for each node.
24-
config[
25-
"attractor_candidates_limit"
26-
] = 100_000 # Maximum number of enumerated attractor candidates.
21+
config["max_motifs_per_node"] = (
22+
1_000_000 # Maximum number of outgoing edges for each node.
23+
)
24+
config["attractor_candidates_limit"] = (
25+
100_000 # Maximum number of enumerated attractor candidates.
26+
)
2727

2828
sd = SuccessionDiagram(bn, config)
2929

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ readme = "README.md"
66
license = { file = "LICENSE" }
77
requires-python = ">=3.11"
88
dependencies = [
9-
'biodivine_aeon >=1.0.1',
9+
'biodivine_aeon >=1.2.5',
1010
'clingo >=5.6.2',
1111
'networkx >=2.8.8',
1212
]

requirements-dev.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ astroid==3.1.0
77
autodocsumm==0.2.12
88
Babel==2.14.0
99
beautifulsoup4==4.12.3
10-
biodivine_aeon==1.0.0a8
11-
black==24.2.0
10+
biodivine_aeon==1.2.5
11+
black==25.1.0
1212
boolean.py==4.0
1313
CacheControl==0.14.0
1414
certifi==2024.2.2

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
biodivine_aeon>=1.0.0
1+
biodivine_aeon>=1.2.5
22
clingo==5.6.2
33
networkx==2.8.8
44
pypint[pint]==1.6.2

tests/succession_diagram_test.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,3 +418,23 @@ def test_attractor_extraction():
418418
sd.build()
419419
eas = sd.expanded_attractor_seeds()
420420
assert eas == {1: [{"A": 0, "B": 0, "C": 1}], 2: [{"A": 1, "B": 1, "C": 1}]}
421+
422+
423+
def test_source_auto_expand():
424+
net = """
425+
A, A
426+
B, B
427+
"""
428+
cfg = biobalm.SuccessionDiagram.default_config()
429+
cfg["auto_expand_source_nodes"] = False
430+
sd = biobalm.SuccessionDiagram.from_rules(net, config=cfg)
431+
sd.expand_dfs()
432+
# root, A fixed, B fixed, A+B fixed
433+
assert len(sd) == (1 + 2 + 2 + 4)
434+
435+
cfg = biobalm.SuccessionDiagram.default_config()
436+
cfg["auto_expand_source_nodes"] = True
437+
sd = biobalm.SuccessionDiagram.from_rules(net, config=cfg)
438+
sd.expand_dfs()
439+
# root, A+B fixed
440+
assert len(sd) == (1 + 4)

0 commit comments

Comments
 (0)