From 454120ee2a55be37c4ed13330590c744df4d4d83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mika=20M=C3=A4ki?= Date: Mon, 9 Dec 2024 18:14:43 +0200 Subject: [PATCH] Reduce log spam --- examples/giese_lisa_fig2.py | 2 +- pttools/analysis/parallel.py | 2 +- pttools/bubble/fluid_reference.py | 2 +- pttools/models/analytic.py | 9 +++++---- pttools/models/const_cs.py | 15 +++++++++------ pttools/models/model.py | 20 +++++++++++--------- pttools/speedup/parallel.py | 4 ++-- 7 files changed, 30 insertions(+), 24 deletions(-) diff --git a/examples/giese_lisa_fig2.py b/examples/giese_lisa_fig2.py index 0c9f0ef9..a2209775 100644 --- a/examples/giese_lisa_fig2.py +++ b/examples/giese_lisa_fig2.py @@ -82,7 +82,7 @@ def kappas_giese( multiple_params=True, # output_dtypes=(float, ), # max_workers=max_workers, - log_progress_percentage=True, + log_progress_percentage=20, kwargs={"model": model} ) return kappas diff --git a/pttools/analysis/parallel.py b/pttools/analysis/parallel.py index a198d304..006bb70d 100644 --- a/pttools/analysis/parallel.py +++ b/pttools/analysis/parallel.py @@ -88,7 +88,7 @@ def create_bubbles( v_walls: np.ndarray, alpha_ns: np.ndarray, func: callable = None, - log_progress_percentage: float = 5, + log_progress_percentage: float = 10, max_workers: int = options.MAX_WORKERS_DEFAULT, allow_bubble_failure: bool = False, kwargs: tp.Dict[str, any] = None, diff --git a/pttools/bubble/fluid_reference.py b/pttools/bubble/fluid_reference.py index 1b47c247..ff1863f9 100644 --- a/pttools/bubble/fluid_reference.py +++ b/pttools/bubble/fluid_reference.py @@ -100,7 +100,7 @@ def create( multiple_params=True, unpack_params=True, output_dtypes=(np.int_, np.float64, np.float64, np.float64, np.float64, np.float64, np.float64), - log_progress_percentage=5 + log_progress_percentage=10 ) file.create_dataset("v_wall", data=v_walls) file.create_dataset("alpha_n", data=alpha_ns) diff --git a/pttools/models/analytic.py b/pttools/models/analytic.py index 9266659d..c6aef7fc 100644 --- a/pttools/models/analytic.py +++ b/pttools/models/analytic.py @@ -45,8 +45,9 @@ def __init__( gen_cs2: bool = True, gen_cs2_neg: bool = True, allow_invalid: bool = False, - auto_potential: bool = False): - if V_b != 0: + auto_potential: bool = False, + log_info: bool = True): + if log_info and V_b != 0: logger.warning( "Got V_b = %s != 0. This may result in inaccurate results with the GW spectrum computation, " "as the GW spectrum equations presume V_b = 0.", V_b) @@ -75,9 +76,9 @@ def __init__( T_min=T_min, T_max=T_max, T_crit_guess=T_crit_guess, name=name, label_latex=label_latex, label_unicode=label_unicode, gen_critical=gen_critical, gen_cs2=gen_cs2, gen_cs2_neg=gen_cs2_neg, - allow_invalid=allow_invalid + allow_invalid=allow_invalid, log_info=log_info ) - if self.a_s <= self.a_b: + if log_info and self.a_s <= self.a_b: logger.warning( f"The model \"{self.name}\" does not satisfy a_s > a_b. " "Please check that the critical temperature is non-negative. " diff --git a/pttools/models/const_cs.py b/pttools/models/const_cs.py index fe247246..49ec9ed6 100644 --- a/pttools/models/const_cs.py +++ b/pttools/models/const_cs.py @@ -60,7 +60,8 @@ def __init__( name: str = None, label_latex: str = None, label_unicode: str = None, - allow_invalid: bool = False): + allow_invalid: bool = False, + log_info: bool = True): # Ensure that these descriptions correspond to those in the base class r""" :param a_s: prefactor of $p$ in the symmetric phase. The convention is as in :notes:`\ ` eq. 7.33. @@ -72,7 +73,8 @@ def __init__( :param T_ref: reference temperature, usually 1 * unit of choice, e,g. 1 GeV :param name: custom name for the model """ - logger.debug(f"Initialising ConstCSModel with css2={css2}, csb2={csb2}.") + if log_info: + logger.debug(f"Initialising ConstCSModel with css2={css2}, csb2={csb2}.") css2_flt, css2_label = cs2_to_float_and_label(css2) csb2_flt, csb2_label = cs2_to_float_and_label(csb2) self.css2 = self.validate_cs2(css2_flt, "css2") @@ -83,7 +85,7 @@ def __init__( "c_{s,s}^2 and c_{s,b}^2 have to be 0 < c_s <= 1." f"Got: c_{{s,s}}^2={css2}, c_{{s,b}}^2={csb2}." ) - if css2_flt > 1/3 or csb2_flt > 1/3: + if log_info and css2_flt > 1/3 or csb2_flt > 1/3: logger.warning( "c_{s,s}^2 > 1/3 or c_{s,b}^2 > 1/3. " "Please ensure that g_eff is monotonic in your model. " @@ -122,7 +124,8 @@ def __init__( g_s=g_s, g_b=g_b, T_min=T_min, T_max=T_max, T_crit_guess=T_crit_guess, name=name, label_latex=label_latex, label_unicode=label_unicode, - allow_invalid=allow_invalid + allow_invalid=allow_invalid, + log_info=log_info ) # This can only be set after self.a_s and self.a_b are set. # This seems to contain invalid assumptions and approximations. @@ -304,7 +307,7 @@ def alpha_n_min_find_params( # --- # Solve numerically # --- - model = ConstCSModel(css2=self.css2, csb2=self.csb2, a_s=a_s_default, a_b=a_b, V_s=V_s_default) + model = ConstCSModel(css2=self.css2, csb2=self.csb2, a_s=a_s_default, a_b=a_b, V_s=V_s_default, log_info=False) # If we are already below the target if model.alpha_n_min < alpha_n_min_target: return a_s_default, a_b, V_s_default, V_b @@ -380,7 +383,7 @@ def alpha_n_min_find_params_solvable( css2: float, csb2: float, alpha_n_target: float): try: - model = ConstCSModel(css2=css2, csb2=csb2, a_s=a_s, a_b=a_b, V_s=V_s, V_b=V_b) + model = ConstCSModel(css2=css2, csb2=csb2, a_s=a_s, a_b=a_b, V_s=V_s, V_b=V_b, log_info=False) except (ValueError, RuntimeError): return np.nan diff = model.alpha_n_min - alpha_n_target diff --git a/pttools/models/model.py b/pttools/models/model.py index c1c567ea..dcadb71e 100644 --- a/pttools/models/model.py +++ b/pttools/models/model.py @@ -44,9 +44,10 @@ def __init__( gen_cs2_neg: bool = True, implicit_V: bool = False, temperature_is_physical: bool = None, - allow_invalid: bool = False): + allow_invalid: bool = False, + log_info: bool = True): - if implicit_V: + if log_info and implicit_V: if V_s != 0 or V_b != 0: logger.warning( "Potentials have been specified for the implicit model: %s. " @@ -98,7 +99,7 @@ def __init__( if gen_critical: # w_crit = wn_max - self.T_crit, self.w_crit = self.criticals(T_crit_guess, allow_invalid) + self.T_crit, self.w_crit = self.criticals(T_crit_guess, allow_fail=allow_invalid, log_info=log_info) self.w_at_alpha_n_min, self.alpha_n_min = self.alpha_n_min_find() # Concrete methods @@ -451,12 +452,13 @@ def criticals(self, t_crit_guess: float, allow_fail: bool = False, log_info: boo wn_min = self.w(t_crit, Phase.SYMMETRIC) alpha_n_at_wn_min = self.alpha_n(wn_min) - logger.info( - f"Initialized model with name={self.name}, T_crit={t_crit}, alpha_n_at_wn_min={alpha_n_at_wn_min}. " - f"At T_crit: w_s={wn_min}, w_b={self.w(t_crit, Phase.BROKEN)}, " - f"e_s={self.e_temp(t_crit, Phase.SYMMETRIC)}, e_b={self.e_temp(t_crit, Phase.BROKEN)}, " - f"p_s={self.p_temp(t_crit, Phase.SYMMETRIC)}, p_b={self.p_temp(t_crit, Phase.BROKEN)}" - ) + if log_info: + logger.info( + f"Initialised model with name={self.name}, T_crit={t_crit}, alpha_n_at_wn_min={alpha_n_at_wn_min}. " + f"At T_crit: w_s={wn_min}, w_b={self.w(t_crit, Phase.BROKEN)}, " + f"e_s={self.e_temp(t_crit, Phase.SYMMETRIC)}, e_b={self.e_temp(t_crit, Phase.BROKEN)}, " + f"p_s={self.p_temp(t_crit, Phase.SYMMETRIC)}, p_b={self.p_temp(t_crit, Phase.BROKEN)}" + ) return t_crit, wn_min def critical_temp( diff --git a/pttools/speedup/parallel.py b/pttools/speedup/parallel.py index 3876cee5..624440a8 100644 --- a/pttools/speedup/parallel.py +++ b/pttools/speedup/parallel.py @@ -51,9 +51,9 @@ def run(self, param, index: int = None, multi_index: tp.Iterable = None): np.floor(percentage / self.log_progress_percentage) != np.floor( percentage_prev / self.log_progress_percentage)): if multi_index is None: - logger.debug("Processed item %s/%s, %s %%", index, self.arr_size, percentage) + logger.debug("Processed item %d/%d, %.2f %%", index, self.arr_size, percentage) else: - logger.debug("Processed item %s, %s/%s, %s %%", multi_index, index, self.arr_size, percentage) + logger.debug("Processed item %s, %d/%d, %.2f %%", multi_index, index, self.arr_size, percentage) return ret