Skip to content

Commit

Permalink
test fixes for codegen; env vars to control algebra selection for pytest
Browse files Browse the repository at this point in the history
  • Loading branch information
vineetbansal committed Aug 6, 2024
1 parent 472ffb2 commit 4f471a5
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 18 deletions.
4 changes: 3 additions & 1 deletion src/osqp/tests/codegen_matrices_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ def setUpClass(cls):
}

model = osqp.OSQP(algebra='builtin')
if not model.has_capability('OSQP_CAPABILITY_DERIVATIVES'):
pytest.skip('No derivatives capability')
model.setup(P=P, q=q, A=A, l=l, u=u, **opts)

model_dir = model.codegen(
Expand Down Expand Up @@ -60,7 +62,7 @@ def tearDownClass(cls):
sh.rmtree('codegen_mat_out', ignore_errors=True)

def setUp(self):
self.model = osqp.OSQP()
self.model = osqp.OSQP(algebra='builtin')
self.model.setup(P=self.P, q=self.q, A=self.A, l=self.l, u=self.u, **self.opts)

def test_solve(self):
Expand Down
4 changes: 3 additions & 1 deletion src/osqp/tests/codegen_vectors_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ def setUpClass(cls):
}

model = osqp.OSQP(algebra='builtin')
if not model.has_capability('OSQP_CAPABILITY_DERIVATIVES'):
pytest.skip('No derivatives capability')
model.setup(P=P, q=q, A=A, l=l, u=u, **opts)

model_dir = model.codegen(
Expand All @@ -56,7 +58,7 @@ def tearDownClass(cls):
sh.rmtree('codegen_vec_out', ignore_errors=True)

def setUp(self):
self.model = osqp.OSQP()
self.model = osqp.OSQP(algebra='builtin')
self.model.setup(P=self.P, q=self.q, A=self.A, l=self.l, u=self.u, **self.opts)

def test_solve(self):
Expand Down
36 changes: 20 additions & 16 deletions src/osqp/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,31 @@
import os
from osqp import algebra_available


def pytest_generate_tests(metafunc):

# detect env vars to decide which algebras to include/skip
algebras_include = os.environ.get('OSQP_ALGEBRA_INCLUDE', 'builtin mkl-direct mkl-indirect cuda').split()
algebras_skip = os.environ.get('OSQP_ALGEBRA_SKIP', '').split()
algebras = [x for x in algebras_include if x not in algebras_skip]

parameters = ('algebra', 'solver_type', 'atol', 'rtol', 'decimal_tol')
values = []
if algebra_available('builtin'):
values.extend(
[
('builtin', 'direct', 1e-3, 1e-4, 4),
]
if algebra_available('builtin') and 'builtin' in algebras:
values.append(
('builtin', 'direct', 1e-3, 1e-4, 4),
)
if algebra_available('mkl') and 'mkl-direct' in algebras:
values.append(
('mkl', 'direct', 1e-3, 1e-4, 4),
)
if algebra_available('mkl'):
values.extend(
[
('mkl', 'direct', 1e-3, 1e-4, 4),
('mkl', 'indirect', 1e-3, 1e-4, 3),
]
if algebra_available('mkl') and 'mkl-indirect' in algebras:
values.append(
('mkl', 'indirect', 1e-3, 1e-4, 3),
)
if algebra_available('cuda'):
values.extend(
[
('cuda', 'indirect', 1e-2, 1e-3, 2),
]
if algebra_available('cuda') and 'cuda' in algebras:
values.append(
('cuda', 'indirect', 1e-2, 1e-3, 2),
)

metafunc.parametrize(parameters, values)

0 comments on commit 4f471a5

Please sign in to comment.