Skip to content

Commit

Permalink
Merge pull request #53 from embotech/python312
Browse files Browse the repository at this point in the history
Python 3.12
  • Loading branch information
SteveDiamond authored Feb 6, 2024
2 parents 4e3ec5a + ee18b24 commit f2f5a19
Show file tree
Hide file tree
Showing 6 changed files with 126 additions and 129 deletions.
18 changes: 10 additions & 8 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
fail-fast: false
matrix:
os: [ ubuntu-20.04, macos-11, windows-2019 ]
python-version: [ 3.7, 3.9, 3.8, "3.10", "3.11" ]
python-version: [ 3.7, 3.9, 3.8, "3.10", "3.11", "3.12" ]

env:
PYTHON_VERSION: ${{ matrix.python-version }}
Expand All @@ -43,13 +43,15 @@ jobs:
- name: Install
run: |
if [[ "$PYTHON_VERSION" == "3.7" ]] || [[ "$PYTHON_VERSION" == "3.8" ]]; then
conda install scipy=1.3 numpy=1.16 nose
conda install scipy=1.3 numpy=1.16 pytest
elif [[ "$PYTHON_VERSION" == "3.9" ]]; then
conda install scipy=1.5 numpy=1.19 nose
conda install scipy=1.5 numpy=1.19 pytest
elif [[ "$PYTHON_VERSION" == "3.10" ]]; then
conda install scipy=1.7 numpy=1.21 nose
conda install scipy=1.7 numpy=1.21 pytest
elif [[ "$PYTHON_VERSION" == "3.11" ]]; then
conda install scipy=1.9.3 numpy=1.23.4 nose
conda install scipy=1.9.3 numpy=1.23.4 pytest
elif [[ "$PYTHON_VERSION" == "3.12" ]]; then
conda install scipy=1.11.3 numpy=1.26.0 pytest
fi
if [[ "$RUNNER_OS" == "macOS" ]]; then
sudo rm -rf /Library/Developer/CommandLineTools
Expand All @@ -58,7 +60,7 @@ jobs:
- name: Test
run: |
make install
python -m nose
python -m pytest
rm -rf build/
build_wheels:
Expand All @@ -69,7 +71,7 @@ jobs:
fail-fast: false
matrix:
os: [ ubuntu-20.04, macos-11, windows-2019 ]
python-version: [ 3.7, 3.9, "3.10", "3.11" ]
python-version: [ 3.7, 3.9, "3.10", "3.11", "3.12" ]
include:
- os: ubuntu-20.04
python-version: 3.8
Expand Down Expand Up @@ -107,7 +109,7 @@ jobs:
env:
CIBW_BUILD: "cp3${{env.PYTHON_SUBVERSION}}-*"
CIBW_SKIP: "*-win32 *-manylinux_i686 *-musllinux*"
uses: joerick/cibuildwheel@v2.11.2
uses: joerick/cibuildwheel@v2.16.5

- name: Build source
if: ${{env.DEPLOY == 'True' && env.SINGLE_ACTION_CONFIG == 'True'}}
Expand Down
2 changes: 1 addition & 1 deletion Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ verify_ssl = true
name = "pypi"

[dev-packages]
nose = "*"
pytest = "*"

[packages]
numpy = "*"
Expand Down
98 changes: 68 additions & 30 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,5 @@ def finalize_options(self):
"numpy >= 1.6",
"scipy >= 0.9"
],
test_suite='nose.collector',
tests_require=['nose']
tests_require=['pytest']
)
123 changes: 45 additions & 78 deletions src/test_interface.py
Original file line number Diff line number Diff line change
@@ -1,35 +1,8 @@
# for python 3 testing compatibility
from __future__ import print_function
import platform

def import_error(msg):
print()
print("## IMPORT ERROR:", msg)
print()

try:
from nose.tools import assert_raises, assert_almost_equals
except ImportError:
import_error("Please install nose to run tests.")
raise

try:
import ecos
except ImportError:
import_error("You must install the ecos module before running tests.")
raise

try:
import numpy as np
except ImportError:
import_error("Please install numpy.")
raise

try:
import scipy.sparse as sp
except ImportError:
import_error("Please install scipy.")
raise
import pytest
import ecos
import numpy as np
import scipy.sparse as sp

# global data structures for problem
c = np.array([-1.])
Expand All @@ -39,51 +12,45 @@ def import_error(msg):
b = np.array([3.])
dims = {'q': [], 'l': 2}

def check_solution(solution, expected):
assert_almost_equals(solution, expected, places=5)

def test_problems():
myopts = {'feastol': 2e-8, 'reltol': 2e-8, 'abstol': 2e-8, 'verbose':True};
sol = ecos.solve(c, G, h, dims, **myopts)
yield check_solution, sol['x'][0], 4

sol = ecos.solve(c, G, h, dims, A, b, **myopts)
yield check_solution, sol['x'][0], 3

new_dims = {'q':[2], 'l': 0}
sol = ecos.solve(c, G, h, new_dims, **myopts)
yield check_solution, sol['x'][0], 2

if platform.python_version_tuple() < ('3','0','0'):
def test_problems_with_longs():
new_dims = {'q': [], 'l': long(2)}
myopts = {'feastol': 2e-8, 'reltol': 2e-8, 'abstol': 2e-8};
sol = ecos.solve(c, G, h, new_dims, **myopts)
yield check_solution, sol['x'][0], 4

sol = ecos.solve(c, G, h, new_dims, A, b, **myopts)
yield check_solution, sol['x'][0], 3

new_dims = {'q':[long(2)], 'l': 0}
sol = ecos.solve(c, G, h, new_dims, **myopts)
yield check_solution, sol['x'][0], 2

def check_keyword(error_type, keyword, value):
assert_raises(error_type, ecos.solve, c,G,h,dims, **{keyword: value})

def test_failures():
yield assert_raises, TypeError, ecos.solve
yield assert_raises, TypeError, ecos.solve, c, G, h, dims, A

yield assert_raises, ValueError, ecos.solve, c, G, h, {'q':[], 'l':0}
yield assert_raises, TypeError, ecos.solve, c, G, h, {'q':[4], 'l':-2}

yield check_keyword, TypeError, 'verbose', 0
yield check_keyword, ValueError, 'feastol', 0
yield check_keyword, ValueError, 'abstol', 0
yield check_keyword, ValueError, 'reltol', 0
yield check_keyword, ValueError, 'feastol_inacc', 0
yield check_keyword, ValueError, 'abstol_inacc', 0
yield check_keyword, ValueError, 'reltol_inacc', 0
yield check_keyword, ValueError, 'max_iters', -1
yield check_keyword, TypeError, 'max_iters', 1.1
def check_solution(solution, expected):
np.testing.assert_almost_equal(solution, expected, decimal=5)

@pytest.mark.parametrize("inputs,expected", [
((c, G, h, dims, {'feastol': 2e-8, 'reltol': 2e-8, 'abstol': 2e-8, 'verbose': False}), 4),
((c, G, h, dims, A, b, {'feastol': 2e-8, 'reltol': 2e-8, 'abstol': 2e-8, 'verbose': False}), 3),
((c, G, h, {'q': [2], 'l': 0}, {'feastol': 2e-8, 'reltol': 2e-8, 'abstol': 2e-8, 'verbose': False}), 2)
])
def test_problems(inputs, expected):
sol = ecos.solve(*inputs[:-1], **inputs[-1])
check_solution(sol['x'][0], expected)


def test_call_failures():
with pytest.raises(TypeError):
ecos.solve()

with pytest.raises(TypeError):
ecos.solve(c, G, h, dims, A)

with pytest.raises(ValueError):
ecos.solve(c, G, h, {'q':[], 'l':0})

with pytest.raises(TypeError):
ecos.solve(c, G, h, {'q':[4], 'l':-2})


@pytest.mark.parametrize("error_type,keyword,value", [
(TypeError, 'verbose', 0),
(ValueError, 'feastol', 0),
(ValueError, 'abstol', 0),
(ValueError, 'reltol', 0),
(ValueError, 'feastol_inacc', 0),
(ValueError, 'abstol_inacc', 0),
(ValueError, 'reltol_inacc', 0),
(ValueError, 'max_iters', -1),
(TypeError, 'max_iters', 1.1),
])
def test_keyword_errors(error_type, keyword, value):
with pytest.raises(error_type):
ecos.solve(c, G, h, dims, **{keyword: value})
11 changes: 1 addition & 10 deletions src/test_interface_bb.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import print_function
import ecos
import numpy as np
import scipy.sparse as sp
Expand All @@ -17,8 +16,6 @@

sol = ecos.solve(c, G, h, dims, verbose=False, mi_verbose=False, int_vars_idx=bool_idx)

print(sol['x'])

c = np.array([-1., -1.])
h = np.array([ 4., 12., 0., 0.])
bool_idx = []
Expand All @@ -33,8 +30,6 @@

sol = ecos.solve(c, G, h, dims, verbose=False, mi_verbose=False, int_vars_idx=bool_idx)

print(sol['x'])

c = np.array([-1., -1.1])
h = np.array([ 4., 12., 0., 0.])
bool_idx = [1,0]
Expand All @@ -49,8 +44,6 @@

sol = ecos.solve(c, G, h, dims, verbose=False, mi_verbose=False, int_vars_idx=bool_idx)

print(sol['x'])


c = np.array([-1., -1.5])
h = np.array([ 4., 12., 0. , 0.])
Expand All @@ -64,6 +57,4 @@
dims = dict()
dims['l'] = 4

sol = ecos.solve(c, G, h, dims, verbose=False, mi_verbose=True, bool_vars_idx=bool_idx)
print(sol)
print(sol['x'])
sol = ecos.solve(c, G, h, dims, verbose=False, mi_verbose=True, bool_vars_idx=bool_idx)

0 comments on commit f2f5a19

Please sign in to comment.