diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ca60a4f3..6425f8fc 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -90,11 +90,11 @@ jobs: - name: Running pylint shell: bash -l {0} run: | - pylint --rcfile pylintrc_for_tests --recursive=y tests - pylint --recursive=y firecrown/connector - pylint --recursive=y firecrown/*.py - pylint --recursive=y firecrown/likelihood/*.py - pylint --recursive=y firecrown/likelihood/gauss_family/*.py + pylint --rcfile pylintrc_for_tests tests + pylint --rcfile pylintrc firecrown/connector + pylint --rcfile pylintrc firecrown/*.py + pylint --rcfile pylintrc firecrown/likelihood/*.py + pylint --rcfile pylintrc firecrown/likelihood/gauss_family/*.py - name: Running pytest shell: bash -l {0} diff --git a/examples/des_y1_3x2pt/des_y1_cosmic_shear_TATT.py b/examples/des_y1_3x2pt/des_y1_cosmic_shear_TATT.py index bb30faee..ab2d15fa 100644 --- a/examples/des_y1_3x2pt/des_y1_cosmic_shear_TATT.py +++ b/examples/des_y1_3x2pt/des_y1_cosmic_shear_TATT.py @@ -100,7 +100,7 @@ def run_likelihood() -> None: sacc_data = sacc.Sacc.load_fits(saccfile) src0_tracer = sacc_data.get_tracer("src0") - z, nz = src0_tracer.z, src0_tracer.nz # pylint: disable-msg=invalid-name + z, nz = src0_tracer.z, src0_tracer.nz # Define a ccl.Cosmology object using default parameters ccl_cosmo = ccl.CosmologyVanillaLCDM() @@ -183,7 +183,6 @@ def run_likelihood() -> None: ia_bias=(z, np.ones_like(z)), use_A_ia=False, ) - # pylint: disable=invalid-name cl_GI = ccl.angular_cl(ccl_cosmo, t_lens, t_ia, ells, p_of_k_a=pk_im) cl_II = ccl.angular_cl(ccl_cosmo, t_ia, t_ia, ells, p_of_k_a=pk_ii) # The weak gravitational lensing power spectrum @@ -192,7 +191,6 @@ def run_likelihood() -> None: cl_theory = ( cl_GG + 2 * cl_GI + cl_II ) # normally we would also have a third term, +cl_II). - # pylint: enable=invalid-name # plt.plot(x, y_theory, label="Total") plt.plot(ells, cells_gg, label="GG firecrown") diff --git a/firecrown/connector/cobaya/ccl.py b/firecrown/connector/cobaya/ccl.py index 3bd7e499..88c79d64 100644 --- a/firecrown/connector/cobaya/ccl.py +++ b/firecrown/connector/cobaya/ccl.py @@ -33,10 +33,10 @@ def initialize(self): assert self.input_style self.map = mapping_builder(input_style=self.input_style) - self.a_bg = np.linspace(0.1, 1.0, 50) # pylint: disable-msg=C0103 - self.z_bg = 1.0 / self.a_bg - 1.0 # pylint: disable-msg=C0103 - self.z_Pk = np.arange(0.2, 6.0, 1) # pylint: disable-msg=C0103 - self.Pk_kmax = 1.0 # pylint: disable-msg=C0103 + self.a_bg = np.linspace(0.1, 1.0, 50) + self.z_bg = 1.0 / self.a_bg - 1.0 + self.z_Pk = np.arange(0.2, 6.0, 1) + self.Pk_kmax = 1.0 def get_param(self, p: str) -> None: """Return the current value of the parameter named 'p'. @@ -119,9 +119,12 @@ def calculate( chi_arr = self.provider.get_comoving_radial_distance(self.z_bg) hoh0_arr = self.provider.get_Hubble(self.z_bg) / self.map.get_H0() - k, z, pk = self.provider.get_Pk_grid() # pylint: disable-msg=C0103 + k, z, pk = self.provider.get_Pk_grid() - # pylint: disable-next=W0201,C0103 + # Note: we havae to define self.a_Pk here because Cobaya does not allow + # us to override the __init__ method. + # + # pylint: disable-next=attribute-defined-outside-init self.a_Pk = self.map.redshift_to_scale_factor(z) pk_a = self.map.redshift_to_scale_factor_p_k(pk) diff --git a/firecrown/connector/mapping.py b/firecrown/connector/mapping.py index 1ce9068c..0ab08841 100644 --- a/firecrown/connector/mapping.py +++ b/firecrown/connector/mapping.py @@ -101,7 +101,7 @@ def transform_p_k_h3_to_p_k(self, p_k_h3): category=DeprecationWarning, ) - def transform_h_to_h_over_h0(self, h): # pylint: disable-msg=C0103 + def transform_h_to_h_over_h0(self, h): """Transform distances h to :math:`h/h_0`.""" assert h is not None # use assertion to silence pylint warning warnings.simplefilter("always", DeprecationWarning) @@ -139,31 +139,31 @@ def set_params( # Typecheck is done automatically using the descriptors and is done to # avoid void very confusing error messages at a later time in case of # error. - self.Omega_c = Omega_c # pylint: disable-msg=C0103 - self.Omega_b = Omega_b # pylint: disable-msg=C0103 - self.h = h # pylint: disable-msg=C0103 + self.Omega_c = Omega_c + self.Omega_b = Omega_b + self.h = h if A_s is not None and sigma8 is not None: raise ValueError("Exactly one of A_s and sigma8 must be supplied") if sigma8 is None: - self.A_s = A_s # pylint: disable-msg=C0103 - self.sigma8 = None # pylint: disable-msg=C0103 + self.A_s = A_s + self.sigma8 = None else: - self.A_s = None # pylint: disable-msg=C0103 - self.sigma8 = sigma8 # pylint: disable-msg=C0103 + self.A_s = None + self.sigma8 = sigma8 self.n_s = n_s - self.Omega_k = Omega_k # pylint: disable-msg=C0103 - self.Omega_g = None # pylint: disable-msg=C0103 - self.Neff = Neff # pylint: disable-msg=C0103 + self.Omega_k = Omega_k + self.Omega_g = None + self.Neff = Neff self.m_nu = m_nu self.m_nu_type = m_nu_type - self.w0 = w0 # pylint: disable-msg=C0103 - self.wa = wa # pylint: disable-msg=C0103 - self.T_CMB = T_CMB # pylint: disable-msg=C0103 + self.w0 = w0 + self.wa = wa + self.T_CMB = T_CMB @staticmethod - def redshift_to_scale_factor(z): # pylint: disable-msg=C0103 + def redshift_to_scale_factor(z): """Given arrays of redshift returns an array of scale factor with the inverse order.""" @@ -198,7 +198,7 @@ def asdict(self) -> Dict[str, Union[Optional[float], List[float]]]: "T_CMB": self.T_CMB, } - def get_H0(self) -> float: # pylint: disable-msg=C0103 + def get_H0(self) -> float: # pylint: disable-msg=invalid-name """Return the value of H0.""" return self.h * 100.0 @@ -247,7 +247,6 @@ def set_params_from_cosmosis(self, cosmosis_params: NamedParameters): # TODO: Verify that CosmoSIS/CAMB does not use Omega_g # TODO: Verify that CosmoSIS/CAMB uses delta_neff, not N_eff - # pylint: disable=invalid-name h = cosmosis_params.get_float("h0") Omega_b = cosmosis_params.get_float("omega_b") Omega_c = cosmosis_params.get_float("omega_c") @@ -263,7 +262,6 @@ def set_params_from_cosmosis(self, cosmosis_params: NamedParameters): m_nu_type = "normal" w0 = cosmosis_params.get_float("w") wa = cosmosis_params.get_float("wa") - # pylint: enable=invalid-name # pylint: disable=duplicate-code self.set_params( @@ -388,23 +386,23 @@ def set_params_from_camb(self, **params_values): # CAMB can use different parameters in place of H0, we must deal with this # possibility here. - H0 = params_values["H0"] # pylint: disable-msg=C0103 - As = params_values["As"] # pylint: disable-msg=C0103 - ns = params_values["ns"] # pylint: disable-msg=C0103 + H0 = params_values["H0"] + As = params_values["As"] + ns = params_values["ns"] ombh2 = params_values["ombh2"] omch2 = params_values["omch2"] - Neff = params_values["nnu"] # pylint: disable-msg=C0103 + Neff = params_values["nnu"] m_nu = params_values["mnu"] - Omega_k0 = params_values["omk"] # pylint: disable-msg=C0103 + Omega_k0 = params_values["omk"] m_nu_type = "normal" - h0 = H0 / 100.0 # pylint: disable-msg=C0103 + h0 = H0 / 100.0 h02 = h0 * h0 - Omega_b0 = ombh2 / h02 # pylint: disable-msg=C0103 - Omega_c0 = omch2 / h02 # pylint: disable-msg=C0103 + Omega_b0 = ombh2 / h02 + Omega_c0 = omch2 / h02 - w = params_values.get("w", -1.0) # pylint: disable-msg=C0103 - wa = params_values.get("wa", 0.0) # pylint: disable-msg=C0103 + w = params_values.get("w", -1.0) + wa = params_values.get("wa", 0.0) # Here we have the following problem, some parameters used by CAMB # are implicit, i.e., since they are not explicitly set the default diff --git a/firecrown/connector/numcosmo/numcosmo.py b/firecrown/connector/numcosmo/numcosmo.py index 5a57c4e3..192475e7 100644 --- a/firecrown/connector/numcosmo/numcosmo.py +++ b/firecrown/connector/numcosmo/numcosmo.py @@ -59,12 +59,12 @@ def set_params_from_numcosmo( self.p_mnl.prepare_if_needed(hi_cosmo) self.dist.prepare_if_needed(hi_cosmo) - h = hi_cosmo.h() # pylint: disable-msg=C0103 - Omega_b = hi_cosmo.Omega_b0() # pylint: disable-msg=invalid-name - Omega_c = hi_cosmo.Omega_c0() # pylint: disable-msg=invalid-name - Omega_k = hi_cosmo.Omega_k0() # pylint: disable-msg=invalid-name - Neff = hi_cosmo.Neff() # pylint: disable-msg=invalid-name - T_gamma0 = hi_cosmo.T_gamma0() # pylint: disable-msg=invalid-name + h = hi_cosmo.h() + Omega_b = hi_cosmo.Omega_b0() + Omega_c = hi_cosmo.Omega_c0() + Omega_k = hi_cosmo.Omega_k0() + Neff = hi_cosmo.Neff() + T_gamma0 = hi_cosmo.T_gamma0() m_nu: Union[float, List[float]] = 0.0 if hi_cosmo.NMassNu() == 0: @@ -78,11 +78,11 @@ def set_params_from_numcosmo( m_nu[i] = nu_info[0] if isinstance(hi_cosmo, Nc.HICosmoDEXcdm): - w0 = hi_cosmo.props.w # pylint: disable-msg=C0103 - wa = 0.0 # pylint: disable-msg=C0103 + w0 = hi_cosmo.props.w + wa = 0.0 elif isinstance(hi_cosmo, Nc.HICosmoDECpl): - w0 = hi_cosmo.props.w0 # pylint: disable-msg=C0103 - wa = hi_cosmo.props.w1 # pylint: disable-msg=C0103 + w0 = hi_cosmo.props.w0 + wa = hi_cosmo.props.w1 else: raise ValueError(f"NumCosmo object {type(hi_cosmo)} not supported.") @@ -94,8 +94,8 @@ def set_params_from_numcosmo( f"NumCosmo HIPrim object type {type(hiprim)} not supported." ) - A_s = hiprim.SA_Ampl() # pylint: disable-msg=invalid-name - n_s = hiprim.props.n_SA # pylint: disable-msg=invalid-name + A_s = hiprim.SA_Ampl() + n_s = hiprim.props.n_SA # pylint: disable=duplicate-code self.set_params( @@ -121,7 +121,7 @@ def calculate_ccl_args(self, mset: Ncm.MSet): # pylint: disable-msg=too-many-lo if self.p_ml: p_m_spline = self.p_ml.get_spline_2d(hi_cosmo) - z = np.array(p_m_spline.xv.dup_array()) # pylint: disable-msg=invalid-name + z = np.array(p_m_spline.xv.dup_array()) k = np.array(p_m_spline.yv.dup_array()) scale = self.redshift_to_scale_factor(z) @@ -138,7 +138,6 @@ def calculate_ccl_args(self, mset: Ncm.MSet): # pylint: disable-msg=too-many-lo if self.p_mnl: p_mnl_spline = self.p_mnl.get_spline_2d(hi_cosmo) - # pylint: disable-next=invalid-name z = np.array(p_mnl_spline.xv.dup_array()) k = np.array(p_mnl_spline.yv.dup_array()) @@ -353,7 +352,7 @@ def do_prepare(self, mset: Ncm.MSet): # pylint: disable-msg=arguments-differ self.likelihood.update(firecrown_params) self.tools.prepare(self.ccl_cosmo) - # pylint: disable-next=invalid-name,arguments-differ + # pylint: disable-next=arguments-differ def do_mean_func(self, _, mean_vector): """ Implements the virtual `Ncm.DataGaussCov` method `mean_func`. diff --git a/firecrown/likelihood/gauss_family/gauss_family.py b/firecrown/likelihood/gauss_family/gauss_family.py index b2b584e1..040dcac1 100644 --- a/firecrown/likelihood/gauss_family/gauss_family.py +++ b/firecrown/likelihood/gauss_family/gauss_family.py @@ -122,7 +122,6 @@ def compute_chisq(self, tools: ModelingTools) -> float: self.predicted_data_vector: npt.NDArray[np.float64] = theory_vector self.measured_data_vector: npt.NDArray[np.float64] = data_vector - # pylint: disable-next=C0103 x = scipy.linalg.solve_triangular(self.cholesky, residuals, lower=True) chisq = np.dot(x, x) diff --git a/firecrown/likelihood/gauss_family/statistic/source/number_counts.py b/firecrown/likelihood/gauss_family/statistic/source/number_counts.py index 17fff1f3..ee19ed47 100644 --- a/firecrown/likelihood/gauss_family/statistic/source/number_counts.py +++ b/firecrown/likelihood/gauss_family/statistic/source/number_counts.py @@ -32,7 +32,7 @@ class NumberCountsArgs: """Class for number counts tracer builder argument.""" scale: float - z: npt.NDArray[np.float64] # pylint: disable-msg=invalid-name + z: npt.NDArray[np.float64] dndz: npt.NDArray[np.float64] bias: Optional[npt.NDArray[np.float64]] = None mag_bias: Optional[Tuple[npt.NDArray[np.float64], npt.NDArray[np.float64]]] = None @@ -169,7 +169,7 @@ def _get_derived_parameters(self) -> DerivedParameterCollection: def apply( self, tools: ModelingTools, tracer_arg: NumberCountsArgs ) -> NumberCountsArgs: - z = tracer_arg.z # pylint: disable-msg=invalid-name + z = tracer_arg.z b_2_z = self.b_2 * np.ones_like(z) b_s_z = self.b_s * np.ones_like(z) # b_1 uses the "bias" field @@ -245,7 +245,6 @@ def apply( z_bar = self.z_c + self.z_m * (self.r_lim - 24.0) # The slope of log(n_tot(z,r_lim)) with respect to r_lim # where n_tot(z,r_lim) is the luminosity function after using fit (C.1) - # pylint: disable-next=invalid-name s = ( self.eta / self.r_lim - 3.0 * self.z_m / z_bar @@ -421,11 +420,11 @@ def _read(self, sacc_data): The data in the sacc format. """ tracer = sacc_data.get_tracer(self.sacc_tracer) - z = getattr(tracer, "z").copy().flatten() # pylint: disable-msg=invalid-name - nz = getattr(tracer, "nz").copy().flatten() # pylint: disable-msg=invalid-name + z = getattr(tracer, "z").copy().flatten() + nz = getattr(tracer, "nz").copy().flatten() indices = np.argsort(z) - z = z[indices] # pylint: disable-msg=invalid-name - nz = nz[indices] # pylint: disable-msg=invalid-name + z = z[indices] + nz = nz[indices] self.tracer_args = NumberCountsArgs( scale=self.scale, z=z, dndz=nz, bias=None, mag_bias=None diff --git a/firecrown/likelihood/gauss_family/statistic/source/weak_lensing.py b/firecrown/likelihood/gauss_family/statistic/source/weak_lensing.py index 6be33e43..b300b252 100644 --- a/firecrown/likelihood/gauss_family/statistic/source/weak_lensing.py +++ b/firecrown/likelihood/gauss_family/statistic/source/weak_lensing.py @@ -32,7 +32,7 @@ class WeakLensingArgs: """Class for weak lensing tracer builder argument.""" scale: float - z: npt.NDArray[np.float64] # pylint: disable-msg=invalid-name + z: npt.NDArray[np.float64] dndz: npt.NDArray[np.float64] ia_bias: Optional[Tuple[npt.NDArray[np.float64], npt.NDArray[np.float64]]] @@ -236,7 +236,7 @@ def apply( tracer_arg, in the context of the given cosmology.""" ccl_cosmo = tools.get_ccl_cosmology() - z = tracer_arg.z # pylint: disable-msg=invalid-name + z = tracer_arg.z c_1, c_d, c_2 = pyccl.nl_pt.translate_IA_norm( ccl_cosmo, z, @@ -353,11 +353,11 @@ def _read(self, sacc_data: sacc.Sacc) -> None: """ tracer = sacc_data.get_tracer(self.sacc_tracer) - z = getattr(tracer, "z").copy().flatten() # pylint: disable-msg=invalid-name - nz = getattr(tracer, "nz").copy().flatten() # pylint: disable-msg=invalid-name + z = getattr(tracer, "z").copy().flatten() + nz = getattr(tracer, "nz").copy().flatten() indices = np.argsort(z) - z = z[indices] # pylint: disable-msg=invalid-name - nz = nz[indices] # pylint: disable-msg=invalid-name + z = z[indices] + nz = nz[indices] self.tracer_args = WeakLensingArgs(scale=self.scale, z=z, dndz=nz, ia_bias=None) diff --git a/firecrown/likelihood/gauss_family/statistic/supernova.py b/firecrown/likelihood/gauss_family/statistic/supernova.py index cdad6a1c..854d609e 100644 --- a/firecrown/likelihood/gauss_family/statistic/supernova.py +++ b/firecrown/likelihood/gauss_family/statistic/supernova.py @@ -26,9 +26,8 @@ def __init__(self, sacc_tracer) -> None: self.sacc_tracer = sacc_tracer self.data_vector: Optional[DataVector] = None - # pylint: disable-next=invalid-name self.a: Optional[npt.NDArray[np.float64]] = None - self.M = parameters.create() # pylint: disable-msg=invalid-name + self.M = parameters.create() def read(self, sacc_data: sacc.Sacc): """Read the data for this statistic from the SACC file.""" @@ -36,7 +35,6 @@ def read(self, sacc_data: sacc.Sacc): data_points = sacc_data.get_data_points( data_type="supernova_distance_mu", tracers=(self.sacc_tracer,) ) - # pylint: disable-next=invalid-name z = np.array([dp.get_tag("z") for dp in data_points]) self.a = 1.0 / (1.0 + z) self.data_vector = DataVector.from_list([dp.value for dp in data_points]) diff --git a/firecrown/likelihood/gauss_family/statistic/two_point.py b/firecrown/likelihood/gauss_family/statistic/two_point.py index 3868d15d..faeb7ee7 100644 --- a/firecrown/likelihood/gauss_family/statistic/two_point.py +++ b/firecrown/likelihood/gauss_family/statistic/two_point.py @@ -336,7 +336,7 @@ def compute_theory_vector(self, tools: ModelingTools) -> TheoryVector: continue if tools.has_pk(pk_name): # Use existing power spectrum - pk = tools.get_pk(pk_name) # pylint: disable-msg=invalid-name + pk = tools.get_pk(pk_name) elif tracer0.has_pt or tracer1.has_pt: if not tracer0.has_pt and tracer1.has_pt: # Mixture of PT and non-PT tracers @@ -349,7 +349,7 @@ def compute_theory_vector(self, tools: ModelingTools) -> TheoryVector: # Compute perturbation power spectrum pt_calculator = tools.get_pt_calculator() - pk = pyccl.nl_pt.get_pt_pk2d( # pylint: disable-msg=invalid-name + pk = pyccl.nl_pt.get_pt_pk2d( ccl_cosmo, tracer0.pt_tracer, tracer2=tracer1.pt_tracer, @@ -391,7 +391,7 @@ def compute_theory_vector(self, tools: ModelingTools) -> TheoryVector: if self.theory_window_function is not None: - def log_interpolator(x, y): # pylint: disable-msg=invalid-name + def log_interpolator(x, y): if np.all(y > 0): # use log-log interpolation intp = scipy.interpolate.InterpolatedUnivariateSpline( diff --git a/firecrown/likelihood/gauss_family/student_t.py b/firecrown/likelihood/gauss_family/student_t.py index 92360010..9c2610bf 100644 --- a/firecrown/likelihood/gauss_family/student_t.py +++ b/firecrown/likelihood/gauss_family/student_t.py @@ -32,7 +32,7 @@ def __init__( nu: Optional[float], ): super().__init__(statistics) - self.nu = parameters.create(nu) # pylint: disable-msg=C0103 + self.nu = parameters.create(nu) def compute_loglike(self, tools: ModelingTools): """Compute the log-likelihood. diff --git a/firecrown/utils.py b/firecrown/utils.py index 3adb2c0d..8c56dbb5 100644 --- a/firecrown/utils.py +++ b/firecrown/utils.py @@ -2,7 +2,7 @@ """ -def upper_triangle_indices(n: int): # pylint: disable-msg=invalid-name +def upper_triangle_indices(n: int): """generator that yields a sequence of tuples that carry the indices for an (n x n) upper-triangular matrix. This is a replacement for the nested loops: diff --git a/pylintrc b/pylintrc new file mode 100644 index 00000000..01f435e7 --- /dev/null +++ b/pylintrc @@ -0,0 +1,55 @@ +[MAIN] + +# Use multiple processes to speed up Pylint. Specifying 0 will auto-detect the +# number of processors available to use, and will cap the count on Windows to +# avoid hangs. +jobs=0 + +# Minimum Python version to use for version dependent checks. Will default to +# the version used to run pylint. +py-version=3.9 + +# Discover python modules and packages in the file system subtree. +recursive=yes + +[MESSAGES CONTROL] + +# Enable the message, report, category or checker with the given id(s). You can +# either give multiple identifier separated by comma (,) or put this option +# multiple time (only on the command line, not in the configuration file where +# it should appear only once). See also the "--disable" option for examples. +enable=c-extension-no-member + +[MISCELLANEOUS] + +# List of note tags to take in consideration, separated by a comma. +notes=FIXME + +[BASIC] + +# Naming style matching correct argument names. +argument-naming-style=any + +# Naming style matching correct attribute names. +attr-naming-style=any + +# Naming style matching correct variable names. +variable-naming-style=any + + +[STRING] + +# This flag controls whether inconsistent-quotes generates a warning when the +# character used as a quote delimiter is used inconsistently within a module. +check-quote-consistency=yes + +[TYPECHECK] + +# Tells whether to warn about missing members when the owner of the attribute +# is inferred to be None. +ignore-none=false + +[FORMAT] + +# Expected format of line ending, e.g. empty (any line ending), LF or CRLF. +expected-line-ending-format=LF