From a25db46a61a86876375eb34c23cedcbfc2f54759 Mon Sep 17 00:00:00 2001 From: Joris Snellenburg Date: Mon, 13 Sep 2021 02:07:38 +0200 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Showing=20equivalence=20be?= =?UTF-8?q?tween=20hard=20coded=20and=20generated=20models?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit model and parameters generated using the simple_generator are shown to be equivalent to the hard coded dicts --- .../decay/test/test_decay_megacomplex.py | 37 +++++++++++++------ 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/glotaran/builtin/megacomplexes/decay/test/test_decay_megacomplex.py b/glotaran/builtin/megacomplexes/decay/test/test_decay_megacomplex.py index 07593df9b..138e08b66 100644 --- a/glotaran/builtin/megacomplexes/decay/test/test_decay_megacomplex.py +++ b/glotaran/builtin/megacomplexes/decay/test/test_decay_megacomplex.py @@ -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): @@ -123,10 +124,19 @@ 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"]}, @@ -134,9 +144,9 @@ class ThreeComponentParallel: "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", } } }, @@ -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)