cvxpy_linear_lstsq

cvxpy_linear_lstsq(outcome_data, shot_data, measurement_data, preparation_data, measurement_basis=None, preparation_basis=None, measurement_qubits=None, preparation_qubits=None, conditional_measurement_indices=None, conditional_preparation_indices=None, trace='auto', psd=True, trace_preserving='auto', partial_trace=None, weights=None, **kwargs)[source]

Constrained weighted linear least-squares tomography fitter.

Overview

This fitter reconstructs the maximum-likelihood estimate by using cvxpy to minimize the constrained least-squares negative log likelihood function

\[\begin{split}\hat{\rho} &= -\mbox{argmin }\log\mathcal{L}{\rho} \\ &= \mbox{argmin }\sum_i w_i^2(\mbox{Tr}[E_j\rho] - \hat{p}_i)^2 \\ &= \mbox{argmin }\|W(Ax - y) \|_2^2\end{split}\]

subject to

  • Positive-semidefinite (psd=True): \(\rho \gg 0\) is constrained to be a positive-semidefinite matrix.

  • Trace (trace=t): \(\mbox{Tr}(\rho) = t\) is constrained to have the specified trace.

  • Trace preserving (trace_preserving=True): When performing process tomography the Choi-state \(\rho\) represents is constrained to be trace preserving.

where

  • \(A\) is the matrix of measurement operators \(A = \sum_i |i\rangle\!\langle\!\langle M_i|\)

  • \(y\) is the vector of expectation value data for each projector corresponding to estimates of \(b_i = Tr[M_i \cdot x]\).

  • \(x\) is the vectorized density matrix (or Choi-matrix) to be fitted \(x = |\rho\rangle\\!\rangle\).

Note

Linear least-squares constructs the full basis matrix \(A\) as a dense numpy array so should not be used for than 5 or 6 qubits. For larger number of qubits try the linear_inversion() fitter function.

Parameters:
  • outcome_data (ndarray) – measurement outcome frequency data.

  • shot_data (ndarray) – basis measurement total shot data.

  • measurement_data (ndarray) – measurement basis index data.

  • preparation_data (ndarray) – preparation basis index data.

  • measurement_basis (MeasurementBasis | None) – Optional, measurement matrix basis.

  • preparation_basis (PreparationBasis | None) – Optional, preparation matrix basis.

  • measurement_qubits (Tuple[int, ...] | None) – Optional, the physical qubits that were measured. If None they are assumed to be [0, ..., M-1] for M measured qubits.

  • preparation_qubits (Tuple[int, ...] | None) – Optional, the physical qubits that were prepared. If None they are assumed to be [0, ..., N-1] for N prepared qubits.

  • conditional_measurement_indices (Tuple[int, ...] | None) – Optional, conditional measurement data indices. If set this will return a list of fitted states conditioned on a fixed basis measurement of these qubits.

  • conditional_preparation_indices (Tuple[int, ...] | None) – Optional, conditional preparation data indices. If set this will return a list of fitted states conditioned on a fixed basis preparation of these qubits.

  • trace (None | float | str) – trace constraint for the fitted matrix. If “auto” this will be set to 1 for QST or the input dimension for QST (default: “auto”).

  • psd (bool) – If True rescale the eigenvalues of fitted matrix to be positive semidefinite (default: True)

  • trace_preserving (None | bool | str) – Enforce the fitted matrix to be trace preserving when fitting a Choi-matrix in quantum process tomography. If “auto” this will be set to True for QPT and False for QST (default: “auto”).

  • partial_trace (ndarray | None) – Enforce conditional fitted Choi matrices to partial trace to POVM matrices.

  • weights (ndarray | None) – Optional array of weights for least squares objective. Weights should be the same shape as the outcome_data.

  • kwargs – kwargs for cvxpy solver.

Raises:
  • QiskitError – If CVXPy is not installed on the current system.

  • AnalysisError – If analysis fails.

Returns:

The fitted matrix rho that maximizes the least-squares likelihood function.

Return type:

Tuple[ndarray, Dict]