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

Propagate concept descriptions #392

Merged
merged 2 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions mira/modeling/amr/petrinet.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ def __init__(self, model: Model):
# on the key otherwise
vmap[key] = name = var.concept.name or str(key)
display_name = var.concept.display_name or name
description = var.concept.description
# State structure
# {
# 'id': str,
Expand All @@ -69,14 +70,16 @@ def __init__(self, model: Model):
# }
states_dict = {
'id': name,
'name': display_name,
'grounding': {
'name': display_name
}
if description:
states_dict['description'] = description
states_dict['grounding'] = {
'identifiers': {k: v for k, v in
var.concept.identifiers.items()
if k != 'biomodels.species'},
'modifiers': var.concept.context,
},
}
}
if var.concept.units:
states_dict['units'] = {
'expression': str(var.concept.units.expression),
Expand Down Expand Up @@ -404,6 +407,7 @@ class Units(BaseModel):
class State(BaseModel):
id: str
name: Optional[str] = None
description: Optional[str] = None
grounding: Optional[Dict] = None
units: Optional[Units] = None

Expand Down
13 changes: 8 additions & 5 deletions mira/modeling/amr/stockflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,19 @@ def __init__(self, model: Model):
for key, var in model.variables.items():
vmap[key] = name = var.concept.name or str(key)
display_name = var.concept.display_name or name
description = var.concept.description
stocks_dict = {
'id': name,
'name': display_name,
'grounding': {
'name': display_name
}
if description:
stocks_dict['description'] = description
stocks_dict['grounding'] = {
'identifiers': {k: v for k, v in
var.concept.identifiers.items()
if k != 'biomodels.species'},
'modifiers': var.concept.context,
},
}
'modifiers': var.concept.context
}
if var.concept.units:
stocks_dict['units'] = {
'expression': str(var.concept.units.expression),
Expand Down
2 changes: 2 additions & 0 deletions mira/sources/amr/petrinet.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ def state_to_concept(state):
# names
name = state['id']
display_name = state.get('name')
description = state.get("description")
grounding = state.get('grounding', {})
identifiers = grounding.get('identifiers', {})
context = grounding.get('modifiers', {})
Expand All @@ -265,6 +266,7 @@ def state_to_concept(state):
units_obj = Unit(expression=units_expr) if units_expr else None
return Concept(name=name,
display_name=display_name,
description=description,
identifiers=identifiers,
context=context,
units=units_obj)
2 changes: 1 addition & 1 deletion mira/sources/amr/stockflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
https://github.com/DARPA-ASKEM/Model-Representations/tree/main/stockflow.
"""
__all__ = ["template_model_from_amr_json",
"stock_to_concept"]
"stock_to_concept", "model_from_url"]

import sympy
import requests
Expand Down
Loading