-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Lazy succession diagram #71
Conversation
Coverage Report
|
TODO for this PR: Add expansion algorithm that can partially expand the succession diagram towards a specific target subspace (i.e. not expand things that contradict this space). |
Coverage Report
|
I think the whole thing is ready for review now :) As mentioned, things around attractor detection need to be benchmarked/optimized a bit more, but at least all the functionality we have on |
@@ -274,3 +274,31 @@ def expression_to_space_list(expression: Expression) -> list[dict[str, int]]: | |||
sub_spaces.append(sub_space) | |||
|
|||
return sub_spaces | |||
|
|||
def space_unique_key(space: dict[str, int], network: BooleanNetwork) -> int: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is OK for now, but these kind of functions make me think that we might want to consider a Space
class that implements __hash__
. To be clear, I'm not saying that's necessarily the right thing to do, just that we should think about it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh yeah, absolutely!
|
||
from nfvsmotifs.space_utils import is_subspace, intersect | ||
|
||
def expand_to_target(sd: SuccessionDiagram, target: dict[str, int], size_limit: int | None = None): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this a separate function and not just an option integrated into expand_bfs
(and expand_dfs
)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My original intuition was that this will be used by the control algorithm and hence there may be features/options that I am not aware of right now but may be incompatible with the "generic" DFS/BFS algorithms.
For example, that you might want to modify the search procedure in some way to "optimise" the SD for control even further. E.g. by picking a specific path to target instead of the "default" path chosen by BFS/DFS.
But I agree that in principle the algorithms could be merged.
I just finished going over everything. I have only a few minor issues to raise:
Overall, it looks good to me, and I'd be happy to merge it. |
I'm just going to merge this and get to work resolving conflicts with the control branch. |
This PR is a substantial refactor of the
SuccessionDiagram
class which makes it (hopefully) simper and more modular while also more "correct". A rough overview of changes (with rationale) follows.First, the list of "general" changes:
benchmark
directory. The reason is that addingbench_*
scripts to the root folder makes it very cluttered. Unfortunately, this means that you'll have to runpip install .
before running benchmarks (seebenchmark/README.md
).pyproject.toml
to makenfvsmotifs
install-able using pip.122
and144
are "disabled" because they have fundamental issues (too many min. trap spaces) that we'd have to overcome to be able to obtain any useful results for them.space_utils
, we can now compute an integer unique key for any space, assuming the underlyingBooleanNetwork
is available. This is used internally bySuccessionDiagram
to identify duplicate nodes, but can be also used as a deterministic key for sorting a list of arbitrary spaces.motif_avoidant
, the computation of the retained set is refactored into a separate function, because now it is actually used in multiple places (and it makes it easier to refactor/change in the future in general).Second, the list of changes to
SuccessionDiagram
specifically:_sd_algorithms
module (see below). TheSuccessionDiagram
class just calls the functions from this module. The reason is that theSuccessionDiagram
class needs to support a lot of non-trivial algorithms and it makes it easier to update/validate these algorithms in isolation.expanded
,attr_expanded
andattractors
of the succession diagram are now just properties of the individual nodes of thenetworkx
graph. This slightly complicates typing but is more "modular" in the long-term.expand_attractors
).target
space, such that any space that intersects with thistarget
is expanded, as long as it is not a proper subspace oftarget
.Furthermore, tests were expanded to cover more cases (we're at 92% coverage compared to 89% on main while adding a bunch of new code). I also tried to make extra sure that the results are deterministic (sorting nodes by node id, spaces by unique key, or explicitly documenting outputs where the order is not guaranteed).
Obviously, most of these are breaking changes but I'll update other active branches ones this is merged.
Performance: I'm still waiting for all performance numbers, but overall what I've seen so far is comparable to the previous PR. The main difference is that this PR does not use symbolic algorithms at all, hence cases where attractor detection which benefited from them might be slower than the previous PR. But this does not concern the speed of SD expansion. I'll experiment a bit more with symbolic attractor detection and attractor detection in general and put these into a separate PR.