Skip to content

Commit

Permalink
Make pylint more permissive about most names (#257)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcpaterno authored Apr 20, 2023
1 parent 62ddd72 commit d6ae83a
Show file tree
Hide file tree
Showing 13 changed files with 128 additions and 79 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
4 changes: 1 addition & 3 deletions examples/des_y1_3x2pt/des_y1_cosmic_shear_TATT.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand All @@ -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")
Expand Down
15 changes: 9 additions & 6 deletions firecrown/connector/cobaya/ccl.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'.
Expand Down Expand Up @@ -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)

Expand Down
54 changes: 26 additions & 28 deletions firecrown/connector/mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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."""

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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")
Expand All @@ -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(
Expand Down Expand Up @@ -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
Expand Down
29 changes: 14 additions & 15 deletions firecrown/connector/numcosmo/numcosmo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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.")

Expand All @@ -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(
Expand All @@ -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)
Expand All @@ -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())

Expand Down Expand Up @@ -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`.
Expand Down
1 change: 0 additions & 1 deletion firecrown/likelihood/gauss_family/gauss_family.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]]]

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)

Expand Down
4 changes: 1 addition & 3 deletions firecrown/likelihood/gauss_family/statistic/supernova.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,15 @@ 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."""

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])
Expand Down
6 changes: 3 additions & 3 deletions firecrown/likelihood/gauss_family/statistic/two_point.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion firecrown/likelihood/gauss_family/student_t.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Loading

0 comments on commit d6ae83a

Please sign in to comment.