Skip to content

Switched back to static solver and adopted dependency graphs#30

Merged
wzh1895 merged 9 commits intomainfrom
dev
Jan 20, 2025
Merged

Switched back to static solver and adopted dependency graphs#30
wzh1895 merged 9 commits intomainfrom
dev

Conversation

@wzh1895
Copy link
Copy Markdown
Owner

@wzh1895 wzh1895 commented Jan 20, 2025

Bumping version up to 0.3.0, this commit switches asdm back to a static solver that determines all dependencies before simulation and stores them in two graphs—one for initialization and another for iteration. These graphs specify the order in which variables are calculated, so there is no longer a need to trace dependencies dynamically during runtime via recursion.

The direct reason for returning to a static solver is the challenge of managing how outflows are constrained by the non-negative stocks they draw from. This involves considering the stock’s level, dependencies among stock-flows and flow-flows, and the intended values of all flows before any constraint is applied. A dynamic solver would have to figure all this out continuously at runtime while name_space values are updated, which is exceptionally difficult: it requires evaluating conditional rules involving multiple variables and following a particular calculation order - both of which contradict the nature of a dynamic solver that calculates dependent variables on demand, without a predefined order. Hence, the decision was made to switch back to a static solver.

This reintroduction of a static solver echoes the original solver that computed variables in 2019 (though it was not yet called asdm). The original solver was almost static because it enumerated and calculated flows by recursively tracing their dependencies, the only dynamic aspect was that it did not explicitly order those flows. The SD model itself effectively served as the dependency graph. However, from today’s perspective, while an SD model diagram captures the majority of explicit dependencies, it does not capture certain implicit dependencies - especially those pertaining to non-negative stock constraints. These must be inferred separately and then merged into a more comprehensive dependency graph, which is precisely the approach taken by this commit.

In addition to reviving the static solver, this commit includes a (crude) finite state machine that manages a model’s various states, enabling more structured simulation controls such as pausing, resuming, and modifying equations on the fly. It also replaces print-based logging with Python’s logging module. A test script is also added to compare simulation results of multiple test models against results from Stella using pytest.

Below is a list of changes summarized:

List of Changes

  • Bump version to 0.3.0
  • Switch asdm back to a static solver that sorts dependencies before the simulation (two graphs: initialization and iteration).
  • Resolve dependency ordering to remove the need for dynamic (on-demand) recursion.
  • Manage outflow constraints by incorporating both explicit and implicit dependencies related to non-negative stocks.
  • Introduce a crude finite state machine to handle various model states for pausing, resuming, and live equation changes.
  • Replace print-based logging with Python’s logging module for better logging control.
  • Added test script.

@wzh1895 wzh1895 merged commit 5a70fee into main Jan 20, 2025
wzh1895 added a commit that referenced this pull request Mar 13, 2026
Switched back to static solver and adopted dependency graphs
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.

1 participant