Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Save predictions to sacc #349

Merged
merged 34 commits into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
d7f51ab
working prototype
tilmantroester Dec 6, 2023
acee539
Add test, rename computed to computed_theory_vector
tilmantroester Dec 6, 2023
08597ff
fix spelling
tilmantroester Dec 7, 2023
aa379cc
Merge branch 'master' into save_predictions
vitenti Jan 10, 2024
52c8222
Fixed linter issues.
vitenti Jan 10, 2024
4f77feb
Improve type usage, now UpdatableCollection allows the user to specif…
vitenti Jan 11, 2024
8acdb04
Moved type definition to __init__.
vitenti Jan 11, 2024
dd85f19
Reorganized theory_vector and data_vector set/get and computation.
vitenti Jan 13, 2024
043bcfb
Merge branch 'master' into save_predictions
vitenti Jan 13, 2024
d93848d
Combining new state machine and new methods.
vitenti Jan 13, 2024
5973790
Fixed reset in cosmosis connector, must be called after all possible …
vitenti Jan 13, 2024
fba2463
Cleaning all quantities computed after updated.
vitenti Jan 13, 2024
1207889
More tests for UpdatableCollection.
vitenti Jan 13, 2024
92b3916
Testing new methods of GaussFamily (and older not tested ones).
vitenti Jan 13, 2024
5d9b462
Adding noise to the realizations and testing it.
vitenti Jan 13, 2024
16904b8
* Reorganizing and renaming.
vitenti Jan 13, 2024
4bd3e4b
* More documentation updates.
vitenti Jan 13, 2024
af11932
* More documentation fix.
vitenti Jan 13, 2024
6962a58
Normalizing make_realization parameters.
vitenti Jan 13, 2024
0798278
Factoring make_realization_vector, which returns a new realization da…
vitenti Jan 13, 2024
123724e
Updated documentation.
vitenti Jan 13, 2024
2c6ca9e
Removed redundant checks.
vitenti Jan 13, 2024
86be99d
Removing more redundancies.
vitenti Jan 13, 2024
04825dd
Merge branch 'master' into save_predictions
marcpaterno Jan 25, 2024
55df315
Apply black
marcpaterno Jan 25, 2024
a155d99
Delete repeated test
marcpaterno Jan 25, 2024
f38f762
Simplify checking of RE match
marcpaterno Jan 25, 2024
3a0c3af
Add COMPUTED state to GaussFamily
marcpaterno Jan 25, 2024
bdc3575
Address failure to test line gauss_family:202
marcpaterno Jan 26, 2024
447c24d
Require 100% coverage on changed lines
marcpaterno Jan 26, 2024
af14c76
Remove needless call to super().__init__
marcpaterno Jan 26, 2024
a0f32d6
Support getting covariance for list of statistics
marcpaterno Jan 28, 2024
2a6134e
Merge branch 'master' into save_predictions
marcpaterno Jan 29, 2024
ef3b08e
Apply black
marcpaterno Jan 29, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ coverage:
patch:
default:
# basic
target: auto
target: 100%
threshold: 0%

# advanced
Expand Down Expand Up @@ -63,4 +63,5 @@ coverage:
removed_code_behavior: fully_covered_patch #off, removals_only, adjust_base",

github_checks:
annotations: true #,false
annotations: true #,false

9 changes: 7 additions & 2 deletions examples/des_y1_3x2pt/des_y1_3x2pt_PT.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ class CclSetup:

@dataclass
class CElls:
"""A package of related C_ell values, to reduce the number of variables
used in the :meth:`run_likelihood` method."""

GG: np.ndarray
GI: np.ndarray
II: np.ndarray
Expand Down Expand Up @@ -234,6 +237,7 @@ def run_likelihood() -> None:
assert likelihood.cov is not None

stat0 = likelihood.statistics[0].statistic
assert isinstance(stat0, TwoPoint)

# x = likelihood.statistics[0].ell_or_theta_
# y_data = likelihood.statistics[0].measured_statistic_
Expand All @@ -243,11 +247,12 @@ def run_likelihood() -> None:

print(list(stat0.cells.keys()))

stat2 = likelihood.statistics[2].statistic
stat2 = likelihood.statistics[2].statistic # pylint: disable=no-member
assert isinstance(stat2, TwoPoint)
print(list(stat2.cells.keys()))

stat3 = likelihood.statistics[3].statistic
stat3 = likelihood.statistics[3].statistic # pylint: disable=no-member
assert isinstance(stat3, TwoPoint)
print(list(stat3.cells.keys()))

plot_predicted_and_measured_statistics(
Expand Down
1 change: 1 addition & 0 deletions examples/des_y1_3x2pt/des_y1_cosmic_shear_TATT.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ def run_likelihood() -> None:
print(f"Log-like = {log_like:.1f}")

# Plot the predicted and measured statistic
assert isinstance(likelihood, ConstGaussian)
two_point_0 = likelihood.statistics[0].statistic
assert isinstance(two_point_0, TwoPoint)

Expand Down
3 changes: 1 addition & 2 deletions examples/des_y1_3x2pt/des_y1_cosmic_shear_pk_modifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,9 @@ def run_likelihood() -> None:
print(f"Log-like = {log_like:.1f}")

# Plot the predicted and measured statistic
assert isinstance(likelihood, ConstGaussian)
two_point_0 = likelihood.statistics[0].statistic
assert isinstance(two_point_0, TwoPoint)

assert isinstance(likelihood, ConstGaussian)
assert likelihood.cov is not None

# Predict CCL Cl
Expand Down
46 changes: 27 additions & 19 deletions firecrown/connector/cosmosis/likelihood.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@ class FirecrownLikelihood:
:param config: current CosmoSIS datablock
"""

likelihood: Likelihood
map: MappingCosmoSIS

def __init__(self, config: cosmosis.datablock):
"""Create the FirecrownLikelihood object from the given configuration."""
likelihood_source = config.get_string(option_section, "likelihood_source", "")
Expand All @@ -61,6 +58,7 @@ def __init__(self, config: cosmosis.datablock):

self.firecrown_module_name = option_section
self.sampling_sections = sections
self.likelihood: Likelihood
try:
self.likelihood, self.tools = load_likelihood(
likelihood_source, build_parameters
Expand All @@ -70,7 +68,7 @@ def __init__(self, config: cosmosis.datablock):
print(f"The Firecrown likelihood needs a required parameter: {err}")
print("*" * 30)
raise
self.map = mapping_builder(
self.map: MappingCosmoSIS = mapping_builder(
input_style="CosmoSIS", require_nonlinear_pk=require_nonlinear_pk
)

Expand Down Expand Up @@ -127,23 +125,31 @@ def execute(self, sample: cosmosis.datablock) -> int:
for section, name, val in derived_params_collection:
sample.put(section, name, val)

self.likelihood.reset()
self.tools.reset()
if not isinstance(self.likelihood, GaussFamily):
self.likelihood.reset()
self.tools.reset()
return 0

# Save concatenated data vector and inverse covariance to enable support
# If we get here, we have a GaussFamily likelihood, and we need to
# save concatenated data vector and inverse covariance to enable support
# for the CosmoSIS Fisher sampler. This can only work for likelihoods
# that have these quantities. Currently, this is only GaussFamily.

if isinstance(self.likelihood, GaussFamily):
sample.put(
"data_vector", "firecrown_theory", self.likelihood.predicted_data_vector
)
sample.put(
"data_vector", "firecrown_data", self.likelihood.measured_data_vector
)
sample.put(
"data_vector", "firecrown_inverse_covariance", self.likelihood.inv_cov
)
sample.put(
"data_vector",
"firecrown_theory",
self.likelihood.get_theory_vector(),
)
sample.put(
"data_vector",
"firecrown_data",
self.likelihood.get_data_vector(),
)
sample.put(
"data_vector",
"firecrown_inverse_covariance",
self.likelihood.inv_cov,
)

# Write out theory and data vectors to the data block the ease
# debugging.
Expand All @@ -164,14 +170,16 @@ def execute(self, sample: cosmosis.datablock) -> int:
sample.put(
"data_vector",
f"theory_{stat.sacc_data_type}_{tracer}",
stat.predicted_statistic_,
stat.get_theory_vector(),
)
sample.put(
"data_vector",
f"data_{stat.sacc_data_type}_{tracer}",
stat.measured_statistic_,
stat.get_data_vector(),
)

self.likelihood.reset()
self.tools.reset()
return 0

def form_error_message(self, exc: MissingSamplerParameterError) -> str:
Expand Down
Loading
Loading