Skip to content

Commit e8a9d87

Browse files
authored
Merge pull request #811 from rhayes777/feature/database_output
Feature/database output
2 parents ae4790f + ba5dab8 commit e8a9d87

62 files changed

Lines changed: 499 additions & 657 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

autofit/database/aggregator/scrape.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,6 @@ def _add_pickles(fit: m.Fit, pickle_path: Path):
233233
try:
234234
filenames = os.listdir(pickle_path)
235235
except FileNotFoundError as e:
236-
logger.info(e)
237236
filenames = []
238237

239238
for filename in filenames:

autofit/non_linear/analysis/analysis.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
from autofit.mapper.prior_model.abstract import AbstractPriorModel
88
from autofit.non_linear.paths.abstract import AbstractPaths
9+
from autofit.non_linear.paths.database import DatabasePaths
910
from autofit.non_linear.result import Result
1011

1112
logger = logging.getLogger(__name__)
@@ -52,7 +53,9 @@ def should_visualize(
5253
3) Visualization can be forced to run via the `force_visualization_overwrite`, for example if a user
5354
wants to plot additional images that were not output on the original run.
5455
55-
4) If PyAutoFit test mode is on visualization is disabled, irrespective of the `force_visualization_overwite`
56+
4) If the analysis is running a database session visualization is switched off.
57+
58+
5) If PyAutoFit test mode is on visualization is disabled, irrespective of the `force_visualization_overwite`
5659
config input.
5760
5861
Parameters
@@ -70,6 +73,9 @@ def should_visualize(
7073
if os.environ.get("PYAUTOFIT_TEST_MODE") == "1":
7174
return False
7275

76+
if isinstance(paths, DatabasePaths):
77+
return False
78+
7379
if conf.instance["general"]["output"]["force_visualize_overwrite"]:
7480
return True
7581

autofit/non_linear/grid/grid_search/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,9 @@ def write_results():
253253
self.logger.debug(
254254
"Writing results"
255255
)
256+
257+
os.makedirs(self.paths.output_path, exist_ok=True)
258+
256259
with open(self.paths.output_path / "results.csv", "w+") as f:
257260
writer = csv.writer(f)
258261
writer.writerow([

autofit/non_linear/mock/mock_samples.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,6 @@ def gaussian_priors_at_sigma(self, sigma=None):
7474

7575
return self._gaussian_tuples
7676

77-
def write_table(self, filename):
78-
pass
79-
8077
@property
8178
def unconverged_sample_size(self):
8279
return self.samples_info["unconverged_sample_size"]

autofit/non_linear/parallel/sneaky.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -389,9 +389,12 @@ def prior_transform_cache(x):
389389
"""
390390
Prior transform call
391391
"""
392+
392393
return FunctionCache.prior_transform(x, *FunctionCache.prior_transform_args,
393394
**FunctionCache.prior_transform_kwargs)
394395

396+
397+
395398
class SneakierPool:
396399
def __init__(
397400
self,
@@ -417,11 +420,10 @@ def __init__(
417420
try:
418421
from mpi4py import MPI
419422
self.comm = MPI.COMM_WORLD
423+
self._processes = self.comm.size
420424
except ModuleNotFoundError:
421-
pass
425+
self._processes = 1
422426

423-
self._processes = self.comm.size
424-
425427
init_args = (
426428
self.fitness_init, self.prior_transform_init,
427429
self.fitness_args, self.fitness_kwargs,

autofit/non_linear/paths/abstract.py

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import dill
12
import json
23
import logging
34
import os
@@ -197,7 +198,10 @@ def search_internal_path(self) -> Path:
197198
"""
198199
The path to the samples folder.
199200
"""
200-
return self.output_path / "search_internal"
201+
202+
os.makedirs(self._files_path / "search_internal", exist_ok=True)
203+
204+
return self._files_path / "search_internal"
201205

202206
@property
203207
def image_path(self) -> Path:
@@ -237,7 +241,12 @@ def output_path(self) -> Path:
237241

238242
@property
239243
def _files_path(self) -> Path:
240-
raise NotImplementedError
244+
"""
245+
This is private for a reason, use the save_json etc. methods to save and load json
246+
"""
247+
files_path = self.output_path / "files"
248+
os.makedirs(files_path, exist_ok=True)
249+
return files_path
241250

242251
def zip_remove(self):
243252
"""
@@ -343,11 +352,11 @@ def _zip_path(self) -> str:
343352
return f"{self.output_path}.zip"
344353

345354
@abstractmethod
346-
def save_json(self, name, object_dict: dict):
355+
def save_json(self, name, object_dict: dict, prefix : str = ""):
347356
pass
348357

349358
@abstractmethod
350-
def load_json(self, name) -> dict:
359+
def load_json(self, name, prefix : str = "") -> dict:
351360
pass
352361

353362
@abstractmethod
@@ -359,19 +368,19 @@ def load_array(self, name) -> np.ndarray:
359368
pass
360369

361370
@abstractmethod
362-
def save_fits(self, name: str, hdu):
371+
def save_fits(self, name: str, hdu, prefix : str = ""):
363372
pass
364373

365374
@abstractmethod
366-
def load_fits(self, name: str):
375+
def load_fits(self, name: str, prefix : str = ""):
367376
pass
368377

369378
@abstractmethod
370-
def save_object(self, name: str, obj: object):
379+
def save_object(self, name: str, obj: object, prefix : str = ""):
371380
pass
372381

373382
@abstractmethod
374-
def load_object(self, name: str):
383+
def load_object(self, name: str, prefix : str = ""):
375384
pass
376385

377386
@abstractmethod
@@ -382,21 +391,11 @@ def remove_object(self, name: str):
382391
def is_object(self, name: str) -> bool:
383392
pass
384393

385-
@abstractmethod
386-
def save_results_internal(self, obj: object):
387-
pass
388-
389-
@abstractmethod
390-
def load_results_internal(self):
391-
pass
392-
393-
@abstractmethod
394-
def save_results_internal_json(self, results_internal_dict: Dict):
395-
pass
394+
def save_search_internal(self, obj):
395+
raise NotImplementedError
396396

397-
@abstractmethod
398-
def load_results_internal_json(self) -> Dict:
399-
pass
397+
def load_search_internal(self):
398+
raise NotImplementedError
400399

401400
@property
402401
@abstractmethod

autofit/non_linear/paths/database.py

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ def __getstate__(self):
121121
del d["session"]
122122
return d
123123

124-
def save_json(self, name, object_dict: Union[dict, list]):
124+
def save_json(self, name, object_dict: Union[dict, list], prefix : str = ""):
125125
"""
126126
Save a dictionary as a json file in the database
127127
@@ -134,7 +134,7 @@ def save_json(self, name, object_dict: Union[dict, list]):
134134
"""
135135
self.fit.set_json(name, object_dict)
136136

137-
def load_json(self, name: str) -> Union[dict, list]:
137+
def load_json(self, name: str, prefix : str = "") -> Union[dict, list]:
138138
"""
139139
Load a json file from the database
140140
@@ -177,7 +177,7 @@ def load_array(self, name: str) -> np.ndarray:
177177
"""
178178
return self.fit.get_array(name)
179179

180-
def save_fits(self, name: str, hdu):
180+
def save_fits(self, name: str, hdu, prefix : str = ""):
181181
"""
182182
Save a fits file in the database
183183
@@ -188,9 +188,9 @@ def save_fits(self, name: str, hdu):
188188
hdu
189189
The hdu to save
190190
"""
191-
self.fit.set_fits(name, hdu)
191+
self.fit.set_hdu(name, hdu)
192192

193-
def load_fits(self, name: str):
193+
def load_fits(self, name: str, prefix : str = ""):
194194
"""
195195
Load a fits file from the database
196196
@@ -205,30 +205,24 @@ def load_fits(self, name: str):
205205
"""
206206
return self.fit.get_hdu(name)
207207

208-
def save_object(self, name: str, obj: object):
208+
def save_object(self, name: str, obj: object, prefix : str = ""):
209209
self.fit[name] = obj
210210

211-
def load_object(self, name: str):
211+
def load_object(self, name: str, prefix : str = ""):
212212
return self.fit[name]
213213

214-
def save_results_internal(self, obj: object):
215-
pass
216-
217-
def load_results_internal(self):
218-
pass
219-
220-
def save_results_internal_json(self, results_internal_dict: Dict):
221-
pass
222-
223-
def load_results_internal_json(self) -> Dict:
224-
pass
225-
226214
def remove_object(self, name: str):
227215
del self.fit[name]
228216

229217
def is_object(self, name: str) -> bool:
230218
return name in self.fit
231219

220+
def save_search_internal(self, obj):
221+
pass
222+
223+
def load_search_internal(self):
224+
pass
225+
232226
@property
233227
def fit(self) -> Fit:
234228
if self._fit is None:
@@ -260,7 +254,6 @@ def completed(self):
260254
def save_summary(self, samples, log_likelihood_function_time):
261255
self.fit.instance = samples.max_log_likelihood()
262256
self.fit.max_log_likelihood = samples.max_log_likelihood_sample.log_likelihood
263-
super().save_summary(samples, log_likelihood_function_time)
264257

265258
def save_samples(self, samples):
266259
if not self.save_all_samples:
@@ -286,10 +279,12 @@ def load_samples_info(self):
286279
return self._load_samples().samples_info
287280

288281
def save_all(self, info, *_, **kwargs):
289-
self.save_identifier()
282+
290283
self.fit.info = info
291284
self.fit.model = self.model
292-
285+
if info:
286+
self.save_json("info", info)
293287
self.save_json("search", to_dict(self.search))
288+
self.save_json("model", self.model.dict())
294289

295290
self.session.commit()

0 commit comments

Comments
 (0)