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

Commit 42cbbf8

Browse files
chriseclecticdcmckayibm
authored andcommitted
Change default solver to CVXPY default for CVX tomography (#300)
* Remove cvxopt from requirements, update docs * add blas+lapack to travis * ignore built docs * install cvxpy through conda * cl * azure install scs instead of cvxpy * Update azure-pipelines.yml * Try building scs from source with py35 * Try splitting scs build from conda install * Try openblas binary used by scs windows ci * Fix typos * Tweak conda usage for python 3.5 * Update setuptools too to try and avoid pypa/pip#6264 * Build scs-python not scs * Attempt to flush pip cache prior to tox in travis * Fix copy paste typo * Try enabling system sitepackages too * Update setuptools on travis too now that we use sitepackages * Rework travis job to avoid need for system site packages * Fix typo
1 parent f024386 commit 42cbbf8

File tree

8 files changed

+119
-97
lines changed

8 files changed

+119
-97
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ test/python/*.pdf
1313
test/python/*.prof
1414
.stestr/
1515

16+
# Built documentation
17+
docs/_build/
18+
docs/stubs/
19+
docs/api/
20+
1621
# dotenv
1722
.env
1823

.travis.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ addons:
1111
packages:
1212
- gcc-4.8
1313
- g++-4.8
14+
- libblas-dev
15+
- liblapack-dev
1416

1517
install_osx: &stage_osx
1618
os: osx
@@ -103,8 +105,10 @@ matrix:
103105
- twine upload dist/qiskit*
104106

105107
language: python
106-
install: pip install -U tox pip virtualenv
108+
install: pip install -U tox pip virtualenv setuptools
107109
script:
110+
- tox --notest
111+
- .tox/$TOXENV/bin/pip install --no-cache-dir --ignore-installed scs
108112
- tox
109113

110114
notifications:

azure-pipelines.yml

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ jobs:
4242
Python35:
4343
python.version: '3.5'
4444
TOXENV: py35
45+
OPENBLAS: https://3f23b170c54c2533c070-1c8a9b3114517dc5fe17b7c3f8c63a43.ssl.cf2.rackcdn.com/openblas-5f998ef_gcc7_1_0_win64.zip
4546
Python36:
4647
python.version: '3.6'
4748
TOXENV: py36
@@ -52,15 +53,44 @@ jobs:
5253
steps:
5354
- powershell: Write-Host "##vso[task.prependpath]$env:CONDA\Scripts"
5455
displayName: Add conda to PATH
55-
- script: conda create --yes --quiet --name qiskit-ignis
56+
- script: conda create --yes --quiet --name qiskit-ignis python=%PYTHON_VERSION%
5657
displayName: Create Anaconda environment
5758
- script: |
5859
call activate qiskit-ignis
59-
conda install --yes --quiet --name qiskit-ignis python=%PYTHON_VERSION% mkl
60+
conda install --yes --quiet --name qiskit-ignis --channel conda-forge python=%PYTHON_VERSION% scs
6061
displayName: Install Anaconda packages
62+
condition: ne(variables['python.version'], '3.5')
63+
- powershell: (new-object System.Net.WebClient).DownloadFile($env:OPENBLAS, 'c:\openblas.zip')
64+
condition: eq(variables['python.version'], '3.5')
65+
displayName: 'Download openblas'
66+
- powershell: Expand-Archive c:\openblas.zip c:\openblas
67+
condition: eq(variables['python.version'], '3.5')
68+
displayName: 'Unzip openblas'
69+
- script: |
70+
call activate qiskit-ignis
71+
conda install --yes --quiet --update-all --name qiskit-ignis python=%PYTHON_VERSION% numpy scipy
72+
displayName: Install Anaconda packages
73+
condition: eq(variables['python.version'], '3.5')
74+
- script: |
75+
call activate qiskit-ignis
76+
set PATH=%PATH%;%BINPATH%;C:\openblas\%64%\bin;
77+
echo %PATH%
78+
dir C:\openblas\%ARCH%\bin
79+
make.exe CC="gcc.exe -m64" USE_LAPACK=1 BLASLDFLAGS="-LC:\openblas\64\bin -lopenblas_5f998ef_gcc7_1_0"
80+
make.exe install
81+
git clone --recursive https://github.com/bodono/scs-python.git
82+
cd scs-python
83+
python setup.py install --scs 'CC="gcc.exe -m64" USE_LAPACK=1 BLASLDFLAGS="-LC:\openblas\64\bin -lopenblas_5f998ef_gcc7_1_0"'
84+
cd ..
85+
condition: eq(variables['python.version'], '3.5')
86+
displayName: 'Install scs from source for python 3.5'
87+
- script: |
88+
call activate qiskit-ignis
89+
conda install --yes --quiet --name qiskit-ignis python=%PYTHON_VERSION% mkl
90+
displayName: 'Install MKL'
6191
- script: |
6292
call activate qiskit-ignis
63-
python -m pip install -c constraints.txt --upgrade pip virtualenv
64-
pip install -c constraints.txt tox
65-
tox -e%TOXENV%
93+
python -m pip install -c constraints.txt --upgrade pip virtualenv setuptools
94+
pip install -c constraints.txt -U tox
95+
tox --sitepackages -e%TOXENV%
6696
displayName: 'Install dependencies and run tests'

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

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def preparation_basis(self):
9999
return self._prep_basis
100100

101101
def fit(self, method='auto', standard_weights=True, beta=0.5, **kwargs):
102-
"""Reconstruct a quantum state using CVXPY convex optimization.
102+
r"""Reconstruct a quantum state using CVXPY convex optimization.
103103
104104
**Fitter method**
105105
@@ -116,13 +116,14 @@ def fit(self, method='auto', standard_weights=True, beta=0.5, **kwargs):
116116
subject to:
117117
118118
* :math:`x >> 0`
119-
* :math:`trace(x) = 1`
119+
* :math:`\text{trace}(x) = 1`
120120
121121
where:
122122
123-
* a is the matrix of measurement operators :math:`a[i] = vec(M_i).H`
123+
* a is the matrix of measurement operators
124+
:math:`a[i] = \text{vec}(M_i).H`
124125
* b is the vector of expectation value data for each projector
125-
:math:`b[i] ~ Tr[M_i.H * x] = (a * x)[i]`
126+
:math:`b[i] ~ \text{Tr}[M_i.H * x] = (a * x)[i]`
126127
* x is the vectorized density matrix to be fitted
127128
128129
**PSD constraint**
@@ -145,13 +146,9 @@ def fit(self, method='auto', standard_weights=True, beta=0.5, **kwargs):
145146
**CVXPY Solvers:**
146147
147148
Various solvers can be called in CVXPY using the `solver` keyword
148-
argument. Solvers included in CVXPY are:
149-
150-
* ``CVXOPT``: SDP and SOCP (default solver)
151-
* ``SCS``: SDP and SOCP
152-
* ``ECOS``: SOCP only
153-
154-
See the documentation on CVXPY for more information on solvers.
149+
argument. See the `CVXPY documentation
150+
<https://www.cvxpy.org/tutorial/advanced/index.html#solve-method-options>`_
151+
for more information on solvers.
155152
156153
References:
157154

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

Lines changed: 49 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,56 @@
2929

3030
def cvx_fit(data, basis_matrix, weights=None, PSD=True, trace=None,
3131
trace_preserving=False, **kwargs):
32-
"""
32+
r"""
3333
Reconstruct a quantum state using CVXPY convex optimization.
3434
35+
**Objective function**
36+
37+
This fitter solves the constrained least-squares minimization:
38+
:math:`minimize: ||a * x - b ||_2`
39+
40+
subject to:
41+
42+
* :math:`x >> 0` (PSD, optional)
43+
* :math:`\text{trace}(x) = t` (trace, optional)
44+
* :math:`\text{partial_trace}(x)` = identity (trace_preserving, optional)
45+
46+
where:
47+
* a is the matrix of measurement operators :math:`a[i] = vec(M_i).H`
48+
* b is the vector of expectation value data for each projector
49+
:math:`b[i] ~ \text{Tr}[M_i.H * x] = (a * x)[i]`
50+
* x is the vectorized density matrix (or Choi-matrix) to be fitted
51+
52+
**PSD constraint**
53+
54+
The PSD keyword constrains the fitted matrix to be
55+
postive-semidefinite, which makes the optimization problem a SDP. If
56+
PSD=False the fitted matrix will still be constrained to be Hermitian,
57+
but not PSD. In this case the optimization problem becomes a SOCP.
58+
59+
**Trace constraint**
60+
61+
The trace keyword constrains the trace of the fitted matrix. If
62+
trace=None there will be no trace constraint on the fitted matrix.
63+
This constraint should not be used for process tomography and the
64+
trace preserving constraint should be used instead.
65+
66+
**Trace preserving (TP) constraint**
67+
68+
The trace_preserving keyword constrains the fitted matrix to be TP.
69+
This should only be used for process tomography, not state tomography.
70+
Note that the TP constraint implicitly enforces the trace of the fitted
71+
matrix to be equal to the square-root of the matrix dimension. If a
72+
trace constraint is also specified that differs from this value the fit
73+
will likely fail.
74+
75+
**CVXPY Solvers**
76+
77+
Various solvers can be called in CVXPY using the `solver` keyword
78+
argument. See the `CVXPY documentation
79+
<https://www.cvxpy.org/tutorial/advanced/index.html#solve-method-options>`_
80+
for more information on solvers.
81+
3582
Args:
3683
data (vector like): vector of expectation values
3784
basis_matrix (matrix like): matrix of measurement operators
@@ -48,57 +95,7 @@ def cvx_fit(data, basis_matrix, weights=None, PSD=True, trace=None,
4895
4996
Returns:
5097
The fitted matrix rho that minimizes
51-
||basis_matrix * vec(rho) - data||_2.
52-
53-
Additional Information:
54-
55-
Objective function
56-
------------------
57-
This fitter solves the constrained least-squares minimization:
58-
59-
minimize: ||a * x - b ||_2
60-
subject to: x >> 0 (PSD, optional)
61-
trace(x) = t (trace, optional)
62-
partial_trace(x) = identity (trace_preserving,
63-
optional)
64-
65-
where:
66-
a is the matrix of measurement operators a[i] = vec(M_i).H
67-
b is the vector of expectation value data for each projector
68-
b[i] ~ Tr[M_i.H * x] = (a * x)[i]
69-
x is the vectorized density matrix (or Choi-matrix) to be fitted
70-
71-
PSD constraint
72-
--------------
73-
The PSD keyword constrains the fitted matrix to be
74-
postive-semidefinite, which makes the optimization problem a SDP. If
75-
PSD=False the fitted matrix will still be constrained to be Hermitian,
76-
but not PSD. In this case the optimization problem becomes a SOCP.
77-
78-
Trace constraint
79-
----------------
80-
The trace keyword constrains the trace of the fitted matrix. If
81-
trace=None there will be no trace constraint on the fitted matrix.
82-
This constraint should not be used for process tomography and the
83-
trace preserving constraint should be used instead.
84-
85-
Trace preserving (TP) constraint
86-
--------------------------------
87-
The trace_preserving keyword constrains the fitted matrix to be TP.
88-
This should only be used for process tomography, not state tomography.
89-
Note that the TP constraint implicitly enforces the trace of the fitted
90-
matrix to be equal to the square-root of the matrix dimension. If a
91-
trace constraint is also specified that differs from this value the fit
92-
will likely fail.
93-
94-
CVXPY Solvers:
95-
-------
96-
Various solvers can be called in CVXPY using the `solver` keyword
97-
argument. Solvers included in CVXPY are:
98-
'CVXOPT': SDP and SOCP (default solver)
99-
'SCS' : SDP and SOCP
100-
'ECOS' : SOCP only
101-
See the documentation on CVXPY for more information on solvers.
98+
:math:`||basis_matrix * vec(rho) - data||_2`.
10299
"""
103100

104101
# Check if CVXPY package is installed
@@ -195,10 +192,6 @@ def cvx_fit(data, basis_matrix, weights=None, PSD=True, trace=None,
195192
iters = 5000
196193
max_iters = kwargs.get('max_iters', 20000)
197194

198-
# Set the default solver to 'CVXOPT'
199-
if 'solver' not in kwargs:
200-
kwargs['solver'] = 'CVXOPT'
201-
202195
problem_solved = False
203196
while not problem_solved:
204197
kwargs['max_iters'] = iters

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

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class ProcessTomographyFitter(TomographyFitter):
2929
"""Maximum-Likelihood estimation process tomography fitter."""
3030

3131
def fit(self, method='auto', standard_weights=True, beta=0.5, **kwargs):
32-
"""Reconstruct a quantum channel using CVXPY convex optimization.
32+
r"""Reconstruct a quantum channel using CVXPY convex optimization.
3333
3434
**Choi matrix**
3535
@@ -54,14 +54,15 @@ def fit(self, method='auto', standard_weights=True, beta=0.5, **kwargs):
5454
subject to:
5555
5656
* :math:`x >> 0` (PSD)
57-
* :math:`trace(x) = dim` (trace)
58-
* :math:`partial_trace(x) = identity` (trace_preserving)
57+
* :math:`\text{trace}(x) = dim` (trace)
58+
* :math:`\text{partial_trace}(x) = \text{identity}` (trace_preserving)
5959
6060
where:
6161
62-
* a is the matrix of measurement operators :math:`a[i] = vec(M_i).H`
62+
* a is the matrix of measurement operators
63+
:math:`a[i] = \text{vec}(M_i).H`
6364
* b is the vector of expectation value data for each projector
64-
:math:`b[i] ~ Tr[M_i.H * x] = (a * x)[i]`
65+
:math:`b[i] ~ \text{Tr}[M_i.H * x] = (a * x)[i]`
6566
* x is the vectorized Choi-matrix to be fitted
6667
6768
**PSD constraint**
@@ -93,13 +94,9 @@ def fit(self, method='auto', standard_weights=True, beta=0.5, **kwargs):
9394
**CVXPY Solvers:**
9495
9596
Various solvers can be called in CVXPY using the `solver` keyword
96-
argument. Solvers included in CVXPY are:
97-
98-
* ``CVXOPT``: SDP and SOCP (default solver)
99-
* ``SCS``: SDP and SOCP
100-
* ``ECOS``: SOCP only
101-
102-
See the documentation on CVXPY for more information on solvers.
97+
argument. See the `CVXPY documentation
98+
<https://www.cvxpy.org/tutorial/advanced/index.html#solve-method-options>`_
99+
for more information on solvers.
103100
104101
References:
105102

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

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def __init__(self,
4141
super().__init__(result, circuits, meas_basis, None)
4242

4343
def fit(self, method='auto', standard_weights=True, beta=0.5, **kwargs):
44-
"""Reconstruct a quantum state using CVXPY convex optimization.
44+
r"""Reconstruct a quantum state using CVXPY convex optimization.
4545
4646
**Fitter method**
4747
@@ -58,13 +58,14 @@ def fit(self, method='auto', standard_weights=True, beta=0.5, **kwargs):
5858
subject to:
5959
6060
* :math:`x >> 0`
61-
* :math:`trace(x) = 1`
61+
* :math:`\text{trace}(x) = 1`
6262
6363
where:
6464
65-
* a is the matrix of measurement operators :math:`a[i] = vec(M_i).H`
65+
* a is the matrix of measurement operators
66+
:math:`a[i] = \text{vec}(M_i).H`
6667
* b is the vector of expectation value data for each projector
67-
:math:`b[i] ~ Tr[M_i.H * x] = (a * x)[i]`
68+
:math:`b[i] ~ \text{Tr}[M_i.H * x] = (a * x)[i]`
6869
* x is the vectorized density matrix to be fitted
6970
7071
**PSD constraint**
@@ -87,13 +88,9 @@ def fit(self, method='auto', standard_weights=True, beta=0.5, **kwargs):
8788
**CVXPY Solvers:**
8889
8990
Various solvers can be called in CVXPY using the `solver` keyword
90-
argument. Solvers included in CVXPY are:
91-
92-
* ``CVXOPT``: SDP and SOCP (default solver)
93-
* ``SCS``: SDP and SOCP
94-
* ``ECOS``: SOCP only
95-
96-
See the documentation on CVXPY for more information on solvers.
91+
argument. See the `CVXPY documentation
92+
<https://www.cvxpy.org/tutorial/advanced/index.html#solve-method-options>`_
93+
for more information on solvers.
9794
9895
References:
9996

requirements-dev.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
cvxpy>=1.0.15
2-
cvxopt>=1.2.3
32
qiskit-aer>=0.1.1
43
scikit-learn>=0.17
54
Sphinx>=1.8.3

0 commit comments

Comments
 (0)