From f54dc4e6cdd8829d3663c31d2dd7b0d2bd460b03 Mon Sep 17 00:00:00 2001 From: nanglo123 Date: Wed, 23 Oct 2024 13:40:06 -0400 Subject: [PATCH 1/2] Make sure that descriptions for concepts are propogated during ingestion and exportation --- mira/modeling/amr/petrinet.py | 10 +++++++--- mira/modeling/amr/stockflow.py | 13 ++++++++----- mira/sources/amr/petrinet.py | 2 ++ mira/sources/amr/stockflow.py | 2 +- 4 files changed, 18 insertions(+), 9 deletions(-) diff --git a/mira/modeling/amr/petrinet.py b/mira/modeling/amr/petrinet.py index 7dc93e7f9..617ef6acb 100644 --- a/mira/modeling/amr/petrinet.py +++ b/mira/modeling/amr/petrinet.py @@ -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, @@ -69,14 +70,17 @@ 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), diff --git a/mira/modeling/amr/stockflow.py b/mira/modeling/amr/stockflow.py index 3faa4a5ad..1b23f14ab 100644 --- a/mira/modeling/amr/stockflow.py +++ b/mira/modeling/amr/stockflow.py @@ -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), diff --git a/mira/sources/amr/petrinet.py b/mira/sources/amr/petrinet.py index 8e9c670f2..4fe03b32b 100644 --- a/mira/sources/amr/petrinet.py +++ b/mira/sources/amr/petrinet.py @@ -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', {}) @@ -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) diff --git a/mira/sources/amr/stockflow.py b/mira/sources/amr/stockflow.py index fecac706f..692c144cb 100644 --- a/mira/sources/amr/stockflow.py +++ b/mira/sources/amr/stockflow.py @@ -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 From 997d55c10587ae2b1d94677d37e86ddd3503efa1 Mon Sep 17 00:00:00 2001 From: nanglo123 Date: Wed, 23 Oct 2024 14:07:09 -0400 Subject: [PATCH 2/2] Add description attribute to State class for petrinet amr, remove trailing comma --- mira/modeling/amr/petrinet.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mira/modeling/amr/petrinet.py b/mira/modeling/amr/petrinet.py index 617ef6acb..a0ebe11f0 100644 --- a/mira/modeling/amr/petrinet.py +++ b/mira/modeling/amr/petrinet.py @@ -79,8 +79,7 @@ def __init__(self, model: Model): 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), @@ -408,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