Repository: rhayes777/PyAutoFit
Pull request #1102 (2025-02-14 14:38:10)

feature/mp fix
Resolves https://github.com/Jammy2211/concr_cosmology/issues/1



Patch:
diff --git a/autofit/graphical/declarative/factor/analysis.py b/autofit/graphical/declarative/factor/analysis.py
index 485872229..c28bd5ae0 100644
--- a/autofit/graphical/declarative/factor/analysis.py
+++ b/autofit/graphical/declarative/factor/analysis.py
@@ -21,7 +21,7 @@ class FactorCallable:
 
     def __call__(self, **kwargs: np.ndarray) -> float:
         """
-        Returns an instance of the prior model and evaluates it, forming
+        Creates an instance of the prior model and evaluates it, forming
         a factor.
 
         Parameters
@@ -85,6 +85,7 @@ class AnalysisFactor(AbstractModelFactor):
             prior_variable_dict=prior_variable_dict,
             name=name,
         )
+        print(name)
 
     def __getstate__(self):
         return self.__dict__
diff --git a/autofit/mapper/variable.py b/autofit/mapper/variable.py
index bc5e1fef6..4327348d2 100644
--- a/autofit/mapper/variable.py
+++ b/autofit/mapper/variable.py
@@ -11,8 +11,8 @@ from autoconf import cached_property
 from autofit.mapper.model_object import ModelObject
 
 if TYPE_CHECKING:
-    from autofit.mapper.operator import LinearOperator 
-    from autofit.mapper.variable_operator import VariableFullOperator, VariableOperator 
+    from autofit.mapper.operator import LinearOperator
+    from autofit.mapper.variable_operator import VariableFullOperator, VariableOperator
 
 
 class Plate:
@@ -86,7 +86,11 @@ class Variable(ModelObject):
         """
         self.plates = plates
         super().__init__(id_=id_)
-        self.name = name or f"{self.__class__.__name__.lower()}_{self.id}"
+        self._name = name
+
+    @property
+    def name(self):
+        return self._name or f"{self.__class__.__name__.lower()}_{self.id}"
 
     def __repr__(self):
         args = ", ".join(chain([self.name], map(repr, self.plates)))
@@ -418,7 +422,7 @@ class VariableData(Dict[Variable, np.ndarray]):
             elif ord == -np.Inf:
                 return absval.min()
             else:
-                return (absval ** ord).sum() ** (1.0 / ord)
+                return (absval**ord).sum() ** (1.0 / ord)
         else:
             return VariableData.norm(self)
 
@@ -434,19 +438,22 @@ class VariableData(Dict[Variable, np.ndarray]):
         sizes = {}
         for v, val in self.items():
             shape = np.shape(val)
-            assert len(shape) == len(v.plates), f"shape must match the number of plates of {v}"
+            assert len(shape) == len(
+                v.plates
+            ), f"shape must match the number of plates of {v}"
             for p, s in zip(v.plates, shape):
-                assert sizes.setdefault(p, s) == s, f"plate sizes must be consistent, {sizes[p]} != {s}"
+                assert (
+                    sizes.setdefault(p, s) == s
+                ), f"plate sizes must be consistent, {sizes[p]} != {s}"
         return sizes
 
     def full_like(self, fill_value, **kwargs):
-        return type(self)({
-            v: np.full_like(val, fill_value, **kwargs)
-            for v, val in self.items()
-        })
+        return type(self)(
+            {v: np.full_like(val, fill_value, **kwargs) for v, val in self.items()}
+        )
 
     def zeros_like(self, **kwargs):
-        return self.full_like(0.)
+        return self.full_like(0.0)
 
 
 class VariableLinearOperator(ABC):
@@ -555,7 +562,7 @@ class InverseVariableOperator(VariableLinearOperator):
     def update(self, *args: Tuple[VariableData, VariableData]):
         # apply Sherman-Morrison formulat
         A = self.operator
-        for (u, v) in args:
+        for u, v in args:
             A1u = A * u
             A1v = v * A
             vTA1u = -A1u.dot(v)
@@ -564,7 +571,7 @@ class InverseVariableOperator(VariableLinearOperator):
         return type(self)(A)
 
     def diagonalupdate(self, d: VariableData):
-        A = self.operator.diagonalupdate(d ** -1)
+        A = self.operator.diagonalupdate(d**-1)
         return type(self)(A)
 
     def to_full(self) -> "VariableFullOperator":


Test patch:
diff --git a/test_autofit/mapper/prior/test_regression.py b/test_autofit/mapper/prior/test_regression.py
index cee75008b..1d91d5c0e 100644
--- a/test_autofit/mapper/prior/test_regression.py
+++ b/test_autofit/mapper/prior/test_regression.py
@@ -1,23 +1,16 @@
+from copy import copy
+
 import pytest
 
 import autofit as af
 
 
-@pytest.fixture(
-    name="prior"
-)
+@pytest.fixture(name="prior")
 def make_prior():
-    return af.GaussianPrior(
-        mean=1,
-        sigma=2,
-        lower_limit=3,
-        upper_limit=4
-    )
+    return af.GaussianPrior(mean=1, sigma=2, lower_limit=3, upper_limit=4)
 
 
-@pytest.fixture(
-    name="message"
-)
+@pytest.fixture(name="message")
 def make_message(prior):
     return prior.message
 
@@ -38,9 +31,7 @@ def test_multiply_limits(message):
     assert message.upper_limit == multiplied.upper_limit
 
 
-@pytest.fixture(
-    name="uniform_prior"
-)
+@pytest.fixture(name="uniform_prior")
 def make_uniform_prior():
     return af.UniformPrior(
         lower_limit=10,
@@ -50,23 +41,24 @@ def make_uniform_prior():
 
 def test_sum_from_arguments(prior, uniform_prior):
     added = prior + prior
-    new = added.gaussian_prior_model_for_arguments({
-        prior: uniform_prior
-    })
+    new = added.gaussian_prior_model_for_arguments({prior: uniform_prior})
     assert new.instance_from_prior_medians() == 30
 
 
 def test_negative_from_arguments(prior, uniform_prior):
     negative = -prior
-    new = negative.gaussian_prior_model_for_arguments({
-        prior: uniform_prior
-    })
+    new = negative.gaussian_prior_model_for_arguments({prior: uniform_prior})
     assert new.instance_from_prior_medians() == -15
 
 
 def test_sum_with_float(prior, uniform_prior):
     added = prior + 15
-    new = added.gaussian_prior_model_for_arguments({
-        prior: uniform_prior
-    })
+    new = added.gaussian_prior_model_for_arguments({prior: uniform_prior})
     assert new.instance_from_prior_medians() == 30
+
+
+def test_name(prior):
+    new = prior.new()
+
+    assert new.id != prior.id
+    assert new.name != prior.name