Skip to content

Commit

Permalink
Merge pull request #350 from gyorilab/scenarios_202408
Browse files Browse the repository at this point in the history
Add updated notebooks and exports for 2024.08 scenarios
  • Loading branch information
bgyori authored Aug 7, 2024
2 parents 9097182 + 6ea9650 commit 3043c9a
Show file tree
Hide file tree
Showing 24 changed files with 193,013 additions and 4 deletions.
2 changes: 2 additions & 0 deletions mira/metamodel/ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,8 @@ def stratify(
# We now apply the stratum assigned to each controller in this particular
# tuple to the controller
for controller, c_stratum in zip(stratified_controllers, c_strata_tuple):
if controller.name in exclude_concepts:
continue
stratified_template.name += f"_{c_stratum}"
controller.with_context(do_rename=modify_names, inplace=True,
**{key: c_stratum})
Expand Down
2 changes: 1 addition & 1 deletion mira/metamodel/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,4 @@ def sanity_check_tm(tm):
assert symbol.name in all_symbols, f"missing symbol: {symbol.name}"
all_initial_names = {init.concept.name for init in tm.initials.values()}
for concept in all_concept_names:
assert concept in all_initial_names
assert concept in all_initial_names, f"missing initial condition for {concept}"
24 changes: 21 additions & 3 deletions mira/modeling/amr/petrinet.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@

from pydantic import BaseModel, Field

from mira.metamodel import expression_to_mathml, safe_parse_expr, \
TemplateModel
from mira.metamodel import expression_to_mathml, TemplateModel
from mira.sources.amr import sanity_check_amr

from .. import Model
from .utils import add_metadata_annotations
Expand Down Expand Up @@ -228,7 +228,7 @@ def to_json(
: JSON
A JSON dict representing the Petri net model.
"""
return {
json_data = {
'header': {
'name': name or self.model_name,
'schema': SCHEMA_URL,
Expand All @@ -250,6 +250,11 @@ def to_json(
}},
'metadata': self.metadata,
}
try:
sanity_check_amr(json_data)
except Exception as e:
logger.warning("Error in AMR sanity check: %s", str(e))
return json_data

def to_pydantic(self, name=None, description=None, model_version=None) -> "ModelSpecification":
"""Return a Pydantic model representation of the Petri net model.
Expand Down Expand Up @@ -349,6 +354,19 @@ def template_model_to_petrinet_json(tm: TemplateModel):
return AMRPetriNetModel(Model(tm)).to_json()


def template_model_to_petrinet_json_file(tm: TemplateModel, fname):
"""Convert a template model to a PetriNet JSON file.
Parameters
----------
tm :
The template model to convert.
fname : str
The file name to write to.
"""
AMRPetriNetModel(Model(tm)).to_json_file(fname)


class Initial(BaseModel):
target: str
expression: str
Expand Down
459 changes: 459 additions & 0 deletions notebooks/scenarios_2024.08/eval_202301_scenario2.ipynb

Large diffs are not rendered by default.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 3043c9a

Please sign in to comment.