示例#1
0
from grove.tomography.utils import to_density_matrix, import_qutip

try:
    # Python 2
    from itertools import izip
except ImportError:  # pragma no coverage
    # Python 3
    izip = zip

import numpy as np
from scipy.sparse import hstack as sphstack, vstack as spvstack
from scipy.sparse.linalg import norm as spnorm

_log = logging.getLogger(__name__)

qt = import_qutip()

FROBENIUS = 'fro'
CHOI = 'choi'

EPS = 1e-8


class CRMBaseError(Exception):
    """
    Base class for errors raised when the confusion rate matrix is defective.
    """
    pass


class CRMUnnormalizedError(CRMBaseError):
    # Python 3
    izip = zip

import numpy as np

from pyquil.gates import I, RX, RY, MEASURE
from pyquil.quil import Program

import grove.tomography.utils as ut
import grove.tomography.operator_utils as o_ut
from grove.tomography.operator_utils import QI, QX, QY
from grove.tomography.utils import bitlist_to_int, sample_assignment_probs

_log = logging.getLogger(__name__)

qt = ut.import_qutip()
cvxpy = ut.import_cvxpy()

# We constrain the number of qubits to prevent the use of large amounts of memory, and prohibitively
# long programs.
MAX_QUBITS_STATE_TOMO = 4
MAX_QUBITS_PROCESS_TOMO = MAX_QUBITS_STATE_TOMO // 2
SEED = 137
SOLVER = "SCS"
if qt:
    TOMOGRAPHY_GATES = OrderedDict([
        (I, QI), (RX(np.pi / 2), (-1j * np.pi / 4 * QX).expm()),
        (RY(np.pi / 2), (-1j * np.pi / 4 * QY).expm()),
        (RX(np.pi), (-1j * np.pi / 2 * QX).expm())
    ])
else:  # pragma no coverage