Skip to content

Commit cf4dc41

Browse files
Jammy2211Jammy2211
authored andcommitted
fix bug in opver ampling
1 parent 6f9aef6 commit cf4dc41

9 files changed

Lines changed: 71 additions & 33 deletions

File tree

autogalaxy/analysis/analysis/analysis.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,3 +127,33 @@ def make_result(
127127
search_internal=search_internal,
128128
analysis=self,
129129
)
130+
131+
def perform_quick_update(self, paths, instance):
132+
"""
133+
Perform a quick visualization update during non-linear search fitting.
134+
135+
This method is called intermittently while the sampler is running to produce
136+
the `subplot+fit` plots of the current maximum-likelihood model fit. The intent
137+
is to provide fast feedback (without waiting for the full run to complete) so that
138+
users can monitor whether the fit is behaving sensibly.
139+
140+
The plot appears both in a matplotlib window (if running locally) and is also saved to the
141+
`output` folder of the output path.
142+
143+
Parameters
144+
----------
145+
paths : af.DirectoryPaths
146+
Object describing the output folder structure where visualization files
147+
should be written.
148+
instance : model instance
149+
The current maximum-likelihood instance of the model, used to generate
150+
the visualization plots.
151+
"""
152+
153+
self.Visualizer().visualize(
154+
analysis=self,
155+
paths=paths,
156+
instance=instance,
157+
during_analysis=True,
158+
quick_update=True,
159+
)

autogalaxy/analysis/plotter_interface.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def mat_plot_1d_from(self) -> MatPlot1D:
9090
output=aplt.Output(path=self.image_path, format=self.fmt),
9191
)
9292

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

108109
def galaxies(

autogalaxy/imaging/model/plotter_interface.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ def should_plot(name):
139139
def fit_imaging(
140140
self,
141141
fit: FitImaging,
142+
quick_update: bool = False
142143
):
143144
"""
144145
Visualizes a `FitImaging` object, which fits an imaging dataset.
@@ -169,9 +170,12 @@ def should_plot(name):
169170
mat_plot_2d=mat_plot_2d,
170171
)
171172

172-
if should_plot("subplot_fit"):
173+
if should_plot("subplot_fit") or quick_update:
173174
fit_plotter.subplot_fit()
174175

176+
if quick_update:
177+
return
178+
175179
if should_plot("subplot_of_galaxies"):
176180
fit_plotter.subplot_of_galaxies()
177181

autogalaxy/imaging/model/visualizer.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ def visualize(
4646
paths: af.DirectoryPaths,
4747
instance: af.ModelInstance,
4848
during_analysis: bool,
49+
quick_update: bool = False,
4950
):
5051
"""
5152
Output images of the maximum log likelihood model inferred by the model-fit. This function is called throughout
@@ -78,13 +79,16 @@ def visualize(
7879
plotter = PlotterInterfaceImaging(
7980
image_path=paths.image_path, title_prefix=analysis.title_prefix
8081
)
81-
plotter.imaging(dataset=analysis.dataset)
82+
# Quick Update only, skips everything after
8283

8384
try:
84-
plotter.fit_imaging(fit=fit)
85+
plotter.fit_imaging(fit=fit, quick_update=quick_update)
8586
except exc.InversionException:
8687
pass
8788

89+
if quick_update:
90+
return
91+
8892
galaxies = fit.galaxies_linear_light_profiles_to_light_profiles
8993

9094
plotter.galaxies(galaxies=galaxies, grid=fit.grids.lp)

autogalaxy/interferometer/model/plotter_interface.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ def should_plot(name):
131131
def fit_interferometer(
132132
self,
133133
fit: FitInterferometer,
134+
quick_update : bool = False,
134135
):
135136
"""
136137
Visualizes a `FitInterferometer` object, which fits an interferometer dataset.
@@ -163,12 +164,15 @@ def should_plot(name):
163164
mat_plot_2d=mat_plot_2d,
164165
)
165166

166-
if should_plot("subplot_fit"):
167+
if should_plot("subplot_fit") or quick_update:
167168
fit_plotter.subplot_fit()
168169

169-
if should_plot("subplot_fit_dirty_images"):
170+
if should_plot("subplot_fit_dirty_images") or quick_update:
170171
fit_plotter.subplot_fit_dirty_images()
171172

173+
if quick_update:
174+
return
175+
172176
if should_plot("subplot_fit_real_space"):
173177
fit_plotter.subplot_fit_real_space()
174178

autogalaxy/interferometer/model/visualizer.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ def visualize(
4343
paths: af.DirectoryPaths,
4444
instance: af.ModelInstance,
4545
during_analysis: bool,
46+
quick_update: bool = False,
4647
):
4748
"""
4849
Outputs images of the maximum log likelihood model inferred by the model-fit. This function is called
@@ -75,28 +76,30 @@ def visualize(
7576
"""
7677
fit = analysis.fit_from(instance=instance)
7778

78-
PlotterInterface = PlotterInterfaceInterferometer(
79+
plotter_interface = PlotterInterfaceInterferometer(
7980
image_path=paths.image_path, title_prefix=analysis.title_prefix
8081
)
81-
PlotterInterface.interferometer(dataset=analysis.interferometer)
82+
83+
try:
84+
plotter_interface.fit_interferometer(
85+
fit=fit, quick_update=quick_update,
86+
)
87+
except exc.InversionException:
88+
pass
89+
90+
if quick_update:
91+
return
8292

8393
galaxies = fit.galaxies_linear_light_profiles_to_light_profiles
8494

85-
PlotterInterface.galaxies(
95+
plotter_interface.galaxies(
8696
galaxies=galaxies,
8797
grid=fit.grids.lp,
8898
)
8999

90-
try:
91-
PlotterInterface.fit_interferometer(
92-
fit=fit,
93-
)
94-
except exc.InversionException:
95-
pass
96-
97100
if fit.inversion is not None:
98101
try:
99-
PlotterInterface.inversion(
102+
plotter_interface.inversion(
100103
inversion=fit.inversion,
101104
)
102105
except IndexError:

autogalaxy/plot/mat_plot/two_d.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ def __init__(
5050
tangential_caustics_plot: Optional[w.TangentialCausticsPlot] = None,
5151
radial_caustics_plot: Optional[w.RadialCausticsPlot] = None,
5252
use_log10: bool = False,
53+
quick_update : bool = False
5354
):
5455
"""
5556
Visualizes data structures (e.g an `Array2D`, `Grid2D`, `VectorField`, etc.) using Matplotlib.
@@ -215,4 +216,5 @@ def __init__(
215216
delaunay_drawer=delaunay_drawer,
216217
voronoi_drawer=voronoi_drawer,
217218
use_log10=use_log10,
219+
quick_update=quick_update,
218220
)

test_autogalaxy/config/general.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ inversion:
1414
use_border_relocator: false # If True, by default a pixelization's border is used to relocate all pixels outside its border to the border.
1515
hpc:
1616
hpc_mode: false
17-
iterations_per_update: 5000
17+
iterations_per_full_update: 5000
1818
adapt:
1919
adapt_minimum_percent: 0.01
2020
adapt_noise_limit: 100000000.0

test_autogalaxy/config/non_linear.yaml

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,14 @@ mock:
44
method: prior
55
printing:
66
silence: false
7-
updates:
8-
iterations_per_update: 2500
9-
remove_state_files_at_end: true
7+
108
MockSearch:
119
initialize:
1210
method: prior
1311
printing:
1412
silence: false
1513
search: {}
16-
updates:
17-
iterations_per_update: 2500
18-
remove_state_files_at_end: true
14+
1915
GridSearch:
2016
general:
2117
number_of_cores: 2
@@ -39,9 +35,7 @@ mcmc:
3935
nsteps: 2000
4036
search:
4137
nwalkers: 50
42-
updates:
43-
iterations_per_update: 2500
44-
remove_state_files_at_end: true
38+
4539
nest:
4640
DynestyDynamic:
4741
initialize:
@@ -72,9 +66,7 @@ nest:
7266
walks: 25
7367
settings:
7468
stagger_resampling_likelihood: false
75-
updates:
76-
iterations_per_update: 2500
77-
remove_state_files_at_end: true
69+
7870
DynestyStatic:
7971
initialize:
8072
method: prior
@@ -102,6 +94,4 @@ nest:
10294
walks: 5
10395
settings:
10496
stagger_resampling_likelihood: false
105-
updates:
106-
iterations_per_update: 2500
107-
remove_state_files_at_end: true
97+

0 commit comments

Comments
 (0)