Skip to content

Commit

Permalink
Merge pull request #392 from nanglo123/propogate_concept_descriptions
Browse files Browse the repository at this point in the history
Propagate concept descriptions
  • Loading branch information
bgyori authored Oct 23, 2024
2 parents 545f076 + 997d55c commit f4fe007
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 10 deletions.
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

0 comments on commit f4fe007

Please sign in to comment.