Skip to content

Commit

Permalink
Added support for python 3.13.x (fitbenchmarking#1372)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
RabiyaF and AndrewLister-STFC authored Nov 25, 2024
1 parent eaf2af8 commit de9b604
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 56 deletions.
38 changes: 24 additions & 14 deletions .github/workflows/integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,34 @@ jobs:
fail-fast: false
matrix:
os: [macos-13, windows-latest]
python: ['3.9', '3.12']
python: ['3.9', '3.13']
exclude:
- os: windows-latest
python: '3.13'
runs-on: ${{ matrix.os }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install python
uses: actions/setup-python@v5
- name: Set up conda
uses: conda-incubator/setup-miniconda@v2
with:
python-version: ${{ matrix.python }}
check-latest: true
- name: Install dependencies
miniconda-version: "latest"
- name: Install dependencies in conda env
shell: bash
run: |
python -m pip install .[bumps,DFO,gradient-free,minuit,SAS,numdifftools,lmfit,nlopt]
source $CONDA/etc/profile.d/conda.sh
conda create -n default-test-env python=${{ matrix.python }} -y
conda activate default-test-env
conda install -c conda-forge nlopt -y
python -m pip install .[bumps,DFO,gradient-free,minuit,SAS,numdifftools,lmfit]
python -m pip install --upgrade .[dev]
python -m pip install "numpy<2.0"
- name: Run macos tests
if: runner.os == 'macOS'
run: ci/unit_tests_default.sh
- name: Run windows tests
if: runner.os == 'Windows'
run: bash ci/unit_tests_default.sh
- name: Run tests
shell: bash
run: |
source $CONDA/etc/profile.d/conda.sh
conda activate default-test-env
if [ "${{ matrix.os }}" == "macos-13" ]; then
ci/unit_tests_default.sh
else
bash ci/unit_tests_default.sh
fi
7 changes: 3 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
- name: Install python
uses: actions/setup-python@v5
with:
python-version: '3.12'
python-version: '3.13'
check-latest: true
- name: Install dependencies
run: |
Expand Down Expand Up @@ -116,7 +116,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python: ['3.9', '3.12']
python: ['3.9', '3.13']
runs-on: ubuntu-latest
steps:
- name: Checkout code
Expand All @@ -130,12 +130,11 @@ jobs:
run: |
python -m pip install .[bumps,DFO,gradient-free,minuit,SAS,numdifftools,lmfit,nlopt]
python -m pip install --upgrade .[dev]
python -m pip install "numpy<2.0"
- name: Run linux tests
if: runner.os == 'Linux'
run: ci/unit_tests_default.sh
- name: Upload test results
if: matrix.python == '3.12'
if: matrix.python == '3.13'
uses: actions/upload-artifact@v4
with:
name: default_unit_tests
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- name: 'Choose Python Version'
uses: actions/setup-python@v5
with:
python-version: '3.12'
python-version: '3.13'
check-latest: true

- name: 'Build'
Expand Down
51 changes: 17 additions & 34 deletions fitbenchmarking/core/tests/test_fitting_benchmarking.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from unittest.mock import patch

import numpy as np
from parameterized import parameterized

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

def test_perform_fit_method(self):
@parameterized.expand(
[
("ENSO.dat", [111.70773805099354, 107.53453144913736]),
("Gauss3.dat", [76.64279628070524, 76.65043476327958]),
("Lanczos1.dat", [0.0009937705466940194, 0.06269418241377904]),
]
)
def test_perform_fit_method(self, file, expected):
"""
The test checks __perform_fit method.
Three /NIST/average_difficulty problem sets
are run with 2 scipy software minimizers.
"""
controller = set_up_controller(file, self.options)
fit = Fit(options=self.options, data_dir="test", checkpointer=self.cp)

testcases = [
{
"file": "ENSO.dat",
"results": [111.70773805099354, 107.53453144913736],
},
{
"file": "Gauss3.dat",
"results": [76.64279628070524, 76.65043476327958],
},
{
"file": "Lanczos1.dat",
"results": [0.0009937705466940194, 0.06269418241377904],
},
]

for case in testcases:
with self.subTest(case["file"]):
controller = set_up_controller(case["file"], self.options)

fit = Fit(
options=self.options, data_dir="test", checkpointer=self.cp
)
for minimizer, acc in zip(["Nelder-Mead", "Powell"], expected):
controller.minimizer = minimizer
accuracy, runtimes, energy = fit._Fit__perform_fit(controller)

for minimizer, acc in zip(
["Nelder-Mead", "Powell"], case["results"]
):
controller.minimizer = minimizer
accuracy, runtimes, energy = fit._Fit__perform_fit(
controller
)

self.assertAlmostEqual(accuracy, acc, 6)
assert len(runtimes) == self.options.num_runs
assert energy != np.inf
self.assertAlmostEqual(accuracy, acc, 6)
assert len(runtimes) == self.options.num_runs
assert energy != np.inf

@patch(
"fitbenchmarking.controllers.base_controller.Controller.eval_confidence"
Expand Down
6 changes: 3 additions & 3 deletions fitbenchmarking/parsing/nist_data_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def nist_func_definition(function, param_names):
# Param_names is sanitized in get_nist_param_names_and_values

local_dict = {}
global_dict = {"__builtins__": {}, "np": np}
global_dict = {"__builtins__": {"__import__": __import__}, "np": np}
exec(
"def fitting_function(x, "
+ ",".join(param_names)
Expand Down Expand Up @@ -83,7 +83,7 @@ def nist_jacobian_definition(jacobian, param_names):
# Sanitizing of jacobian_scipy_format is done so exec use is valid
# Param_names is sanitized in get_nist_param_names_and_values
local_dict = {}
global_dict = {"__builtins__": {}, "np": np}
global_dict = {"__builtins__": {"__import__": __import__}, "np": np}
exec(
"def jacobian_function(x, "
+ new_param_name
Expand Down Expand Up @@ -142,7 +142,7 @@ def nist_hessian_definition(hessian, param_names):
# Sanitizing of hessian_scipy_format is done so exec use is valid
# param_names is sanitized in get_nist_param_names_and_values
local_dict = {}
global_dict = {"__builtins__": {}, "np": np}
global_dict = {"__builtins__": {"__import__": __import__}, "np": np}
exec(
"def hessian_function(x, "
+ new_param_name
Expand Down

0 comments on commit de9b604

Please sign in to comment.