Skip to content

Commit

Permalink
Merge pull request #178 from indralab/shared-representation-export-im…
Browse files Browse the repository at this point in the history
…provements

Update metadata for shared representations
  • Loading branch information
bgyori authored Jun 21, 2023
2 parents 3144326 + f577a06 commit 7d94ca2
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 16 deletions.
17 changes: 2 additions & 15 deletions mira/modeling/askenet/petrinet.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from mira.metamodel import expression_to_mathml

from .. import Model
from .utils import add_metadata_annotations

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -189,21 +190,7 @@ def __init__(self, model: Model):
}
self.parameters.append(param_dict)

# There are two ways we can do this. First is to add
# the metadata directly into this element. Second is to
# have another grouping element in the middle, in case there
# are a lot of other parts that live in this element. The
# other thing we need to consider is should we put some of
# these parts in the base_schema, such as license, authors,
# references, time scale, and model types. Some others such
# as pathogens, diseases, hosts, locations, start time,
# and end time can be optional
for k, v in model.template_model.annotations.dict().items():
if k in ["name", "description"]:
# name and description already have a privileged place
# in the petrinet schema so don't get added again
continue
self.metadata[k] = v
add_metadata_annotations(self.metadata, model)

def to_json(self, name=None, description=None, model_version=None):
"""Return a JSON dict structure of the Petri net model."""
Expand Down
7 changes: 6 additions & 1 deletion mira/modeling/askenet/regnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from mira.metamodel import *

from .. import Model, is_production, is_degradation
from .utils import add_metadata_annotations

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -43,6 +44,7 @@ def __init__(self, model: Model):
model.template_model.annotations.name else "Model"
self.model_description = model.template_model.annotations.description \
if model.template_model.annotations.description else self.model_name
self.metadata = {}
vmap = {}
for key, var in model.variables.items():
# Use the variable's concept name if possible but fall back
Expand Down Expand Up @@ -146,6 +148,8 @@ def __init__(self, model: Model):
}
self.parameters.append(param_dict)

add_metadata_annotations(self.metadata, model)

def to_json(self, name=None, description=None, model_version=None):
"""Return a JSON dict structure of the Petri net model."""
return {
Expand All @@ -158,7 +162,8 @@ def to_json(self, name=None, description=None, model_version=None):
'vertices': self.states,
'edges': self.transitions,
'parameters': self.parameters,
}
},
'metadata': self.metadata,
}

def to_pydantic(self, name=None, description=None, model_version=None) -> "ModelSpecification":
Expand Down
10 changes: 10 additions & 0 deletions mira/modeling/askenet/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
def add_metadata_annotations(metadata, model):
annotations_subset = {
k: v
for k, v in model.template_model.annotations.dict().items()
if k not in ["name", "description"]
# name and description already have a privileged place
# in the petrinet schema so don't get added again
}
if annotations_subset:
metadata['annotations'] = annotations_subset

0 comments on commit 7d94ca2

Please sign in to comment.