Skip to content

Commit

Permalink
Only generate percolated PN if needed, but keep a parent reference to…
Browse files Browse the repository at this point in the history
… speed it up.
  • Loading branch information
daemontus committed Aug 23, 2024
1 parent e100ea8 commit 2182237
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
12 changes: 5 additions & 7 deletions biobalm/succession_diagram.py
Original file line number Diff line number Diff line change
Expand Up @@ -1033,6 +1033,10 @@ def node_percolated_petri_net(
if percolated_pn is None and not compute:
raise KeyError(f"Percolated network not computed for node {node_id}.")

if parent_id is None:
# If no parent node is directly provided, we can try to use a cached one.
parent_id = node["parent_node"]

if percolated_pn is None:
base_pn = self.petri_net
percolate_space = node_space
Expand Down Expand Up @@ -1449,6 +1453,7 @@ def _ensure_node(self, parent_id: int | None, stable_motif: BooleanSpace) -> int
attractor_candidates=None,
attractor_seeds=None,
attractor_sets=None,
parent_node=parent_id,
)
self.node_indices[key] = child_id
else:
Expand All @@ -1459,13 +1464,6 @@ def _ensure_node(self, parent_id: int | None, stable_motif: BooleanSpace) -> int
if parent_id is not None:
self._ensure_edge(parent_id, child_id, stable_motif)

# Compute the percolated petri net here, because we know the parent node ID
# and using its already percolated petri net helps a lot.
#
# (For percolated network and nfvs, knowing the parent ID is not as useful,
# so the parent is not used and we can just compute them lazily)
self.node_percolated_petri_net(child_id, compute=True, parent_id=parent_id)

return child_id

def _ensure_edge(self, parent_id: int, child_id: int, stable_motif: BooleanSpace):
Expand Down
8 changes: 8 additions & 0 deletions biobalm/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,14 @@ class NodeData(TypedDict):
have associated attractors.
"""

parent_node: int | None
"""
The ID of one of the predecessor nodes through which this node was first
discovered, or `None` if the node was discovered through other means
(usually either the root, or a minimal trap space that was added without
expanding its predecessors).
"""


class SuccessionDiagramConfiguration(TypedDict):
"""
Expand Down

0 comments on commit 2182237

Please sign in to comment.