From 284daef5aa4615c4c6a5ac95f35627ce2dbbb495 Mon Sep 17 00:00:00 2001 From: vschac Date: Fri, 13 Jun 2025 13:25:56 -0400 Subject: [PATCH 01/12] updated save in example --- .gitignore | 1 + examples/v4_example.py | 27 +++++++++++++++------------ 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/.gitignore b/.gitignore index 940ff1f..8872c2a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ examples/*.pdf examples/*.npy examples/output/* +examples/outputs/* *.pyc build/ plot_test_outputs/ diff --git a/examples/v4_example.py b/examples/v4_example.py index 0638c08..92e6222 100644 --- a/examples/v4_example.py +++ b/examples/v4_example.py @@ -214,23 +214,26 @@ # 7. SAVE/LOAD FUNCTIONALITY # =============================================================================== print('\n7. === SAVE/LOAD DEMONSTRATION ===') -handler.output_dir = 'output' # Set output directory -# Save some results -handler.save_output(P_1loop_result, 'one_loop_example', type='csv') -handler.save_params('example_params', P=P_linear, C_window=0.75) +# Update the default parameters before saving the handler instance +handler.update_default_params( + P=P_linear, + C_window=0.75, + P_window=np.array([0.2, 0.2]), +) +handler.save_instance('example_handler') +# ^^ This will also save the parameters used to make the handler's fastpt instance -# Load them back -loaded_result = handler.load('one_loop_example_output.csv') -loaded_params = handler.load_params('example_params') +# Load them back in a new handler instance +loaded_handler = FPTHandler.load_instance('outputs/example_handler') -# And to use the loaded parameters: -handler.run('one_loop_dd', **loaded_params) -# or using Fast-PT directly: -fpt.one_loop_dd(**loaded_params) +# Now use the loaded handler with stored parameters to run calculations: +handler.run('one_loop_dd') +# or using the loaded Fast-PT instance directly: +loaded_handler.fastpt.one_loop_dd(**loaded_handler.default_params) print('✓ Saved and loaded results and parameters') -print(f' → Loaded parameters: {list(loaded_params.keys())}') +print(f' → Loaded parameters: {list(loaded_handler.default_params.keys())}') # =============================================================================== # 8. CACHE INFORMATION From a31bc33fafe103357c674efe2a0e14b0731b0026 Mon Sep 17 00:00:00 2001 From: Vincent Schacknies <136936124+vschac@users.noreply.github.com> Date: Mon, 23 Jun 2025 11:11:07 -0500 Subject: [PATCH 02/12] Update ci.yml --- .github/workflows/ci.yml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a744bd2..06b5aa6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -3,12 +3,11 @@ name: FAST-PT CI on: push: branches: - - main - - code-upgrades - - structural-changes + - beta-fpt pull_request: branches: - - main + - beta-fpt + workflow_dispatch: jobs: test: From 046b4c64243fe92135e681290c27901aea74a2ee Mon Sep 17 00:00:00 2001 From: Vincent Schacknies <136936124+vschac@users.noreply.github.com> Date: Mon, 23 Jun 2025 11:30:57 -0500 Subject: [PATCH 03/12] Update ci.yml --- .github/workflows/ci.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 06b5aa6..555f1af 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -32,5 +32,9 @@ jobs: pip install -e . pip install pytest + - name: Install optional dependencies + run: | + pip install classy camb + - name: Run unit/benchmark tests run: pytest tests/ --disable-warnings From 2b8359e95d4f4f87a9816c8f46689cb7422d58b5 Mon Sep 17 00:00:00 2001 From: vschac Date: Mon, 23 Jun 2025 11:49:32 -0500 Subject: [PATCH 04/12] skipped pk tests if class/camb not installed --- tests/test_handler.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tests/test_handler.py b/tests/test_handler.py index 798f61b..f20bd08 100644 --- a/tests/test_handler.py +++ b/tests/test_handler.py @@ -1067,6 +1067,8 @@ def test_save_and_use_in_run(fpt, temp_output_dir): ################# POWER SPECTRA GENERATOR TESTS ################# def test_generate_power_spectra_basic(handler): + pytest.importorskip("classy", reason="classy is not installed") + pytest.importorskip("camb", reason="camb is not installed") """Test basic single-mode power spectra generation with default parameters""" # Test class with default parameters class_result = handler.generate_power_spectra(method='class') @@ -1081,6 +1083,8 @@ def test_generate_power_spectra_basic(handler): assert np.all(camb_result > 0) def test_generate_power_spectra_methods(handler): + pytest.importorskip("classy", reason="classy is not installed") + pytest.importorskip("camb", reason="camb is not installed") """Test power spectra generation with different methods""" # Generate power spectra with different methods but same params class_result = handler.generate_power_spectra(method='class', omega_cdm=0.12, h=0.7, omega_b=0.022, z=0.5) @@ -1107,6 +1111,8 @@ def test_generate_power_spectra_single_mode_array_error(handler): handler.generate_power_spectra(omega_cdm=[0.1, 0.2]) def test_generate_power_spectra_params(handler): + pytest.importorskip("classy", reason="classy is not installed") + pytest.importorskip("camb", reason="camb is not installed") """Test power spectra generation with different parameter values""" # Generate with different parameter values base_result = handler.generate_power_spectra(method='class') @@ -1118,6 +1124,8 @@ def test_generate_power_spectra_params(handler): assert not np.allclose(base_result, high_cdm_result) def test_bulk_power_spectra(handler): + pytest.importorskip("classy", reason="classy is not installed") + pytest.importorskip("camb", reason="camb is not installed") """Test bulk mode power spectra generation""" # Test with arrays of different lengths bulk_results = handler.generate_power_spectra( @@ -1139,6 +1147,8 @@ def test_bulk_power_spectra(handler): assert np.all(result > 0) def test_bulk_power_spectra_single_entry(handler): + pytest.importorskip("classy", reason="classy is not installed") + pytest.importorskip("camb", reason="camb is not installed") """Test bulk mode with single entry arrays""" # When all parameters are length 1, should return a single result single_bulk_result = handler.generate_power_spectra( @@ -1154,6 +1164,8 @@ def test_bulk_power_spectra_single_entry(handler): assert len(single_bulk_result) == len(handler.fastpt.k_original) def test_diff_power_spectra_basic(handler): + pytest.importorskip("classy", reason="classy is not installed") + pytest.importorskip("camb", reason="camb is not installed") """Test diff mode power spectra generation""" # Test with basic parameters diff_results = handler.generate_power_spectra( @@ -1178,6 +1190,8 @@ def test_diff_power_spectra_basic(handler): assert len(value) == len(handler.fastpt.k_original) def test_diff_power_spectra_multi_param(handler): + pytest.importorskip("classy", reason="classy is not installed") + pytest.importorskip("camb", reason="camb is not installed") """Test diff mode with multiple variable parameters""" diff_results = handler.generate_power_spectra( mode='diff', @@ -1196,6 +1210,8 @@ def test_diff_power_spectra_multi_param(handler): assert (0.0, 2) in diff_results.keys(), "h high variation not found" def test_diff_power_spectra_requires_length_3(handler): + pytest.importorskip("classy", reason="classy is not installed") + pytest.importorskip("camb", reason="camb is not installed") """Test that diff mode requires at least one parameter with length 3""" with pytest.raises(ValueError, match="must have length 3"): handler.generate_power_spectra( @@ -1207,6 +1223,8 @@ def test_diff_power_spectra_requires_length_3(handler): ) def test_diff_power_spectra_with_multiple_z(handler): + pytest.importorskip("classy", reason="classy is not installed") + pytest.importorskip("camb", reason="camb is not installed") """Test diff mode with multiple redshifts""" diff_results = handler.generate_power_spectra( mode='diff', @@ -1227,6 +1245,8 @@ def test_diff_power_spectra_with_multiple_z(handler): assert len(z05_keys) == 3 def test_camb_specific_params(handler): + pytest.importorskip("classy", reason="classy is not installed") + pytest.importorskip("camb", reason="camb is not installed") """Test CAMB-specific parameters""" # With nonlinear=True result_nl = handler.generate_power_spectra( @@ -1253,6 +1273,8 @@ def test_camb_specific_params(handler): assert not np.allclose(result_nl, result_halofit) def test_class_camb_parameter_consistency(handler): + pytest.importorskip("classy", reason="classy is not installed") + pytest.importorskip("camb", reason="camb is not installed") """Test consistency in parameter handling between CLASS and CAMB""" # Generate spectra with same parameters params = { From a271e0c46707fbe0d2f5d28c08169988b0eea8e0 Mon Sep 17 00:00:00 2001 From: Vincent Schacknies <136936124+vschac@users.noreply.github.com> Date: Mon, 23 Jun 2025 11:53:03 -0500 Subject: [PATCH 05/12] Update ci.yml --- .github/workflows/ci.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 555f1af..06b5aa6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -32,9 +32,5 @@ jobs: pip install -e . pip install pytest - - name: Install optional dependencies - run: | - pip install classy camb - - name: Run unit/benchmark tests run: pytest tests/ --disable-warnings From d416ec39c2800aa640ca3e774d75f684b7bb13fa Mon Sep 17 00:00:00 2001 From: Vincent Schacknies <136936124+vschac@users.noreply.github.com> Date: Mon, 23 Jun 2025 12:01:52 -0500 Subject: [PATCH 06/12] Update ci.yml --- .github/workflows/ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 06b5aa6..9d418de 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -30,6 +30,7 @@ jobs: run: | python -m pip install --upgrade pip pip install -e . + pip install numpy==1.26.4 pip install pytest - name: Run unit/benchmark tests From ca561dd3c27ef6bbff550a291816b1fc7b41a928 Mon Sep 17 00:00:00 2001 From: Vincent Schacknies <136936124+vschac@users.noreply.github.com> Date: Mon, 23 Jun 2025 12:06:58 -0500 Subject: [PATCH 07/12] Update ci.yml --- .github/workflows/ci.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9d418de..59c1fe2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -4,9 +4,11 @@ on: push: branches: - beta-fpt + - master pull_request: branches: - beta-fpt + - master workflow_dispatch: jobs: @@ -15,7 +17,7 @@ jobs: strategy: matrix: - python-version: ["3.13", "3.11"] + python-version: ["3.13", "3.11", "3.7"] steps: - name: Checkout repository @@ -34,4 +36,4 @@ jobs: pip install pytest - name: Run unit/benchmark tests - run: pytest tests/ --disable-warnings + run: pytest tests/ From a513e04037b4382df044a0b97f752f15acb564dd Mon Sep 17 00:00:00 2001 From: Vincent Schacknies <136936124+vschac@users.noreply.github.com> Date: Mon, 23 Jun 2025 12:13:02 -0500 Subject: [PATCH 08/12] Update ci.yml --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 59c1fe2..39ccadf 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,7 +17,7 @@ jobs: strategy: matrix: - python-version: ["3.13", "3.11", "3.7"] + python-version: ["3.13", "3.11", "3.8"] steps: - name: Checkout repository From 6fe8b4d0b32cd482ce37c3be2c4711bc983ae3db Mon Sep 17 00:00:00 2001 From: Vincent Schacknies <136936124+vschac@users.noreply.github.com> Date: Mon, 23 Jun 2025 12:14:50 -0500 Subject: [PATCH 09/12] Update ci.yml --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 39ccadf..b4b2f79 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,7 +17,7 @@ jobs: strategy: matrix: - python-version: ["3.13", "3.11", "3.8"] + python-version: ["3.13", "3.11", "3.9"] steps: - name: Checkout repository From b86a9b023670de71722f6ebc282a2bd7c525da5d Mon Sep 17 00:00:00 2001 From: vschac Date: Mon, 23 Jun 2025 12:33:59 -0500 Subject: [PATCH 10/12] marked tests for skip --- tests/test_benchmarks.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tests/test_benchmarks.py b/tests/test_benchmarks.py index d9a735d..3f7402c 100644 --- a/tests/test_benchmarks.py +++ b/tests/test_benchmarks.py @@ -3,6 +3,8 @@ from fastpt import FASTPT import os import warnings +import sys +import platform data_path = os.path.join(os.path.dirname(__file__), 'benchmarking', 'Pk_test.dat') d = np.loadtxt(data_path) @@ -36,6 +38,10 @@ def calc_and_show(bmark, stored, func): plt.show() def test_one_loop_dd(fpt): + pytest.mark.skipif( + sys.version_info >= (3, 13) or platform.machine() == "arm64", + reason="Strict benchmark comparison is not reliable on Python 3.13+ or ARM64 runners" + ) bmark = fpt.one_loop_dd(P, C_window=C_window)[0] stored = np.loadtxt('tests/benchmarking/P_dd_benchmark.txt') # calc_and_show(bmark, stored, "one_loop_dd") @@ -45,6 +51,10 @@ def test_one_loop_dd(fpt): assert np.allclose(bmark, stored) def test_one_loop_dd_bias(fpt): + pytest.mark.skipif( + sys.version_info >= (3, 13) or platform.machine() == "arm64", + reason="Strict benchmark comparison is not reliable on Python 3.13+ or ARM64 runners" + ) bmark = list(fpt.one_loop_dd_bias(P, C_window=C_window)) new_array = np.zeros(3000) new_array[0] = bmark[7] @@ -58,6 +68,10 @@ def test_one_loop_dd_bias(fpt): assert np.allclose(bmark, stored) def test_one_loop_dd_bias_b3nl(fpt): + pytest.mark.skipif( + sys.version_info >= (3, 13) or platform.machine() == "arm64", + reason="Strict benchmark comparison is not reliable on Python 3.13+ or ARM64 runners" + ) bmark = list(fpt.one_loop_dd_bias_b3nl(P, C_window=C_window)) new_array = np.zeros(3000) new_array[0] = bmark[7] @@ -71,6 +85,10 @@ def test_one_loop_dd_bias_b3nl(fpt): assert np.allclose(bmark, stored) def test_one_loop_dd_bias_lpt_NL(fpt): + pytest.mark.skipif( + sys.version_info >= (3, 13) or platform.machine() == "arm64", + reason="Strict benchmark comparison is not reliable on Python 3.13+ or ARM64 runners" + ) bmark = list(fpt.one_loop_dd_bias_lpt_NL(P, C_window=C_window)) new_array = np.zeros(3000) new_array[0] = bmark[6] @@ -137,6 +155,10 @@ def test_RSD_ABsum_mu(fpt): assert np.allclose(bmark, np.loadtxt('tests/benchmarking/P_RSD_ABsum_mu_benchmark.txt')) def test_IRres(fpt): + pytest.mark.skipif( + sys.version_info >= (3, 13) or platform.machine() == "arm64", + reason="Strict benchmark comparison is not reliable on Python 3.13+ or ARM64 runners" + ) bmark = fpt.IRres(P, C_window=C_window) stored = np.transpose(np.loadtxt('tests/benchmarking/P_IRres_benchmark.txt')) # calc_and_show(bmark, stored, "IRres") From 41735b3e13902fc95153ef5d1e2517b423da9701 Mon Sep 17 00:00:00 2001 From: vschac Date: Mon, 23 Jun 2025 12:38:02 -0500 Subject: [PATCH 11/12] moved skip to decorator --- tests/test_benchmarks.py | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/tests/test_benchmarks.py b/tests/test_benchmarks.py index 3f7402c..a92077d 100644 --- a/tests/test_benchmarks.py +++ b/tests/test_benchmarks.py @@ -37,8 +37,12 @@ def calc_and_show(bmark, stored, func): plt.legend() plt.show() +@pytest.mark.skipif( + sys.version_info >= (3, 13) or platform.machine() == "arm64", + reason="Strict benchmark comparison is not reliable on Python 3.13+ or ARM64 runners" + ) def test_one_loop_dd(fpt): - pytest.mark.skipif( + pytestmark = pytest.mark.skipif( sys.version_info >= (3, 13) or platform.machine() == "arm64", reason="Strict benchmark comparison is not reliable on Python 3.13+ or ARM64 runners" ) @@ -50,11 +54,11 @@ def test_one_loop_dd(fpt): " We can guarantee a precision of 9e-5 up until a k value of 10.") assert np.allclose(bmark, stored) -def test_one_loop_dd_bias(fpt): - pytest.mark.skipif( +@pytest.mark.skipif( sys.version_info >= (3, 13) or platform.machine() == "arm64", reason="Strict benchmark comparison is not reliable on Python 3.13+ or ARM64 runners" ) +def test_one_loop_dd_bias(fpt): bmark = list(fpt.one_loop_dd_bias(P, C_window=C_window)) new_array = np.zeros(3000) new_array[0] = bmark[7] @@ -67,11 +71,11 @@ def test_one_loop_dd_bias(fpt): " We can guarantee a precision of 9e-5 up until a k value of 10.") assert np.allclose(bmark, stored) -def test_one_loop_dd_bias_b3nl(fpt): - pytest.mark.skipif( +@pytest.mark.skipif( sys.version_info >= (3, 13) or platform.machine() == "arm64", reason="Strict benchmark comparison is not reliable on Python 3.13+ or ARM64 runners" ) +def test_one_loop_dd_bias_b3nl(fpt): bmark = list(fpt.one_loop_dd_bias_b3nl(P, C_window=C_window)) new_array = np.zeros(3000) new_array[0] = bmark[7] @@ -84,11 +88,11 @@ def test_one_loop_dd_bias_b3nl(fpt): " We can guarantee a precision of 6e-4 up until a k value of 10.") assert np.allclose(bmark, stored) -def test_one_loop_dd_bias_lpt_NL(fpt): - pytest.mark.skipif( +@pytest.mark.skipif( sys.version_info >= (3, 13) or platform.machine() == "arm64", reason="Strict benchmark comparison is not reliable on Python 3.13+ or ARM64 runners" ) +def test_one_loop_dd_bias_lpt_NL(fpt): bmark = list(fpt.one_loop_dd_bias_lpt_NL(P, C_window=C_window)) new_array = np.zeros(3000) new_array[0] = bmark[6] @@ -154,11 +158,11 @@ def test_RSD_ABsum_mu(fpt): bmark = np.transpose(fpt.RSD_ABsum_mu(P, 1.0, 1.0, C_window=C_window)) assert np.allclose(bmark, np.loadtxt('tests/benchmarking/P_RSD_ABsum_mu_benchmark.txt')) -def test_IRres(fpt): - pytest.mark.skipif( +@pytest.mark.skipif( sys.version_info >= (3, 13) or platform.machine() == "arm64", reason="Strict benchmark comparison is not reliable on Python 3.13+ or ARM64 runners" ) +def test_IRres(fpt): bmark = fpt.IRres(P, C_window=C_window) stored = np.transpose(np.loadtxt('tests/benchmarking/P_IRres_benchmark.txt')) # calc_and_show(bmark, stored, "IRres") From 7d253b7c900da507634c13cac64ca9b8cbbf4b95 Mon Sep 17 00:00:00 2001 From: vschac Date: Thu, 10 Jul 2025 14:11:17 -0400 Subject: [PATCH 12/12] removed second skip --- tests/test_benchmarks.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/tests/test_benchmarks.py b/tests/test_benchmarks.py index a92077d..b5a91ad 100644 --- a/tests/test_benchmarks.py +++ b/tests/test_benchmarks.py @@ -42,10 +42,6 @@ def calc_and_show(bmark, stored, func): reason="Strict benchmark comparison is not reliable on Python 3.13+ or ARM64 runners" ) def test_one_loop_dd(fpt): - pytestmark = pytest.mark.skipif( - sys.version_info >= (3, 13) or platform.machine() == "arm64", - reason="Strict benchmark comparison is not reliable on Python 3.13+ or ARM64 runners" - ) bmark = fpt.one_loop_dd(P, C_window=C_window)[0] stored = np.loadtxt('tests/benchmarking/P_dd_benchmark.txt') # calc_and_show(bmark, stored, "one_loop_dd")