Skip to content
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

Checking for historicity of states #4623

Closed
Voxanimus opened this issue May 7, 2024 · 2 comments
Closed

Checking for historicity of states #4623

Voxanimus opened this issue May 7, 2024 · 2 comments
Labels
needs-triage Issue has yet to be looked at by a maintainer question Issues that do not require code changes

Comments

@Voxanimus
Copy link

Question

I am currently trying to verify that for some state A an other state B is in the history of A.
I tried something like this:

lineage = [
            history.state
            for history in current_state.history.lineage
        ]

        if len(found_states) > 0 and found_states[-1] == current_state:
            return True

        if self._initial_state not in lineage:
            return False

        for found_state in found_states:
            if not found_state in lineage:
                return False
        return True

The problem is history.state is a weakproxy so I add a .__repr__.self__ to make a strong reference. But still sometimes the garbage collector is remoing weak proxies and make the program crash.

Does someone have a better way to do this ?

@Voxanimus Voxanimus added needs-triage Issue has yet to be looked at by a maintainer question Issues that do not require code changes labels May 7, 2024
@rhelmot
Copy link
Member

rhelmot commented May 14, 2024

The state option EFFICIENT_STATE_MERGING does what you want. It used to be named something more explicitly related to state strong references, but it seems to have been renamed at some point...

There's a builtin mechanism for holding on to the lineage of states - a StateHierarchy. You can construct one, then pass it to the construction of a SimulationManager, and it should automatically track the information you need, which you can query with methods on the hierarchy object.

@Voxanimus
Copy link
Author

I find another solution. Since for each state I go through I have an associtaed block I compare address instead of comparing block object. I believe this is working well for my use case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-triage Issue has yet to be looked at by a maintainer question Issues that do not require code changes
Projects
None yet
Development

No branches or pull requests

2 participants