Skip to content

Commit

Permalink
♻️ Showing equivalence between hard coded and generated models
Browse files Browse the repository at this point in the history
model and parameters generated using the simple_generator are shown to be equivalent to the hard coded dicts
  • Loading branch information
jsnel committed Sep 13, 2021
1 parent 9e207a6 commit a25db46
Showing 1 changed file with 26 additions and 11 deletions.
37 changes: 26 additions & 11 deletions glotaran/builtin/megacomplexes/decay/test/test_decay_megacomplex.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from glotaran.model import Model
from glotaran.parameter import ParameterGroup
from glotaran.project import Scheme
from glotaran.testing.simple_generator import SimpleGenerator


def _create_gaussian_clp(labels, amplitudes, centers, widths, axis):
Expand Down Expand Up @@ -123,20 +124,29 @@ class OneComponentOneChannelGaussianIrf:


class ThreeComponentParallel:
model = DecayModel.from_dict(
generator = SimpleGenerator(
rates=[300e-3, 500e-4, 700e-5],
irf={"center": 1.3, "width": 7.8},
k_matrix="parallel",
)
model, initial_parameters = generator.model_and_parameters
ref_model = DecayModel.from_dict(
{
"initial_concentration": {
"j1": {"compartments": ["s1", "s2", "s3"], "parameters": ["j.1", "j.1", "j.1"]},
"j1": {
"compartments": ["s1", "s2", "s3"],
"parameters": ["inputs.1", "inputs.1", "inputs.1"],
},
},
"megacomplex": {
"mc1": {"k_matrix": ["k1"]},
},
"k_matrix": {
"k1": {
"matrix": {
("s1", "s1"): "kinetic.1",
("s2", "s2"): "kinetic.2",
("s3", "s3"): "kinetic.3",
("s1", "s1"): "rates.1",
("s2", "s2"): "rates.2",
("s3", "s3"): "rates.3",
}
}
},
Expand All @@ -156,29 +166,34 @@ class ThreeComponentParallel:
},
}
)
assert str(model) == str(ref_model)

initial_parameters = ParameterGroup.from_dict(
initial_parameters_ref = ParameterGroup.from_dict(
{
"kinetic": [
"rates": [
["1", 300e-3],
["2", 500e-4],
["3", 700e-5],
],
"irf": [["center", 1.3], ["width", 7.8]],
"j": [["1", 1, {"vary": False, "non-negative": False}]],
"inputs": [["1", 1, {"vary": False}]],
}
)
wanted_parameters = ParameterGroup.from_dict(
assert str(initial_parameters) == str(initial_parameters_ref)
generator.rates = [301e-3, 502e-4, 705e-5]
wanted_parameters = generator.parameters
wanted_parameters_ref = ParameterGroup.from_dict(
{
"kinetic": [
"rates": [
["1", 301e-3],
["2", 502e-4],
["3", 705e-5],
],
"irf": [["center", 1.3], ["width", 7.8]],
"j": [["1", 1, {"vary": False, "non-negative": False}]],
"inputs": [["1", 1, {"vary": False}]],
}
)
assert str(wanted_parameters) == str(wanted_parameters_ref)
time = np.arange(-10, 100, 1.5)
pixel = np.arange(600, 750, 10)

Expand Down

0 comments on commit a25db46

Please sign in to comment.