Skip to content

Commit

Permalink
Fix default cvxpy solver (#1283)
Browse files Browse the repository at this point in the history
### 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.
  • Loading branch information
coruscating authored Oct 12, 2023
1 parent f32e985 commit f3a2668
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
7 changes: 5 additions & 2 deletions qiskit_experiments/library/tomography/fitters/cvxpy_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ def decorated_func(*args, **kwargs):
return decorated_func


def solve_iteratively(problem: Problem, initial_iters: int, scale: int = 2, **solve_kwargs) -> None:
def solve_iteratively(
problem: Problem, initial_iters: int, scale: int = 2, solver: str = "SCS", **solve_kwargs
) -> None:
"""Solve a CVXPY problem increasing iterations if solution is inaccurate.
If the problem is not solved with the ``initial_iters`` value of
Expand All @@ -79,6 +81,7 @@ def solve_iteratively(problem: Problem, initial_iters: int, scale: int = 2, **so
when solving the problem
scale: Scale factor for increasing the initial_iters up to
max_iters at each step (Default: 2).
solver: The solver to use. Defaults to the Splitting Conic Solver.
solve_kwargs: kwargs for problem.solve method.
Raises:
Expand All @@ -90,7 +93,7 @@ def solve_iteratively(problem: Problem, initial_iters: int, scale: int = 2, **so
problem_solved = False
while not problem_solved:
solve_kwargs["max_iters"] = current_max_iters
problem.solve(**solve_kwargs)
problem.solve(solver=solver, **solve_kwargs)
if problem.status in ["optimal_inaccurate", "optimal"]:
problem_solved = True
elif problem.status == "unbounded_inaccurate":
Expand Down
1 change: 1 addition & 0 deletions test/library/calibration/test_drag.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ def test_end_to_end(self, freq, betas, p0_opt):
self.assertExperimentDone(expdata)
result = expdata.analysis_results(1)

# pylint: disable=no-member
self.assertTrue(abs(result.value.n - backend.experiment_helper.ideal_beta) < self.test_tol)
self.assertEqual(result.quality, "good")
self.assertEqual(expdata.metadata["meas_level"], MeasLevel.CLASSIFIED)
Expand Down
21 changes: 11 additions & 10 deletions test/library/calibration/test_rough_amplitude.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,15 @@ def test_experiment_config(self):
class TestSpecializations(QiskitExperimentsTestCase):
"""Test the specialized versions of the calibration."""

def setUp(self):
@classmethod
def setUpClass(cls):
"""Setup the tests"""
super().setUp()
super().setUpClass()

library = FixedFrequencyTransmon()

self.backend = SingleTransmonTestBackend(noise=False)
self.cals = Calibrations.from_backend(self.backend, libraries=[library])
cls.backend = SingleTransmonTestBackend(noise=False)
cls.cals = Calibrations.from_backend(cls.backend, libraries=[library])

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

self.cals.add_schedule(x12, 0)
self.cals.add_schedule(sx12, 0)
self.cals.add_parameter_value(0.4, "amp", 0, "x12")
self.cals.add_parameter_value(0.2, "amp", 0, "sx12")
self.cals.add_parameter_value(160, "duration", 0, "x12")
self.cals.add_parameter_value(160, "duration", 0, "sx12")
cls.cals.add_schedule(x12, 0)
cls.cals.add_schedule(sx12, 0)
cls.cals.add_parameter_value(0.4, "amp", 0, "x12")
cls.cals.add_parameter_value(0.2, "amp", 0, "sx12")
cls.cals.add_parameter_value(160, "duration", 0, "x12")
cls.cals.add_parameter_value(160, "duration", 0, "sx12")

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

0 comments on commit f3a2668

Please sign in to comment.