diff --git a/glotaran/analysis/test/test_constraints.py b/glotaran/analysis/test/test_constraints.py index 82f80fd6a..8b10b82ab 100644 --- a/glotaran/analysis/test/test_constraints.py +++ b/glotaran/analysis/test/test_constraints.py @@ -15,7 +15,7 @@ def test_constraint(index_dependent, grouped): model = deepcopy(suite.model) model.megacomplex["m1"].is_index_dependent = index_dependent - model.constraints.append(ZeroConstraint.from_dict({"target": "s2"})) + model.clp_constraints.append(ZeroConstraint.from_dict({"target": "s2"})) print("grouped", grouped, "index_dependent", index_dependent) dataset = simulate( diff --git a/glotaran/analysis/test/test_relations.py b/glotaran/analysis/test/test_relations.py index 480db3124..f515c59af 100644 --- a/glotaran/analysis/test/test_relations.py +++ b/glotaran/analysis/test/test_relations.py @@ -16,7 +16,9 @@ def test_relations(index_dependent, grouped): model = deepcopy(suite.model) model.megacomplex["m1"].is_index_dependent = index_dependent - model.relations.append(Relation.from_dict({"source": "s1", "target": "s2", "parameter": "3"})) + model.clp_relations.append( + Relation.from_dict({"source": "s1", "target": "s2", "parameter": "3"}) + ) parameters = ParameterGroup.from_list([11e-4, 22e-5, 2]) print("grouped", grouped, "index_dependent", index_dependent) diff --git a/glotaran/analysis/util.py b/glotaran/analysis/util.py index e25e79136..61c1cc612 100644 --- a/glotaran/analysis/util.py +++ b/glotaran/analysis/util.py @@ -113,12 +113,12 @@ def apply_constraints( index: Any | None, ) -> CalculatedMatrix: - if len(model.constraints) == 0: + if len(model.clp_constraints) == 0: return matrix clp_labels = matrix.clp_labels removed_clp_labels = [ - c.target for c in model.constraints if c.target in clp_labels and c.applies(index) + c.target for c in model.clp_constraints if c.target in clp_labels and c.applies(index) ] reduced_clp_labels = [c for c in clp_labels if c not in removed_clp_labels] mask = [label in reduced_clp_labels for label in clp_labels] @@ -133,14 +133,14 @@ def apply_relations( index: Any | None, ) -> CalculatedMatrix: - if len(model.relations) == 0: + if len(model.clp_relations) == 0: return matrix clp_labels = matrix.clp_labels relation_matrix = np.diagflat([1.0 for _ in clp_labels]) idx_to_delete = [] - for relation in model.relations: + for relation in model.clp_relations: if relation.target in clp_labels and relation.applies(index): if relation.source not in clp_labels: @@ -166,7 +166,7 @@ def retrieve_clps( reduced_clps: xr.DataArray, index: Any | None, ) -> xr.DataArray: - if len(model.relations) == 0 and len(model.constraints) == 0: + if len(model.clp_relations) == 0 and len(model.clp_constraints) == 0: return reduced_clps clps = np.zeros(len(clp_labels)) @@ -175,7 +175,7 @@ def retrieve_clps( idx = clp_labels.index(label) clps[idx] = reduced_clps[i] - for relation in model.relations: + for relation in model.clp_relations: relation = relation.fill(model, parameters) if ( relation.target in clp_labels diff --git a/glotaran/builtin/io/yml/test/test_model_parser.py b/glotaran/builtin/io/yml/test/test_model_parser.py index cc98520ef..53a1b01f8 100644 --- a/glotaran/builtin/io/yml/test/test_model_parser.py +++ b/glotaran/builtin/io/yml/test/test_model_parser.py @@ -61,15 +61,15 @@ def test_dataset(model): def test_constraints(model): - print(model.constraints) - assert len(model.constraints) == 2 + print(model.clp_constraints) + assert len(model.clp_constraints) == 2 - zero = model.constraints[0] + zero = model.clp_constraints[0] assert isinstance(zero, ZeroConstraint) assert zero.target == "s1" assert zero.interval == [[1, 100], [2, 200]] - only = model.constraints[1] + only = model.clp_constraints[1] assert isinstance(only, OnlyConstraint) assert only.target == "s1" assert only.interval == [[1, 100], [2, 200]] @@ -88,10 +88,10 @@ def test_penalties(model): def test_relations(model): - print(model.relations) - assert len(model.relations) == 1 + print(model.clp_relations) + assert len(model.clp_relations) == 1 - rel = model.relations[0] + rel = model.clp_relations[0] assert rel.source == "s1" assert rel.target == "s2" diff --git a/glotaran/builtin/io/yml/test/test_model_spec.yml b/glotaran/builtin/io/yml/test/test_model_spec.yml index 2c485fa82..7714ec16e 100644 --- a/glotaran/builtin/io/yml/test/test_model_spec.yml +++ b/glotaran/builtin/io/yml/test/test_model_spec.yml @@ -71,7 +71,7 @@ megacomplex: s1: shape1 s2: shape2 -constraints: +clp_constraints: - type: zero target: s1 interval: @@ -92,7 +92,7 @@ clp_area_penalties: parameter: 55 weight: 0.0016 -relations: +clp_relations: - source: s1 target: s2 parameter: 8 diff --git a/glotaran/deprecation/modules/builtin_io_yml.py b/glotaran/deprecation/modules/builtin_io_yml.py index 0bc5c59df..6d82143cc 100644 --- a/glotaran/deprecation/modules/builtin_io_yml.py +++ b/glotaran/deprecation/modules/builtin_io_yml.py @@ -40,18 +40,27 @@ def model_spec_deprecations(spec: MutableMapping[Any, Any]) -> None: deprecate_dict_entry( dict_to_check=spec, deprecated_usage="spectral_relations", - new_usage="relations", + new_usage="clp_relations", to_be_removed_in_version="0.7.0", - swap_keys=("spectral_relations", "relations"), + swap_keys=("spectral_relations", "clp_relations"), stacklevel=load_model_stack_level, ) - if "relations" in spec: - for relation in spec["relations"]: + deprecate_dict_entry( + dict_to_check=spec, + deprecated_usage="relations", + new_usage="clp_relations", + to_be_removed_in_version="0.7.0", + swap_keys=("relations", "clp_relations"), + stacklevel=load_model_stack_level, + ) + + if "clp_relations" in spec: + for relation in spec["clp_relations"]: deprecate_dict_entry( dict_to_check=relation, - deprecated_usage="compartment", - new_usage="source", + deprecated_usage="clp_relations:\n - compartment", + new_usage="clp_relations:\n - source", to_be_removed_in_version="0.7.0", swap_keys=("compartment", "source"), stacklevel=load_model_stack_level, @@ -60,18 +69,27 @@ def model_spec_deprecations(spec: MutableMapping[Any, Any]) -> None: deprecate_dict_entry( dict_to_check=spec, deprecated_usage="spectral_constraints", - new_usage="constraints", + new_usage="clp_constraints", + to_be_removed_in_version="0.7.0", + swap_keys=("spectral_constraints", "clp_constraints"), + stacklevel=load_model_stack_level, + ) + + deprecate_dict_entry( + dict_to_check=spec, + deprecated_usage="constraints", + new_usage="clp_constraints", to_be_removed_in_version="0.7.0", - swap_keys=("spectral_constraints", "constraints"), + swap_keys=("constraints", "clp_constraints"), stacklevel=load_model_stack_level, ) - if "constraints" in spec: - for constraint in spec["constraints"]: + if "clp_constraints" in spec: + for constraint in spec["clp_constraints"]: deprecate_dict_entry( dict_to_check=constraint, - deprecated_usage="constraint.compartment", - new_usage="constraint.target", + deprecated_usage="clp_constraints:\n - compartment", + new_usage="clp_constraints:\n - target", to_be_removed_in_version="0.7.0", swap_keys=("compartment", "target"), stacklevel=load_model_stack_level, diff --git a/glotaran/deprecation/modules/test/test_builtin_io_yml.py b/glotaran/deprecation/modules/test/test_builtin_io_yml.py index 873230366..9634f295e 100644 --- a/glotaran/deprecation/modules/test/test_builtin_io_yml.py +++ b/glotaran/deprecation/modules/test/test_builtin_io_yml.py @@ -29,7 +29,19 @@ """ ), 3, - "relations", + "clp_relations", + [{"source": "s1"}, {"source": "s2"}], + ), + ( + dedent( + """ + relations: + - compartment: s1 + - compartment: s2 + """ + ), + 3, + "clp_relations", [{"source": "s1"}, {"source": "s2"}], ), ( @@ -41,7 +53,19 @@ """ ), 3, - "constraints", + "clp_constraints", + [{"target": "s1"}, {"target": "s2"}], + ), + ( + dedent( + """ + constraints: + - compartment: s1 + - compartment: s2 + """ + ), + 3, + "clp_constraints", [{"target": "s1"}, {"target": "s2"}], ), ( @@ -86,7 +110,9 @@ "type: kinetic-spectrum", "type: spectrum", "spectral_relations", + "relations", "spectral_constraints", + "constraints", "equal_area_penalties", "center_dispersion", "width_dispersion", diff --git a/glotaran/model/model.py b/glotaran/model/model.py index 6d20d1b97..4e8ceb74e 100644 --- a/glotaran/model/model.py +++ b/glotaran/model/model.py @@ -24,8 +24,8 @@ default_model_items = { "clp_area_penalties": EqualAreaPenalty, - "constraints": Constraint, - "relations": Relation, + "clp_constraints": Constraint, + "clp_relations": Relation, "weights": Weight, } @@ -254,8 +254,8 @@ def global_megacomplex(self) -> dict[str, Megacomplex]: return self.megacomplex def need_index_dependent(self) -> bool: - """Returns true if e.g. relations with intervals are present.""" - return any(i.interval is not None for i in self.constraints + self.relations) + """Returns true if e.g. clp_relations with intervals are present.""" + return any(i.interval is not None for i in self.clp_constraints + self.clp_relations) def is_groupable(self, parameters: ParameterGroup, data: dict[str, xr.DataArray]) -> bool: if any(d.has_global_model() for d in self.dataset.values()): diff --git a/glotaran/model/test/test_model.py b/glotaran/model/test/test_model.py index b8a446b1d..e34b0585b 100644 --- a/glotaran/model/test/test_model.py +++ b/glotaran/model/test/test_model.py @@ -227,15 +227,15 @@ def test_model_init(): assert "clp_area_penalties" in model._model_items assert issubclass(model._model_items["clp_area_penalties"], EqualAreaPenalty) - assert hasattr(model, "constraints") - assert isinstance(model.constraints, list) - assert "constraints" in model._model_items - assert issubclass(model._model_items["constraints"], Constraint) - - assert hasattr(model, "relations") - assert isinstance(model.relations, list) - assert "relations" in model._model_items - assert issubclass(model._model_items["relations"], Relation) + assert hasattr(model, "clp_constraints") + assert isinstance(model.clp_constraints, list) + assert "clp_constraints" in model._model_items + assert issubclass(model._model_items["clp_constraints"], Constraint) + + assert hasattr(model, "clp_relations") + assert isinstance(model.clp_relations, list) + assert "clp_relations" in model._model_items + assert issubclass(model._model_items["clp_relations"], Relation) assert hasattr(model, "weights") assert isinstance(model.weights, list)