Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions autogalaxy/analysis/analysis/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,33 @@ def make_result(
search_internal=search_internal,
analysis=self,
)

def perform_quick_update(self, paths, instance):
"""
Perform a quick visualization update during non-linear search fitting.

This method is called intermittently while the sampler is running to produce
the `subplot+fit` plots of the current maximum-likelihood model fit. The intent
is to provide fast feedback (without waiting for the full run to complete) so that
users can monitor whether the fit is behaving sensibly.

The plot appears both in a matplotlib window (if running locally) and is also saved to the
`output` folder of the output path.

Parameters
----------
paths : af.DirectoryPaths
Object describing the output folder structure where visualization files
should be written.
instance : model instance
The current maximum-likelihood instance of the model, used to generate
the visualization plots.
"""

self.Visualizer().visualize(
analysis=self,
paths=paths,
instance=instance,
during_analysis=True,
quick_update=True,
)
3 changes: 2 additions & 1 deletion autogalaxy/analysis/plotter_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def mat_plot_1d_from(self) -> MatPlot1D:
output=aplt.Output(path=self.image_path, format=self.fmt),
)

def mat_plot_2d_from(self) -> MatPlot2D:
def mat_plot_2d_from(self, quick_update : bool = False) -> MatPlot2D:
"""
Returns a 2D matplotlib plotting object whose `Output` class uses the `image_path`, such that it outputs
images to the `image` folder of the non-linear search.
Expand All @@ -103,6 +103,7 @@ def mat_plot_2d_from(self) -> MatPlot2D:
return MatPlot2D(
title=aplt.Title(prefix=self.title_prefix),
output=aplt.Output(path=self.image_path, format=self.fmt),
quick_update=quick_update,
)

def galaxies(
Expand Down
6 changes: 5 additions & 1 deletion autogalaxy/imaging/model/plotter_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ def should_plot(name):
def fit_imaging(
self,
fit: FitImaging,
quick_update: bool = False
):
"""
Visualizes a `FitImaging` object, which fits an imaging dataset.
Expand Down Expand Up @@ -169,9 +170,12 @@ def should_plot(name):
mat_plot_2d=mat_plot_2d,
)

if should_plot("subplot_fit"):
if should_plot("subplot_fit") or quick_update:
fit_plotter.subplot_fit()

if quick_update:
return

if should_plot("subplot_of_galaxies"):
fit_plotter.subplot_of_galaxies()

Expand Down
8 changes: 6 additions & 2 deletions autogalaxy/imaging/model/visualizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def visualize(
paths: af.DirectoryPaths,
instance: af.ModelInstance,
during_analysis: bool,
quick_update: bool = False,
):
"""
Output images of the maximum log likelihood model inferred by the model-fit. This function is called throughout
Expand Down Expand Up @@ -78,13 +79,16 @@ def visualize(
plotter = PlotterInterfaceImaging(
image_path=paths.image_path, title_prefix=analysis.title_prefix
)
plotter.imaging(dataset=analysis.dataset)
# Quick Update only, skips everything after

try:
plotter.fit_imaging(fit=fit)
plotter.fit_imaging(fit=fit, quick_update=quick_update)
except exc.InversionException:
pass

if quick_update:
return

galaxies = fit.galaxies_linear_light_profiles_to_light_profiles

plotter.galaxies(galaxies=galaxies, grid=fit.grids.lp)
Expand Down
8 changes: 6 additions & 2 deletions autogalaxy/interferometer/model/plotter_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ def should_plot(name):
def fit_interferometer(
self,
fit: FitInterferometer,
quick_update : bool = False,
):
"""
Visualizes a `FitInterferometer` object, which fits an interferometer dataset.
Expand Down Expand Up @@ -163,12 +164,15 @@ def should_plot(name):
mat_plot_2d=mat_plot_2d,
)

if should_plot("subplot_fit"):
if should_plot("subplot_fit") or quick_update:
fit_plotter.subplot_fit()

if should_plot("subplot_fit_dirty_images"):
if should_plot("subplot_fit_dirty_images") or quick_update:
fit_plotter.subplot_fit_dirty_images()

if quick_update:
return

if should_plot("subplot_fit_real_space"):
fit_plotter.subplot_fit_real_space()

Expand Down
25 changes: 14 additions & 11 deletions autogalaxy/interferometer/model/visualizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ def visualize(
paths: af.DirectoryPaths,
instance: af.ModelInstance,
during_analysis: bool,
quick_update: bool = False,
):
"""
Outputs images of the maximum log likelihood model inferred by the model-fit. This function is called
Expand Down Expand Up @@ -75,28 +76,30 @@ def visualize(
"""
fit = analysis.fit_from(instance=instance)

PlotterInterface = PlotterInterfaceInterferometer(
plotter_interface = PlotterInterfaceInterferometer(
image_path=paths.image_path, title_prefix=analysis.title_prefix
)
PlotterInterface.interferometer(dataset=analysis.interferometer)

try:
plotter_interface.fit_interferometer(
fit=fit, quick_update=quick_update,
)
except exc.InversionException:
pass

if quick_update:
return

galaxies = fit.galaxies_linear_light_profiles_to_light_profiles

PlotterInterface.galaxies(
plotter_interface.galaxies(
galaxies=galaxies,
grid=fit.grids.lp,
)

try:
PlotterInterface.fit_interferometer(
fit=fit,
)
except exc.InversionException:
pass

if fit.inversion is not None:
try:
PlotterInterface.inversion(
plotter_interface.inversion(
inversion=fit.inversion,
)
except IndexError:
Expand Down
2 changes: 2 additions & 0 deletions autogalaxy/plot/mat_plot/two_d.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ def __init__(
tangential_caustics_plot: Optional[w.TangentialCausticsPlot] = None,
radial_caustics_plot: Optional[w.RadialCausticsPlot] = None,
use_log10: bool = False,
quick_update : bool = False
):
"""
Visualizes data structures (e.g an `Array2D`, `Grid2D`, `VectorField`, etc.) using Matplotlib.
Expand Down Expand Up @@ -215,4 +216,5 @@ def __init__(
delaunay_drawer=delaunay_drawer,
voronoi_drawer=voronoi_drawer,
use_log10=use_log10,
quick_update=quick_update,
)
2 changes: 1 addition & 1 deletion test_autogalaxy/config/general.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ inversion:
use_border_relocator: false # If True, by default a pixelization's border is used to relocate all pixels outside its border to the border.
hpc:
hpc_mode: false
iterations_per_update: 5000
iterations_per_full_update: 5000
adapt:
adapt_minimum_percent: 0.01
adapt_noise_limit: 100000000.0
Expand Down
20 changes: 5 additions & 15 deletions test_autogalaxy/config/non_linear.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,14 @@ mock:
method: prior
printing:
silence: false
updates:
iterations_per_update: 2500
remove_state_files_at_end: true

MockSearch:
initialize:
method: prior
printing:
silence: false
search: {}
updates:
iterations_per_update: 2500
remove_state_files_at_end: true

GridSearch:
general:
number_of_cores: 2
Expand All @@ -39,9 +35,7 @@ mcmc:
nsteps: 2000
search:
nwalkers: 50
updates:
iterations_per_update: 2500
remove_state_files_at_end: true

nest:
DynestyDynamic:
initialize:
Expand Down Expand Up @@ -72,9 +66,7 @@ nest:
walks: 25
settings:
stagger_resampling_likelihood: false
updates:
iterations_per_update: 2500
remove_state_files_at_end: true

DynestyStatic:
initialize:
method: prior
Expand Down Expand Up @@ -102,6 +94,4 @@ nest:
walks: 5
settings:
stagger_resampling_likelihood: false
updates:
iterations_per_update: 2500
remove_state_files_at_end: true

Loading