@@ -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 )
0 commit comments