From 902fb82a3ac904e6f411d70660b9ac0c7c963c67 Mon Sep 17 00:00:00 2001 From: Marc Paterno Date: Mon, 12 Dec 2022 16:35:37 -0600 Subject: [PATCH 1/7] Simplify flow of control re: pylint --- firecrown/likelihood/likelihood.py | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/firecrown/likelihood/likelihood.py b/firecrown/likelihood/likelihood.py index 49b3b523..401d8c68 100644 --- a/firecrown/likelihood/likelihood.py +++ b/firecrown/likelihood/likelihood.py @@ -109,16 +109,15 @@ def load_likelihood( f"Firecrown initialization script {filename} does not define " f"a `build_likelihood` factory function." ) - else: - warnings.simplefilter("always", DeprecationWarning) - warnings.warn( - "The use of a likelihood variable in Firecrown's initialization " - "script is deprecated. Any parameters passed to the likelihood " - "will be ignored. The script should define a `build_likelihood` " - "factory function.", - category=DeprecationWarning, - ) - likelihood = mod.likelihood + warnings.simplefilter("always", DeprecationWarning) + warnings.warn( + "The use of a likelihood variable in Firecrown's initialization " + "script is deprecated. Any parameters passed to the likelihood " + "will be ignored. The script should define a `build_likelihood` " + "factory function.", + category=DeprecationWarning, + ) + likelihood = mod.likelihood else: if not callable(mod.build_likelihood): raise TypeError( From beb8ea49b0b15661b10510b4d81bdf6a1c935ce9 Mon Sep 17 00:00:00 2001 From: Marc Paterno Date: Mon, 12 Dec 2022 16:35:59 -0600 Subject: [PATCH 2/7] Improve variable naming re: pylint --- firecrown/parameters.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/firecrown/parameters.py b/firecrown/parameters.py index bb3eb91c..62604f5c 100644 --- a/firecrown/parameters.py +++ b/firecrown/parameters.py @@ -161,8 +161,8 @@ def __init__(self, derived_parameters: List[DerivedParameter]): self.derived_parameters: Dict[str, DerivedParameter] = {} - for dp in derived_parameters: - self.add_required_parameter(dp) + for parameter in derived_parameters: + self.add_required_parameter(parameter) def __add__(self, other: Optional[DerivedParameterCollection]): """Return a new DerivedParameterCollection with the lists of DerivedParameter From f0ed3ef96fccfd872dee978bd6d1e90dde7562d5 Mon Sep 17 00:00:00 2001 From: Marc Paterno Date: Mon, 12 Dec 2022 16:36:25 -0600 Subject: [PATCH 3/7] Add documentation to functions --- firecrown/parameters.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/firecrown/parameters.py b/firecrown/parameters.py index 62604f5c..99d95386 100644 --- a/firecrown/parameters.py +++ b/firecrown/parameters.py @@ -42,6 +42,10 @@ def __init__(self, *args, **kwargs) -> None: self.lower_case: bool = False def use_lower_case_keys(self, enable: bool) -> None: + """Control whether keys will be translated into lower case. + If `enable` is True, such translation will be done. + This can help make sure code works with CosmoSIS, because such translation + is done inside CosmoSIS itself.""" self.lower_case = enable def get_from_prefix_param(self, prefix: Optional[str], param: str) -> float: @@ -230,9 +234,11 @@ def __init__(self): self.value = None def set_value(self, value: float): + """Set the value of this parameter.""" self.value = value def get_value(self) -> float: + """Get the current value of this parameter.""" return self.value @@ -245,13 +251,25 @@ def __init__(self, value: float): self.value = value def set_value(self, value: float): + """Set the value of this parameter.""" self.value = value def get_value(self) -> float: + """Return the current value of this parameter.""" return self.value def create(value: Optional[float] = None): + """Create a new parameter. + + If `value` is `None`, the result will be a `SamplerParameter`; Firecrown + will expect this value to be supplied by the sampling framwork. If `value` + is a `float` quantity, then Firecrown will expect this parameter to *not* + be supplied by the sampling framework, and instead the provided value will + be used for every sample. + + Only `None` or a `float` value is allowed. + """ if value is None: return SamplerParameter() return InternalParameter(value) From 457135d4756630111e4052a5453d06b200518249 Mon Sep 17 00:00:00 2001 From: Marc Paterno Date: Tue, 13 Dec 2022 09:34:03 -0600 Subject: [PATCH 4/7] Fix error in name of descriptor --- .../likelihood/gauss_family/statistic/source/number_counts.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/firecrown/likelihood/gauss_family/statistic/source/number_counts.py b/firecrown/likelihood/gauss_family/statistic/source/number_counts.py index 8888e188..38ef0a86 100644 --- a/firecrown/likelihood/gauss_family/statistic/source/number_counts.py +++ b/firecrown/likelihood/gauss_family/statistic/source/number_counts.py @@ -251,7 +251,7 @@ class NumberCounts(Source): """Source class for number counts.""" systematics: UpdatableCollection - tracer_arg: NumberCountsArgs + tracer_args: NumberCountsArgs def __init__( self, From 0274c47a8a63b183b78362eac266bd83599ae324 Mon Sep 17 00:00:00 2001 From: Marc Paterno Date: Tue, 13 Dec 2022 09:57:56 -0600 Subject: [PATCH 5/7] Remove use of warnings.UserWarning The name warnings.UserWarning does not exist. The default exception type used by `warn` is just UserWarning. Since this is the default, there is no actual need to specify it. --- firecrown/likelihood/gauss_family/statistic/two_point.py | 1 - 1 file changed, 1 deletion(-) diff --git a/firecrown/likelihood/gauss_family/statistic/two_point.py b/firecrown/likelihood/gauss_family/statistic/two_point.py index cec7d497..93bb0c4e 100644 --- a/firecrown/likelihood/gauss_family/statistic/two_point.py +++ b/firecrown/likelihood/gauss_family/statistic/two_point.py @@ -238,7 +238,6 @@ def read(self, sacc_data): warnings.warn( f"Tracers '{tracers}' have 2pt data and you have specified " "`ell_or_theta` in the configuration. `ell_or_theta` is being ignored!", - warnings.UserWarning, stacklevel=2, ) From cdece1a70290c9aa5e3793ae92879a53c110992d Mon Sep 17 00:00:00 2001 From: Marc Paterno Date: Tue, 13 Dec 2022 10:00:36 -0600 Subject: [PATCH 6/7] Simply control flow re: pylint --- .../likelihood/gauss_family/statistic/two_point.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/firecrown/likelihood/gauss_family/statistic/two_point.py b/firecrown/likelihood/gauss_family/statistic/two_point.py index 93bb0c4e..d000cf5a 100644 --- a/firecrown/likelihood/gauss_family/statistic/two_point.py +++ b/firecrown/likelihood/gauss_family/statistic/two_point.py @@ -314,12 +314,11 @@ def log_interpolator(x, y): np.log(x), np.log(y), ext=2 ) return lambda x_, intp=intp: np.exp(intp(np.log(x_))) - else: - # only use log for x - intp = scipy.interpolate.InterpolatedUnivariateSpline( - np.log(x), y, ext=2 - ) - return lambda x_, intp=intp: intp(np.log(x_)) + # only use log for x + intp = scipy.interpolate.InterpolatedUnivariateSpline( + np.log(x), y, ext=2 + ) + return lambda x_, intp=intp: intp(np.log(x_)) theory_interpolator = log_interpolator(self.ell_or_theta_, theory_vector) ell = self.theory_window_function.values From fc8a988209375cd58dda1881bd6ff679071bbcf4 Mon Sep 17 00:00:00 2001 From: Marc Paterno Date: Thu, 15 Dec 2022 14:20:42 -0600 Subject: [PATCH 7/7] Add type annotation for mypy --- .../likelihood/gauss_family/statistic/source/number_counts.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/firecrown/likelihood/gauss_family/statistic/source/number_counts.py b/firecrown/likelihood/gauss_family/statistic/source/number_counts.py index 38ef0a86..3d0141f4 100644 --- a/firecrown/likelihood/gauss_family/statistic/source/number_counts.py +++ b/firecrown/likelihood/gauss_family/statistic/source/number_counts.py @@ -278,7 +278,7 @@ def __init__( self.systematics.append(systematic) self.scale = scale - self.current_tracer_args = None + self.current_tracer_args: Optional[NumberCountsArgs] = None self.scale_ = None self.tracer_ = None