예제 #1
0
    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
    TOMOGRAPHY_GATES = {}
from grove.tomography.process_tomography import (TRACE_PRESERVING)
from grove.tomography.state_tomography import (DEFAULT_STATE_TOMO_SETTINGS,
                                               state_tomography_programs,
                                               do_state_tomography, StateTomography,
                                               UNIT_TRACE,
                                               POSITIVE)
from grove.tomography.tomography import (MAX_QUBITS_STATE_TOMO,
                                         default_channel_ops)
from grove.tomography.utils import (make_histogram,
                                    sample_bad_readout, basis_state_preps,
                                    estimate_assignment_probs, BELL_STATE_PROGRAM,
                                    BAD_2Q_READOUT, EPS, SEED, import_qutip, import_cvxpy)
from grove.tomography.operator_utils import POVM_PI_BASIS

qt = import_qutip()
cvxpy = import_cvxpy()

if not qt:
    pytest.skip("Qutip not installed, skipping tests", allow_module_level=True)

if not cvxpy:
    pytest.skip("CVXPY not installed, skipping tests", allow_module_level=True)


SHOTS_PATH = os.path.join(os.path.dirname(__file__), 'state_shots.json')
RESULTS_PATH = os.path.join(os.path.dirname(__file__), 'state_results.json')
sample_bad_readout = MagicMock(sample_bad_readout)
sample_bad_readout.side_effect = [np.array(shots) for shots in json.load(open(SHOTS_PATH, 'r'))]

cxn = MagicMock(QVMConnection)
cxn.run_and_measure.side_effect = json.load(open(RESULTS_PATH, 'r'))