From 1746e2f337c3b5545b5a59ceb79e2feb34c95f42 Mon Sep 17 00:00:00 2001 From: James Nightingale Date: Tue, 9 May 2023 17:12:33 +0100 Subject: [PATCH 1/2] added method --- autofit/non_linear/analysis/analysis.py | 34 +++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/autofit/non_linear/analysis/analysis.py b/autofit/non_linear/analysis/analysis.py index f5b1f3f06..c0fb986f8 100644 --- a/autofit/non_linear/analysis/analysis.py +++ b/autofit/non_linear/analysis/analysis.py @@ -1,6 +1,8 @@ import logging from abc import ABC +from autoconf import conf + from autofit.mapper.prior_model.abstract import AbstractPriorModel from autofit.non_linear.paths.abstract import AbstractPaths from autofit.non_linear.result import Result @@ -38,6 +40,38 @@ def with_model(self, model): model=model ) + def should_visualize(self, paths: AbstractPaths) -> bool: + """ + Whether a visualize method should continue and perform visualization, or be terminated early. + + If a model-fit has already completed, the default behaviour is for visualization to be bypassed in order + to make model-fits run faster. However, visualization can be forced to run via + the `force_visualization_overwrite`, for example if a user wants to plot additional images that were not + output on the original run. + + PyAutoFit test mode also disables visualization, irrespective of the `force_visualization_overwite` + config input. + + Parameters + ---------- + paths + The PyAutoFit paths object which manages all paths, e.g. where the non-linear search outputs are stored, + visualization and the pickled objects used by the aggregator output by this function. + + + Returns + ------- + A bool determining whether visualization should be performed or not. + """ + + if os.environ.get("PYAUTOFIT_TEST_MODE") == "1": + return False + + if paths.is_complete and not conf.instance["general"]["output"]["force_visualize_overwrite"]: + return False + + return True + def log_likelihood_function(self, instance): raise NotImplementedError() From cd308647022dacb18e4e2d070f1eeb4bf4fed185 Mon Sep 17 00:00:00 2001 From: James Nightingale Date: Wed, 10 May 2023 12:43:42 +0100 Subject: [PATCH 2/2] review --- autofit/non_linear/analysis/analysis.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/autofit/non_linear/analysis/analysis.py b/autofit/non_linear/analysis/analysis.py index c0fb986f8..2ee6ebdbb 100644 --- a/autofit/non_linear/analysis/analysis.py +++ b/autofit/non_linear/analysis/analysis.py @@ -1,5 +1,6 @@ import logging from abc import ABC +import os from autoconf import conf @@ -67,10 +68,7 @@ def should_visualize(self, paths: AbstractPaths) -> bool: if os.environ.get("PYAUTOFIT_TEST_MODE") == "1": return False - if paths.is_complete and not conf.instance["general"]["output"]["force_visualize_overwrite"]: - return False - - return True + return not paths.is_complete or conf.instance["general"]["output"]["force_visualize_overwrite"] def log_likelihood_function(self, instance): raise NotImplementedError()