コード例 #1
0
def run_circuit_and_tomography(circuit, qubits, method):
    choi_ideal = Choi(circuit).data
    qst = tomo.process_tomography_circuits(circuit, qubits)
    job = qiskit.execute(qst, Aer.get_backend('qasm_simulator'), shots=5000)
    tomo_fit = tomo.ProcessTomographyFitter(job.result(), qst)
    choi = tomo_fit.fit(method=method).data
    return (choi, choi_ideal)
コード例 #2
0
def run_circuit_and_tomography(circuit, qubits):
    job = qiskit.execute(circuit, Aer.get_backend('unitary_simulator'))
    U = job.result().get_unitary(circuit)
    choi_ideal = outer(U.ravel(order='F'))
    qst = tomo.process_tomography_circuits(circuit, qubits)
    job = qiskit.execute(qst, Aer.get_backend('qasm_simulator'), shots=5000)
    tomo_fit = tomo.ProcessTomographyFitter(job.result(), qst)
    choi_cvx = tomo_fit.fit(method='cvx').data
    choi_mle = tomo_fit.fit(method='lstsq').data
    return (choi_cvx, choi_mle, choi_ideal)
コード例 #3
0
def create_qpt_experiment(target_circuits: List[QuantumCircuit],
                          control: int,
                          target: int,
                          backend: BaseBackend,
                          mit_readout: bool = True,
                          inst_map: InstructionScheduleMap = None,
                          basis_gate: List[str] = None,
                          sanity_check: bool = False,
                          shots: int = 2048,
                          return_schedule=False)\
        -> Tuple[Union[PulseQobj, Schedule], List[List[QuantumCircuit]], List[str]]:
    """ Create circuits and schedules for QPT.

    Args:
        target_circuits: List of target circuits for QPT experiment.
        control: index of control qubit.
        target: index of target qubit.
        backend: Target quantum system.
        mit_readout: If use readout mitigation.
        inst_map: instruction mapping object.
        basis_gate: basis gates.
        sanity_check: check memory slot mapping of generated qobj.
        shots: Number of shots.
        return_schedule: set ``True`` when return schedule object instead of qobj.

    Returns:
        Qobj, Schedules, Quantum circuits, Measurement labels

    Additional Information:
        Bit ordering is little endian as a convention of computational science community,
        as the rest of qiskit does. When you measure the CR process tomography of q0 and q1,
        you will observe XZ (ZX) interaction when q0 (q1) is control qubit.
    """
    qubits = sorted([control, target])

    back_config = backend.configuration()
    back_defaults = backend.defaults()

    if inst_map is None:
        inst_map = back_defaults.circuit_instruction_map

    if basis_gate is None:
        basis_gate = back_config.basis_gates

    if isinstance(target_circuits, QuantumCircuit):
        target_circuits = [target_circuits]

    exp_circs = []

    # create the measurement circuits for error mitigation, optional
    qr = target_circuits[0].qregs[0]
    if mit_readout:
        meas_circs, meas_labels = mit.complete_meas_cal(qubit_list=qubits,
                                                        qr=qr,
                                                        circlabel='mcal')
        exp_circs.extend(meas_circs)
    else:
        meas_labels = []

    # create qpt circuit
    qpt_qcs_list = []
    for target_circuit in target_circuits:
        # extract quantum registers from target circuit
        qr = target_circuit.qregs[0]
        qr0 = qr[qubits[0]]
        qr1 = qr[qubits[1]]
        qpt_qcs = tomo.process_tomography_circuits(target_circuit,
                                                   measured_qubits=[qr0, qr1])
        qpt_qcs_list.append(qpt_qcs)
        exp_circs.extend(qpt_qcs)

    # transpile
    exp_circs = qiskit.transpile(exp_circs, backend, basis_gates=basis_gate)

    # schedule with measure alignment
    exp_scheds = align_measures(qiskit.schedule(exp_circs,
                                                backend=backend,
                                                inst_map=inst_map),
                                inst_map=inst_map)

    if return_schedule:
        return exp_scheds, qpt_qcs_list, meas_labels

    # assemble pulse qobj
    qobj = qiskit.assemble(exp_scheds,
                           backend=backend,
                           meas_level=2,
                           shots=shots)

    # sanity check
    if sanity_check:
        for experiment in qobj.experiments:
            for inst in experiment.instructions:
                if inst.name == 'acquire':
                    memory_slot_map = inst.memory_slot
                    if memory_slot_map[qubits[0]] != __reserved_registers[0] or \
                            memory_slot_map[qubits[0]] != __reserved_registers[1]:
                        warnings.warn('Wrong memory slots are assigned. '
                                      'QPT fitter may return invalid result.')

        assert len(qobj.experiments) <= back_config.max_experiments

    return qobj, qpt_qcs_list, meas_labels