From aa3188dfe0e554c3b2c11766ae212638339ec8eb Mon Sep 17 00:00:00 2001 From: Daniel Chang Date: Wed, 7 Aug 2024 11:30:43 -0400 Subject: [PATCH] rename parameters in stratify and other MIRA changes (#148) --- .../procedures/python3/replace_ratelaw.py | 9 ++++++--- .../mira_model_edit/procedures/python3/stratify.py | 5 +++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/askem_beaker/contexts/mira_model_edit/procedures/python3/replace_ratelaw.py b/src/askem_beaker/contexts/mira_model_edit/procedures/python3/replace_ratelaw.py index 131fb7e..dd932df 100644 --- a/src/askem_beaker/contexts/mira_model_edit/procedures/python3/replace_ratelaw.py +++ b/src/askem_beaker/contexts/mira_model_edit/procedures/python3/replace_ratelaw.py @@ -1,3 +1,4 @@ +import sympy def replace_rate_law_sympy(model, template_name, new_rate_law): """Replace the rate law of transition. The new rate law passed in will be a sympy.Expr object @@ -8,8 +9,6 @@ def replace_rate_law_sympy(model, template_name, new_rate_law): typically the name of the transition new_rate_law : The new rate law to replace the existing rate law with - local_dict : - A dictionary of local variables to use when parsing. Returns ------- @@ -18,9 +17,13 @@ def replace_rate_law_sympy(model, template_name, new_rate_law): """ assert isinstance(model, TemplateModel) tm = model + local_dict = { key:sympy.Symbol(key) for key, _value in tm.parameters.items() } + for k, v in tm.get_concepts_name_map().items(): + local_dict[k] = sympy.Symbol(k) + for template in tm.templates: if template.name == template_name: - template.set_rate_law(new_rate_law, local_dict=None) + template.set_rate_law(new_rate_law, local_dict=local_dict) return tm model = replace_rate_law_sympy(model, "{{ template_name }}", "{{ new_rate_law }}") diff --git a/src/askem_beaker/contexts/mira_model_edit/procedures/python3/stratify.py b/src/askem_beaker/contexts/mira_model_edit/procedures/python3/stratify.py index d614c01..6236e65 100644 --- a/src/askem_beaker/contexts/mira_model_edit/procedures/python3/stratify.py +++ b/src/askem_beaker/contexts/mira_model_edit/procedures/python3/stratify.py @@ -7,5 +7,6 @@ cartesian_control={{ cartesian_control|default(False) }}, modify_names={{ modify_names|default(True) }}, concepts_to_stratify={{ concepts_to_stratify|default(None) }}, #If none given, will stratify all concepts. - params_to_stratify= {{ params_to_stratify|default(None) }} #If none given, will stratify all parameters. -) \ No newline at end of file + params_to_stratify= {{ params_to_stratify|default(None) }}, #If none given, will stratify all parameters. + param_renaming_uses_strata_names = True +)