<jupyter_start><jupyter_text>$\langle XXXXXXXX\rangle$ Stabilizer example    Adapted from Ignis example by <NAME><jupyter_code>import numpy as np
from qiskit import *
from qiskit.providers.aer import QasmSimulator, noise

from qiskit.ignis.mitigation import (expectation_value, 
                                     expval_meas_mitigator_circuits,
                                     ExpvalMeasMitigatorFitter)

import mthree<jupyter_output><empty_output><jupyter_text>Load systems and simulators<jupyter_code>IBMQ.load_account()
pro= IBMQ.get_provider(project='internal-test')
sim = QasmSimulator()
backend = pro.backends.ibmq_dublin
# Test Circuit Measure <XXXXXXXX> stabilizer
# Eight qubit stabilizer
qubits=[1, 4, 7, 10, 12, 2, 3, 5]

qc = QuantumCircuit(8, 8)
qc.h(0)
qc.cx(0, 1)
qc.cx(1, 2)
qc.cx(2, 3)
qc.cx(3, 4)
qc.cx(0, 5)
qc.cx(5, 6)
qc.cx(6, 7)
qc.h(range(8))
qc.measure(range(8), range(8))

shots = 8192
#Get ideal result and raw counts from backend
result_target = execute(qc, sim, shots=shots, initial_layout=qubits).result()
result_noise = execute(qc, backend, shots=shots, initial_layout=qubits).result()
counts_target = result_target.get_counts(0)
counts_noise = result_noise.get_counts(0)<jupyter_output><empty_output><jupyter_text>Apply M3 correction<jupyter_code>mit = mthree.M3Mitigation(backend)
mit.tensored_cals_from_system(qubits)
mit_counts, details = mit.apply_correction(counts_noise, qubits=qubits, details=True)
details<jupyter_output><empty_output><jupyter_text>Apply CTMP correction<jupyter_code>circuits1, metadata1 = expval_meas_mitigator_circuits(len(qubits), method='tensored')
job_cal1 = execute(circuits1, backend, shots=8192, initial_layout=qubits)
result_cal1 = job_cal1.result()
ctmp_mitigator = ExpvalMeasMitigatorFitter(result_cal1, metadata1).fit()<jupyter_output><empty_output><jupyter_text>Tally all results<jupyter_code>print('Ideal:', expectation_value(counts_target)[0])
print('Raw:', expectation_value(counts_noise)[0])
print('CTMP mitigated:', expectation_value(counts_noise, meas_mitigator=ctmp_mitigator)[0])
print('M3 mitigated:', expectation_value(mit_counts)[0])<jupyter_output>Ideal: 1.0
Raw: 0.497802734375
CTMP mitigated: 1.3377458081929379
M3 mitigated: 0.9543008693805328
{'fraction_non_alphanumeric': 0.11722595078299776, 'fraction_numerical': 0.04697986577181208, 'mean_word_length': 7.043165467625899, 'pattern_counts': {'":': 0, '<': 22, '<?xml version=': 0, '>': 22, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '650716', 'license': 'Apache-2.0', 'n_tokens_mistral': 924, 'n_tokens_neox': 825, 'n_words': 145, 'path': 'examples/m3_x8_stabilizer_example.ipynb', 'repo_name': 'mtreinish/mthree', 'size': '2239'}