From d187a17f1abb2afd10c2330391c40a41d60f4aa3 Mon Sep 17 00:00:00 2001 From: Javier Sanchez Date: Thu, 15 Feb 2024 12:32:20 -0500 Subject: [PATCH 01/13] some fixes --- augur/generate.py | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/augur/generate.py b/augur/generate.py index 4c8bc8b..8c0e924 100644 --- a/augur/generate.py +++ b/augur/generate.py @@ -209,7 +209,7 @@ def generate_sacc_and_stats(config): sources[sacc_tracer].bias = bias sys_params[f'{sacc_tracer}_bias'] = bias sys_params[f'{sacc_tracer}_delta_z'] = delta_z[i] - + # Read data vector combinations if 'statistics' not in config.keys(): raise ValueError('statistics key is required in config file') @@ -231,8 +231,18 @@ def generate_sacc_and_stats(config): ells_here = ells[ells < ell_max] else: ells_here = ells - for ell in ells_here: - S.add_data_point(key, (tr1, tr2), 0.0, ell=ell, error=1e30) + # Trying to add bandpower windows + ells_aux = np.arange(0, np.max(ells_here)+1) + wgt = np.zeros((len(ells_aux), len(ells_here))) + for i in range(len(ells_here)): + in_win = (ells_aux > ell_edges[i]) & (ells_aux < ell_edges[i+1]) + wgt[in_win, i] = 1.0 + win = sacc.BandpowerWindow(ells_aux, wgt) + S.add_ell_cl(key, tr1, tr2, + ells_here, np.zeros(len(ells_here)), window=win) + # # For some reason add_ell_cl does not update the sacc file properly on the fly... + # for i, ell in enumerate(ells_here): + # S.add_data_point(key, (tr1, tr2), 0.0, ell=ell, error=1e30, window=win[i]) # Now create TwoPoint objects for firecrown _aux_stat = TwoPoint(source0=sources[tr1], source1=sources[tr2], sacc_data_type=key) @@ -264,19 +274,23 @@ def generate(config, return_all_outputs=False, write_sacc=True, force_read=True) Returns: ------- - noise : float - Noise power for Cls for that particular tracer. That is 1/nbar for - number counts and e**2/nbar for weak lensing tracer. + lk : firecrown.likelihood.ConstGaussian + Likelihood object, only returned if `return_all_outputs` is True. + S : sacc.Sacc + Sacc object with fake data vector and covariance. It is only returned if `return_all_outputs` + is True. + tools : firecrown.modeling.ModelingTools + Modeling tools, only returned if `return_all_outputs` is True. + sys_params : dict + Dictionary containing the modeling systematic parameters. It is only returned if `return_all_outputs` + is True. - Note: - ----- - The input number_densities are #/arcmin. - The output units are in steradian. """ config = parse_config(config) # Generate placeholders S, cosmo, stats, sys_params = generate_sacc_and_stats(config) + # Generate likelihood object lk = ConstGaussian(statistics=stats) # Pass the correct binning/tracers From d8b6537756b5c101c36520112bd4b2f96ab047c8 Mon Sep 17 00:00:00 2001 From: Javier Sanchez Date: Thu, 15 Feb 2024 12:36:04 -0500 Subject: [PATCH 02/13] commenting out bandpower windows --- augur/generate.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/augur/generate.py b/augur/generate.py index 8c0e924..fc94158 100644 --- a/augur/generate.py +++ b/augur/generate.py @@ -232,14 +232,14 @@ def generate_sacc_and_stats(config): else: ells_here = ells # Trying to add bandpower windows - ells_aux = np.arange(0, np.max(ells_here)+1) - wgt = np.zeros((len(ells_aux), len(ells_here))) - for i in range(len(ells_here)): - in_win = (ells_aux > ell_edges[i]) & (ells_aux < ell_edges[i+1]) - wgt[in_win, i] = 1.0 - win = sacc.BandpowerWindow(ells_aux, wgt) + #ells_aux = np.arange(0, np.max(ells_here)+1) + #wgt = np.zeros((len(ells_aux), len(ells_here))) + #for i in range(len(ells_here)): + # in_win = (ells_aux > ell_edges[i]) & (ells_aux < ell_edges[i+1]) + # wgt[in_win, i] = 1.0 + #win = sacc.BandpowerWindow(ells_aux, wgt) S.add_ell_cl(key, tr1, tr2, - ells_here, np.zeros(len(ells_here)), window=win) + ells_here, np.zeros(len(ells_here))) #, window=win) # # For some reason add_ell_cl does not update the sacc file properly on the fly... # for i, ell in enumerate(ells_here): # S.add_data_point(key, (tr1, tr2), 0.0, ell=ell, error=1e30, window=win[i]) From 34f45273fb5f9e6309965fd398ebab953843c926 Mon Sep 17 00:00:00 2001 From: Javier Sanchez Date: Thu, 15 Feb 2024 13:35:00 -0500 Subject: [PATCH 03/13] fixes for firecrown v.1.7.0 --- augur/analyze.py | 10 +++++-- augur/generate.py | 16 ++++------- environment.yml | 2 +- pylintrc | 71 +++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 85 insertions(+), 14 deletions(-) create mode 100644 pylintrc diff --git a/augur/analyze.py b/augur/analyze.py index 1d228db..3a0adc6 100644 --- a/augur/analyze.py +++ b/augur/analyze.py @@ -128,7 +128,9 @@ def f(self, x, labels, pars_fid, sys_fid): self.tools.reset() self.lk.reset() cosmo = ccl.Cosmology(**_pars) - self.lk.update(ParamsMap(_sys_pars)) + pmap = ParamsMap(_sys_pars) + self.lk.update(pmap) + self.tools.update(pmap) self.tools.prepare(cosmo) f_out = self.lk.compute_theory_vector(self.tools) elif x.ndim == 2: @@ -146,8 +148,10 @@ def f(self, x, labels, pars_fid, sys_fid): raise ValueError(f'Parameter name {labels[j]} not recognized') self.tools.reset() self.lk.reset() - self.lk.update(ParamsMap(_sys_pars)) + pmap = ParamsMap(_sys_pars) + self.lk.update(pmap) cosmo = ccl.Cosmology(**_pars) + self.tools.update(pmap) self.tools.prepare(cosmo) f_out.append(self.lk.compute_theory_vector(self.tools)) return np.array(f_out) @@ -196,7 +200,7 @@ def compute_fisher_bias(self): # and the same length import os _calculate_biased_cls = True - _cls_fid = self.lk.measured_data_vector # Get the fiducial data vector + _cls_fid = self.lk.get_data_vector() # Get the fiducial data vector # Try to read the biased data vector if 'biased_dv' in self.config['fisher_bias']: diff --git a/augur/generate.py b/augur/generate.py index fc94158..8e37a66 100644 --- a/augur/generate.py +++ b/augur/generate.py @@ -252,7 +252,7 @@ def generate_sacc_and_stats(config): return S, cosmo, stats, sys_params -def generate(config, return_all_outputs=False, write_sacc=True, force_read=True): +def generate(config, return_all_outputs=False, write_sacc=True): """ Generate likelihood object and sacc file with fiducial cosmology @@ -267,10 +267,7 @@ def generate(config, return_all_outputs=False, write_sacc=True, force_read=True) likelihood object. write_sacc : bool If `True` it writes a sacc file with fiducial data vector. - force_read : bool - If `True` it repopulates the likelihood data vector with the contents of the Sacc file - generated here. Note: For high-condition covariances where the Cholesky decomposition - fails, setting force_read to `True` may result in a `LinAlgError`. + Returns: ------- @@ -307,6 +304,7 @@ def generate(config, return_all_outputs=False, write_sacc=True, force_read=True) cosmo.compute_nonlin_power() tools = ModelingTools(pt_calculator=pt_calculator) lk.update(sys_params) + tools.update(sys_params) tools.prepare(cosmo) # Run the likelihood (to get the theory) lk.compute_loglike(tools) @@ -320,7 +318,7 @@ def generate(config, return_all_outputs=False, write_sacc=True, force_read=True) st = st.statistic st.ready = False S.add_ell_cl(st.sacc_data_type, st.sacc_tracers[0], st.sacc_tracers[1], - st.ell_or_theta_, st.predicted_statistic_) + st.ell_or_theta_, st.get_theory_vector()) if config['cov_options']['cov_type'] == 'gaus_internal': fsky = config['cov_options']['fsky'] cov = get_gaus_cov(S, lk, cosmo, fsky, config) @@ -382,9 +380,7 @@ def generate(config, return_all_outputs=False, write_sacc=True, force_read=True) print(config['fiducial_sacc_path']) S.save_fits(config['fiducial_sacc_path'], overwrite=True) # Update covariance and inverse -- TODO need to update cholesky!! - if force_read: - # Hacky way to overwrite... - lk.read(S) - lk.measured_data_vector = lk.get_data_vector() + lk = ConstGaussian(statistics=stats) + lk.read(S) if return_all_outputs: return lk, S, tools, sys_params diff --git a/environment.yml b/environment.yml index a3bafba..055fb6c 100644 --- a/environment.yml +++ b/environment.yml @@ -10,4 +10,4 @@ dependencies: - flake8 - pip: - tjpcov - - qp + - qp-prob diff --git a/pylintrc b/pylintrc new file mode 100644 index 0000000..0e8627d --- /dev/null +++ b/pylintrc @@ -0,0 +1,71 @@ +[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 + +# Add custom pylint plugins +# load-plugins=pylint_plugins.duplicate_code + +[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 +disable=too-few-public-methods + +[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 + +# Naming style matching correct module level constants names. +const-naming-style=any + +# Naming style matching correct method names. +method-naming-style=any + +# Naming style matching correct function names. +function-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 + +[DESIGN] +max-args=20 +max-attributes=20 From 0467197f06ab7e9a8691692350fdb07ef542ffee Mon Sep 17 00:00:00 2001 From: Javier Sanchez Date: Thu, 15 Feb 2024 13:37:47 -0500 Subject: [PATCH 04/13] fixes to environment --- environment.yml | 9 ++++----- setup.cfg | 2 +- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/environment.yml b/environment.yml index 055fb6c..8058980 100644 --- a/environment.yml +++ b/environment.yml @@ -2,12 +2,11 @@ name: forecasting channels: - conda-forge dependencies: - - firecrown + - firecrown>=1.7.0 + - flake8 - healpy - jinja2 + - numdifftools - numpydoc - - pip - - flake8 - - pip: - - tjpcov - qp-prob + - tjpcov diff --git a/setup.cfg b/setup.cfg index fbcdfb7..891b9ec 100644 --- a/setup.cfg +++ b/setup.cfg @@ -17,7 +17,7 @@ install_requires = jinja2 healpy numpydoc - qp + qp-prob [options.packages.find] exclude = From e290b28588c12981adeb37585e9a912cb573a371 Mon Sep 17 00:00:00 2001 From: Javier Sanchez Date: Tue, 20 Feb 2024 15:15:42 -0500 Subject: [PATCH 05/13] added back bandpower windows, preparing for fc 1.7.1 --- augur/generate.py | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/augur/generate.py b/augur/generate.py index 8e37a66..b3c2ec6 100644 --- a/augur/generate.py +++ b/augur/generate.py @@ -232,17 +232,15 @@ def generate_sacc_and_stats(config): else: ells_here = ells # Trying to add bandpower windows - #ells_aux = np.arange(0, np.max(ells_here)+1) - #wgt = np.zeros((len(ells_aux), len(ells_here))) - #for i in range(len(ells_here)): - # in_win = (ells_aux > ell_edges[i]) & (ells_aux < ell_edges[i+1]) - # wgt[in_win, i] = 1.0 - #win = sacc.BandpowerWindow(ells_aux, wgt) + ells_aux = np.arange(0, np.max(ells_here)+1) + wgt = np.zeros((len(ells_aux), len(ells_here))) + for i in range(len(ells_here)): + in_win = (ells_aux > ell_edges[i]) & (ells_aux < ell_edges[i+1]) + wgt[in_win, i] = 1.0 + win = sacc.BandpowerWindow(ells_aux, wgt) S.add_ell_cl(key, tr1, tr2, - ells_here, np.zeros(len(ells_here))) #, window=win) - # # For some reason add_ell_cl does not update the sacc file properly on the fly... - # for i, ell in enumerate(ells_here): - # S.add_data_point(key, (tr1, tr2), 0.0, ell=ell, error=1e30, window=win[i]) + ells_here, np.zeros(len(ells_here)), window=win) + # Now create TwoPoint objects for firecrown _aux_stat = TwoPoint(source0=sources[tr1], source1=sources[tr2], sacc_data_type=key) @@ -318,7 +316,8 @@ def generate(config, return_all_outputs=False, write_sacc=True): st = st.statistic st.ready = False S.add_ell_cl(st.sacc_data_type, st.sacc_tracers[0], st.sacc_tracers[1], - st.ell_or_theta_, st.get_theory_vector()) + st.ell_or_theta_, st.get_theory_vector(), + window=st.theory_window_function) if config['cov_options']['cov_type'] == 'gaus_internal': fsky = config['cov_options']['fsky'] cov = get_gaus_cov(S, lk, cosmo, fsky, config) From a9e974c05bf6cba88feea4a8df4e4b5f8438abcb Mon Sep 17 00:00:00 2001 From: Javier Sanchez Date: Tue, 20 Feb 2024 16:09:47 -0500 Subject: [PATCH 06/13] changed requirements --- environment.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/environment.yml b/environment.yml index 8058980..f284945 100644 --- a/environment.yml +++ b/environment.yml @@ -2,7 +2,7 @@ name: forecasting channels: - conda-forge dependencies: - - firecrown>=1.7.0 + - firecrown>=1.7.1 - flake8 - healpy - jinja2 From 0be1d7621505c5cbcab5c77764586e0cc52ba512 Mon Sep 17 00:00:00 2001 From: Javier Sanchez Date: Tue, 20 Feb 2024 16:14:14 -0500 Subject: [PATCH 07/13] flake8 fixes --- augur/generate.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/augur/generate.py b/augur/generate.py index b3c2ec6..cd95c4c 100644 --- a/augur/generate.py +++ b/augur/generate.py @@ -209,7 +209,7 @@ def generate_sacc_and_stats(config): sources[sacc_tracer].bias = bias sys_params[f'{sacc_tracer}_bias'] = bias sys_params[f'{sacc_tracer}_delta_z'] = delta_z[i] - + # Read data vector combinations if 'statistics' not in config.keys(): raise ValueError('statistics key is required in config file') @@ -236,11 +236,11 @@ def generate_sacc_and_stats(config): wgt = np.zeros((len(ells_aux), len(ells_here))) for i in range(len(ells_here)): in_win = (ells_aux > ell_edges[i]) & (ells_aux < ell_edges[i+1]) - wgt[in_win, i] = 1.0 + wgt[in_win, i] = 1.0 win = sacc.BandpowerWindow(ells_aux, wgt) S.add_ell_cl(key, tr1, tr2, ells_here, np.zeros(len(ells_here)), window=win) - + # Now create TwoPoint objects for firecrown _aux_stat = TwoPoint(source0=sources[tr1], source1=sources[tr2], sacc_data_type=key) @@ -265,20 +265,19 @@ def generate(config, return_all_outputs=False, write_sacc=True): likelihood object. write_sacc : bool If `True` it writes a sacc file with fiducial data vector. - Returns: ------- lk : firecrown.likelihood.ConstGaussian Likelihood object, only returned if `return_all_outputs` is True. S : sacc.Sacc - Sacc object with fake data vector and covariance. It is only returned if `return_all_outputs` - is True. + Sacc object with fake data vector and covariance. It is only returned if + `return_all_outputs` is True. tools : firecrown.modeling.ModelingTools Modeling tools, only returned if `return_all_outputs` is True. sys_params : dict - Dictionary containing the modeling systematic parameters. It is only returned if `return_all_outputs` - is True. + Dictionary containing the modeling systematic parameters. It is only returned if + `return_all_outputs` is True. """ From 5c96bc5ac5aa857fbb911da9560583a933cce69a Mon Sep 17 00:00:00 2001 From: Javier Sanchez Date: Tue, 20 Feb 2024 16:21:53 -0500 Subject: [PATCH 08/13] trying to fix CI --- .github/workflows/continuous-integration.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/continuous-integration.yaml b/.github/workflows/continuous-integration.yaml index 1639000..d25378c 100644 --- a/.github/workflows/continuous-integration.yaml +++ b/.github/workflows/continuous-integration.yaml @@ -9,7 +9,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: ['3.9'] + python-version: ['3.11'] steps: - uses: conda-incubator/setup-miniconda@v2 @@ -25,7 +25,7 @@ jobs: - name: Install dependencies shell: bash -l {0} run: | - conda env update -f augur/environment.yml + conda env update -f augur/environment.yml --all conda activate forecasting cd augur python -m pip install --no-deps --editable . From 5a2629540e6dedfb69102a51cd594461c8c05630 Mon Sep 17 00:00:00 2001 From: Javier Sanchez Date: Tue, 20 Feb 2024 16:30:43 -0500 Subject: [PATCH 09/13] trying to fix CI --- .github/workflows/continuous-integration.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/continuous-integration.yaml b/.github/workflows/continuous-integration.yaml index d25378c..4424731 100644 --- a/.github/workflows/continuous-integration.yaml +++ b/.github/workflows/continuous-integration.yaml @@ -25,7 +25,7 @@ jobs: - name: Install dependencies shell: bash -l {0} run: | - conda env update -f augur/environment.yml --all + conda env update -f augur/environment.yml conda activate forecasting cd augur python -m pip install --no-deps --editable . From d9052e5fe2e2519a563dd9b3c996098c49412787 Mon Sep 17 00:00:00 2001 From: Javier Sanchez Date: Thu, 22 Feb 2024 12:26:04 -0500 Subject: [PATCH 10/13] updated version --- augur/_version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/augur/_version.py b/augur/_version.py index d3ec452..493f741 100644 --- a/augur/_version.py +++ b/augur/_version.py @@ -1 +1 @@ -__version__ = "0.2.0" +__version__ = "0.3.0" From 7bc1ad2f5be8d07061000c0dcb4946a80e158425 Mon Sep 17 00:00:00 2001 From: Javier Sanchez Date: Thu, 22 Feb 2024 13:32:49 -0500 Subject: [PATCH 11/13] fixed bug in order of operations --- augur/analyze.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/augur/analyze.py b/augur/analyze.py index 3a0adc6..352fc1e 100644 --- a/augur/analyze.py +++ b/augur/analyze.py @@ -41,6 +41,7 @@ def __init__(self, config, likelihood=None, tools=None, req_params=None): self.lk = likelihood # Just to save some typing self.tools = tools self.req_params = req_params + self.data_fid = self.lk.get_data_vector() _config = parse_config(config) # Load full config # Get the fiducial cosmological parameters @@ -190,7 +191,7 @@ def get_fisher_matrix(self, method='5pt_stencil'): else: return self.Fij - def compute_fisher_bias(self): + def get_fisher_bias(self): # Compute Fisher bias following the generalized Amara formalism # More details in Bianca's thesis and the note here: # https://github.com/LSSTDESC/augur/blob/note_bianca/note/main.tex @@ -199,8 +200,14 @@ def compute_fisher_bias(self): # They should have the same ells as the original data-vector # and the same length import os + + if self.derivatives is None: + self.get_derivatives() + + if self.Fij is None: + self.get_fisher_matrix() + _calculate_biased_cls = True - _cls_fid = self.lk.get_data_vector() # Get the fiducial data vector # Try to read the biased data vector if 'biased_dv' in self.config['fisher_bias']: @@ -220,7 +227,7 @@ def compute_fisher_bias(self): raise ValueError('The length of the provided Cls should be equal \ to the length of the data-vector') _calculate_biased_cls = False - self.biased_cls = biased_cls['dv_sys'] - _cls_fid + self.biased_cls = biased_cls['dv_sys'] - self.data_fid # If there's no biased data vector, calculate it if _calculate_biased_cls: @@ -244,13 +251,8 @@ def compute_fisher_bias(self): else: raise ValueError('bias_params is required if no biased_dv file is passed') - self.biased_cls = self.f(_x_here, _labels_here, _pars_here, _sys_here) - _cls_fid + self.biased_cls = self.f(_x_here, _labels_here, _pars_here, _sys_here) - self.data_fid - if self.derivatives is None: - self.get_derivatives() Bj = np.einsum('l, lm, jm', self.biased_cls, self.lk.inv_cov, self.derivatives) - - if self.Fij is None: - self.get_fisher_matrix() bi = np.einsum('ij, j', np.linalg.inv(self.Fij), Bj) self.bi = bi From 5c6cc7ee811a41ecb2b515e7d5aa6eaa8657b147 Mon Sep 17 00:00:00 2001 From: Javier Sanchez Date: Thu, 22 Feb 2024 13:59:32 -0500 Subject: [PATCH 12/13] fixing flake8 --- augur/analyze.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/augur/analyze.py b/augur/analyze.py index 352fc1e..ba3e0aa 100644 --- a/augur/analyze.py +++ b/augur/analyze.py @@ -203,7 +203,7 @@ def get_fisher_bias(self): if self.derivatives is None: self.get_derivatives() - + if self.Fij is None: self.get_fisher_matrix() From 917167bf717ce6438593cad94dfe05da80c4f460 Mon Sep 17 00:00:00 2001 From: Javier Sanchez Date: Thu, 22 Feb 2024 14:06:47 -0500 Subject: [PATCH 13/13] fixing tests --- augur/tests/test_analyze.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/augur/tests/test_analyze.py b/augur/tests/test_analyze.py index c6d1080..5badba1 100644 --- a/augur/tests/test_analyze.py +++ b/augur/tests/test_analyze.py @@ -5,4 +5,4 @@ def test_analyze(): fish = Analyze('./examples/config_test.yml') fish.get_derivatives() fish.get_fisher_matrix() - fish.compute_fisher_bias() + fish.get_fisher_bias()