Skip to content

Commit f3a2668

Browse files
authored
Fix default cvxpy solver (#1283)
### Summary Similar to Qiskit/qiskit#11002, this PR fixes the default solver for cvxpy to SCS. The 1.4.0 release changing the default solver to Clarabel breaks tomography experiments because Clarabel expects `max_iter` instead of `max_iters`. Also fixes a new lint error in `test_drag.py` and reduces `test_ef_update`'s runtime.
1 parent f32e985 commit f3a2668

File tree

3 files changed

+17
-12
lines changed

3 files changed

+17
-12
lines changed

qiskit_experiments/library/tomography/fitters/cvxpy_utils.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,9 @@ def decorated_func(*args, **kwargs):
6464
return decorated_func
6565

6666

67-
def solve_iteratively(problem: Problem, initial_iters: int, scale: int = 2, **solve_kwargs) -> None:
67+
def solve_iteratively(
68+
problem: Problem, initial_iters: int, scale: int = 2, solver: str = "SCS", **solve_kwargs
69+
) -> None:
6870
"""Solve a CVXPY problem increasing iterations if solution is inaccurate.
6971
7072
If the problem is not solved with the ``initial_iters`` value of
@@ -79,6 +81,7 @@ def solve_iteratively(problem: Problem, initial_iters: int, scale: int = 2, **so
7981
when solving the problem
8082
scale: Scale factor for increasing the initial_iters up to
8183
max_iters at each step (Default: 2).
84+
solver: The solver to use. Defaults to the Splitting Conic Solver.
8285
solve_kwargs: kwargs for problem.solve method.
8386
8487
Raises:
@@ -90,7 +93,7 @@ def solve_iteratively(problem: Problem, initial_iters: int, scale: int = 2, **so
9093
problem_solved = False
9194
while not problem_solved:
9295
solve_kwargs["max_iters"] = current_max_iters
93-
problem.solve(**solve_kwargs)
96+
problem.solve(solver=solver, **solve_kwargs)
9497
if problem.status in ["optimal_inaccurate", "optimal"]:
9598
problem_solved = True
9699
elif problem.status == "unbounded_inaccurate":

test/library/calibration/test_drag.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ def test_end_to_end(self, freq, betas, p0_opt):
7474
self.assertExperimentDone(expdata)
7575
result = expdata.analysis_results(1)
7676

77+
# pylint: disable=no-member
7778
self.assertTrue(abs(result.value.n - backend.experiment_helper.ideal_beta) < self.test_tol)
7879
self.assertEqual(result.quality, "good")
7980
self.assertEqual(expdata.metadata["meas_level"], MeasLevel.CLASSIFIED)

test/library/calibration/test_rough_amplitude.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -100,14 +100,15 @@ def test_experiment_config(self):
100100
class TestSpecializations(QiskitExperimentsTestCase):
101101
"""Test the specialized versions of the calibration."""
102102

103-
def setUp(self):
103+
@classmethod
104+
def setUpClass(cls):
104105
"""Setup the tests"""
105-
super().setUp()
106+
super().setUpClass()
106107

107108
library = FixedFrequencyTransmon()
108109

109-
self.backend = SingleTransmonTestBackend(noise=False)
110-
self.cals = Calibrations.from_backend(self.backend, libraries=[library])
110+
cls.backend = SingleTransmonTestBackend(noise=False)
111+
cls.cals = Calibrations.from_backend(cls.backend, libraries=[library])
111112

112113
# Add some pulses on the 1-2 transition.
113114
d0 = pulse.DriveChannel(0)
@@ -119,12 +120,12 @@ def setUp(self):
119120
with pulse.frequency_offset(-300e6, d0):
120121
pulse.play(pulse.Drag(Parameter("duration"), Parameter("amp"), 40, 0.0), d0)
121122

122-
self.cals.add_schedule(x12, 0)
123-
self.cals.add_schedule(sx12, 0)
124-
self.cals.add_parameter_value(0.4, "amp", 0, "x12")
125-
self.cals.add_parameter_value(0.2, "amp", 0, "sx12")
126-
self.cals.add_parameter_value(160, "duration", 0, "x12")
127-
self.cals.add_parameter_value(160, "duration", 0, "sx12")
123+
cls.cals.add_schedule(x12, 0)
124+
cls.cals.add_schedule(sx12, 0)
125+
cls.cals.add_parameter_value(0.4, "amp", 0, "x12")
126+
cls.cals.add_parameter_value(0.2, "amp", 0, "sx12")
127+
cls.cals.add_parameter_value(160, "duration", 0, "x12")
128+
cls.cals.add_parameter_value(160, "duration", 0, "sx12")
128129

129130
def test_ef_circuits(self):
130131
"""Test that we get the expected circuits with calibrations for the EF experiment."""

0 commit comments

Comments
 (0)