Skip to content

Commit

Permalink
Merge pull request #106 from jcrozum/succession-api-and-docs
Browse files Browse the repository at this point in the history
SuccessionDiagram api improvements and docs
  • Loading branch information
jcrozum committed Mar 4, 2024
2 parents 3e00da3 + 8ab13c3 commit 0da3e96
Show file tree
Hide file tree
Showing 18 changed files with 435 additions and 228 deletions.
6 changes: 3 additions & 3 deletions balm/_sd_algorithms/compute_attractor_seeds.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def compute_attractor_seeds(
if balm.succession_diagram.DEBUG:
print(f"[{node_id}] Start computing attractor seeds.")

node_space = sd.node_space(node_id)
node_space = sd.node_data(node_id)["space"]

if len(node_space) == sd.network.variable_count():
# This node is a fixed-point.
Expand All @@ -39,8 +39,8 @@ def compute_attractor_seeds(
# Compute the list of child spaces if the node is expanded. Otherwise
# "pretend" that there are no children.
child_spaces = []
if sd.node_is_expanded(node_id):
child_spaces = [sd.node_space(s) for s in sd.node_successors(node_id)]
if sd.node_data(node_id)["expanded"]:
child_spaces = [sd.node_data(s)["space"] for s in sd.node_successors(node_id)]

# Fix everything in the NFVS to zero, as long as
# it isn't already fixed by our `node_space`.
Expand Down
6 changes: 3 additions & 3 deletions balm/_sd_algorithms/expand_attractor_seeds.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def expand_attractor_seeds(sd: SuccessionDiagram, size_limit: int | None = None)

# Retrieve the stable motifs of children that are already expanded.
expanded_children = [
x for x in sd.node_successors(node) if sd.node_is_expanded(x)
x for x in sd.node_successors(node) if sd.node_data(x)["expanded"]
]
expanded_motifs = [
sd.edge_stable_motif(node, child) for child in expanded_children
Expand All @@ -61,15 +61,15 @@ def expand_attractor_seeds(sd: SuccessionDiagram, size_limit: int | None = None)
# and continue to the next one.
successors.pop()
continue
if sd.node_is_expanded(successors[-1]):
if sd.node_data(successors[-1])["expanded"]:
# The next node to explore is expanded (by some previous procedure)
# but not "seen" in this search yet. We need to visit this node
# regardless of other conditions
break
# Now, we need to asses if the next successor has some candidate states which
# are not covered by the already expanded children.

successor_space = sd.node_space(successors[-1])
successor_space = sd.node_data(successors[-1])["space"]
retained_set = make_retained_set(
sd.symbolic, sd.node_nfvs(node), successor_space
)
Expand Down
4 changes: 2 additions & 2 deletions balm/_sd_algorithms/expand_minimal_spaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def expand_minimal_spaces(sd: SuccessionDiagram, size_limit: int | None = None)
successors = sorted(successors, reverse=True) # For determinism!
# (reversed because we explore the list from the back)

node_space = sd.node_space(node)
node_space = sd.node_data(node)["space"]

# Remove all immediate successors that are already visited or those who
# do not cover any new minimal trap space.
Expand All @@ -52,7 +52,7 @@ def expand_minimal_spaces(sd: SuccessionDiagram, size_limit: int | None = None)
# of this node is already in the succession diagram.
if len(successors) == 0:
if sd.node_is_minimal(node):
minimal_traps.remove(sd.node_space(node))
minimal_traps.remove(sd.node_data(node)["space"])
continue

# At this point, we know that `s` is not visited and it contains
Expand Down
2 changes: 1 addition & 1 deletion balm/_sd_algorithms/expand_to_target.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def expand_to_target(

while len(current_level) > 0:
for node in current_level:
node_space = sd.node_space(node)
node_space = sd.node_data(node)["space"]

if intersect(node_space, target) is None:
# If `node_space` does not intersect with `target`, it is not relevant
Expand Down
10 changes: 5 additions & 5 deletions balm/control.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def __init__(
Example
-------
>>> import balm
>>> sd = balm.SuccessionDiagram.from_bnet(
>>> sd = balm.SuccessionDiagram.from_rules(
... \"\"\"
... A, B & C
... B, A & C
Expand Down Expand Up @@ -87,7 +87,7 @@ def __init__(
self._control: list[ControlOverrides] = []
for c in control:
cs = sorted(map(lambda x: sorted(x.items()), c))
self._control.append(list(map(dict, cs)))
self._control.append(list(map(dict, cs))) # type: ignore

self._strategy = strategy
self._succession = succession
Expand Down Expand Up @@ -198,7 +198,7 @@ def succession_control(
-------
>>> import balm
>>> from balm.control import succession_control
>>> sd = balm.SuccessionDiagram.from_bnet(
>>> sd = balm.SuccessionDiagram.from_rules(
... \"\"\"
... S, S
... A, S | B
Expand Down Expand Up @@ -237,7 +237,7 @@ def succession_control(
-------
>>> import balm
>>> from balm.control import succession_control
>>> sd = balm.SuccessionDiagram.from_bnet(
>>> sd = balm.SuccessionDiagram.from_rules(
... \"\"\"
... S, S
... A, S | B
Expand Down Expand Up @@ -335,7 +335,7 @@ def successions_to_target(
)

for s in succession_diagram.node_ids():
fixed_vars = succession_diagram.node_space(s)
fixed_vars = succession_diagram.node_data(s)["space"]
if not is_subspace(fixed_vars, target):
continue

Expand Down
4 changes: 2 additions & 2 deletions balm/drivers.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def find_single_node_LDOIs(
Example
_______
>>> import balm
>>> sd = balm.SuccessionDiagram.from_bnet('A, A\\nB, A')
>>> sd = balm.SuccessionDiagram.from_rules('A, A\\nB, A')
>>> ldois = balm.drivers.find_single_node_LDOIs(sd.network)
>>> for k in sorted(ldois):
... print(f'{k} ==> {sorted(ldois[k].items())}')
Expand Down Expand Up @@ -107,7 +107,7 @@ def find_single_drivers(
Example
-------
>>> import balm
>>> sd = balm.SuccessionDiagram.from_bnet('A, A\\nB, A')
>>> sd = balm.SuccessionDiagram.from_rules('A, A\\nB, A')
>>> drivers = balm.drivers.find_single_drivers({'B': 0}, sd.network)
>>> sorted(list(drivers))
[('A', 0), ('B', 0)]
Expand Down
2 changes: 1 addition & 1 deletion balm/interaction_graph_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def feedback_vertex_set(
--------
>>> import balm
>>> from balm.interaction_graph_utils import feedback_vertex_set
>>> sd = balm.SuccessionDiagram.from_bnet(\"\"\"
>>> sd = balm.SuccessionDiagram.from_rules(\"\"\"
... A, B
... B, A
... C, D
Expand Down
19 changes: 11 additions & 8 deletions balm/motif_avoidant.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
A module responsible for detecting motif-avoidant attractors within terminal restriction space.
A module responsible for detecting motif-avoidant attractors within terminal restriction space.
"""

from __future__ import annotations
Expand Down Expand Up @@ -103,13 +103,16 @@ def detect_motif_avoidant_attractors(
"""
Compute a sub-list of `candidates` which correspond to motif-avoidant
attractors. Other method inputs:
- `graph` and `petri_net` represent the model in which the property
should be checked.
- `terminal_restriction_space` is a symbolic set of states which contains
all motif avoidant attractors (i.e. if a candidate state can leave this
set, the candidate cannot be an attractor).
- `max_iterations` specifies how much time should be spent on the "simpler"
preprocessing before applying a more complete method.
`graph` and `petri_net` represent the model in which the property
should be checked.
`terminal_restriction_space` is a symbolic set of states which contains
all motif avoidant attractors (i.e. if a candidate state can leave this
set, the candidate cannot be an attractor).
`max_iterations` specifies how much time should be spent on the "simpler"
preprocessing before applying a more complete method.
"""
if ensure_subspace is None:
ensure_subspace = {}
Expand Down
Loading

1 comment on commit 0da3e96

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage

Coverage Report
FileStmtsMissCoverMissing
balm
   control.py1141488%102, 114, 120, 124, 129, 138–154, 472, 475, 488
   interaction_graph_utils.py30487%6–8, 145–146
   motif_avoidant.py152299%25, 124
   petri_net_translation.py1481193%18–22, 58, 94, 207–208, 232–233, 242, 346
   space_utils.py129497%25–27, 252, 278
   succession_diagram.py2571694%6, 184–189, 197, 257–258, 268, 274, 390, 580, 772, 810, 847
   symbolic_utils.py26388%10–12, 44
   trappist_core.py1833084%11–15, 45, 47, 82, 129, 195, 197, 199, 227–230, 234–236, 256–262, 320, 322, 352, 392, 394, 425, 454
balm/_sd_algorithms
   compute_attractor_seeds.py30197%8
   expand_attractor_seeds.py51590%6, 42, 97–102
   expand_bfs.py28196%6
   expand_dfs.py30197%6
   expand_minimal_spaces.py37295%6, 31
   expand_source_SCCs.py164696%19–21, 91, 101, 143, 287
   expand_to_target.py31390%6, 38, 43
TOTAL147110393% 

Tests Skipped Failures Errors Time
361 0 💤 0 ❌ 0 🔥 53.100s ⏱️

Please sign in to comment.