Repository: rhayes777/PyAutoFit
Pull request #933 (2024-02-12 10:07:12)

feature/serailise paths
Tests and fixes supporting changes to autoconf resolving https://github.com/rhayes777/PyAutoFit/issues/918



Patch:
diff --git a/autofit/non_linear/paths/abstract.py b/autofit/non_linear/paths/abstract.py
index bc4d7d201..0b5d2e805 100644
--- a/autofit/non_linear/paths/abstract.py
+++ b/autofit/non_linear/paths/abstract.py
@@ -70,7 +70,8 @@ class AbstractPaths(ABC):
         self.unique_tag = unique_tag
 
         self._non_linear_name = None
-        self.__identifier = identifier or None
+        self.__custom_identifier = identifier
+        self.__identifier = None
 
         self.is_identifier_in_paths = is_identifier_in_paths
 
@@ -160,6 +161,8 @@ class AbstractPaths(ABC):
 
     @property
     def _identifier(self):
+        if self.__custom_identifier is not None:
+            return self.__custom_identifier
         if self.__identifier is None:
             if None in (self.model, self.search):
                 logger.debug(
diff --git a/autofit/non_linear/paths/database.py b/autofit/non_linear/paths/database.py
index 5ed2b3655..6cb5c62a8 100644
--- a/autofit/non_linear/paths/database.py
+++ b/autofit/non_linear/paths/database.py
@@ -33,6 +33,8 @@ class DatabasePaths(AbstractPaths):
         self.save_all_samples = save_all_samples
         self.unique_tag = unique_tag
 
+    __nullify_fields__ = ("session",)
+
     parent: "DatabasePaths"
 
     @AbstractPaths.parent.setter


Test patch:
diff --git a/test_autofit/non_linear/paths/test_serialise_paths.py b/test_autofit/non_linear/paths/test_serialise_paths.py
index fa0fe6fbf..a12602869 100644
--- a/test_autofit/non_linear/paths/test_serialise_paths.py
+++ b/test_autofit/non_linear/paths/test_serialise_paths.py
@@ -12,3 +12,33 @@ def test_path_prefix():
     paths = from_dict(to_dict(paths))
 
     assert paths.path_prefix == path_prefix
+
+
+def test_identifier():
+    paths = af.DirectoryPaths()
+    new_paths = from_dict(to_dict(paths))
+
+    assert new_paths.identifier == paths.identifier
+
+
+def test_identifier_with_model():
+    paths = af.DirectoryPaths()
+    paths.model = af.Model(af.Gaussian)
+    new_paths = from_dict(to_dict(paths))
+
+    assert new_paths.identifier == paths.identifier
+
+
+def test_serialise_search():
+    search = af.DynestyStatic(
+        path_prefix=Path("searches"),
+    )
+
+    assert "paths" in to_dict(search)["arguments"]
+
+
+def test_serialise_database_paths(session):
+    paths = af.DatabasePaths(session)
+    paths = from_dict(to_dict(paths))
+
+    assert paths.session is None
diff --git a/test_autofit/non_linear/test_dict.py b/test_autofit/non_linear/test_dict.py
index 785c2cc36..3b62add66 100644
--- a/test_autofit/non_linear/test_dict.py
+++ b/test_autofit/non_linear/test_dict.py
@@ -7,26 +7,38 @@ from autoconf.dictable import to_dict, from_dict
 @pytest.fixture(name="dynesty_dict")
 def make_dynesty_dict():
     return {
-        "type": "instance",
-        "class_path": "autofit.non_linear.search.nest.dynesty.search.static.DynestyStatic",
         "arguments": {
+            "bootstrap": None,
             "bound": "multi",
+            "enlarge": None,
+            "facc": 0.5,
+            "fmove": 0.9,
+            "initial_values": {"arguments": {}, "type": "dict"},
+            "initializer": {
+                "arguments": {},
+                "class_path": "autofit.non_linear.initializer.InitializerPrior",
+                "type": "instance",
+            },
+            "inplace": False,
+            "iterations_per_update": 500,
             "max_move": 100,
+            "name": "",
             "nlive": 150,
-            "fmove": 0.9,
-            "enlarge": None,
-            "bootstrap": None,
-            "walks": 5,
+            "number_of_cores": 1,
+            "path_prefix": None,
+            "paths": {
+                "arguments": {},
+                "class_path": "autofit.non_linear.paths.null.NullPaths",
+                "type": "instance",
+            },
             "sample": "auto",
-            "name": "",
             "slices": 5,
-            "facc": 0.5,
             "unique_tag": None,
-            "path_prefix": None,
-            "iterations_per_update": 500,
             "use_gradient": False,
-            "number_of_cores": 1,
+            "walks": 5,
         },
+        "class_path": "autofit.non_linear.search.nest.dynesty.search.static.DynestyStatic",
+        "type": "instance",
     }