Skip to content

Commit dd748d4

Browse files
authored
Merge pull request #241 from Jammy2211/feature/jax_remove_profiling
Feature/jax remove profiling
2 parents b8ad1ba + 52e4c89 commit dd748d4

89 files changed

Lines changed: 667 additions & 1444 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.

autogalaxy/__init__.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
from autoconf.dictable import register_parser
2+
from autofit import conf
3+
4+
conf.instance.register(__file__)
5+
16
from autoconf.dictable import from_dict, from_json, output_to_json, to_dict
27
from autoarray.dataset import preprocess # noqa
38
from autoarray.dataset.imaging.dataset import Imaging # noqa
@@ -112,6 +117,4 @@
112117
from autoconf.fitsable import output_to_fits
113118
from autoconf.fitsable import hdu_list_for_output_from
114119

115-
conf.instance.register(__file__)
116-
117120
__version__ = "2025.5.10.1"

autogalaxy/aggregator/agg_util.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ def adapt_images_from(
140140

141141
galaxy_name_image_dict[value.header["EXTNAME"].lower()] = adapt_image
142142

143-
instance = fit.model.instance_from_prior_medians(ignore_prior_limits=True)
143+
instance = fit.model.instance_from_prior_medians(ignore_assertions=True)
144144

145145
adapt_images = AdaptImages(galaxy_name_image_dict=galaxy_name_image_dict)
146146

autogalaxy/analysis/analysis/analysis.py

Lines changed: 3 additions & 135 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ def __init__(self, cosmology: LensingCosmology = Planck15):
3737
self.cosmology = cosmology
3838

3939
def galaxies_via_instance_from(
40-
self, instance: af.ModelInstance, run_time_dict: Optional[Dict] = None
40+
self,
41+
instance: af.ModelInstance,
4142
) -> List[Galaxy]:
4243
"""
4344
Create a list of galaxies from a model instance, which is used to fit the dataset.
@@ -60,10 +61,9 @@ def galaxies_via_instance_from(
6061
if getattr(instance, "extra_galaxies", None) is not None:
6162
return Galaxies(
6263
galaxies=instance.galaxies + instance.extra_galaxies,
63-
run_time_dict=run_time_dict,
6464
)
6565

66-
return Galaxies(galaxies=instance.galaxies, run_time_dict=run_time_dict)
66+
return Galaxies(galaxies=instance.galaxies)
6767

6868
def dataset_model_via_instance_from(
6969
self, instance: af.ModelInstance
@@ -126,135 +126,3 @@ def make_result(
126126
search_internal=search_internal,
127127
analysis=self,
128128
)
129-
130-
def profile_log_likelihood_function(
131-
self, instance: af.ModelInstance, paths: Optional[af.DirectoryPaths] = None
132-
) -> Tuple[Dict, Dict]:
133-
"""
134-
This function is optionally called throughout a model-fit to profile the log likelihood function.
135-
136-
All function calls inside the `log_likelihood_function` that are decorated with the `profile_func` are timed
137-
with their times stored in a dictionary called the `run_time_dict`.
138-
139-
An `info_dict` is also created which stores information on aspects of the model and dataset that dictate
140-
run times, so the profiled times can be interpreted with this context.
141-
142-
The results of this profiling are then output to hard-disk in the `profiling` folder of the model-fit results,
143-
which they can be inspected to ensure run-times are as expected.
144-
145-
Parameters
146-
----------
147-
instance
148-
An instance of the model that is being fitted to the data by this analysis (whose parameters have been set
149-
via a non-linear search).
150-
paths
151-
The paths object which manages all paths, e.g. where the non-linear search outputs are stored,
152-
visualization and the pickled objects used by the aggregator output by this function.
153-
154-
Returns
155-
-------
156-
Two dictionaries, the profiling dictionary and info dictionary, which contain the profiling times of the
157-
`log_likelihood_function` and information on the model and dataset used to perform the profiling.
158-
"""
159-
160-
if isinstance(paths, af.DatabasePaths):
161-
return
162-
163-
run_time_dict = {}
164-
info_dict = {}
165-
166-
repeats = conf.instance["general"]["profiling"]["repeats"]
167-
info_dict["repeats"] = repeats
168-
169-
# Ensure numba functions are compiled before profiling begins.
170-
171-
fit = self.fit_from(instance=instance)
172-
fit.figure_of_merit
173-
174-
start = time.time()
175-
176-
for _ in range(repeats):
177-
try:
178-
fit = self.fit_from(instance=instance)
179-
fit.figure_of_merit
180-
except Exception:
181-
logger.info(
182-
"Profiling failed. Returning without outputting information."
183-
)
184-
return
185-
186-
fit_time = (time.time() - start) / repeats
187-
188-
run_time_dict["fit_time"] = fit_time
189-
190-
fit = self.fit_from(instance=instance, run_time_dict=run_time_dict)
191-
fit.figure_of_merit
192-
193-
try:
194-
info_dict["image_pixels"] = self.dataset.grids.lp.shape_slim
195-
info_dict["sub_total_light_profiles"] = (
196-
self.dataset.grids.lp.over_sampler.sub_total
197-
)
198-
except AttributeError:
199-
pass
200-
201-
if fit.model_obj.has(cls=aa.Pixelization):
202-
info_dict["use_w_tilde"] = fit.inversion.settings.use_w_tilde
203-
try:
204-
info_dict["sub_total_pixelization"] = (
205-
self.dataset.grids.pixelization.over_sampler.sub_total
206-
)
207-
except AttributeError:
208-
pass
209-
info_dict["use_positive_only_solver"] = (
210-
fit.inversion.settings.use_positive_only_solver
211-
)
212-
info_dict["force_edge_pixels_to_zeros"] = (
213-
fit.inversion.settings.force_edge_pixels_to_zeros
214-
)
215-
info_dict["use_w_tilde_numpy"] = fit.inversion.settings.use_w_tilde_numpy
216-
info_dict["source_pixels"] = len(fit.inversion.reconstruction)
217-
218-
if hasattr(fit.inversion, "w_tilde"):
219-
info_dict["w_tilde_curvature_preload_size"] = (
220-
fit.inversion.w_tilde.curvature_preload.shape[0]
221-
)
222-
223-
self.output_profiling_info(
224-
paths=paths, run_time_dict=run_time_dict, info_dict=info_dict
225-
)
226-
227-
return run_time_dict, info_dict
228-
229-
def output_profiling_info(
230-
self, paths: Optional[af.DirectoryPaths], run_time_dict: Dict, info_dict: Dict
231-
):
232-
"""
233-
Output the log likelihood function profiling information to hard-disk as a json file.
234-
235-
This function is separate from the `profile_log_likelihood_function` function above such that it can be
236-
called by children `Analysis` classes that profile additional aspects of the model-fit and therefore add
237-
extra information to the `run_time_dict` and `info_dict`.
238-
239-
Parameters
240-
----------
241-
paths
242-
The paths object which manages all paths, e.g. where the non-linear search outputs are stored,
243-
visualization and the pickled objects used by the aggregator output by this function.
244-
run_time_dict
245-
A dictionary containing the profiling times of the functions called by the `log_likelihood_function`.
246-
info_dict
247-
A dictionary containing information on the model and dataset used to perform the profiling, where these
248-
settings typically control the overall run-time.
249-
"""
250-
251-
if paths is None:
252-
return
253-
254-
os.makedirs(paths.profile_path, exist_ok=True)
255-
256-
with open(path.join(paths.profile_path, "run_time_dict.json"), "w+") as f:
257-
json.dump(run_time_dict, f, indent=4)
258-
259-
with open(path.join(paths.profile_path, "info_dict.json"), "w+") as f:
260-
json.dump(info_dict, f, indent=4)

autogalaxy/config/general.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
jax:
2+
use_jax: true # If True, uses JAX internally, whereas False uses normal Numpy.
13
fits:
24
flip_for_ds9: true
35
grid:

autogalaxy/config/priors/README.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ They appear as follows:
1313
width_modifier:
1414
type: Absolute
1515
value: 20.0
16-
gaussian_limits:
16+
limits:
1717
lower: -inf
1818
upper: inf
1919
@@ -27,9 +27,9 @@ The sections of this example config set the following:
2727
width_modifier
2828
When the results of a search are passed to a subsequent search to set up the priors of its non-linear search,
2929
this entry describes how the Prior is passed.
30-
gaussian_limits
30+
limits
3131
When the results of a search are passed to a subsequent search, they are passed using a GaussianPrior. The
32-
gaussian_limits set the physical lower and upper limits of this GaussianPrior, such that parameter samples
32+
limits set the physical lower and upper limits of this GaussianPrior, such that parameter samples
3333
can not go beyond these limits.
3434

3535
The files ``template_module.yaml`` and ``TemplateObject.yaml`` give templates one can use to set up prior default

autogalaxy/config/priors/ellipse/ellipse.yaml

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,47 +3,39 @@ Ellipse:
33
type: Gaussian
44
mean: 0.0
55
sigma: 0.3
6-
lower_limit: -inf
7-
upper_limit: inf
86
width_modifier:
97
type: Absolute
108
value: 0.05
11-
gaussian_limits:
9+
limits:
1210
lower: -inf
1311
upper: inf
1412
centre_1:
1513
type: Gaussian
1614
mean: 0.0
1715
sigma: 0.3
18-
lower_limit: -inf
19-
upper_limit: inf
2016
width_modifier:
2117
type: Absolute
2218
value: 0.05
23-
gaussian_limits:
19+
limits:
2420
lower: -inf
2521
upper: inf
2622
ell_comps_0:
2723
type: Gaussian
2824
mean: 0.0
2925
sigma: 0.3
30-
lower_limit: -1.0
31-
upper_limit: 1.0
3226
width_modifier:
3327
type: Absolute
3428
value: 0.2
35-
gaussian_limits:
29+
limits:
3630
lower: -1.0
3731
upper: 1.0
3832
ell_comps_1:
3933
type: Gaussian
4034
mean: 0.0
4135
sigma: 0.3
42-
lower_limit: -1.0
43-
upper_limit: 1.0
4436
width_modifier:
4537
type: Absolute
4638
value: 0.2
47-
gaussian_limits:
39+
limits:
4840
lower: -1.0
4941
upper: 1.0

autogalaxy/config/priors/ellipse/ellipse_multipole.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ EllipseMultipole:
66
width_modifier:
77
type: Absolute
88
value: 0.05
9-
gaussian_limits:
9+
limits:
1010
lower: -inf
1111
upper: inf
1212
multipole_comps_1:
@@ -16,6 +16,6 @@ EllipseMultipole:
1616
width_modifier:
1717
type: Absolute
1818
value: 0.05
19-
gaussian_limits:
19+
limits:
2020
lower: -inf
2121
upper: inf

autogalaxy/config/priors/galaxy/redshift.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ Redshift:
66
width_modifier:
77
type: Absolute
88
value: 1.0
9-
gaussian_limits:
9+
limits:
1010
lower: 0.0
1111
upper: inf

autogalaxy/config/priors/image_mesh/hilbert.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Hilbert:
66
width_modifier:
77
type: Absolute
88
value: 100.0
9-
gaussian_limits:
9+
limits:
1010
lower: 50.0
1111
upper: inf
1212
weight_floor:
@@ -16,7 +16,7 @@ Hilbert:
1616
width_modifier:
1717
type: Absolute
1818
value: 0.1
19-
gaussian_limits:
19+
limits:
2020
lower: 0.0
2121
upper: inf
2222
weight_power:
@@ -26,6 +26,6 @@ Hilbert:
2626
width_modifier:
2727
type: Absolute
2828
value: 5.0
29-
gaussian_limits:
29+
limits:
3030
lower: 0.0
3131
upper: inf

autogalaxy/config/priors/image_mesh/kmeans.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ KMeans:
66
width_modifier:
77
type: Absolute
88
value: 100.0
9-
gaussian_limits:
9+
limits:
1010
lower: 50.0
1111
upper: inf
1212
weight_floor:
@@ -16,7 +16,7 @@ KMeans:
1616
width_modifier:
1717
type: Absolute
1818
value: 0.1
19-
gaussian_limits:
19+
limits:
2020
lower: 0.0
2121
upper: inf
2222
weight_power:
@@ -26,6 +26,6 @@ KMeans:
2626
width_modifier:
2727
type: Absolute
2828
value: 5.0
29-
gaussian_limits:
29+
limits:
3030
lower: 0.0
3131
upper: inf

0 commit comments

Comments
 (0)