Skip to content

Commit 054fc83

Browse files
committed
ci: mark 9 slow SDP tests, skip on non-coverage CI jobs
Saves ~6 minutes on 7 of 8 matrix jobs by skipping expensive SDP tests (bell_inequality I3322, PPT distinguishability YYD, extended nonlocal game quantum bounds). Slow tests still run on the coverage job (ubuntu, Python 3.12) via --runslow flag.
1 parent 3d06695 commit 054fc83

6 files changed

Lines changed: 58 additions & 31 deletions

File tree

.github/workflows/build-test-actions.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,10 @@ jobs:
5555
uv sync --group dev --no-group docs --no-group lint
5656
- name: Run tests
5757
if: matrix.python-version != '3.12' || matrix.os != 'ubuntu-latest'
58-
run: uv run pytest -v
59-
- name: Run tests with coverage
58+
run: uv run pytest -v -m "not slow"
59+
- name: Run tests with coverage (including slow tests)
6060
if: matrix.python-version == '3.12' && matrix.os == 'ubuntu-latest'
61-
run: uv run pytest -v --cov-config=.coveragerc --cov-report=xml --cov-report term-missing:skip-covered --cov=toqito
61+
run: uv run pytest -v --runslow --cov-config=.coveragerc --cov-report=xml --cov-report term-missing:skip-covered --cov=toqito
6262
- name: Upload coverage information
6363
if: matrix.python-version == '3.12' && matrix.os == 'ubuntu-latest'
6464
uses: codecov/codecov-action@v5

conftest.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
"""Root conftest for toqito test suite."""
2+
3+
import pytest
4+
5+
6+
def pytest_addoption(parser):
7+
"""Add --runslow command-line option."""
8+
parser.addoption("--runslow", action="store_true", default=False, help="run slow tests")
9+
10+
11+
def pytest_configure(config):
12+
"""Register the slow marker."""
13+
config.addinivalue_line("markers", "slow: marks tests as slow (deselect with '-m \"not slow\"')")
14+
15+
16+
def pytest_collection_modifyitems(config, items):
17+
"""Skip slow tests unless --runslow is given."""
18+
if config.getoption("--runslow"):
19+
return
20+
skip_slow = pytest.mark.skip(reason="need --runslow option to run")
21+
for item in items:
22+
if "slow" in item.keywords:
23+
item.add_marker(skip_slow)

toqito/nonlocal_games/tests/test_extended_nonlocal_game.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,13 +477,15 @@ def test_four_mub_unentangled_value(self):
477477
expected = (3 + np.sqrt(5)) / 8
478478
self.assertAlmostEqual(res, expected, places=5)
479479

480+
@pytest.mark.slow
480481
def test_four_mub_quantum_lower_bound(self):
481482
"""Quantum heuristic lower bound of the 4-MUB game."""
482483
pi, pred_mat = self.four_mub_game()
483484
game = ExtendedNonlocalGame(pi, pred_mat)
484485
lb = game.quantum_value_lower_bound(initial_bob_is_random=True, seed=42, iters=50, tol=1e-6, verbose=False)
485486
self.assertAlmostEqual(lb, 0.660986, delta=7e-3)
486487

488+
@pytest.mark.slow
487489
def test_four_mub_npa_upper_bound_k1ab(self):
488490
"""NPA upper bound at k='1+ab' for the 4-MUB game."""
489491
pi, pred_mat = self.four_mub_game()
@@ -520,6 +522,7 @@ def _get_bb84_game(self):
520522
prob_mat[1, 1] = 1 / 2
521523
return ExtendedNonlocalGame(prob_mat, pred_mat)
522524

525+
@pytest.mark.slow
523526
def test_quantum_lb_max_steps_reached_verbose_print(self, capsys):
524527
"""Test verbose print when see-saw reaches max steps."""
525528
game = self._get_bb84_game()

toqito/nonlocal_games/tests/test_nonlocal_game.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import unittest
44

55
import numpy as np
6+
import pytest
67

78
from toqito.nonlocal_games.nonlocal_game import NonlocalGame
89

@@ -168,6 +169,7 @@ def test_ffl_game_classical_value_rep_2(self):
168169
expected_res = 2 / 3
169170
self.assertEqual(np.isclose(res, expected_res), True)
170171

172+
@pytest.mark.slow
171173
def test_ffl_game_quantum_value_lower_bound_value_rep_2(self):
172174
"""Lower bound on quantum value for the FFL game for 2 reps."""
173175
prob_mat, pred_mat = self.ffl_nonlocal_game()

toqito/state_opt/tests/test_bell_inequality_max.py

Lines changed: 23 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -558,34 +558,29 @@ def test_classical_nonbinary_cg_to_fp_internal_error():
558558
# --- Qubit Solver Tests ---
559559

560560

561-
@pytest.mark.parametrize(
562-
"joint_coe, a_coe, b_coe, a_val, b_val, expected",
563-
# Bell I3322 inequality.
564-
[
565-
(
566-
np.array([[1, 1, -1], [1, 1, 1], [-1, 1, 0]]),
567-
np.array([0, -1, 0]),
568-
np.array([-1, -2, 0]),
569-
np.array([0, 1]),
570-
np.array([0, 1]),
571-
0.250,
572-
),
573-
# Bell CHSH inequality.
574-
(
575-
np.array([[1, 1], [1, -1]]),
576-
np.array([0, 0]),
577-
np.array([0, 0]),
578-
np.array([1, -1]),
579-
np.array([1, -1]),
580-
2 * np.sqrt(2),
581-
),
582-
],
583-
)
584-
def test_bell_inequality_max_qubits_valid(joint_coe, a_coe, b_coe, a_val, b_val, expected):
585-
"""Test bell_inequality_max_qubits returns the expected value using valid input."""
586-
# Call via module alias
587-
result = bim.bell_inequality_max_qubits(joint_coe, a_coe, b_coe, a_val, b_val)
588-
assert pytest.approx(result, 0.01) == expected
561+
@pytest.mark.slow
562+
def test_bell_inequality_max_qubits_i3322():
563+
"""Test bell_inequality_max_qubits with I3322 inequality (slow SDP)."""
564+
result = bim.bell_inequality_max_qubits(
565+
np.array([[1, 1, -1], [1, 1, 1], [-1, 1, 0]]),
566+
np.array([0, -1, 0]),
567+
np.array([-1, -2, 0]),
568+
np.array([0, 1]),
569+
np.array([0, 1]),
570+
)
571+
assert pytest.approx(result, 0.01) == 0.250
572+
573+
574+
def test_bell_inequality_max_qubits_chsh():
575+
"""Test bell_inequality_max_qubits with CHSH inequality."""
576+
result = bim.bell_inequality_max_qubits(
577+
np.array([[1, 1], [1, -1]]),
578+
np.array([0, 0]),
579+
np.array([0, 0]),
580+
np.array([1, -1]),
581+
np.array([1, -1]),
582+
)
583+
assert pytest.approx(result, 0.01) == 2 * np.sqrt(2)
589584

590585

591586
@pytest.mark.parametrize(

toqito/state_opt/tests/test_ppt_distinguishability.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from toqito.states import basis, bell
88

99

10+
@pytest.mark.slow
1011
def test_ppt_distinguishability_yyd_density_matrices():
1112
"""PPT distinguishing the YYD states from :footcite:`Yu_2012_Four` should yield `7/8 ~ 0.875`.
1213
@@ -62,6 +63,7 @@ def test_ppt_distinguishability_yyd_density_matrices():
6263
assert np.isclose(primal_res, 3 / 4, atol=0.001)
6364

6465

66+
@pytest.mark.slow
6567
def test_ppt_distinguishability_yyd_vectors():
6668
"""PPT distinguishing the YYD states from :footcite:`Yu_2012_Four` should yield `7/8 ~ 0.875`.
6769
@@ -113,6 +115,7 @@ def test_ppt_distinguishability_yyd_vectors():
113115
assert np.isclose(primal_res, 3 / 4, atol=0.001)
114116

115117

118+
@pytest.mark.slow
116119
def test_ppt_distinguishability_yyd_states_no_probs():
117120
"""PPT distinguishing the YYD states from :footcite:`Yu_2012_Four` should yield `7/8 ~ 0.875`.
118121
@@ -153,6 +156,7 @@ def test_ppt_distinguishability_yyd_states_no_probs():
153156
assert np.isclose(primal_res, 3 / 4, atol=0.001)
154157

155158

159+
@pytest.mark.slow
156160
def test_ppt_distinguishability_four_bell_states():
157161
r"""PPT distinguishing the four Bell states.
158162

0 commit comments

Comments
 (0)