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

Recursively reason over flow control relationships #302

Merged
merged 15 commits into from
Apr 1, 2024

Conversation

cthoyt
Copy link
Member

@cthoyt cthoyt commented Feb 29, 2024

The goal in this PR is when importing vensim models, to recursively walk through all of the flow relationships to identify for each, what are the stocks involved. This will allow for making more appropriate control structure that for each relationship can properly incorporate controllers based on the stocks referenced in the rate law.

What's solved:

  • Recursively resolving dependencies of flow rates

What's not solved:

  • Identifying which entities in a flow rate is a controller. After more look into the data model of the MDL file, it's not clear to me if this can be inferred purely from the rate laws

# if a state is present in a rate law, and the state isn't an input to the rate
# law, then that state is a controller of the rate law
if (
Copy link
Member Author

Choose a reason for hiding this comment

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

@nanglo123 please resurrect this, and maybe we can add some unit tests that correspond to when this gets used

@nanglo123 nanglo123 force-pushed the recursive-flow-control branch from b96a680 to 923a344 Compare March 27, 2024 14:53
@@ -564,3 +582,69 @@ def with_lookup_to_piecewise(expr_text: str) -> str:
conditions = ",".join(f"({y}, {variable} >= {x})" for x, y in pairs)
sympy_str = f"Piecewise({conditions})"
return sympy_str


def get_identifier_to_expr(pysd_model, name_to_expr_str):
Copy link
Member Author

@cthoyt cthoyt Mar 28, 2024

Choose a reason for hiding this comment

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

@nanglo123 here's the function that resolves the recursive rate laws

@bgyori bgyori marked this pull request as ready for review April 1, 2024 15:17
@nanglo123 nanglo123 force-pushed the recursive-flow-control branch from ccd67c7 to 9343e28 Compare April 1, 2024 15:18
@bgyori bgyori merged commit d7c71bd into main Apr 1, 2024
4 checks passed
@cthoyt cthoyt deleted the recursive-flow-control branch April 2, 2024 07:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants