-
Notifications
You must be signed in to change notification settings - Fork 7
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
Multi-level modeling support from AMRs #614
Comments
Code to sample from parameter distributions should probably go here:
|
Hi @SamWitty I have a question about how to sample from a In the pyciemss/pyciemss/mira_integration/compiled_dynamics.py Lines 83 to 110 in e48ff2f
In particular, on line 99, I pass the values of the parameters that have already been compiled to Pyro as free symbols that are used to parse the sympy expressions:
However, to my surprise, the pyciemss/compiled_dynamics.py:26:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
../../../../.pyenv/versions/miniconda3-3.11-24.1.2-0/envs/pyciemss/lib/python3.12/functools.py:909: in wrapper
return dispatch(args[0].__class__)(*args, **kw)
pyciemss/mira_integration/compiled_dynamics.py:99: in _compile_param_values_mira
param_value = mira_distribution_to_pyro(param_dist, free_symbols=values)
pyciemss/mira_integration/distributions.py:419: in mira_distribution_to_pyro
k: safe_sympytorch_parse_expr(v, local_dict=free_symbols)
pyciemss/mira_integration/distributions.py:53: in safe_sympytorch_parse_expr
return sympytorch.SymPyModule(expressions=[expr.args[0]])(**local_dict).squeeze()
../../../../.pyenv/versions/miniconda3-3.11-24.1.2-0/envs/pyciemss/lib/python3.12/site-packages/torch/nn/modules/module.py:1511: in _wrapped_call_impl
return self._call_impl(*args, **kwargs)
../../../../.pyenv/versions/miniconda3-3.11-24.1.2-0/envs/pyciemss/lib/python3.12/site-packages/torch/nn/modules/module.py:1520: in _call_impl
return forward_call(*args, **kwargs)
../../../../.pyenv/versions/miniconda3-3.11-24.1.2-0/envs/pyciemss/lib/python3.12/site-packages/sympytorch/sympy_module.py:265: in forward
out = torch.broadcast_tensors(*out)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
tensors = (PyroSample(prior=Beta()),)
def broadcast_tensors(*tensors):
r"""broadcast_tensors(*tensors) -> List of Tensors
Broadcasts the given tensors according to :ref:`broadcasting-semantics`.
Args:
*tensors: any number of tensors of the same type
.. warning::
More than one element of a broadcasted tensor may refer to a single
memory location. As a result, in-place operations (especially ones that
are vectorized) may result in incorrect behavior. If you need to write
to the tensors, please clone them first.
Example::
>>> x = torch.arange(3).view(1, 3)
>>> y = torch.arange(2).view(2, 1)
>>> a, b = torch.broadcast_tensors(x, y)
>>> a.size()
torch.Size([2, 3])
>>> a
tensor([[0, 1, 2],
[0, 1, 2]])
"""
# This wrapper exists to support variadic args.
if has_torch_function(tensors):
return handle_torch_function(broadcast_tensors, tensors, *tensors)
> return _VF.broadcast_tensors(tensors) # type: ignore[attr-defined]
E TypeError: expected Tensor as element 0 in argument 0, but got PyroSample The reason for this is described in the Pyro documentation: https://docs.pyro.ai/en/stable/nn.html#pyro.nn.module.PyroSample assert isinstance(my_module, PyroModule)
my_module.x = PyroSample(Normal(0, 1)) # independent
my_module.y = PyroSample(lambda self: Normal(self.x, 1)) # dependent Note that pyciemss/pyciemss/mira_integration/compiled_dynamics.py Lines 103 to 104 in e48ff2f
If the beta_mean = Parameter(name='beta_mean',
distribution=Distribution(type="Beta1",
parameters={'alpha': sympy.Integer(10)*sympy.Symbol("gamma_mean"),
'beta': sympy.Integer(10)}))
gamma_mean = Parameter(name='gamma_mean',
distribution=Distribution(type="InverseGamma1",
parameters={'alpha': sympy.Integer(10),
'beta': sympy.Integer(10)})) The unevaluated Here are some options:
It seems that I would need to perform options 1-3 on Any advice would be appreciated. |
The current issue is now that there is a git checkout 614-multi-level-modeling-support-from-amrs
pytest tests/test_compiled_dynamics.py -k hierarchical results in: ======================================================================================= FAILURES ========================================================================================
______________________________________________________ test_hierarchical_compiled_dynamics[40.0-0.0-cyclic_model0-acyclic_model0] _______________________________________________________
acyclic_model = <tests.fixtures.ModelFixture object at 0x324891250>, cyclic_model = <tests.fixtures.ModelFixture object at 0x324a921e0>, start_time = 0.0, end_time = 40.0
@pytest.mark.parametrize("acyclic_model", ACYCLIC_MODELS)
@pytest.mark.parametrize("cyclic_model", CYCLIC_MODELS)
@pytest.mark.parametrize("start_time", START_TIMES)
@pytest.mark.parametrize("end_time", END_TIMES)
def test_hierarchical_compiled_dynamics(
acyclic_model, cyclic_model, start_time, end_time
):
"""
Test the loading and dependency analysis of hierarchical compiled dynamics models.
This test verifies the following:
- An acyclic MIRA model can be loaded from a URL and is of type TemplateModel.
- The dependencies of the acyclic MIRA model are sorted as expected.
- Attempting to sort dependencies for a cyclic MIRA model raises a NetworkXUnfeasible exception.
- A CompiledDynamics model can be loaded from an acyclic URL and is of the correct type.
- The prior and posterior dependencies of the CompiledDynamics model match the expected structure
when given the specified start and end times.
"""
acyclic_mira_model = model_from_url(acyclic_model.url)
assert isinstance(acyclic_mira_model, mira.metamodel.TemplateModel)
#assert sort_mira_dependencies(acyclic_mira_model) == acyclic_model.important_parameter
with pytest.raises(nx.NetworkXUnfeasible):
cyclic_mira_model = model_from_url(cyclic_model.url)
print(cyclic_model.url)
sort_mira_dependencies(cyclic_mira_model)
> model = CompiledDynamics.load(acyclic_model.url)
tests/test_compiled_dynamics.py:109:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
../../../../.pyenv/versions/miniconda3-3.11-24.1.2-0/envs/pyciemss/lib/python3.12/functools.py:946: in _method
return method.__get__(obj, cls)(*args, **kwargs)
pyciemss/compiled_dynamics.py:170: in _load_from_url_or_path
return cls.load(model)
../../../../.pyenv/versions/miniconda3-3.11-24.1.2-0/envs/pyciemss/lib/python3.12/functools.py:946: in _method
return method.__get__(obj, cls)(*args, **kwargs)
pyciemss/compiled_dynamics.py:180: in _load_from_template_model
return cls.load(mira.modeling.Model(template))
../../../../.pyenv/versions/miniconda3-3.11-24.1.2-0/envs/pyciemss/lib/python3.12/functools.py:946: in _method
return method.__get__(obj, cls)(*args, **kwargs)
pyciemss/compiled_dynamics.py:185: in _load_from_mira_model
return cls(src)
pyciemss/compiled_dynamics.py:66: in __init__
self.instantiate_parameters()
../../../../.pyenv/versions/miniconda3-3.11-24.1.2-0/envs/pyciemss/lib/python3.12/site-packages/pyro/nn/module.py:829: in cached_fn
return fn(self, *args, **kwargs)
pyciemss/compiled_dynamics.py:110: in instantiate_parameters
param_val = getattr(self, f"persistent_{param_name}")
../../../../.pyenv/versions/miniconda3-3.11-24.1.2-0/envs/pyciemss/lib/python3.12/site-packages/pyro/nn/module.py:607: in __getattr__
prior = prior(self)
pyciemss/mira_integration/compiled_dynamics.py:140: in param_value
k: getattr(model, f"persistent_{k}")
../../../../.pyenv/versions/miniconda3-3.11-24.1.2-0/envs/pyciemss/lib/python3.12/site-packages/pyro/nn/module.py:607: in __getattr__
prior = prior(self)
E RecursionError: maximum recursion depth exceeded
!!! Recursion detected (same locals & position)
--------------------------------------------------------------------------------- Captured stdout call ----------------------------------------------------------------------------------
https://raw.githubusercontent.com/DARPA-ASKEM/simulation-integration/main/data/models/beta_mean_cycle_sir_model.json
______________________________________________________ test_hierarchical_compiled_dynamics[40.0-0.0-cyclic_model0-acyclic_model1] _______________________________________________________
acyclic_model = <tests.fixtures.ModelFixture object at 0x3248b0500>, cyclic_model = <tests.fixtures.ModelFixture object at 0x324a921e0>, start_time = 0.0, end_time = 40.0
@pytest.mark.parametrize("acyclic_model", ACYCLIC_MODELS)
@pytest.mark.parametrize("cyclic_model", CYCLIC_MODELS)
@pytest.mark.parametrize("start_time", START_TIMES)
@pytest.mark.parametrize("end_time", END_TIMES)
def test_hierarchical_compiled_dynamics(
acyclic_model, cyclic_model, start_time, end_time
):
"""
Test the loading and dependency analysis of hierarchical compiled dynamics models.
This test verifies the following:
- An acyclic MIRA model can be loaded from a URL and is of type TemplateModel.
- The dependencies of the acyclic MIRA model are sorted as expected.
- Attempting to sort dependencies for a cyclic MIRA model raises a NetworkXUnfeasible exception.
- A CompiledDynamics model can be loaded from an acyclic URL and is of the correct type.
- The prior and posterior dependencies of the CompiledDynamics model match the expected structure
when given the specified start and end times.
"""
acyclic_mira_model = model_from_url(acyclic_model.url)
assert isinstance(acyclic_mira_model, mira.metamodel.TemplateModel)
#assert sort_mira_dependencies(acyclic_mira_model) == acyclic_model.important_parameter
with pytest.raises(nx.NetworkXUnfeasible):
cyclic_mira_model = model_from_url(cyclic_model.url)
print(cyclic_model.url)
sort_mira_dependencies(cyclic_mira_model)
> model = CompiledDynamics.load(acyclic_model.url)
tests/test_compiled_dynamics.py:109:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
../../../../.pyenv/versions/miniconda3-3.11-24.1.2-0/envs/pyciemss/lib/python3.12/functools.py:946: in _method
return method.__get__(obj, cls)(*args, **kwargs)
pyciemss/compiled_dynamics.py:170: in _load_from_url_or_path
return cls.load(model)
../../../../.pyenv/versions/miniconda3-3.11-24.1.2-0/envs/pyciemss/lib/python3.12/functools.py:946: in _method
return method.__get__(obj, cls)(*args, **kwargs)
pyciemss/compiled_dynamics.py:180: in _load_from_template_model
return cls.load(mira.modeling.Model(template))
../../../../.pyenv/versions/miniconda3-3.11-24.1.2-0/envs/pyciemss/lib/python3.12/functools.py:946: in _method
return method.__get__(obj, cls)(*args, **kwargs)
pyciemss/compiled_dynamics.py:185: in _load_from_mira_model
return cls(src)
pyciemss/compiled_dynamics.py:66: in __init__
self.instantiate_parameters()
../../../../.pyenv/versions/miniconda3-3.11-24.1.2-0/envs/pyciemss/lib/python3.12/site-packages/pyro/nn/module.py:829: in cached_fn
return fn(self, *args, **kwargs)
pyciemss/compiled_dynamics.py:110: in instantiate_parameters
param_val = getattr(self, f"persistent_{param_name}")
../../../../.pyenv/versions/miniconda3-3.11-24.1.2-0/envs/pyciemss/lib/python3.12/site-packages/pyro/nn/module.py:607: in __getattr__
prior = prior(self)
pyciemss/mira_integration/compiled_dynamics.py:140: in param_value
k: getattr(model, f"persistent_{k}")
../../../../.pyenv/versions/miniconda3-3.11-24.1.2-0/envs/pyciemss/lib/python3.12/site-packages/pyro/nn/module.py:607: in __getattr__
prior = prior(self)
E RecursionError: maximum recursion depth exceeded
!!! Recursion detected (same locals & position)
--------------------------------------------------------------------------------- Captured stdout call ----------------------------------------------------------------------------------
https://raw.githubusercontent.com/DARPA-ASKEM/simulation-integration/main/data/models/beta_mean_cycle_sir_model.json
______________________________________________________ test_hierarchical_compiled_dynamics[40.0-0.0-cyclic_model1-acyclic_model0] _______________________________________________________
acyclic_model = <tests.fixtures.ModelFixture object at 0x324891250>, cyclic_model = <tests.fixtures.ModelFixture object at 0x324a92420>, start_time = 0.0, end_time = 40.0
@pytest.mark.parametrize("acyclic_model", ACYCLIC_MODELS)
@pytest.mark.parametrize("cyclic_model", CYCLIC_MODELS)
@pytest.mark.parametrize("start_time", START_TIMES)
@pytest.mark.parametrize("end_time", END_TIMES)
def test_hierarchical_compiled_dynamics(
acyclic_model, cyclic_model, start_time, end_time
):
"""
Test the loading and dependency analysis of hierarchical compiled dynamics models.
This test verifies the following:
- An acyclic MIRA model can be loaded from a URL and is of type TemplateModel.
- The dependencies of the acyclic MIRA model are sorted as expected.
- Attempting to sort dependencies for a cyclic MIRA model raises a NetworkXUnfeasible exception.
- A CompiledDynamics model can be loaded from an acyclic URL and is of the correct type.
- The prior and posterior dependencies of the CompiledDynamics model match the expected structure
when given the specified start and end times.
"""
acyclic_mira_model = model_from_url(acyclic_model.url)
assert isinstance(acyclic_mira_model, mira.metamodel.TemplateModel)
#assert sort_mira_dependencies(acyclic_mira_model) == acyclic_model.important_parameter
with pytest.raises(nx.NetworkXUnfeasible):
cyclic_mira_model = model_from_url(cyclic_model.url)
print(cyclic_model.url)
sort_mira_dependencies(cyclic_mira_model)
> model = CompiledDynamics.load(acyclic_model.url)
tests/test_compiled_dynamics.py:109:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
../../../../.pyenv/versions/miniconda3-3.11-24.1.2-0/envs/pyciemss/lib/python3.12/functools.py:946: in _method
return method.__get__(obj, cls)(*args, **kwargs)
pyciemss/compiled_dynamics.py:170: in _load_from_url_or_path
return cls.load(model)
../../../../.pyenv/versions/miniconda3-3.11-24.1.2-0/envs/pyciemss/lib/python3.12/functools.py:946: in _method
return method.__get__(obj, cls)(*args, **kwargs)
pyciemss/compiled_dynamics.py:180: in _load_from_template_model
return cls.load(mira.modeling.Model(template))
../../../../.pyenv/versions/miniconda3-3.11-24.1.2-0/envs/pyciemss/lib/python3.12/functools.py:946: in _method
return method.__get__(obj, cls)(*args, **kwargs)
pyciemss/compiled_dynamics.py:185: in _load_from_mira_model
return cls(src)
pyciemss/compiled_dynamics.py:66: in __init__
self.instantiate_parameters()
../../../../.pyenv/versions/miniconda3-3.11-24.1.2-0/envs/pyciemss/lib/python3.12/site-packages/pyro/nn/module.py:829: in cached_fn
return fn(self, *args, **kwargs)
pyciemss/compiled_dynamics.py:110: in instantiate_parameters
param_val = getattr(self, f"persistent_{param_name}")
../../../../.pyenv/versions/miniconda3-3.11-24.1.2-0/envs/pyciemss/lib/python3.12/site-packages/pyro/nn/module.py:607: in __getattr__
prior = prior(self)
pyciemss/mira_integration/compiled_dynamics.py:140: in param_value
k: getattr(model, f"persistent_{k}")
../../../../.pyenv/versions/miniconda3-3.11-24.1.2-0/envs/pyciemss/lib/python3.12/site-packages/pyro/nn/module.py:607: in __getattr__
prior = prior(self)
E RecursionError: maximum recursion depth exceeded
!!! Recursion detected (same locals & position)
--------------------------------------------------------------------------------- Captured stdout call ----------------------------------------------------------------------------------
https://raw.githubusercontent.com/DARPA-ASKEM/simulation-integration/main/data/models/beta_mean_gamma_cycle_sir_model.json
______________________________________________________ test_hierarchical_compiled_dynamics[40.0-0.0-cyclic_model1-acyclic_model1] _______________________________________________________
acyclic_model = <tests.fixtures.ModelFixture object at 0x3248b0500>, cyclic_model = <tests.fixtures.ModelFixture object at 0x324a92420>, start_time = 0.0, end_time = 40.0
@pytest.mark.parametrize("acyclic_model", ACYCLIC_MODELS)
@pytest.mark.parametrize("cyclic_model", CYCLIC_MODELS)
@pytest.mark.parametrize("start_time", START_TIMES)
@pytest.mark.parametrize("end_time", END_TIMES)
def test_hierarchical_compiled_dynamics(
acyclic_model, cyclic_model, start_time, end_time
):
"""
Test the loading and dependency analysis of hierarchical compiled dynamics models.
This test verifies the following:
- An acyclic MIRA model can be loaded from a URL and is of type TemplateModel.
- The dependencies of the acyclic MIRA model are sorted as expected.
- Attempting to sort dependencies for a cyclic MIRA model raises a NetworkXUnfeasible exception.
- A CompiledDynamics model can be loaded from an acyclic URL and is of the correct type.
- The prior and posterior dependencies of the CompiledDynamics model match the expected structure
when given the specified start and end times.
"""
acyclic_mira_model = model_from_url(acyclic_model.url)
assert isinstance(acyclic_mira_model, mira.metamodel.TemplateModel)
#assert sort_mira_dependencies(acyclic_mira_model) == acyclic_model.important_parameter
with pytest.raises(nx.NetworkXUnfeasible):
cyclic_mira_model = model_from_url(cyclic_model.url)
print(cyclic_model.url)
sort_mira_dependencies(cyclic_mira_model)
> model = CompiledDynamics.load(acyclic_model.url)
tests/test_compiled_dynamics.py:109:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
../../../../.pyenv/versions/miniconda3-3.11-24.1.2-0/envs/pyciemss/lib/python3.12/functools.py:946: in _method
return method.__get__(obj, cls)(*args, **kwargs)
pyciemss/compiled_dynamics.py:170: in _load_from_url_or_path
return cls.load(model)
../../../../.pyenv/versions/miniconda3-3.11-24.1.2-0/envs/pyciemss/lib/python3.12/functools.py:946: in _method
return method.__get__(obj, cls)(*args, **kwargs)
pyciemss/compiled_dynamics.py:180: in _load_from_template_model
return cls.load(mira.modeling.Model(template))
../../../../.pyenv/versions/miniconda3-3.11-24.1.2-0/envs/pyciemss/lib/python3.12/functools.py:946: in _method
return method.__get__(obj, cls)(*args, **kwargs)
pyciemss/compiled_dynamics.py:185: in _load_from_mira_model
return cls(src)
pyciemss/compiled_dynamics.py:66: in __init__
self.instantiate_parameters()
../../../../.pyenv/versions/miniconda3-3.11-24.1.2-0/envs/pyciemss/lib/python3.12/site-packages/pyro/nn/module.py:829: in cached_fn
return fn(self, *args, **kwargs)
pyciemss/compiled_dynamics.py:110: in instantiate_parameters
param_val = getattr(self, f"persistent_{param_name}")
../../../../.pyenv/versions/miniconda3-3.11-24.1.2-0/envs/pyciemss/lib/python3.12/site-packages/pyro/nn/module.py:607: in __getattr__
prior = prior(self)
pyciemss/mira_integration/compiled_dynamics.py:140: in param_value
k: getattr(model, f"persistent_{k}")
../../../../.pyenv/versions/miniconda3-3.11-24.1.2-0/envs/pyciemss/lib/python3.12/site-packages/pyro/nn/module.py:607: in __getattr__
prior = prior(self)
E RecursionError: maximum recursion depth exceeded
!!! Recursion detected (same locals & position)
--------------------------------------------------------------------------------- Captured stdout call ----------------------------------------------------------------------------------
https://raw.githubusercontent.com/DARPA-ASKEM/simulation-integration/main/data/models/beta_mean_gamma_cycle_sir_model.json
______________________________________________________ test_hierarchical_compiled_dynamics[40.0-0.0-cyclic_model2-acyclic_model0] _______________________________________________________
acyclic_model = <tests.fixtures.ModelFixture object at 0x324891250>, cyclic_model = <tests.fixtures.ModelFixture object at 0x324a92390>, start_time = 0.0, end_time = 40.0
@pytest.mark.parametrize("acyclic_model", ACYCLIC_MODELS)
@pytest.mark.parametrize("cyclic_model", CYCLIC_MODELS)
@pytest.mark.parametrize("start_time", START_TIMES)
@pytest.mark.parametrize("end_time", END_TIMES)
def test_hierarchical_compiled_dynamics(
acyclic_model, cyclic_model, start_time, end_time
):
"""
Test the loading and dependency analysis of hierarchical compiled dynamics models.
This test verifies the following:
- An acyclic MIRA model can be loaded from a URL and is of type TemplateModel.
- The dependencies of the acyclic MIRA model are sorted as expected.
- Attempting to sort dependencies for a cyclic MIRA model raises a NetworkXUnfeasible exception.
- A CompiledDynamics model can be loaded from an acyclic URL and is of the correct type.
- The prior and posterior dependencies of the CompiledDynamics model match the expected structure
when given the specified start and end times.
"""
acyclic_mira_model = model_from_url(acyclic_model.url)
assert isinstance(acyclic_mira_model, mira.metamodel.TemplateModel)
#assert sort_mira_dependencies(acyclic_mira_model) == acyclic_model.important_parameter
with pytest.raises(nx.NetworkXUnfeasible):
cyclic_mira_model = model_from_url(cyclic_model.url)
print(cyclic_model.url)
sort_mira_dependencies(cyclic_mira_model)
> model = CompiledDynamics.load(acyclic_model.url)
tests/test_compiled_dynamics.py:109:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
../../../../.pyenv/versions/miniconda3-3.11-24.1.2-0/envs/pyciemss/lib/python3.12/functools.py:946: in _method
return method.__get__(obj, cls)(*args, **kwargs)
pyciemss/compiled_dynamics.py:170: in _load_from_url_or_path
return cls.load(model)
../../../../.pyenv/versions/miniconda3-3.11-24.1.2-0/envs/pyciemss/lib/python3.12/functools.py:946: in _method
return method.__get__(obj, cls)(*args, **kwargs)
pyciemss/compiled_dynamics.py:180: in _load_from_template_model
return cls.load(mira.modeling.Model(template))
../../../../.pyenv/versions/miniconda3-3.11-24.1.2-0/envs/pyciemss/lib/python3.12/functools.py:946: in _method
return method.__get__(obj, cls)(*args, **kwargs)
pyciemss/compiled_dynamics.py:185: in _load_from_mira_model
return cls(src)
pyciemss/compiled_dynamics.py:66: in __init__
self.instantiate_parameters()
../../../../.pyenv/versions/miniconda3-3.11-24.1.2-0/envs/pyciemss/lib/python3.12/site-packages/pyro/nn/module.py:829: in cached_fn
return fn(self, *args, **kwargs)
pyciemss/compiled_dynamics.py:110: in instantiate_parameters
param_val = getattr(self, f"persistent_{param_name}")
../../../../.pyenv/versions/miniconda3-3.11-24.1.2-0/envs/pyciemss/lib/python3.12/site-packages/pyro/nn/module.py:607: in __getattr__
prior = prior(self)
pyciemss/mira_integration/compiled_dynamics.py:140: in param_value
k: getattr(model, f"persistent_{k}")
../../../../.pyenv/versions/miniconda3-3.11-24.1.2-0/envs/pyciemss/lib/python3.12/site-packages/pyro/nn/module.py:607: in __getattr__
prior = prior(self)
E RecursionError: maximum recursion depth exceeded
!!! Recursion detected (same locals & position)
--------------------------------------------------------------------------------- Captured stdout call ----------------------------------------------------------------------------------
https://raw.githubusercontent.com/DARPA-ASKEM/simulation-integration/main/data/models/gamma_mean_beta_mean_cycle_sir_model.json
______________________________________________________ test_hierarchical_compiled_dynamics[40.0-0.0-cyclic_model2-acyclic_model1] _______________________________________________________
acyclic_model = <tests.fixtures.ModelFixture object at 0x3248b0500>, cyclic_model = <tests.fixtures.ModelFixture object at 0x324a92390>, start_time = 0.0, end_time = 40.0
@pytest.mark.parametrize("acyclic_model", ACYCLIC_MODELS)
@pytest.mark.parametrize("cyclic_model", CYCLIC_MODELS)
@pytest.mark.parametrize("start_time", START_TIMES)
@pytest.mark.parametrize("end_time", END_TIMES)
def test_hierarchical_compiled_dynamics(
acyclic_model, cyclic_model, start_time, end_time
):
"""
Test the loading and dependency analysis of hierarchical compiled dynamics models.
This test verifies the following:
- An acyclic MIRA model can be loaded from a URL and is of type TemplateModel.
- The dependencies of the acyclic MIRA model are sorted as expected.
- Attempting to sort dependencies for a cyclic MIRA model raises a NetworkXUnfeasible exception.
- A CompiledDynamics model can be loaded from an acyclic URL and is of the correct type.
- The prior and posterior dependencies of the CompiledDynamics model match the expected structure
when given the specified start and end times.
"""
acyclic_mira_model = model_from_url(acyclic_model.url)
assert isinstance(acyclic_mira_model, mira.metamodel.TemplateModel)
#assert sort_mira_dependencies(acyclic_mira_model) == acyclic_model.important_parameter
with pytest.raises(nx.NetworkXUnfeasible):
cyclic_mira_model = model_from_url(cyclic_model.url)
print(cyclic_model.url)
sort_mira_dependencies(cyclic_mira_model)
> model = CompiledDynamics.load(acyclic_model.url)
tests/test_compiled_dynamics.py:109:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
../../../../.pyenv/versions/miniconda3-3.11-24.1.2-0/envs/pyciemss/lib/python3.12/functools.py:946: in _method
return method.__get__(obj, cls)(*args, **kwargs)
pyciemss/compiled_dynamics.py:170: in _load_from_url_or_path
return cls.load(model)
../../../../.pyenv/versions/miniconda3-3.11-24.1.2-0/envs/pyciemss/lib/python3.12/functools.py:946: in _method
return method.__get__(obj, cls)(*args, **kwargs)
pyciemss/compiled_dynamics.py:180: in _load_from_template_model
return cls.load(mira.modeling.Model(template))
../../../../.pyenv/versions/miniconda3-3.11-24.1.2-0/envs/pyciemss/lib/python3.12/functools.py:946: in _method
return method.__get__(obj, cls)(*args, **kwargs)
pyciemss/compiled_dynamics.py:185: in _load_from_mira_model
return cls(src)
pyciemss/compiled_dynamics.py:66: in __init__
self.instantiate_parameters()
../../../../.pyenv/versions/miniconda3-3.11-24.1.2-0/envs/pyciemss/lib/python3.12/site-packages/pyro/nn/module.py:829: in cached_fn
return fn(self, *args, **kwargs)
pyciemss/compiled_dynamics.py:110: in instantiate_parameters
param_val = getattr(self, f"persistent_{param_name}")
../../../../.pyenv/versions/miniconda3-3.11-24.1.2-0/envs/pyciemss/lib/python3.12/site-packages/pyro/nn/module.py:607: in __getattr__
prior = prior(self)
pyciemss/mira_integration/compiled_dynamics.py:140: in param_value
k: getattr(model, f"persistent_{k}")
../../../../.pyenv/versions/miniconda3-3.11-24.1.2-0/envs/pyciemss/lib/python3.12/site-packages/pyro/nn/module.py:607: in __getattr__
prior = prior(self)
E RecursionError: maximum recursion depth exceeded
!!! Recursion detected (same locals & position)
--------------------------------------------------------------------------------- Captured stdout call ----------------------------------------------------------------------------------
https://raw.githubusercontent.com/DARPA-ASKEM/simulation-integration/main/data/models/gamma_mean_beta_mean_cycle_sir_model.json
================================================================================ short test summary info ================================================================================
FAILED tests/test_compiled_dynamics.py::test_hierarchical_compiled_dynamics[40.0-0.0-cyclic_model0-acyclic_model0] - RecursionError: maximum recursion depth exceeded
FAILED tests/test_compiled_dynamics.py::test_hierarchical_compiled_dynamics[40.0-0.0-cyclic_model0-acyclic_model1] - RecursionError: maximum recursion depth exceeded
FAILED tests/test_compiled_dynamics.py::test_hierarchical_compiled_dynamics[40.0-0.0-cyclic_model1-acyclic_model0] - RecursionError: maximum recursion depth exceeded
FAILED tests/test_compiled_dynamics.py::test_hierarchical_compiled_dynamics[40.0-0.0-cyclic_model1-acyclic_model1] - RecursionError: maximum recursion depth exceeded
FAILED tests/test_compiled_dynamics.py::test_hierarchical_compiled_dynamics[40.0-0.0-cyclic_model2-acyclic_model0] - RecursionError: maximum recursion depth exceeded
FAILED tests/test_compiled_dynamics.py::test_hierarchical_compiled_dynamics[40.0-0.0-cyclic_model2-acyclic_model1] - RecursionError: maximum recursion depth exceeded
=========================================================================== 6 failed, 33 deselected in 22.28s ======================================================================== |
Ben Gyori has now support for expressions in distribution parameters so we can generate multi-level models. We need to properly sort the expressions so they are evaluated in order.
The text was updated successfully, but these errors were encountered: