@@ -107,7 +107,9 @@ def run_simulation(self, n_jobs=None):
107107
108108 rep_end_time = time .time ()
109109 rep_duration = rep_end_time - rep_start_time
110- self .logger .info (f"Repetition { i_rep + 1 } completed in { rep_duration :.2f} s" )
110+ self .logger .info (
111+ f"Repetition { i_rep + 1 } completed in { rep_duration :.2f} s"
112+ )
111113
112114 else :
113115 self .logger .info (f"Starting parallel execution with n_jobs={ n_jobs } " )
@@ -138,7 +140,9 @@ def save_results(self, output_path: str = "results", file_prefix: str = ""):
138140 "Script" : [self .__class__ .__name__ ],
139141 "Date" : [datetime .now ().strftime ("%Y-%m-%d %H:%M" )],
140142 "Total Runtime (minutes)" : [self .total_runtime / 60 ],
141- "Python Version" : [f"{ sys .version_info .major } .{ sys .version_info .minor } .{ sys .version_info .micro } " ],
143+ "Python Version" : [
144+ f"{ sys .version_info .major } .{ sys .version_info .minor } .{ sys .version_info .micro } "
145+ ],
142146 "Config File" : [self .config_file ],
143147 }
144148 )
@@ -161,7 +165,14 @@ def save_config(self, output_path: str):
161165 self .logger .warning (f"Adding .yaml extension to output path: { output_path } " )
162166
163167 with open (output_path , "w" ) as file :
164- yaml .dump (self .config , file , sort_keys = False , default_flow_style = False , indent = 2 , allow_unicode = True )
168+ yaml .dump (
169+ self .config ,
170+ file ,
171+ sort_keys = False ,
172+ default_flow_style = False ,
173+ indent = 2 ,
174+ allow_unicode = True ,
175+ )
165176
166177 self .logger .info (f"Configuration saved to { output_path } " )
167178
@@ -174,7 +185,9 @@ def _load_config(self, config_path: str) -> Dict[str, Any]:
174185 with open (config_path , "r" ) as file :
175186 config = yaml .safe_load (file )
176187 else :
177- raise ValueError (f"Unsupported config file format: { config_path } . Use .yaml or .yml" )
188+ raise ValueError (
189+ f"Unsupported config file format: { config_path } . Use .yaml or .yml"
190+ )
178191
179192 return config
180193
@@ -198,7 +211,9 @@ def _setup_logging(self, log_level: str, log_file: Optional[str]):
198211 # Console handler
199212 ch = logging .StreamHandler ()
200213 ch .setLevel (level )
201- formatter = logging .Formatter ("%(asctime)s - %(name)s - %(levelname)s - %(message)s" )
214+ formatter = logging .Formatter (
215+ "%(asctime)s - %(name)s - %(levelname)s - %(message)s"
216+ )
202217 ch .setFormatter (formatter )
203218 self .logger .addHandler (ch )
204219
@@ -256,7 +271,9 @@ def _process_repetition(self, i_rep):
256271 dml_params = dict (zip (self .dml_parameters .keys (), dml_param_values ))
257272 i_param_comb += 1
258273
259- comb_results = self ._process_parameter_combination (i_rep , i_param_comb , dgp_params , dml_params , dml_data )
274+ comb_results = self ._process_parameter_combination (
275+ i_rep , i_param_comb , dgp_params , dml_params , dml_data
276+ )
260277
261278 # Merge results
262279 for result_name , result_list in comb_results .items ():
@@ -266,11 +283,14 @@ def _process_repetition(self, i_rep):
266283
267284 return rep_results
268285
269- def _process_parameter_combination (self , i_rep , i_param_comb , dgp_params , dml_params , dml_data ):
286+ def _process_parameter_combination (
287+ self , i_rep , i_param_comb , dgp_params , dml_params , dml_data
288+ ):
270289 """Process a single parameter combination."""
271290 # Log parameter combination
272291 self .logger .debug (
273- f"Rep { i_rep + 1 } , Combo { i_param_comb } /{ self .total_combinations } : " f"DGPs { dgp_params } , DML { dml_params } "
292+ f"Rep { i_rep + 1 } , Combo { i_param_comb } /{ self .total_combinations } : "
293+ f"DGPs { dgp_params } , DML { dml_params } "
274294 )
275295 param_start_time = time .time ()
276296
@@ -279,7 +299,9 @@ def _process_parameter_combination(self, i_rep, i_param_comb, dgp_params, dml_pa
279299
280300 # Log timing
281301 param_duration = time .time () - param_start_time
282- self .logger .debug (f"Parameter combination completed in { param_duration :.2f} s" )
302+ self .logger .debug (
303+ f"Parameter combination completed in { param_duration :.2f} s"
304+ )
283305
284306 # Process results
285307 if repetition_results is None :
@@ -298,7 +320,8 @@ def _process_parameter_combination(self, i_rep, i_param_comb, dgp_params, dml_pa
298320
299321 except Exception as e :
300322 self .logger .error (
301- f"Error: repetition { i_rep + 1 } , DGP parameters { dgp_params } , " f"DML parameters { dml_params } : { str (e )} "
323+ f"Error: repetition { i_rep + 1 } , DGP parameters { dgp_params } , "
324+ f"DML parameters { dml_params } : { str (e )} "
302325 )
303326 self .logger .exception ("Exception details:" )
304327 return {}
@@ -333,9 +356,13 @@ def _compute_coverage(thetas, oracle_thetas, confint, joint_confint=None):
333356 if joint_confint is not None :
334357 joint_lower_bound = joint_confint .iloc [:, 0 ]
335358 joint_upper_bound = joint_confint .iloc [:, 1 ]
336- joint_coverage_mask = (joint_lower_bound < oracle_thetas ) & (oracle_thetas < joint_upper_bound )
359+ joint_coverage_mask = (joint_lower_bound < oracle_thetas ) & (
360+ oracle_thetas < joint_upper_bound
361+ )
337362
338363 result_dict ["Uniform Coverage" ] = np .all (joint_coverage_mask )
339- result_dict ["Uniform CI Length" ] = np .mean (joint_upper_bound - joint_lower_bound )
364+ result_dict ["Uniform CI Length" ] = np .mean (
365+ joint_upper_bound - joint_lower_bound
366+ )
340367
341368 return result_dict
0 commit comments