From fd75ac69acad006d7801da6e8af6a5ba4b74a394 Mon Sep 17 00:00:00 2001 From: Sam Witty Date: Thu, 2 Nov 2023 13:16:07 -0400 Subject: [PATCH 1/5] add support for regnet now that mira has been fixed --- pyciemss/mira_integration/compiled_dynamics.py | 2 +- setup.cfg | 2 +- tests/fixtures.py | 10 +++++----- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/pyciemss/mira_integration/compiled_dynamics.py b/pyciemss/mira_integration/compiled_dynamics.py index 806c75b1f..f3ee2b0a9 100644 --- a/pyciemss/mira_integration/compiled_dynamics.py +++ b/pyciemss/mira_integration/compiled_dynamics.py @@ -50,7 +50,7 @@ def _compile_initial_state_mira( src: mira.modeling.Model, ) -> Callable[..., Tuple[torch.Tensor]]: symbolic_initials = { - get_name(var): src.template_model.initials[get_name(var)].expression.args[0] + get_name(var): src.variables[get_name(var)].data['expression'].args[0] for var in src.variables.values() } numeric_initial_state_func = sympytorch.SymPyModule( diff --git a/setup.cfg b/setup.cfg index d8c222fe5..25a911f84 100644 --- a/setup.cfg +++ b/setup.cfg @@ -9,7 +9,7 @@ license_files = LICENSE install_requires = jupyter torch >= 1.8.0 - mira @ git+https://github.com/indralab/mira.git@0.2.0 + mira @ git+https://github.com/indralab/mira.git@0.2.1 chirho @ git+https://github.com/BasisResearch/chirho@f3019d4b22f4e49261efbf8da90a30095af2afbc sympytorch torchdiffeq diff --git a/tests/fixtures.py b/tests/fixtures.py index 140f826bb..6edc28f36 100644 --- a/tests/fixtures.py +++ b/tests/fixtures.py @@ -10,19 +10,19 @@ # "https://raw.githubusercontent.com/DARPA-ASKEM/Model-Representations/main/petrinet/examples/flux_typed.json", # "https://raw.githubusercontent.com/DARPA-ASKEM/Model-Representations/main/petrinet/examples/flux_typed_aug.json", # "https://raw.githubusercontent.com/DARPA-ASKEM/Model-Representations/main/petrinet/examples/ont_pop_vax.json", - "https://raw.githubusercontent.com/DARPA-ASKEM/Model-Representations/main/petrinet/examples/sir.json", + # "https://raw.githubusercontent.com/DARPA-ASKEM/Model-Representations/main/petrinet/examples/sir.json", # "https://raw.githubusercontent.com/DARPA-ASKEM/Model-Representations/main/petrinet/examples/sir_flux_span.json", - "https://raw.githubusercontent.com/DARPA-ASKEM/Model-Representations/main/petrinet/examples/sir_typed.json", - "https://raw.githubusercontent.com/DARPA-ASKEM/Model-Representations/main/petrinet/examples/sir_typed_aug.json", + # "https://raw.githubusercontent.com/DARPA-ASKEM/Model-Representations/main/petrinet/examples/sir_typed.json", + # "https://raw.githubusercontent.com/DARPA-ASKEM/Model-Representations/main/petrinet/examples/sir_typed_aug.json", ] REGNET_URLS = [ - # "https://raw.githubusercontent.com/DARPA-ASKEM/Model-Representations/main/regnet/examples/lotka_volterra.json", + "https://raw.githubusercontent.com/DARPA-ASKEM/Model-Representations/main/regnet/examples/lotka_volterra.json", # "https://raw.githubusercontent.com/DARPA-ASKEM/Model-Representations/main/regnet/examples/syntax_edge_cases.json", ] STOCKFLOW_URLS = [ - "https://raw.githubusercontent.com/DARPA-ASKEM/Model-Representations/main/stockflow/examples/sir.json" + # "https://raw.githubusercontent.com/DARPA-ASKEM/Model-Representations/main/stockflow/examples/sir.json" ] MODEL_URLS = PETRI_URLS + REGNET_URLS + STOCKFLOW_URLS From e98b295f98d662cdf1c601170d958be6f6e325e1 Mon Sep 17 00:00:00 2001 From: Sam Witty Date: Thu, 2 Nov 2023 13:18:01 -0400 Subject: [PATCH 2/5] lint --- pyciemss/mira_integration/compiled_dynamics.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyciemss/mira_integration/compiled_dynamics.py b/pyciemss/mira_integration/compiled_dynamics.py index f3ee2b0a9..8f80a6b22 100644 --- a/pyciemss/mira_integration/compiled_dynamics.py +++ b/pyciemss/mira_integration/compiled_dynamics.py @@ -50,7 +50,7 @@ def _compile_initial_state_mira( src: mira.modeling.Model, ) -> Callable[..., Tuple[torch.Tensor]]: symbolic_initials = { - get_name(var): src.variables[get_name(var)].data['expression'].args[0] + get_name(var): src.variables[get_name(var)].data["expression"].args[0] for var in src.variables.values() } numeric_initial_state_func = sympytorch.SymPyModule( From 688315c52d14be60606a150ebafdf257cf905623 Mon Sep 17 00:00:00 2001 From: Sam Witty Date: Thu, 2 Nov 2023 13:20:52 -0400 Subject: [PATCH 3/5] uncomment other mistakenly commented tests --- tests/fixtures.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/fixtures.py b/tests/fixtures.py index 6edc28f36..061101789 100644 --- a/tests/fixtures.py +++ b/tests/fixtures.py @@ -10,10 +10,10 @@ # "https://raw.githubusercontent.com/DARPA-ASKEM/Model-Representations/main/petrinet/examples/flux_typed.json", # "https://raw.githubusercontent.com/DARPA-ASKEM/Model-Representations/main/petrinet/examples/flux_typed_aug.json", # "https://raw.githubusercontent.com/DARPA-ASKEM/Model-Representations/main/petrinet/examples/ont_pop_vax.json", - # "https://raw.githubusercontent.com/DARPA-ASKEM/Model-Representations/main/petrinet/examples/sir.json", + "https://raw.githubusercontent.com/DARPA-ASKEM/Model-Representations/main/petrinet/examples/sir.json", # "https://raw.githubusercontent.com/DARPA-ASKEM/Model-Representations/main/petrinet/examples/sir_flux_span.json", - # "https://raw.githubusercontent.com/DARPA-ASKEM/Model-Representations/main/petrinet/examples/sir_typed.json", - # "https://raw.githubusercontent.com/DARPA-ASKEM/Model-Representations/main/petrinet/examples/sir_typed_aug.json", + "https://raw.githubusercontent.com/DARPA-ASKEM/Model-Representations/main/petrinet/examples/sir_typed.json", + "https://raw.githubusercontent.com/DARPA-ASKEM/Model-Representations/main/petrinet/examples/sir_typed_aug.json", ] REGNET_URLS = [ @@ -22,7 +22,7 @@ ] STOCKFLOW_URLS = [ - # "https://raw.githubusercontent.com/DARPA-ASKEM/Model-Representations/main/stockflow/examples/sir.json" + "https://raw.githubusercontent.com/DARPA-ASKEM/Model-Representations/main/stockflow/examples/sir.json" ] MODEL_URLS = PETRI_URLS + REGNET_URLS + STOCKFLOW_URLS From b1c33c6a24cc287a99a6f058ab35e9b845b9b41a Mon Sep 17 00:00:00 2001 From: Sam Witty Date: Thu, 2 Nov 2023 14:00:28 -0400 Subject: [PATCH 4/5] swap out dict access for explicit iteration --- pyciemss/mira_integration/compiled_dynamics.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyciemss/mira_integration/compiled_dynamics.py b/pyciemss/mira_integration/compiled_dynamics.py index 8f80a6b22..234b5d357 100644 --- a/pyciemss/mira_integration/compiled_dynamics.py +++ b/pyciemss/mira_integration/compiled_dynamics.py @@ -50,7 +50,7 @@ def _compile_initial_state_mira( src: mira.modeling.Model, ) -> Callable[..., Tuple[torch.Tensor]]: symbolic_initials = { - get_name(var): src.variables[get_name(var)].data["expression"].args[0] + get_name(var): var.data["expression"].args[0] for var in src.variables.values() } numeric_initial_state_func = sympytorch.SymPyModule( From 1200408dc5477e14256f9ab102cbf64cd0df43fe Mon Sep 17 00:00:00 2001 From: Sam Witty Date: Thu, 2 Nov 2023 14:01:08 -0400 Subject: [PATCH 5/5] lint --- pyciemss/mira_integration/compiled_dynamics.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pyciemss/mira_integration/compiled_dynamics.py b/pyciemss/mira_integration/compiled_dynamics.py index 234b5d357..31cccc8aa 100644 --- a/pyciemss/mira_integration/compiled_dynamics.py +++ b/pyciemss/mira_integration/compiled_dynamics.py @@ -50,8 +50,7 @@ def _compile_initial_state_mira( src: mira.modeling.Model, ) -> Callable[..., Tuple[torch.Tensor]]: symbolic_initials = { - get_name(var): var.data["expression"].args[0] - for var in src.variables.values() + get_name(var): var.data["expression"].args[0] for var in src.variables.values() } numeric_initial_state_func = sympytorch.SymPyModule( expressions=[symbolic_initials[get_name(var)] for var in src.variables.values()]