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

AMR no longer loads in new version of mira #378

Closed
djinnome opened this issue Oct 1, 2024 · 1 comment
Closed

AMR no longer loads in new version of mira #378

djinnome opened this issue Oct 1, 2024 · 1 comment

Comments

@djinnome
Copy link
Contributor

djinnome commented Oct 1, 2024

In mira 0.7.0:

git clone https://github.com/gyorilab/mira.git
cd mira
git checkout 0.7.0
pip install -e .
python
>>> from  mira.sources.amr import model_from_url
>>> url = 'https://raw.githubusercontent.com/DARPA-ASKEM/Model-Representations/pde-petri-amrs/petrinet/examples/pde/advection/advection_backward_1_0.01_3.json'
>>> model = model_from_url(url)
>>> model

results in:

TemplateModel(templates=[NaturalDegradation(rate_law=0.01*t, name='r_a_0_0_boundary', display_name=None, type='NaturalDegradation', subject=Concept(name='a_0', display_name='a_0', description=None, identifiers={}, context={}, units=None), provenance=[]), NaturalConversion(rate_law=-a_0*u/dx, name='r_a_0_1_0', display_name=None, type='NaturalConversion', subject=Concept(name='a_1', display_name='a_1', description=None, identifiers={}, context={}, units=None), outcome=Concept(name='a_0', display_name='a_0', description=None, identifiers={}, context={}, units=None), provenance=[]), NaturalConversion(rate_law=-a_1*u/dx, name='r_a_0_2_1', display_name=None, type='NaturalConversion', subject=Concept(name='a_2', display_name='a_2', description=None, identifiers={}, context={}, units=None), outcome=Concept(name='a_1', display_name='a_1', description=None, identifiers={}, context={}, units=None), provenance=[]), NaturalProduction(rate_law=-a_2*u/dx, name='r_a_0_boundary_2', display_name=None, type='NaturalProduction', outcome=Concept(name='a_2', display_name='a_2', description=None, identifiers={}, context={}, units=None), provenance=[])], parameters={'u': Parameter(name='u', display_name=None, description=None, identifiers={}, context={}, units=None, value=1.0, distribution=Distribution(type='StandardUniform1', parameters={'minimum': 0.0, 'maximum': 1.0})), 'dx': Parameter(name='dx', display_name=None, description=None, identifiers={}, context={}, units=None, value=1.0, distribution=Distribution(type='StandardUniform1', parameters={'minimum': 0.0, 'maximum': 1.0}))}, initials={'a_0': Initial(concept=Concept(name='a_0', display_name='a_0', description=None, identifiers={}, context={}, units=None), expression=0.4), 'a_1': Initial(concept=Concept(name='a_1', display_name='a_1', description=None, identifiers={}, context={}, units=None), expression=1.0), 'a_2': Initial(concept=Concept(name='a_2', display_name='a_2', description=None, identifiers={}, context={}, units=None), expression=0.4)}, observables={}, annotations=Annotations(name='Advection Model', description='Advection as Petrinet model created by Dan Bryce and Drisana Iverson (Mosaphir)', license=None, authors=[], references=[], time_scale=None, time_start=None, time_end=None, locations=[], pathogens=[], diseases=[], hosts=[], model_types=[]), time=Time(name='t', units=Unit(expression=day)))

However, when I run the same command in the most recent version of mira (with pydantic2)

git checkout main
pip install -e .
python
>>> from  mira.sources.amr import model_from_url
>>> url = 'https://raw.githubusercontent.com/DARPA-ASKEM/Model-Representations/pde-petri-amrs/petrinet/examples/pde/advection/advection_backward_1_0.01_3.json'
>>> model = model_from_url(url)

I get the following error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/zuck016/Projects/ASKEM/mira/mira/sources/amr/__init__.py", line 27, in model_from_url
    return model_from_json(model_json)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/zuck016/Projects/ASKEM/mira/mira/sources/amr/__init__.py", line 67, in model_from_json
    return petrinet.template_model_from_amr_json(model_json)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/zuck016/Projects/ASKEM/mira/mira/sources/amr/petrinet.py", line 121, in template_model_from_amr_json
    parameter_to_mira(parameter, param_symbols=symbols)
  File "/Users/zuck016/Projects/ASKEM/mira/mira/sources/util.py", line 193, in parameter_to_mira
    safe_parse_expr(param_value)
  File "/Users/zuck016/Projects/ASKEM/mira/mira/metamodel/utils.py", line 38, in safe_parse_expr
    return sympy.parse_expr(get_parseable_expression(s),
                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/zuck016/Projects/ASKEM/mira/mira/metamodel/utils.py", line 16, in get_parseable_expression
    s = s.replace('lambda', 'XXlambdaXX')
        ^^^^^^^^^
AttributeError: 'int' object has no attribute 'replace'
@djinnome djinnome mentioned this issue Oct 1, 2024
@bgyori
Copy link
Member

bgyori commented Oct 4, 2024

Fixed in #379

@bgyori bgyori closed this as completed Oct 4, 2024
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