Skip to content
This repository was archived by the owner on Jun 12, 2023. It is now read-only.

Commit 9599847

Browse files
Merge pull request #539 from mtreinish/prepare-0.5.1
Backport bug fixes and prepare 0.5.1
2 parents 4bafe96 + 489bd9d commit 9599847

File tree

9 files changed

+79
-23
lines changed

9 files changed

+79
-23
lines changed

.github/workflows/main.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,32 @@ jobs:
3737
QISKIT_IN_PARALLEL: TRUE
3838
run: tox -e py
3939
if: runner.os == 'macOS'
40+
tests-no-opt:
41+
name: tests-python3.8-no-optional-dependencies
42+
runs-on: ${{ matrix.os }}
43+
strategy:
44+
matrix:
45+
python-version: [3.8]
46+
os: ["ubuntu-latest"]
47+
steps:
48+
- uses: actions/checkout@v2
49+
- name: Set up Python ${{ matrix.python-version }}
50+
uses: actions/setup-python@v2
51+
with:
52+
python-version: ${{ matrix.python-version }}
53+
- name: Pip cache
54+
uses: actions/cache@v2
55+
with:
56+
path: ~/.cache/pip
57+
key: ${{ runner.os }}-${{ matrix.python-version }}-pip-tests-${{ hashFiles('setup.py','requirements-dev.txt','constraints.txt') }}
58+
restore-keys: |
59+
${{ runner.os }}-${{ matrix.python-version }}-pip-tests-
60+
${{ runner.os }}-${{ matrix.python-version }}-pip-
61+
${{ runner.os }}-${{ matrix.python-version }}
62+
- name: Install Deps
63+
run: python -m pip install -U tox setuptools virtualenv wheel
64+
- name: Install and Run Tests
65+
run: tox -e no-opt
4066
windows-tests:
4167
name: tests-python${{ matrix.python-version }}-windows
4268
runs-on: windows-latest

.pylintrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ ignore-mixin-members=yes
295295
# (useful for modules/projects where namespaces are manipulated during runtime
296296
# and thus existing member attributes cannot be deduced by static analysis. It
297297
# supports qualified module names, as well as Unix pattern matching.
298-
ignored-modules=matplotlib.cm,numpy.random,retworkx
298+
ignored-modules=matplotlib.cm,numpy.random,retworkx,numba
299299

300300
# List of class names for which member attributes should not be checked (useful
301301
# for classes with dynamically set attributes). This supports the use of

constraints.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ pylint==2.4.4
22
astroid==2.3.3
33
pywin32==225
44
setuptools==49.6.0
5+
pyfakefs==4.1.0

docs/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
# The short X.Y version
4747
version = ''
4848
# The full version, including alpha/beta/rc tags
49-
release = '0.5.0'
49+
release = '0.5.1'
5050

5151
# -- General configuration ---------------------------------------------------
5252

qiskit/ignis/VERSION.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.5.0
1+
0.5.1

qiskit/ignis/mitigation/expval/base_meas_mitigator.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -166,13 +166,13 @@ def stddev_upper_bound(self, shots: int = 1, qubits: Optional[List[int]] = None)
166166
return gamma / np.sqrt(shots)
167167

168168
def plot_assignment_matrix(self,
169-
qubits: Optional[List[int]] = None,
170-
ax: Optional[plt.axes] = None) -> plt.axes:
169+
qubits=None,
170+
ax=None):
171171
"""Matrix plot of the readout error assignment matrix.
172172
173173
Args:
174-
qubits: Optional, qubits being measured for operator expval.
175-
ax: Optional. Axes object to add plot to.
174+
qubits (list(int)): Optional, qubits being measured for operator expval.
175+
ax (axes): Optional. Axes object to add plot to.
176176
177177
Returns:
178178
plt.axes: the figure axes object.
@@ -195,13 +195,13 @@ def plot_assignment_matrix(self,
195195
return ax
196196

197197
def plot_mitigation_matrix(self,
198-
qubits: Optional[List[int]] = None,
199-
ax: Optional[plt.axes] = None) -> plt.axes:
198+
qubits=None,
199+
ax=None):
200200
"""Matrix plot of the readout error mitigation matrix.
201201
202202
Args:
203-
qubits: Optional, qubits being measured for operator expval.
204-
ax: Optional. Axes object to add plot to.
203+
qubits (list(int)): Optional, qubits being measured for operator expval.
204+
ax (plt.axes): Optional. Axes object to add plot to.
205205
206206
Returns:
207207
plt.axes: the figure axes object.
@@ -247,12 +247,12 @@ def _int_to_bitstring(i, num_qubits=None):
247247
return label
248248

249249
@staticmethod
250-
def _plot_axis(mat: np.ndarray, ax: plt.axes) -> plt.axes:
250+
def _plot_axis(mat, ax):
251251
"""Helper function for setting up axes for plots.
252252
253253
Args:
254-
mat: the N-qubit matrix to plot.
255-
ax: Optional. Axes object to add plot to.
254+
mat (np.ndarray): the N-qubit matrix to plot.
255+
ax (plt.axes): Optional. Axes object to add plot to.
256256
257257
Returns:
258258
plt.axes: the figure object and axes object.

qiskit/ignis/verification/tomography/fitters/base_fitter.py

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class TomographyFitter:
4040
"""Base maximum-likelihood estimate tomography fitter class"""
4141

4242
_HAS_SDP_SOLVER = None
43+
_HAS_SDP_SOLVER_NOT_SCS = False
4344

4445
def __init__(self,
4546
result: Union[Result, List[Result]],
@@ -120,12 +121,14 @@ def fit(self,
120121
**kwargs) -> np.array:
121122
r"""Reconstruct a quantum state using CVXPY convex optimization.
122123
123-
**Fitter method**
124+
**Fitter method**
124125
125-
The ``cvx`` fitter method used CVXPY convex optimization package.
126-
The ``lstsq`` method uses least-squares fitting (linear inversion).
127-
The ``auto`` method will use 'cvx' if the CVXPY package is found on
128-
the system, otherwise it will default to 'lstsq'.
126+
The ``'cvx'`` fitter method uses the CVXPY convex optimization package
127+
with a SDP solver.
128+
The ``'lstsq'`` method uses least-squares fitting.
129+
The ``'auto'`` method will use ``'cvx'`` if the both the CVXPY and a suitable
130+
SDP solver packages are found on the system, otherwise it will default
131+
to ``'lstsq'``.
129132
130133
**Objective function**
131134
@@ -165,9 +168,14 @@ def fit(self,
165168
**CVXPY Solvers:**
166169
167170
Various solvers can be called in CVXPY using the `solver` keyword
168-
argument. See the `CVXPY documentation
171+
argument. If ``psd=True`` an SDP solver is required other an SOCP
172+
solver is required. See the `CVXPY documentation
169173
<https://www.cvxpy.org/tutorial/advanced/index.html#solve-method-options>`_
170174
for more information on solvers.
175+
Note that the default SDP solver ('SCS') distributed
176+
with CVXPY will not be used for the ``'auto'`` method due its reduced
177+
accuracy compared to other solvers. When using the ``'cvx'`` method we
178+
strongly recommend installing one of the other supported SDP solvers.
171179
172180
References:
173181
@@ -200,7 +208,11 @@ def fit(self,
200208
# Choose automatic method
201209
if method == 'auto':
202210
self._check_for_sdp_solver()
203-
if self._HAS_SDP_SOLVER:
211+
if self._HAS_SDP_SOLVER_NOT_SCS:
212+
# We don't use the SCS solver for automatic method as it has
213+
# lower accuracy than the other supported SDP solvers which
214+
# typically results in the returned matrix not being
215+
# completely positive.
204216
method = 'cvx'
205217
else:
206218
method = 'lstsq'
@@ -516,15 +528,17 @@ def _check_for_sdp_solver(cls):
516528
# pylint:disable=import-error
517529
import cvxpy
518530
solvers = cvxpy.installed_solvers()
519-
if 'CVXOPT' in solvers:
531+
# Check for other SDP solvers cvxpy supports
532+
if 'CVXOPT' in solvers or 'MOSEK' in solvers:
533+
cls._HAS_SDP_SOLVER_NOT_SCS = True
520534
cls._HAS_SDP_SOLVER = True
521535
return
522536
if 'SCS' in solvers:
523537
# Try example problem to see if built with BLAS
524538
# SCS solver cannot solver larger than 2x2 matrix
525539
# problems without BLAS
526540
try:
527-
var = cvxpy.Variable((4, 4), PSD=True)
541+
var = cvxpy.Variable((5, 5), PSD=True)
528542
obj = cvxpy.Minimize(cvxpy.norm(var))
529543
cvxpy.Problem(obj).solve(solver='SCS')
530544
cls._HAS_SDP_SOLVER = True

qiskit/ignis/verification/tomography/fitters/cvx_fit.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,8 @@ def cvx_fit(data: np.array,
198198
if 'solver' not in kwargs:
199199
if 'CVXOPT' in cvxpy.installed_solvers():
200200
kwargs['solver'] = 'CVXOPT'
201+
elif 'MOSEK' in cvxpy.installed_solvers():
202+
kwargs['solver'] = 'MOSEK'
201203

202204
problem_solved = False
203205
while not problem_solved:
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
fixes:
3+
- |
4+
Fix the ``"auto"`` method of the
5+
:class:`~qiskit.ignis.verification.tomography.TomographyFitter`,
6+
:class:`~qiskit.ignis.verification.tomography.StateTomographyFitter`, and
7+
:class:`~qiskit.ignis.verification.tomography.ProcessTomographyFitter` to
8+
only use ``"cvx"`` if CVXPY is installed *and* a third-party SDP solver
9+
other than SCS is available. This is because the SCS solver has lower
10+
accuracy than other solver methods and often returns a density matrix or
11+
Choi-matrix that is not completely-positive and fails validation when used
12+
with the :func:`qiskit.quantum_info.state_fidelity` or
13+
:func:`qiskit.quantum_info.process_fidelity` functions.

0 commit comments

Comments
 (0)