-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Dataclass generator serialization (#426)
* Organizing warnings and filters for tests. * Add missing default values. * Renaming MeasuredType to Measurement. * Adding pydantic and working on serialization. * InferredZDist tutorial draft. * Improving tutorials cross ref. * New inferred_zdist_serialization tutorial. * Adding support for serializing factories. * Updated global factory use. * Updated tutorial to show factory serialization. * Remove obsolete parameter to fix ComoSIS complaint * Lock scipy version because update breaks CCL * Change spelling: 1d -> 2D * Introduce LogLinearElls generator * Tweaks to tutorials * Improve and test error messages * Add type annotation * Add test of global TattAlignmentSystematic * Test the failure modes of base_model_from_yaml --------- Co-authored-by: Marc Paterno <paterno@fnal.gov>
- Loading branch information
Showing
34 changed files
with
1,724 additions
and
537 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ dependencies: | |
- cobaya | ||
- pygobject-stubs | ||
- pyccl>=2.8.0 | ||
- pydantic | ||
- pytest | ||
- quarto | ||
- sacc>=0.11 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,7 +31,6 @@ feedback = 0 | |
zmin = 0.0 | ||
zmax = 4.0 | ||
nz = 100 | ||
kmin = 1e-4 | ||
kmax = 50.0 | ||
nk = 1000 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
"""Generator support for TwoPoint statistics.""" | ||
|
||
from typing import Annotated | ||
from pydantic import BaseModel, Field, model_validator | ||
|
||
import numpy as np | ||
import numpy.typing as npt | ||
|
||
|
||
class LogLinearElls(BaseModel): | ||
"""Generator for log-linear integral ell values. | ||
Not all ell values will be generated. The result will contain each integral | ||
value from min to mid. Starting from mid, and going up to max, there will be | ||
n_log logarithmically spaced values. | ||
Note that midpoint must be strictly greater than minimum, and strictly less | ||
than maximum. n_log must be positive. | ||
""" | ||
|
||
minimum: Annotated[int, Field(ge=0)] | ||
midpoint: Annotated[int, Field(ge=0)] | ||
maximum: Annotated[int, Field(ge=0)] | ||
n_log: Annotated[int, Field(ge=1)] | ||
|
||
@model_validator(mode="after") | ||
def require_increasing(self) -> "LogLinearElls": | ||
"""Validate the ell values.""" | ||
assert self.minimum < self.midpoint | ||
assert self.midpoint < self.maximum | ||
return self | ||
|
||
def generate(self) -> npt.NDArray[np.int64]: | ||
"""Generate the log-linear ell values. | ||
The result will contain each integral value from min to mid. Starting | ||
from mid, and going up to max, there will be n_log logarithmically | ||
spaced values. | ||
""" | ||
minimum, midpoint, maximum, n_log = ( | ||
self.minimum, | ||
self.midpoint, | ||
self.maximum, | ||
self.n_log, | ||
) | ||
lower_range = np.linspace(minimum, midpoint - 1, midpoint - minimum) | ||
upper_range = np.logspace(np.log10(midpoint), np.log10(maximum), n_log) | ||
concatenated = np.concatenate((lower_range, upper_range)) | ||
# Round the results to the nearest integer values. | ||
# N.B. the dtype of the result is np.dtype[float64] | ||
return np.unique(np.around(concatenated)).astype(np.int64) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.