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

lambda parameter in SIDARTHE causing problems again #182

Closed
djinnome opened this issue Jun 22, 2023 · 1 comment
Closed

lambda parameter in SIDARTHE causing problems again #182

djinnome opened this issue Jun 22, 2023 · 1 comment

Comments

@djinnome
Copy link

Hi folks,

When I tried to create an ASKEM Model Representation from the SIDARTHE_mira template model, I ran into the following issue:

import requests
import mira
from mira.modeling.askenet.petrinet import AskeNetPetriNetModel
url = 'https://raw.githubusercontent.com/indralab/mira/main/notebooks/evaluation_2023.01/scenario2_sidarthe_mira.json'
res = requests.get(url)
model_json = res.json()
mira_template_model = mira.metamodel.TemplateModel.from_json(model_json)
mira_model = mira.modeling.Model(mira_template_model)
askenet_model = AskeNetPetriNetModel(mira_model)
askenet_mira_template_model = mira.sources.askenet.petrinet.template_model_from_askenet_json(askenet_model.to_json())
ValueError: Error from parse_expr with transformed code: 'Infected *lambda '


The above exception was the direct cause of the following exception:

Traceback (most recent call last):

  File ~/.pyenv/versions/jz-sviivr/lib/python3.10/site-packages/IPython/core/interactiveshell.py:3505 in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)

  Cell In[28], line 10
    askenet_mira_template_model = mira.sources.askenet.petrinet.template_model_from_askenet_json(askenet_model.to_json())

  File ~/.pyenv/versions/jz-sviivr/lib/python3.10/site-packages/mira/sources/askenet/petrinet.py:187 in template_model_from_askenet_json
    templates.extend(transition_to_templates(rate_obj,

  File ~/.pyenv/versions/jz-sviivr/lib/python3.10/site-packages/mira/sources/askenet/petrinet.py:243 in transition_to_templates
    rate_law = sympy.parse_expr(rate_law_expression, local_dict=symbols) \

  File ~/.pyenv/versions/jz-sviivr/lib/python3.10/site-packages/sympy/parsing/sympy_parser.py:1101 in parse_expr
    raise e from ValueError(f"Error from parse_expr with transformed code: {code!r}")

  File ~/.pyenv/versions/jz-sviivr/lib/python3.10/site-packages/sympy/parsing/sympy_parser.py:1092 in parse_expr
    rv = eval_expr(code, local_dict, global_dict)

  File ~/.pyenv/versions/jz-sviivr/lib/python3.10/site-packages/sympy/parsing/sympy_parser.py:907 in eval_expr
    expr = eval(

  File <string>:1
    Infected *lambda
              ^
SyntaxError: invalid syntax
djinnome added a commit to ciemss/pyciemss that referenced this issue Jun 22, 2023
@bgyori
Copy link
Member

bgyori commented Jun 22, 2023

Hi @djinnome, the issue is that this isn't the right function to call when deserializing a MIRA TemplateModel from JSON. The function mira.sources.askenet.petrinet.template_model_from_askenet_json should be used on AskeNet/AMR JSON input, whereas https://raw.githubusercontent.com/indralab/mira/main/notebooks/evaluation_2023.01/scenario2_sidarthe_mira.json is a JSON dump of a MIRA TemplateModel object. For the latter, the from mira.metamodel import model_from_json_file function could be used.

@bgyori bgyori closed this as completed Jun 22, 2023
SamWitty pushed a commit to ciemss/pyciemss that referenced this issue Jun 26, 2023
* Error: gyorilab/mira#182

* Multiple controllers are added together

* still getting pydantic error

* Error: gyorilab/mira#183

* added more .gitignore because of silly things like .idea

* added sidarthe amr

* Still can't parse SIDARTHE model using mira yet

* removed offending lambda to XXlambdaXX in AMR

* SIDARTHE MIRA model and SIDARTHE AMR model produce same outputs

* cleaned up test_askenet to have more understandable variable names

* Confirmed that all of Sabina's models can be converted to ASKEM and loaded into a ScaledBetaNoisePetriNetODESystem without errors.  Next up: try to interpret the sympy rate law

* AMR can have lambda and it will still pass all tests. (Mira template still needs XXlambdaXX)
anirban-chaudhuri added a commit to ciemss/pyciemss that referenced this issue Jul 6, 2023
* Started notebook for examples regarding TA2 issues for model validation (#178)

* Started notebook for examples regarding TA2 issues for model validation

* Started notebook to produce AskeNet Model Representation examples in JSON format. Note: created JSON dictionary successfully; Error creating JSON fileg

* Success for SIAERDH model conversion to AMR

* created AMR for Model2 from custom models (SEIARHD), see JSON file

* added total_population as a parameter

* Deaceased -> Deceased

* Fixed a few more minor errors

* added SIRHD and SEIARHDS models

* added SIRHD and SEIARHDS models

---------

Co-authored-by: Jeremy Zucker <[email protected]>
Co-authored-by: sabinala <[email protected]>
Co-authored-by: Jeremy Zucker <[email protected]>

* remove .idea

* gitignore

* Update SEIARHD_AMR.json

removed git conflicts in favor of local

* Fixing issue in deriv method (#187)

* Error: gyorilab/mira#182

* Multiple controllers are added together

* still getting pydantic error

* Error: gyorilab/mira#183

* added more .gitignore because of silly things like .idea

* added sidarthe amr

* Still can't parse SIDARTHE model using mira yet

* removed offending lambda to XXlambdaXX in AMR

* SIDARTHE MIRA model and SIDARTHE AMR model produce same outputs

* cleaned up test_askenet to have more understandable variable names

* Confirmed that all of Sabina's models can be converted to ASKEM and loaded into a ScaledBetaNoisePetriNetODESystem without errors.  Next up: try to interpret the sympy rate law

* AMR can have lambda and it will still pass all tests. (Mira template still needs XXlambdaXX)

* Changes to interfaces to support data IO for TA4 (#190)

* added data

* added interface_utils

* Added updated demo with data processing

* revised interfaces with AMR

* removed old file

* added test for interfaces demo

* added results

* Add detailed docstrings for TA4 interfaces (#191)

* added detailed docstrings for askem interfaces

* added return description

* indent error

* Removed untested `add_uncertainty` from TA4 interfaces (#192)

* removed add_uncertainty from TA4 interfaces, as they are not thoroughly tested

* fixed test

* Add parameter interventions to TA4 interfaces (#193)

* first pass at adding interventions to interfaces. Incomplete formatting.

* lingering notebook

* adding interventions to outputs

* messy but it works.

* Removed test_samples_intervened_values because it compares timepoint with timepoint_id, which will not work.  Added test_load_and_sample_petri_net to confirm it outputs the correct dataframe under intervention

* adde expected intervened samples

* added load_and_calibrate_and_sample_petri

* Cleaned up demo.ipynb

* Cleaned up demo.ipynb

* cleaned up documentation of assign_interventions_to_timepoints

---------

Co-authored-by: Jeremy Zucker <[email protected]>

* End-to-end integration of ensemble modeling w/ TA4 (#194)

* first pass at ensemble interface for TA4

* processed output of ensemble modeling

* added ensemble calibration interface

* added tests and docstrings

* added timepoints to ensemble output processing

* removed lingering files (#199)

---------

Co-authored-by: ShantMahserejian <[email protected]>
Co-authored-by: Jeremy Zucker <[email protected]>
Co-authored-by: sabinala <[email protected]>
Co-authored-by: Jeremy Zucker <[email protected]>
Co-authored-by: Sam Witty <[email protected]>
marjoleinpnnl pushed a commit to ciemss/pyciemss that referenced this issue Aug 10, 2023
* Error: gyorilab/mira#182

* Multiple controllers are added together

* still getting pydantic error

* Error: gyorilab/mira#183

* added more .gitignore because of silly things like .idea

* added sidarthe amr

* Still can't parse SIDARTHE model using mira yet

* removed offending lambda to XXlambdaXX in AMR

* SIDARTHE MIRA model and SIDARTHE AMR model produce same outputs

* cleaned up test_askenet to have more understandable variable names

* Confirmed that all of Sabina's models can be converted to ASKEM and loaded into a ScaledBetaNoisePetriNetODESystem without errors.  Next up: try to interpret the sympy rate law

* AMR can have lambda and it will still pass all tests. (Mira template still needs XXlambdaXX)
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

No branches or pull requests

2 participants