Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
20 changes: 0 additions & 20 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,26 +29,6 @@ jobs:
run: |
pre-commit run -a

test_code_python3p8:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.8"]
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install .[dev]
- name: Test code
run: |
mkdir test_report
tox


test_code_and_coverage_report_python3p11:
runs-on: ubuntu-latest
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ coverage.xml
*.cover
.hypothesis/
.pytest_cache/
test_report/

# Translations
*.mo
Expand Down
36 changes: 18 additions & 18 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Default image, if not specified
image: "python:3.8"
image: "python:3.11"

stages:
- Static Analysis
Expand Down Expand Up @@ -96,34 +96,34 @@ mypy:
- test_report/cov_report
expire_in: 1 hour

tox-3.6:
extends: ".tox"
stage: "Test"
image: "python:3.6"
rules:
- if: '$CI_COMMIT_TAG'
when: always

tox-3.7:
extends: ".tox"
stage: "Test"
image: "python:3.7"
#tox-3.7:
# extends: ".tox"
# stage: "Test"
# image: "python:3.7"
# rules:
# - if: '$CI_COMMIT_TAG'
# when: always

tox-3.8:
tox-3.9:
extends: ".tox"
stage: "Test"
image: "python:3.8"
image: "python:3.9"
rules:
- if: '$CI_COMMIT_TAG'
when: always

tox-3.9:
tox-3.11:
extends: ".tox"
stage: "Test"
image: "python:3.9"
image: "python:3.11"

#tox-3.13:
# extends: ".tox"
# stage: "Test"
# image: "python:3.13"
# rules:
# - if: '$CI_COMMIT_TAG'
# when: always


# tox_slowtests:
Expand Down Expand Up @@ -153,7 +153,7 @@ tox-3.9:
# needs: []

test_report:
needs: ["tox-3.9"]
needs: ["tox-3.11"]
stage: Publish test report
image:
name: oberonamsterdam/wkhtmltopdf
Expand Down
2 changes: 1 addition & 1 deletion docs/content/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ LPUPropagation
lpu.lpu_propagation.LPUPropagation.propagate_random
lpu.lpu_propagation.LPUPropagation.propagate_systematic
lpu.lpu_propagation.LPUPropagation.propagate_cov
lpu.lpu_propagation.LPUPropagation.propagate_flattened_cov
lpu.lpu_propagation.LPUPropagation.propagate_cov_flattened
lpu.lpu_propagation.LPUPropagation.process_jacobian

Digital Effects Tables
Expand Down
2 changes: 1 addition & 1 deletion punpy/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "1.0.1"
__version__ = "1.0.7"
54 changes: 28 additions & 26 deletions punpy/digital_effects_table/measurement_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,18 +337,24 @@ def propagate_ds(
repeat_dim_err_corrs=repeat_dim_err_corrs,
)

if not include_corr:
ds_vars = copy.deepcopy(list(template.keys()))
for key in ds_vars:
if key[:8] == "err_corr":
template.pop(key)

# create dataset template
ds_out = obsarray.create_ds(template, self.sizes_dict)

# add trivial first dimension to so we can loop over output_vars later
if self.output_vars == 1:
if u_rand_y is not None:
if isinstance(u_rand_y, np.ndarray):
u_rand_y = u_rand_y[None, ...]
if u_syst_y is not None:
if isinstance(u_syst_y, np.ndarray):
u_syst_y = u_syst_y[None, ...]
if u_stru_y is not None:
if isinstance(u_stru_y, np.ndarray):
u_stru_y = u_stru_y[None, ...]
if corr_stru_y is not None:
if isinstance(corr_stru_y, np.ndarray):
corr_stru_y = corr_stru_y[None, ...]

# loop through measurands
Expand All @@ -364,7 +370,7 @@ def propagate_ds(
ucomp_sys = "u_sys_" + self.yvariable[i]
ucomp_str = "u_str_" + self.yvariable[i]

if u_rand_y is None:
if not isinstance(u_rand_y, np.ndarray):
ds_out = self.templ.remove_unc_component(
ds_out, self.yvariable[i], ucomp_ran
)
Expand All @@ -374,7 +380,7 @@ def propagate_ds(
else:
ds_out[ucomp_ran].values = u_rand_y[i]

if u_syst_y is None:
if not isinstance(u_syst_y, np.ndarray):
ds_out = self.templ.remove_unc_component(
ds_out, self.yvariable[i], ucomp_sys
)
Expand All @@ -384,7 +390,7 @@ def propagate_ds(
else:
ds_out[ucomp_sys].values = u_syst_y[i]

if u_stru_y is None:
if not isinstance(u_stru_y, np.ndarray):
ds_out = self.templ.remove_unc_component(
ds_out,
self.yvariable[i],
Expand All @@ -405,10 +411,6 @@ def propagate_ds(
i,
use_ds_out_pre_unmodified,
)
else:
ds_out.drop("err_corr_str_" + self.yvariable[i])

# ds_out.drop("err_corr_str_between")

if (ds_out_pre is not None) and not use_ds_out_pre_unmodified:
self.templ.join_with_preexisting_ds(
Expand Down Expand Up @@ -500,6 +502,12 @@ def propagate_ds_total(
repeat_dim_err_corrs=repeat_dim_err_corrs,
)

if not include_corr:
ds_vars = copy.deepcopy(list(template.keys()))
for key in ds_vars:
if key[:8] == "err_corr":
template.pop(key)

# create dataset template
ds_out = obsarray.create_ds(template, self.sizes_dict)

Expand Down Expand Up @@ -537,18 +545,6 @@ def propagate_ds_total(
use_ds_out_pre_unmodified,
)

else:
if len(self.str_corr_dims) == 1:
ds_out.drop("err_corr_tot_" + self.yvariable[i])
else:
for ii in range(len(self.str_corr_dims)):
ds_out.drop(
"err_corr_tot_"
+ self.yvariable[i]
+ "_"
+ self.str_corr_dims[ii]
)

if (ds_out_pre is not None) and not use_ds_out_pre_unmodified:
self.templ.join_with_preexisting_ds(
ds_out, ds_out_pre, drop=self.yvariable[i]
Expand Down Expand Up @@ -645,6 +641,12 @@ def propagate_ds_specific(
simple_systematic=simple_systematic,
)

if not include_corr:
ds_vars = copy.deepcopy(list(template.keys()))
for key in ds_vars:
if key[:8] == "err_corr":
template.pop(key)

# create dataset template
ds_out = obsarray.create_ds(template, self.sizes_dict)

Expand Down Expand Up @@ -805,7 +807,7 @@ def propagate_ds_all(
include_corr=include_corr,
)

def run(self, *args, expand=False):
def run_meas_function(self, *args, expand=False):
"""
Function to calculate the measurand by running input quantities through measurement function.

Expand Down Expand Up @@ -1219,7 +1221,7 @@ def _check_sizes_and_run(self, *args, expand=False, ds_out_pre=None):
"punpy.MeasurementFunction: When using a measurement function with multiple measurands with different shapes, you cannot set parallel_cores to 0 (the default) when creating the prop object."
)

# define dictionary with dimension sizes (needs to be done before self.run() when expand==True)
# define dictionary with dimension sizes (needs to be done before self.run_meas_function() when expand==True)
if self.sizes_dict is None and expand:
self.sizes_dict = {}
for i in range(self.output_vars):
Expand All @@ -1239,7 +1241,7 @@ def _check_sizes_and_run(self, *args, expand=False, ds_out_pre=None):
continue

# run the measurement function
y = self.run(*args, expand=expand)
y = self.run_meas_function(*args, expand=expand)

if self.output_vars == 1:
y = y[None, ...]
Expand Down
Binary file modified punpy/digital_effects_table/tests/propagate_ds_example.nc
Binary file not shown.
14 changes: 7 additions & 7 deletions punpy/digital_effects_table/tests/test_measurement_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def test_gaslaw(self):
)
ds_y_tot = gl.propagate_ds_total(ds)

prop = MCPropagation(3000, dtype="float32", verbose=False)
prop = MCPropagation(1000, dtype="float32", verbose=False)
gl = IdealGasLaw(
prop,
["pressure", "temperature", "n_moles"],
Expand All @@ -156,10 +156,10 @@ def test_gaslaw(self):
)

npt.assert_allclose(ds_y["volume"].values, volume, rtol=0.002)
npt.assert_allclose(ds_y["u_ran_volume"].values, u_ran_volume, rtol=0.08)
npt.assert_allclose(ds_y["u_sys_volume"].values, u_sys_volume, rtol=0.08)
npt.assert_allclose(ds_y["u_str_volume"].values, u_str_volume, rtol=0.08)
npt.assert_allclose(ds_y["u_str_volume"].values, u_str_volume, rtol=0.08)
npt.assert_allclose(ds_y["u_ran_volume"].values, u_ran_volume, rtol=0.1)
npt.assert_allclose(ds_y["u_sys_volume"].values, u_sys_volume, rtol=0.1)
npt.assert_allclose(ds_y["u_str_volume"].values, u_str_volume, rtol=0.1)
npt.assert_allclose(ds_y["u_str_volume"].values, u_str_volume, rtol=0.1)
npt.assert_allclose(
ds_y.unc["volume"].total_unc().values, u_tot_volume, rtol=0.12
)
Expand Down Expand Up @@ -349,7 +349,7 @@ def test_hypernets(self):
)

hmf.setup(0.1)
y = hmf.run(calib_data, L0data.variables, L0data)
y = hmf.run_meas_function(calib_data, L0data.variables, L0data)
u_y_rand = hmf.propagate_random(L0data, calib_data)
print(u_y_rand)
# print(u_y_rand,L0data)
Expand Down Expand Up @@ -427,7 +427,7 @@ def test_hypernets_repeat_dim(self):
corr_dims=-99,
)
hmf.setup(0.1)
y = hmf.run(calib_data, L0data)
y = hmf.run_meas_function(calib_data, L0data)
u_y_rand = hmf.propagate_random(L0data, calib_data)
# print(list(L1data.variables))
mask = np.where(
Expand Down
2 changes: 1 addition & 1 deletion punpy/lpu/lpu_propagation.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ def propagate_standard(
return_Jacobian,
)

def propagate_flattened_cov(
def propagate_cov_flattened(
self,
func,
x,
Expand Down
37 changes: 30 additions & 7 deletions punpy/mc/mc_propagation.py
Original file line number Diff line number Diff line change
Expand Up @@ -999,7 +999,7 @@ def _perform_checks(
count = 0
for i in range(len(x)):
if u_x[i] is None:
if hasattr(x[i], "__len__"):
if hasattr(x[i], "shape"):
u_x[i] = np.zeros(x[i].shape)
else:
u_x[i] = 0.0
Expand Down Expand Up @@ -1519,6 +1519,10 @@ def run_samples(
[
np.any(np.isfinite(MC_y[i][ivar]))
for ivar in range(output_vars)
if (
hasattr(MC_y[i][ivar], "__len__")
and (len(MC_y[i][ivar]) > 0)
)
]
)
],
Expand All @@ -1533,6 +1537,10 @@ def run_samples(
[
np.any(np.isfinite(MC_y[i][ivar]))
for ivar in range(output_vars)
if (
hasattr(MC_y[i][ivar], "__len__")
and (len(MC_y[i][ivar]) > 0)
)
]
)
],
Expand All @@ -1549,6 +1557,10 @@ def run_samples(
[
np.all(np.isfinite(MC_y[i][ivar]))
for ivar in range(output_vars)
if (
hasattr(MC_y[i][ivar], "__len__")
and (len(MC_y[i][ivar]) > 0)
)
]
)
],
Expand All @@ -1563,6 +1575,10 @@ def run_samples(
[
np.all(np.isfinite(MC_y[i][ivar]))
for ivar in range(output_vars)
if (
hasattr(MC_y[i][ivar], "__len__")
and (len(MC_y[i][ivar]) > 0)
)
]
)
],
Expand Down Expand Up @@ -1667,14 +1683,18 @@ def process_samples(
complex_shapes = False

if complex_shapes:
MC_y2 = np.empty(output_vars, dtype=object)
u_func = np.empty(output_vars, dtype=object)

for i in range(output_vars):
MC_y2[i] = np.empty((self.MCsteps,) + yshapes[i])
for j in range(self.MCsteps):
MC_y2[i][j] = MC_y[j, i]
u_func[i] = np.std(np.array(MC_y2[i]), axis=0, dtype=self.dtype)
u_func[i] = np.std(
np.array(list(MC_y[:, i])), axis=0, dtype=self.dtype
)

# for i in range(output_vars):
# MC_y2[i] = np.empty((self.MCsteps,) + yshapes[i])
# for j in range(self.MCsteps):
# MC_y2[i][j] = MC_y[j, i]
# u_func[i] = np.std(np.array(MC_y2[i]), axis=0, dtype=self.dtype)

else:
u_func = np.std(MC_y, axis=0, dtype=self.dtype)
Expand Down Expand Up @@ -1728,7 +1748,10 @@ def process_samples(
if fixed_corr is None:
if complex_shapes:
corr_ys[i] = cm.calculate_corr(
MC_y2[i], corrdims, PD_corr, self.dtype
np.array(list(MC_y[:, i])),
corrdims,
PD_corr,
self.dtype,
)
else:
corr_ys[i] = cm.calculate_corr(
Expand Down
Loading