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

Commit

Permalink
Merge pull request #539 from mtreinish/prepare-0.5.1
Browse files Browse the repository at this point in the history
Backport bug fixes and prepare 0.5.1
  • Loading branch information
chriseclectic authored Nov 12, 2020
2 parents 4bafe96 + 489bd9d commit 9599847
Show file tree
Hide file tree
Showing 9 changed files with 79 additions and 23 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,32 @@ jobs:
QISKIT_IN_PARALLEL: TRUE
run: tox -e py
if: runner.os == 'macOS'
tests-no-opt:
name: tests-python3.8-no-optional-dependencies
runs-on: ${{ matrix.os }}
strategy:
matrix:
python-version: [3.8]
os: ["ubuntu-latest"]
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Pip cache
uses: actions/cache@v2
with:
path: ~/.cache/pip
key: ${{ runner.os }}-${{ matrix.python-version }}-pip-tests-${{ hashFiles('setup.py','requirements-dev.txt','constraints.txt') }}
restore-keys: |
${{ runner.os }}-${{ matrix.python-version }}-pip-tests-
${{ runner.os }}-${{ matrix.python-version }}-pip-
${{ runner.os }}-${{ matrix.python-version }}
- name: Install Deps
run: python -m pip install -U tox setuptools virtualenv wheel
- name: Install and Run Tests
run: tox -e no-opt
windows-tests:
name: tests-python${{ matrix.python-version }}-windows
runs-on: windows-latest
Expand Down
2 changes: 1 addition & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ ignore-mixin-members=yes
# (useful for modules/projects where namespaces are manipulated during runtime
# and thus existing member attributes cannot be deduced by static analysis. It
# supports qualified module names, as well as Unix pattern matching.
ignored-modules=matplotlib.cm,numpy.random,retworkx
ignored-modules=matplotlib.cm,numpy.random,retworkx,numba

# List of class names for which member attributes should not be checked (useful
# for classes with dynamically set attributes). This supports the use of
Expand Down
1 change: 1 addition & 0 deletions constraints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ pylint==2.4.4
astroid==2.3.3
pywin32==225
setuptools==49.6.0
pyfakefs==4.1.0
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
# The short X.Y version
version = ''
# The full version, including alpha/beta/rc tags
release = '0.5.0'
release = '0.5.1'

# -- General configuration ---------------------------------------------------

Expand Down
2 changes: 1 addition & 1 deletion qiskit/ignis/VERSION.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.5.0
0.5.1
22 changes: 11 additions & 11 deletions qiskit/ignis/mitigation/expval/base_meas_mitigator.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,13 +166,13 @@ def stddev_upper_bound(self, shots: int = 1, qubits: Optional[List[int]] = None)
return gamma / np.sqrt(shots)

def plot_assignment_matrix(self,
qubits: Optional[List[int]] = None,
ax: Optional[plt.axes] = None) -> plt.axes:
qubits=None,
ax=None):
"""Matrix plot of the readout error assignment matrix.
Args:
qubits: Optional, qubits being measured for operator expval.
ax: Optional. Axes object to add plot to.
qubits (list(int)): Optional, qubits being measured for operator expval.
ax (axes): Optional. Axes object to add plot to.
Returns:
plt.axes: the figure axes object.
Expand All @@ -195,13 +195,13 @@ def plot_assignment_matrix(self,
return ax

def plot_mitigation_matrix(self,
qubits: Optional[List[int]] = None,
ax: Optional[plt.axes] = None) -> plt.axes:
qubits=None,
ax=None):
"""Matrix plot of the readout error mitigation matrix.
Args:
qubits: Optional, qubits being measured for operator expval.
ax: Optional. Axes object to add plot to.
qubits (list(int)): Optional, qubits being measured for operator expval.
ax (plt.axes): Optional. Axes object to add plot to.
Returns:
plt.axes: the figure axes object.
Expand Down Expand Up @@ -247,12 +247,12 @@ def _int_to_bitstring(i, num_qubits=None):
return label

@staticmethod
def _plot_axis(mat: np.ndarray, ax: plt.axes) -> plt.axes:
def _plot_axis(mat, ax):
"""Helper function for setting up axes for plots.
Args:
mat: the N-qubit matrix to plot.
ax: Optional. Axes object to add plot to.
mat (np.ndarray): the N-qubit matrix to plot.
ax (plt.axes): Optional. Axes object to add plot to.
Returns:
plt.axes: the figure object and axes object.
Expand Down
32 changes: 23 additions & 9 deletions qiskit/ignis/verification/tomography/fitters/base_fitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class TomographyFitter:
"""Base maximum-likelihood estimate tomography fitter class"""

_HAS_SDP_SOLVER = None
_HAS_SDP_SOLVER_NOT_SCS = False

def __init__(self,
result: Union[Result, List[Result]],
Expand Down Expand Up @@ -120,12 +121,14 @@ def fit(self,
**kwargs) -> np.array:
r"""Reconstruct a quantum state using CVXPY convex optimization.
**Fitter method**
**Fitter method**
The ``cvx`` fitter method used CVXPY convex optimization package.
The ``lstsq`` method uses least-squares fitting (linear inversion).
The ``auto`` method will use 'cvx' if the CVXPY package is found on
the system, otherwise it will default to 'lstsq'.
The ``'cvx'`` fitter method uses the CVXPY convex optimization package
with a SDP solver.
The ``'lstsq'`` method uses least-squares fitting.
The ``'auto'`` method will use ``'cvx'`` if the both the CVXPY and a suitable
SDP solver packages are found on the system, otherwise it will default
to ``'lstsq'``.
**Objective function**
Expand Down Expand Up @@ -165,9 +168,14 @@ def fit(self,
**CVXPY Solvers:**
Various solvers can be called in CVXPY using the `solver` keyword
argument. See the `CVXPY documentation
argument. If ``psd=True`` an SDP solver is required other an SOCP
solver is required. See the `CVXPY documentation
<https://www.cvxpy.org/tutorial/advanced/index.html#solve-method-options>`_
for more information on solvers.
Note that the default SDP solver ('SCS') distributed
with CVXPY will not be used for the ``'auto'`` method due its reduced
accuracy compared to other solvers. When using the ``'cvx'`` method we
strongly recommend installing one of the other supported SDP solvers.
References:
Expand Down Expand Up @@ -200,7 +208,11 @@ def fit(self,
# Choose automatic method
if method == 'auto':
self._check_for_sdp_solver()
if self._HAS_SDP_SOLVER:
if self._HAS_SDP_SOLVER_NOT_SCS:
# We don't use the SCS solver for automatic method as it has
# lower accuracy than the other supported SDP solvers which
# typically results in the returned matrix not being
# completely positive.
method = 'cvx'
else:
method = 'lstsq'
Expand Down Expand Up @@ -516,15 +528,17 @@ def _check_for_sdp_solver(cls):
# pylint:disable=import-error
import cvxpy
solvers = cvxpy.installed_solvers()
if 'CVXOPT' in solvers:
# Check for other SDP solvers cvxpy supports
if 'CVXOPT' in solvers or 'MOSEK' in solvers:
cls._HAS_SDP_SOLVER_NOT_SCS = True
cls._HAS_SDP_SOLVER = True
return
if 'SCS' in solvers:
# Try example problem to see if built with BLAS
# SCS solver cannot solver larger than 2x2 matrix
# problems without BLAS
try:
var = cvxpy.Variable((4, 4), PSD=True)
var = cvxpy.Variable((5, 5), PSD=True)
obj = cvxpy.Minimize(cvxpy.norm(var))
cvxpy.Problem(obj).solve(solver='SCS')
cls._HAS_SDP_SOLVER = True
Expand Down
2 changes: 2 additions & 0 deletions qiskit/ignis/verification/tomography/fitters/cvx_fit.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,8 @@ def cvx_fit(data: np.array,
if 'solver' not in kwargs:
if 'CVXOPT' in cvxpy.installed_solvers():
kwargs['solver'] = 'CVXOPT'
elif 'MOSEK' in cvxpy.installed_solvers():
kwargs['solver'] = 'MOSEK'

problem_solved = False
while not problem_solved:
Expand Down
13 changes: 13 additions & 0 deletions releasenotes/notes/no-auto-scs-b82ebef53508fc7b.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
fixes:
- |
Fix the ``"auto"`` method of the
:class:`~qiskit.ignis.verification.tomography.TomographyFitter`,
:class:`~qiskit.ignis.verification.tomography.StateTomographyFitter`, and
:class:`~qiskit.ignis.verification.tomography.ProcessTomographyFitter` to
only use ``"cvx"`` if CVXPY is installed *and* a third-party SDP solver
other than SCS is available. This is because the SCS solver has lower
accuracy than other solver methods and often returns a density matrix or
Choi-matrix that is not completely-positive and fails validation when used
with the :func:`qiskit.quantum_info.state_fidelity` or
:func:`qiskit.quantum_info.process_fidelity` functions.

0 comments on commit 9599847

Please sign in to comment.