Skip to content

Commit de9b604

Browse files
Added support for python 3.13.x (fitbenchmarking#1372)
* made code compatible with python 3.13 * changed from 3.x to 3.13 for testing temp commit * updated all workflows to use 3.x * Updated integration tests to use conda env * removed the integration test hack for testing --------- Co-authored-by: Andrew Lister <48282025+AndrewLister-STFC@users.noreply.github.com>
1 parent eaf2af8 commit de9b604

File tree

5 files changed

+48
-56
lines changed

5 files changed

+48
-56
lines changed

.github/workflows/integration.yml

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,34 @@ jobs:
1313
fail-fast: false
1414
matrix:
1515
os: [macos-13, windows-latest]
16-
python: ['3.9', '3.12']
16+
python: ['3.9', '3.13']
17+
exclude:
18+
- os: windows-latest
19+
python: '3.13'
1720
runs-on: ${{ matrix.os }}
1821
steps:
1922
- name: Checkout code
2023
uses: actions/checkout@v4
21-
- name: Install python
22-
uses: actions/setup-python@v5
24+
- name: Set up conda
25+
uses: conda-incubator/setup-miniconda@v2
2326
with:
24-
python-version: ${{ matrix.python }}
25-
check-latest: true
26-
- name: Install dependencies
27+
miniconda-version: "latest"
28+
- name: Install dependencies in conda env
29+
shell: bash
2730
run: |
28-
python -m pip install .[bumps,DFO,gradient-free,minuit,SAS,numdifftools,lmfit,nlopt]
31+
source $CONDA/etc/profile.d/conda.sh
32+
conda create -n default-test-env python=${{ matrix.python }} -y
33+
conda activate default-test-env
34+
conda install -c conda-forge nlopt -y
35+
python -m pip install .[bumps,DFO,gradient-free,minuit,SAS,numdifftools,lmfit]
2936
python -m pip install --upgrade .[dev]
30-
python -m pip install "numpy<2.0"
31-
- name: Run macos tests
32-
if: runner.os == 'macOS'
33-
run: ci/unit_tests_default.sh
34-
- name: Run windows tests
35-
if: runner.os == 'Windows'
36-
run: bash ci/unit_tests_default.sh
37+
- name: Run tests
38+
shell: bash
39+
run: |
40+
source $CONDA/etc/profile.d/conda.sh
41+
conda activate default-test-env
42+
if [ "${{ matrix.os }}" == "macos-13" ]; then
43+
ci/unit_tests_default.sh
44+
else
45+
bash ci/unit_tests_default.sh
46+
fi

.github/workflows/main.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
- name: Install python
2727
uses: actions/setup-python@v5
2828
with:
29-
python-version: '3.12'
29+
python-version: '3.13'
3030
check-latest: true
3131
- name: Install dependencies
3232
run: |
@@ -116,7 +116,7 @@ jobs:
116116
strategy:
117117
fail-fast: false
118118
matrix:
119-
python: ['3.9', '3.12']
119+
python: ['3.9', '3.13']
120120
runs-on: ubuntu-latest
121121
steps:
122122
- name: Checkout code
@@ -130,12 +130,11 @@ jobs:
130130
run: |
131131
python -m pip install .[bumps,DFO,gradient-free,minuit,SAS,numdifftools,lmfit,nlopt]
132132
python -m pip install --upgrade .[dev]
133-
python -m pip install "numpy<2.0"
134133
- name: Run linux tests
135134
if: runner.os == 'Linux'
136135
run: ci/unit_tests_default.sh
137136
- name: Upload test results
138-
if: matrix.python == '3.12'
137+
if: matrix.python == '3.13'
139138
uses: actions/upload-artifact@v4
140139
with:
141140
name: default_unit_tests

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
- name: 'Choose Python Version'
1515
uses: actions/setup-python@v5
1616
with:
17-
python-version: '3.12'
17+
python-version: '3.13'
1818
check-latest: true
1919

2020
- name: 'Build'

fitbenchmarking/core/tests/test_fitting_benchmarking.py

Lines changed: 17 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from unittest.mock import patch
1111

1212
import numpy as np
13+
from parameterized import parameterized
1314

1415
from fitbenchmarking import test_files
1516
from fitbenchmarking.controllers.scipy_controller import ScipyController
@@ -168,47 +169,29 @@ def setUp(self):
168169
self.options = Options(additional_options={"software": ["scipy"]})
169170
self.cp = Checkpoint(self.options)
170171

171-
def test_perform_fit_method(self):
172+
@parameterized.expand(
173+
[
174+
("ENSO.dat", [111.70773805099354, 107.53453144913736]),
175+
("Gauss3.dat", [76.64279628070524, 76.65043476327958]),
176+
("Lanczos1.dat", [0.0009937705466940194, 0.06269418241377904]),
177+
]
178+
)
179+
def test_perform_fit_method(self, file, expected):
172180
"""
173181
The test checks __perform_fit method.
174182
Three /NIST/average_difficulty problem sets
175183
are run with 2 scipy software minimizers.
176184
"""
185+
controller = set_up_controller(file, self.options)
186+
fit = Fit(options=self.options, data_dir="test", checkpointer=self.cp)
177187

178-
testcases = [
179-
{
180-
"file": "ENSO.dat",
181-
"results": [111.70773805099354, 107.53453144913736],
182-
},
183-
{
184-
"file": "Gauss3.dat",
185-
"results": [76.64279628070524, 76.65043476327958],
186-
},
187-
{
188-
"file": "Lanczos1.dat",
189-
"results": [0.0009937705466940194, 0.06269418241377904],
190-
},
191-
]
192-
193-
for case in testcases:
194-
with self.subTest(case["file"]):
195-
controller = set_up_controller(case["file"], self.options)
196-
197-
fit = Fit(
198-
options=self.options, data_dir="test", checkpointer=self.cp
199-
)
188+
for minimizer, acc in zip(["Nelder-Mead", "Powell"], expected):
189+
controller.minimizer = minimizer
190+
accuracy, runtimes, energy = fit._Fit__perform_fit(controller)
200191

201-
for minimizer, acc in zip(
202-
["Nelder-Mead", "Powell"], case["results"]
203-
):
204-
controller.minimizer = minimizer
205-
accuracy, runtimes, energy = fit._Fit__perform_fit(
206-
controller
207-
)
208-
209-
self.assertAlmostEqual(accuracy, acc, 6)
210-
assert len(runtimes) == self.options.num_runs
211-
assert energy != np.inf
192+
self.assertAlmostEqual(accuracy, acc, 6)
193+
assert len(runtimes) == self.options.num_runs
194+
assert energy != np.inf
212195

213196
@patch(
214197
"fitbenchmarking.controllers.base_controller.Controller.eval_confidence"

fitbenchmarking/parsing/nist_data_functions.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def nist_func_definition(function, param_names):
3232
# Param_names is sanitized in get_nist_param_names_and_values
3333

3434
local_dict = {}
35-
global_dict = {"__builtins__": {}, "np": np}
35+
global_dict = {"__builtins__": {"__import__": __import__}, "np": np}
3636
exec(
3737
"def fitting_function(x, "
3838
+ ",".join(param_names)
@@ -83,7 +83,7 @@ def nist_jacobian_definition(jacobian, param_names):
8383
# Sanitizing of jacobian_scipy_format is done so exec use is valid
8484
# Param_names is sanitized in get_nist_param_names_and_values
8585
local_dict = {}
86-
global_dict = {"__builtins__": {}, "np": np}
86+
global_dict = {"__builtins__": {"__import__": __import__}, "np": np}
8787
exec(
8888
"def jacobian_function(x, "
8989
+ new_param_name
@@ -142,7 +142,7 @@ def nist_hessian_definition(hessian, param_names):
142142
# Sanitizing of hessian_scipy_format is done so exec use is valid
143143
# param_names is sanitized in get_nist_param_names_and_values
144144
local_dict = {}
145-
global_dict = {"__builtins__": {}, "np": np}
145+
global_dict = {"__builtins__": {"__import__": __import__}, "np": np}
146146
exec(
147147
"def hessian_function(x, "
148148
+ new_param_name

0 commit comments

Comments
 (0)