Skip to content

Commit

Permalink
profiling_dict -> run_time_dict
Browse files Browse the repository at this point in the history
  • Loading branch information
Jammy2211 committed Jun 11, 2023
1 parent 5a2fa54 commit 986ace5
Show file tree
Hide file tree
Showing 12 changed files with 70 additions and 70 deletions.
28 changes: 14 additions & 14 deletions autogalaxy/analysis/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def __init__(self, cosmology: LensingCosmology = Planck15):
self.cosmology = cosmology

def plane_via_instance_from(
self, instance: af.ModelInstance, profiling_dict: Optional[Dict] = None
self, instance: af.ModelInstance, run_time_dict: Optional[Dict] = None
) -> Plane:
"""
Create a `Plane` from the galaxies contained in a model instance.
Expand All @@ -62,9 +62,9 @@ def plane_via_instance_from(
if hasattr(instance, "clumps"):
return Plane(
galaxies=instance.galaxies + instance.clumps,
profiling_dict=profiling_dict,
run_time_dict=run_time_dict,
)
return Plane(galaxies=instance.galaxies, profiling_dict=profiling_dict)
return Plane(galaxies=instance.galaxies, run_time_dict=run_time_dict)

@property
def fit_func(self) -> Callable:
Expand All @@ -77,7 +77,7 @@ def profile_log_likelihood_function(
This function is optionally called throughout a model-fit to profile the log likelihood function.
All function calls inside the `log_likelihood_function` that are decorated with the `profile_func` are timed
with their times stored in a dictionary called the `profiling_dict`.
with their times stored in a dictionary called the `run_time_dict`.
An `info_dict` is also created which stores information on aspects of the model and dataset that dictate
run times, so the profiled times can be interpreted with this context.
Expand All @@ -99,7 +99,7 @@ def profile_log_likelihood_function(
Two dictionaries, the profiling dictionary and info dictionary, which contain the profiling times of the
`log_likelihood_function` and information on the model and dataset used to perform the profiling.
"""
profiling_dict = {}
run_time_dict = {}
info_dict = {}

repeats = conf.instance["general"]["profiling"]["repeats"]
Expand All @@ -122,9 +122,9 @@ def profile_log_likelihood_function(

fit_time = (time.time() - start) / repeats

profiling_dict["fit_time"] = fit_time
run_time_dict["fit_time"] = fit_time

fit = self.fit_func(instance=instance, profiling_dict=profiling_dict)
fit = self.fit_func(instance=instance, run_time_dict=run_time_dict)
fit.figure_of_merit

try:
Expand All @@ -151,27 +151,27 @@ def profile_log_likelihood_function(
] = fit.inversion.w_tilde.curvature_preload.shape[0]

self.output_profiling_info(
paths=paths, profiling_dict=profiling_dict, info_dict=info_dict
paths=paths, run_time_dict=run_time_dict, info_dict=info_dict
)

return profiling_dict, info_dict
return run_time_dict, info_dict

def output_profiling_info(
self, paths: Optional[af.DirectoryPaths], profiling_dict: Dict, info_dict: Dict
self, paths: Optional[af.DirectoryPaths], run_time_dict: Dict, info_dict: Dict
):
"""
Output the log likelihood function profiling information to hard-disk as a json file.
This function is separate from the `profile_log_likelihood_function` function above such that it can be
called by children `Analysis` classes that profile additional aspects of the model-fit and therefore add
extra information to the `profiling_dict` and `info_dict`.
extra information to the `run_time_dict` and `info_dict`.
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.
profiling_dict
run_time_dict
A dictionary containing the profiling times of the functions called by the `log_likelihood_function`.
info_dict
A dictionary containing information on the model and dataset used to perform the profiling, where these
Expand All @@ -183,8 +183,8 @@ def output_profiling_info(

os.makedirs(paths.profile_path, exist_ok=True)

with open(path.join(paths.profile_path, "profiling_dict.json"), "w+") as f:
json.dump(profiling_dict, f, indent=4)
with open(path.join(paths.profile_path, "run_time_dict.json"), "w+") as f:
json.dump(run_time_dict, f, indent=4)

with open(path.join(paths.profile_path, "info_dict.json"), "w+") as f:
json.dump(info_dict, f, indent=4)
Expand Down
12 changes: 6 additions & 6 deletions autogalaxy/imaging/fit_imaging.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def __init__(
settings_pixelization: aa.SettingsPixelization = aa.SettingsPixelization(),
settings_inversion: aa.SettingsInversion = aa.SettingsInversion(),
preloads: aa.Preloads = Preloads(),
profiling_dict: Optional[Dict] = None,
run_time_dict: Optional[Dict] = None,
):
"""
Fits an imaging dataset using a `Plane` object.
Expand Down Expand Up @@ -65,7 +65,7 @@ def __init__(
preloads
Contains preloaded calculations (e.g. linear algebra matrices) which can skip certain calculations in
the fit.
profiling_dict
run_time_dict
A dictionary which if passed to the fit records how long fucntion calls which have the `profile_func`
decorator take to run.
"""
Expand All @@ -75,7 +75,7 @@ def __init__(

super().__init__(
dataset=dataset,
profiling_dict=profiling_dict,
run_time_dict=run_time_dict,
)
AbstractFitInversion.__init__(
self=self, model_obj=plane, settings_inversion=settings_inversion
Expand Down Expand Up @@ -145,7 +145,7 @@ def plane_to_inversion(self) -> PlaneToInversion:
settings_pixelization=self.settings_pixelization,
settings_inversion=self.settings_inversion,
preloads=self.preloads,
profiling_dict=self.profiling_dict,
run_time_dict=self.run_time_dict,
)

@cached_property
Expand Down Expand Up @@ -305,7 +305,7 @@ def refit_with_new_preloads(
-------
A new fit which has used new preloads input into this function but the same dataset, plane and other settings.
"""
profiling_dict = {} if self.profiling_dict is not None else None
run_time_dict = {} if self.run_time_dict is not None else None

settings_inversion = (
self.settings_inversion
Expand All @@ -319,5 +319,5 @@ def refit_with_new_preloads(
settings_pixelization=self.settings_pixelization,
settings_inversion=settings_inversion,
preloads=preloads,
profiling_dict=profiling_dict,
run_time_dict=run_time_dict,
)
22 changes: 11 additions & 11 deletions autogalaxy/imaging/model/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def fit_imaging_via_instance_from(
self,
instance: af.ModelInstance,
preload_overwrite: Optional[Preloads] = None,
profiling_dict: Optional[Dict] = None,
run_time_dict: Optional[Dict] = None,
) -> FitImaging:
"""
Given a model instance create a `FitImaging` object.
Expand All @@ -166,7 +166,7 @@ def fit_imaging_via_instance_from(
via a non-linear search).
preload_overwrite
If a `Preload` object is input this is used instead of the preloads stored as an attribute in the analysis.
profiling_dict
run_time_dict
A dictionary which times functions called to fit the model to data, for profiling.
Returns
Expand All @@ -177,20 +177,20 @@ def fit_imaging_via_instance_from(
instance = self.instance_with_associated_adapt_images_from(instance=instance)

plane = self.plane_via_instance_from(
instance=instance, profiling_dict=profiling_dict
instance=instance, run_time_dict=run_time_dict
)

return self.fit_imaging_via_plane_from(
plane=plane,
preload_overwrite=preload_overwrite,
profiling_dict=profiling_dict,
run_time_dict=run_time_dict,
)

def fit_imaging_via_plane_from(
self,
plane: Plane,
preload_overwrite: Optional[Preloads] = None,
profiling_dict: Optional[Dict] = None,
run_time_dict: Optional[Dict] = None,
) -> FitImaging:
"""
Given a `Plane`, which the analysis constructs from a model instance, create a `FitImaging` object.
Expand All @@ -204,7 +204,7 @@ def fit_imaging_via_plane_from(
The plane of galaxies whose model images are used to fit the imaging data.
preload_overwrite
If a `Preload` object is input this is used instead of the preloads stored as an attribute in the analysis.
profiling_dict
run_time_dict
A dictionary which times functions called to fit the model to data, for profiling.
Returns
Expand All @@ -221,7 +221,7 @@ def fit_imaging_via_plane_from(
settings_pixelization=self.settings_pixelization,
settings_inversion=self.settings_inversion,
preloads=preloads,
profiling_dict=profiling_dict,
run_time_dict=run_time_dict,
)

@property
Expand Down Expand Up @@ -410,7 +410,7 @@ def profile_log_likelihood_function(
This function is optionally called throughout a model-fit to profile the log likelihood function.
All function calls inside the `log_likelihood_function` that are decorated with the `profile_func` are timed
with their times stored in a dictionary called the `profiling_dict`.
with their times stored in a dictionary called the `run_time_dict`.
An `info_dict` is also created which stores information on aspects of the model and dataset that dictate
run times, so the profiled times can be interpreted with this context.
Expand All @@ -432,14 +432,14 @@ def profile_log_likelihood_function(
Two dictionaries, the profiling dictionary and info dictionary, which contain the profiling times of the
`log_likelihood_function` and information on the model and dataset used to perform the profiling.
"""
profiling_dict, info_dict = super().profile_log_likelihood_function(
run_time_dict, info_dict = super().profile_log_likelihood_function(
instance=instance,
)

info_dict["psf_shape_2d"] = self.dataset.psf.shape_native

self.output_profiling_info(
paths=paths, profiling_dict=profiling_dict, info_dict=info_dict
paths=paths, run_time_dict=run_time_dict, info_dict=info_dict
)

return profiling_dict, info_dict
return run_time_dict, info_dict
14 changes: 7 additions & 7 deletions autogalaxy/interferometer/fit_interferometer.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def __init__(
settings_pixelization: aa.SettingsPixelization = aa.SettingsPixelization(),
settings_inversion: aa.SettingsInversion = aa.SettingsInversion(),
preloads: aa.Preloads = Preloads(),
profiling_dict: Optional[Dict] = None,
run_time_dict: Optional[Dict] = None,
):
"""
Fits an interferometer dataset using a `Plane` object.
Expand Down Expand Up @@ -61,7 +61,7 @@ def __init__(
preloads
Contains preloaded calculations (e.g. linear algebra matrices) which can skip certain calculations in
the fit.
profiling_dict
run_time_dict
A dictionary which if passed to the fit records how long fucntion calls which have the `profile_func`
decorator take to run.
"""
Expand All @@ -72,7 +72,7 @@ def __init__(
settings_inversion.use_w_tilde = False

super().__init__(
dataset=dataset, use_mask_in_fit=False, profiling_dict=profiling_dict
dataset=dataset, use_mask_in_fit=False, run_time_dict=run_time_dict
)
AbstractFitInversion.__init__(
self=self, model_obj=plane, settings_inversion=settings_inversion
Expand Down Expand Up @@ -241,10 +241,10 @@ def refit_with_new_preloads(
-------
A new fit which has used new preloads input into this function but the same dataset, plane and other settings.
"""
if self.profiling_dict is not None:
profiling_dict = {}
if self.run_time_dict is not None:
run_time_dict = {}
else:
profiling_dict = None
run_time_dict = None

if settings_inversion is None:
settings_inversion = self.settings_inversion
Expand All @@ -255,5 +255,5 @@ def refit_with_new_preloads(
settings_pixelization=self.settings_pixelization,
settings_inversion=settings_inversion,
preloads=preloads,
profiling_dict=profiling_dict,
run_time_dict=run_time_dict,
)
20 changes: 10 additions & 10 deletions autogalaxy/interferometer/model/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ def log_likelihood_function(self, instance: af.ModelInstance) -> float:
def fit_interferometer_via_instance_from(
self,
instance: af.ModelInstance,
profiling_dict: Optional[Dict] = None,
run_time_dict: Optional[Dict] = None,
) -> FitInterferometer:
"""
Given a model instance create a `FitInterferometer` object.
Expand All @@ -174,7 +174,7 @@ def fit_interferometer_via_instance_from(
via a non-linear search).
preload_overwrite
If a `Preload` object is input this is used instead of the preloads stored as an attribute in the analysis.
profiling_dict
run_time_dict
A dictionary which times functions called to fit the model to data, for profiling.
Returns
Expand All @@ -185,18 +185,18 @@ def fit_interferometer_via_instance_from(
instance = self.instance_with_associated_adapt_images_from(instance=instance)

plane = self.plane_via_instance_from(
instance=instance, profiling_dict=profiling_dict
instance=instance, run_time_dict=run_time_dict
)

return self.fit_interferometer_via_plane_from(
plane=plane, profiling_dict=profiling_dict
plane=plane, run_time_dict=run_time_dict
)

def fit_interferometer_via_plane_from(
self,
plane: Plane,
preload_overwrite: Optional[Preloads] = None,
profiling_dict: Optional[Dict] = None,
run_time_dict: Optional[Dict] = None,
) -> FitInterferometer:
"""
Given a `Plane`, which the analysis constructs from a model instance, create a `FitInterferometer` object.
Expand All @@ -223,7 +223,7 @@ def fit_interferometer_via_plane_from(
settings_pixelization=self.settings_pixelization,
settings_inversion=self.settings_inversion,
preloads=preloads,
profiling_dict=profiling_dict,
run_time_dict=run_time_dict,
)

@property
Expand Down Expand Up @@ -417,7 +417,7 @@ def profile_log_likelihood_function(
This function is optionally called throughout a model-fit to profile the log likelihood function.
All function calls inside the `log_likelihood_function` that are decorated with the `profile_func` are timed
with their times stored in a dictionary called the `profiling_dict`.
with their times stored in a dictionary called the `run_time_dict`.
An `info_dict` is also created which stores information on aspects of the model and dataset that dictate
run times, so the profiled times can be interpreted with this context.
Expand All @@ -439,15 +439,15 @@ def profile_log_likelihood_function(
Two dictionaries, the profiling dictionary and info dictionary, which contain the profiling times of the
`log_likelihood_function` and information on the model and dataset used to perform the profiling.
"""
profiling_dict, info_dict = super().profile_log_likelihood_function(
run_time_dict, info_dict = super().profile_log_likelihood_function(
instance=instance,
)

info_dict["number_of_visibilities"] = self.dataset.visibilities.shape[0]
info_dict["transformer_cls"] = self.dataset.transformer.__class__.__name__

self.output_profiling_info(
paths=paths, profiling_dict=profiling_dict, info_dict=info_dict
paths=paths, run_time_dict=run_time_dict, info_dict=info_dict
)

return profiling_dict, info_dict
return run_time_dict, info_dict
4 changes: 2 additions & 2 deletions autogalaxy/plane/plane.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def __init__(
self,
galaxies,
redshift: Optional[float] = None,
profiling_dict: Optional[Dict] = None,
run_time_dict: Optional[Dict] = None,
):
"""
A plane of galaxies where all galaxies are at the same redshift.
Expand Down Expand Up @@ -52,7 +52,7 @@ def __init__(
self.redshift = redshift
self.galaxies = galaxies

self.profiling_dict = profiling_dict
self.run_time_dict = run_time_dict

def dict(self) -> Dict:
plane_dict = super().dict()
Expand Down
4 changes: 2 additions & 2 deletions autogalaxy/plane/plane_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ def galaxies_in_redshift_ordered_planes_from(galaxies, plane_redshifts):
return galaxies_in_redshift_ordered_planes


def planes_via_galaxies_from(galaxies, profiling_dict=None, plane_cls=Plane):
def planes_via_galaxies_from(galaxies, run_time_dict=None, plane_cls=Plane):
plane_redshifts = ordered_plane_redshifts_from(galaxies=galaxies)

galaxies_in_planes = galaxies_in_redshift_ordered_planes_from(
Expand All @@ -221,7 +221,7 @@ def planes_via_galaxies_from(galaxies, profiling_dict=None, plane_cls=Plane):
for plane_index in range(0, len(plane_redshifts)):
planes.append(
plane_cls(
galaxies=galaxies_in_planes[plane_index], profiling_dict=profiling_dict
galaxies=galaxies_in_planes[plane_index], run_time_dict=run_time_dict
)
)

Expand Down
Loading

0 comments on commit 986ace5

Please sign in to comment.