Skip to content

Commit

Permalink
Made minor bug fixes in ops.py and init.py and added test that doesnt…
Browse files Browse the repository at this point in the history
… currently pass for replace_initial_id
  • Loading branch information
nanglo123 committed Aug 29, 2023
1 parent 2484668 commit 3db7084
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 8 deletions.
13 changes: 6 additions & 7 deletions mira/modeling/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

class Transition:
def __init__(
self, key, consumed, produced, control, rate, template_type, template: Template,
self, key, consumed, produced, control, rate, template_type, template: Template,
):
self.key = key
self.consumed = consumed
Expand Down Expand Up @@ -65,7 +65,7 @@ def __init__(self, template_model):
self.make_model()

def assemble_variable(
self, concept: Concept, initials: Optional[Mapping[str, Initial]] = None,
self, concept: Concept, initials: Optional[Mapping[str, Initial]] = None,
):
"""Assemble a variable from a concept and optional
dictionary of initial values.
Expand All @@ -92,12 +92,12 @@ def assemble_variable(
if key in self.variables:
return self.variables[key]

# initialize initial_value before assignment in conditional to avoid localUnboundError
initial_value = None
if initials:
for k, v in initials.items():
if v.concept.name == concept.name:
initial_value = v.value
else:
initial_value = None

data = {
'name': concept.name,
Expand Down Expand Up @@ -143,8 +143,8 @@ def make_model(self):
value = self.template_model.parameters[key].value
distribution = self.template_model.parameters[key].distribution
self.get_create_parameter(
ModelParameter(key, value, distribution,
placeholder=False))
ModelParameter(key, value, distribution,
placeholder=False))

for template in self.template_model.templates:
# Handle subjects
Expand Down Expand Up @@ -242,4 +242,3 @@ def num_controllers(template):
return len(template.controllers)
else:
return 0

2 changes: 1 addition & 1 deletion mira/modeling/askenet/ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def replace_parameter_id(tm, old_id, new_id):
@amr_to_mira
def replace_initial_id(tm, old_id, new_id):
"""Replace the ID of an initial."""
for init, initial in copy.deepcopy(tm.initials.items()):
for init, initial in copy.deepcopy(tm.initials).items():
if init == old_id:
initial.concept.name = new_id
tm.initials[new_id] = initial
Expand Down
21 changes: 21 additions & 0 deletions tests/test_modeling/test_askenet_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,27 @@ def test_replace_parameter_id(self):

self.assertTrue(expression_flag and mathml_flag)

# Currently this test fails
def test_replace_initial_id(self):
old_id = 'S'
new_id = 'TEST'
amr = _d(self.sir_amr)
new_amr = replace_initial_id(amr, old_id, new_id)

print(amr['semantics']['ode']['initials'])
print(new_amr['semantics']['ode']['initials'])

old_semantics_ode_initials = amr['semantics']['ode']['initials']
new_semantics_ode_initials = new_amr['semantics']['ode']['initials']

# Currently, output amr initials list does not contain changed initial id, input amr contains 3 initials
# Output amr is missing the initials that was changed
# Zipping the two amr initial lists will only iterate through the smaller of two list (output amr initials list)

# for old_initials, new_initials in zip(old_semantics_ode_initials, new_semantics_ode_initials):
# if old_initials['target'] == old_id:
# self.assertEqual(new_initials['target'], new_id)

def test_remove_state(self):
removed_state = 'S'
amr = _d(self.sir_amr)
Expand Down

0 comments on commit 3db7084

Please sign in to comment.