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
Quantum Error Correction
Method 1: Repetition Code
= QuantumRegister(3)
q = ClassicalRegister(3)
c = QuantumCircuit(q,c)
qc
0)
qc.h(
0,1)
qc.cx(0,2)
qc.cx(
range(3), range(3))
qc.measure(
# Construct a simulator using a noise model from a real backend.
= QiskitRuntimeService(channel="ibm_quantum", token="fbc77e68310da5c90990728b892ef5e327787a28a126ad837f8fb88280922284da2784a01e90dc9ccd3be7d48bbe76ca0b8375ac0d3f0f312b1e19da181a18ed")
provider = provider.get_backend("ibm_brisbane")
backend = AerSimulator.from_backend(backend)
aersim_backend # Perform noisy simulation
= aersim_backend.run(qc).result().get_counts()
results plot_histogram(results)
= QuantumRegister(5)
q = ClassicalRegister(2)
c = QuantumCircuit(q,c)
qc
0)
qc.h(
0,1)
qc.cx(0,2)
qc.cx(
0,3)
qc.cx(1,3)
qc.cx(
1,4)
qc.cx(2,4)
qc.cx(
3,4], range(2))
qc.measure([
"mpl",style="clifford")
qc.draw(
# 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)
= QuantumRegister(5)
q = ClassicalRegister(2)
c = QuantumCircuit(q,c)
qc
0)
qc.h(
0,1)
qc.cx(0,2)
qc.cx(
0)
qc.x(
0,3)
qc.cx(1,3)
qc.cx(
1,4)
qc.cx(2,4)
qc.cx(
3,4], range(2))
qc.measure([
# Construct a simulator using a noise model from a real backend.
= QiskitRuntimeService(channel="ibm_quantum", token="fbc77e68310da5c90990728b892ef5e327787a28a126ad837f8fb88280922284da2784a01e90dc9ccd3be7d48bbe76ca0b8375ac0d3f0f312b1e19da181a18ed")
provider = provider.get_backend("ibm_brisbane")
backend = AerSimulator.from_backend(backend)
aersim_backend # Perform noisy simulation
= aersim_backend.run(qc).result().get_counts()
results plot_histogram(results)
= QuantumRegister(5)
q = ClassicalRegister(2)
c = QuantumCircuit(q,c)
qc
0)
qc.h(
0,1)
qc.cx(0,2)
qc.cx(range(3))
qc.h(
3,0)
qc.cx(3,1)
qc.cx(
4,1)
qc.cx(4,2)
qc.cx(
3,4])
qc.h([
3,4], range(2))
qc.measure([
"mpl", style="clifford") qc.draw(
Method 2: Error Mitigation Matrix
= QuantumRegister(2)
q = ClassicalRegister(2)
c = QuantumCircuit(q,c)
qc
range(2), range(2))
qc.measure(
# Construct a simulator using a noise model from a real backend.
= QiskitRuntimeService(channel="ibm_quantum", token="fbc77e68310da5c90990728b892ef5e327787a28a126ad837f8fb88280922284da2784a01e90dc9ccd3be7d48bbe76ca0b8375ac0d3f0f312b1e19da181a18ed")
provider = provider.get_backend("ibm_brisbane")
backend = AerSimulator.from_backend(backend)
aersim_backend # Perform noisy simulation
= aersim_backend.run(qc).result().get_counts()
results plot_histogram(results)
= QuantumRegister(2)
q = ClassicalRegister(2)
c = QuantumCircuit(q,c)
qc
0)
qc.x(
range(2), range(2))
qc.measure(
# Construct a simulator using a noise model from a real backend.
= QiskitRuntimeService(channel="ibm_quantum", token="fbc77e68310da5c90990728b892ef5e327787a28a126ad837f8fb88280922284da2784a01e90dc9ccd3be7d48bbe76ca0b8375ac0d3f0f312b1e19da181a18ed")
provider = provider.get_backend("ibm_brisbane")
backend = AerSimulator.from_backend(backend)
aersim_backend # Perform noisy simulation
= aersim_backend.run(qc).result().get_counts()
results plot_histogram(results)
= QuantumRegister(2)
q = ClassicalRegister(2)
c = QuantumCircuit(q,c)
qc
1)
qc.x(
range(2), range(2))
qc.measure(
# Construct a simulator using a noise model from a real backend.
= QiskitRuntimeService(channel="ibm_quantum", token="fbc77e68310da5c90990728b892ef5e327787a28a126ad837f8fb88280922284da2784a01e90dc9ccd3be7d48bbe76ca0b8375ac0d3f0f312b1e19da181a18ed")
provider = provider.get_backend("ibm_brisbane")
backend = AerSimulator.from_backend(backend)
aersim_backend # Perform noisy simulation
= aersim_backend.run(qc).result().get_counts()
results plot_histogram(results)
= QuantumRegister(2)
q = ClassicalRegister(2)
c = QuantumCircuit(q,c)
qc
0)
qc.x(1)
qc.x(
range(2), range(2))
qc.measure(
# Construct a simulator using a noise model from a real backend.
= QiskitRuntimeService(channel="ibm_quantum", token="fbc77e68310da5c90990728b892ef5e327787a28a126ad837f8fb88280922284da2784a01e90dc9ccd3be7d48bbe76ca0b8375ac0d3f0f312b1e19da181a18ed")
provider = provider.get_backend("ibm_brisbane")
backend = AerSimulator.from_backend(backend)
aersim_backend # Perform noisy simulation
= aersim_backend.run(qc).result().get_counts()
results plot_histogram(results)