-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reformat notebook, improve composition tests
- Loading branch information
Showing
3 changed files
with
106 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,59 @@ | ||
from mira.metamodel.composition import * | ||
from mira.sources.amr import model_from_url | ||
from mira.examples.sir import sir, sir_2_city | ||
from mira.metamodel.composition import compose_two_models, compose | ||
from mira.metamodel.template_model import TemplateModel | ||
from mira.metamodel.templates import * | ||
from mira.examples.concepts import * | ||
|
||
infection = ControlledConversion( | ||
subject=susceptible, | ||
outcome=infected, | ||
controller=infected, | ||
) | ||
recovery = NaturalConversion( | ||
subject=infected, | ||
outcome=recovered, | ||
) | ||
|
||
def test_model_compose(): | ||
sir_petrinet_url = 'https://raw.githubusercontent.com/DARPA-ASKEM/' \ | ||
'Model-Representations/main/petrinet/examples/sir.json' | ||
lotka_regnet_url = ('https://raw.githubusercontent.com/DARPA-ASKEM' | ||
'/Model-Representations/main/regnet' | ||
'/examples/lotka_volterra.json') | ||
reinfection = ControlledConversion( | ||
subject=recovered, | ||
outcome=infected, | ||
controller=infected, | ||
) | ||
|
||
tm0 = model_from_url(sir_petrinet_url) | ||
tm1 = model_from_url(lotka_regnet_url) | ||
dying = NaturalConversion( | ||
subject=infected, | ||
outcome=dead | ||
) | ||
|
||
new_tm = compose([tm0, tm1, sir, sir_2_city]) | ||
sir = TemplateModel( | ||
templates=[ | ||
infection, | ||
recovery, | ||
] | ||
) | ||
|
||
sir_reinfection = TemplateModel( | ||
templates=[ | ||
infection, | ||
recovery, | ||
reinfection | ||
] | ||
) | ||
|
||
sir_dying = TemplateModel( | ||
templates=[ | ||
infection, | ||
dying, | ||
recovery, | ||
] | ||
) | ||
|
||
|
||
def test_compose_two_models(): | ||
composed_model = compose_two_models(sir_reinfection, sir) | ||
assert len(composed_model.templates) == 3 | ||
|
||
|
||
def test_compose_list(): | ||
model_list = [sir_reinfection, sir_dying, sir] | ||
composed_model = compose(model_list) | ||
assert len(composed_model.templates) == 4 |