Quantum Error Correction

from qiskit import QuantumCircuit, QuantumRegister, ClassicalRegister
from qiskit_ibm_runtime import QiskitRuntimeService
from qiskit_aer import AerSimulator
from qiskit.visualization import plot_histogram
import numpy as np

Method 1: Repetition Code

q = QuantumRegister(3)
c = ClassicalRegister(3)
qc = QuantumCircuit(q,c)

qc.h(0)

qc.cx(0,1)
qc.cx(0,2)

qc.measure(range(3), range(3))

# Construct a simulator using a noise model from a real backend.
provider = QiskitRuntimeService(channel="ibm_quantum", token="fbc77e68310da5c90990728b892ef5e327787a28a126ad837f8fb88280922284da2784a01e90dc9ccd3be7d48bbe76ca0b8375ac0d3f0f312b1e19da181a18ed")
backend = provider.get_backend("ibm_brisbane")
aersim_backend = AerSimulator.from_backend(backend)
# Perform noisy simulation
results = aersim_backend.run(qc).result().get_counts()
plot_histogram(results)

q = QuantumRegister(5)
c = ClassicalRegister(2)
qc = QuantumCircuit(q,c)

qc.h(0)

qc.cx(0,1)
qc.cx(0,2)

qc.cx(0,3)
qc.cx(1,3)

qc.cx(1,4)
qc.cx(2,4)

qc.measure([3,4], range(2))


qc.draw("mpl",style="clifford")

# Construct a simulator using a noise model from a real backend.
#provider = QiskitRuntimeService(channel="ibm_quantum", token="fbc77e68310da5c90990728b892ef5e327787a28a126ad837f8fb88280922284da2784a01e90dc9ccd3be7d48bbe76ca0b8375ac0d3f0f312b1e19da181a18ed")
#backend = provider.get_backend("ibm_brisbane")
#aersim_backend = AerSimulator.from_backend(backend)
# Perform noisy simulation
#results = aersim_backend.run(qc).result().get_counts()
#plot_histogram(results)

q = QuantumRegister(5)
c = ClassicalRegister(2)
qc = QuantumCircuit(q,c)

qc.h(0)

qc.cx(0,1)
qc.cx(0,2)

qc.x(0)

qc.cx(0,3)
qc.cx(1,3)

qc.cx(1,4)
qc.cx(2,4)

qc.measure([3,4], range(2))

# Construct a simulator using a noise model from a real backend.
provider = QiskitRuntimeService(channel="ibm_quantum", token="fbc77e68310da5c90990728b892ef5e327787a28a126ad837f8fb88280922284da2784a01e90dc9ccd3be7d48bbe76ca0b8375ac0d3f0f312b1e19da181a18ed")
backend = provider.get_backend("ibm_brisbane")
aersim_backend = AerSimulator.from_backend(backend)
# Perform noisy simulation
results = aersim_backend.run(qc).result().get_counts()
plot_histogram(results)

q = QuantumRegister(5)
c = ClassicalRegister(2)
qc = QuantumCircuit(q,c)

qc.h(0)

qc.cx(0,1)
qc.cx(0,2)
qc.h(range(3))

qc.cx(3,0)
qc.cx(3,1)

qc.cx(4,1)
qc.cx(4,2)

qc.h([3,4])

qc.measure([3,4], range(2))

qc.draw("mpl", style="clifford")

Method 2: Error Mitigation Matrix

q = QuantumRegister(2)
c = ClassicalRegister(2)
qc = QuantumCircuit(q,c)

qc.measure(range(2), range(2))

# Construct a simulator using a noise model from a real backend.
provider = QiskitRuntimeService(channel="ibm_quantum", token="fbc77e68310da5c90990728b892ef5e327787a28a126ad837f8fb88280922284da2784a01e90dc9ccd3be7d48bbe76ca0b8375ac0d3f0f312b1e19da181a18ed")
backend = provider.get_backend("ibm_brisbane")
aersim_backend = AerSimulator.from_backend(backend)
# Perform noisy simulation
results = aersim_backend.run(qc).result().get_counts()
plot_histogram(results)

q = QuantumRegister(2)
c = ClassicalRegister(2)
qc = QuantumCircuit(q,c)

qc.x(0)

qc.measure(range(2), range(2))


# Construct a simulator using a noise model from a real backend.
provider = QiskitRuntimeService(channel="ibm_quantum", token="fbc77e68310da5c90990728b892ef5e327787a28a126ad837f8fb88280922284da2784a01e90dc9ccd3be7d48bbe76ca0b8375ac0d3f0f312b1e19da181a18ed")
backend = provider.get_backend("ibm_brisbane")
aersim_backend = AerSimulator.from_backend(backend)
# Perform noisy simulation
results = aersim_backend.run(qc).result().get_counts()
plot_histogram(results)

q = QuantumRegister(2)
c = ClassicalRegister(2)
qc = QuantumCircuit(q,c)

qc.x(1)

qc.measure(range(2), range(2))

# Construct a simulator using a noise model from a real backend.
provider = QiskitRuntimeService(channel="ibm_quantum", token="fbc77e68310da5c90990728b892ef5e327787a28a126ad837f8fb88280922284da2784a01e90dc9ccd3be7d48bbe76ca0b8375ac0d3f0f312b1e19da181a18ed")
backend = provider.get_backend("ibm_brisbane")
aersim_backend = AerSimulator.from_backend(backend)
# Perform noisy simulation
results = aersim_backend.run(qc).result().get_counts()
plot_histogram(results)

q = QuantumRegister(2)
c = ClassicalRegister(2)
qc = QuantumCircuit(q,c)

qc.x(0)
qc.x(1)

qc.measure(range(2), range(2))

# Construct a simulator using a noise model from a real backend.
provider = QiskitRuntimeService(channel="ibm_quantum", token="fbc77e68310da5c90990728b892ef5e327787a28a126ad837f8fb88280922284da2784a01e90dc9ccd3be7d48bbe76ca0b8375ac0d3f0f312b1e19da181a18ed")
backend = provider.get_backend("ibm_brisbane")
aersim_backend = AerSimulator.from_backend(backend)
# Perform noisy simulation
results = aersim_backend.run(qc).result().get_counts()
plot_histogram(results)