qiskit-community / qiskit-ignis

Ignis (deprecated) provides tools for quantum hardware verification, noise characterization, and error correction.
Apache License 2.0
167 stars 160 forks source link

CTMP mitigator works only for circuits with even number of qubits #562

Open HwajungKang opened 3 years ago

HwajungKang commented 3 years ago

Informations

What is the current behavior?

Applying CTMP mitigator on circuits with odd number of qubits makes expectation value worse rather than making it closer to the ideal value. works opposite to error mitigation. It behaves right for the circuits with even number of qubits, though. You can check with the code below by changing the variable n_q for the number of qubits.

Steps to reproduce the problem


import numpy as np
from qiskit import *
from qiskit.providers.aer.noise import NoiseModel
from qiskit.ignis.mitigation import (expval_meas_mitigator_circuits,
                                     ExpvalMeasMitigatorFitter,
                                     expectation_value)
from qiskit.test.mock import FakeMelbourne

###################

def circ(n_q):

    qc = QuantumCircuit(n_q)
    qc.h(0)
    qc.cx(range(n_q-1), range(1, n_q))
    qc.measure_all()

    return qc

####################

sim = Aer.get_backend('qasm_simulator')
backend = FakeMelbourne()

n_q = 7 # number of qubits

qc = circ(n_q)
counts_raw = execute(qc, backend, shots=8192).result().get_counts()

circ_ctmp, data_ctmp = expval_meas_mitigator_circuits(n_q, method='CTMP')
result_ctmp = execute(circ_ctmp, backend, shots=8192).result()
ctmp_mitigator = ExpvalMeasMitigatorFitter(result_ctmp, data_ctmp).fit()

counts_ideal = execute(qc, sim, shots=8192).result().get_counts()

ideal = i1nt(expectation_value(counts_ideal)[0])
raw = expectation_value(counts_raw)[0]
mitigated = expectation_value(counts_raw, meas_mitigator=ctmp_mitigator)[0]

print('Ideal expectation value: {}'.format(ideal))
print('Raw expectation value: {}'.format(raw))
print('CTMP mitigated expectation value: {}'.format(mitigated))

What is the expected behavior?

Suggested solutions

chriseclectic commented 3 years ago

@georgesbarron Do you have any ideas for this?