In Qiskit, it is possible to get closer to a real device by adding Noise when simulating a circuit with a simulator. However, setting Noise is highly specialized and extremely difficult. (In my opinion ...)
So, when I searched for an easy way to create a NoiseModel, I found it, so I will summarize it here.
First, create a circuit that creates a GHZ state without Noise for comparison.
GHZ state
GHZ state at 3qubits
|GHZ> = \frac{|000>+|111>}{\sqrt{2}}
import
python
# matplotlib inline
from qiskit import execute, QuantumCircuit, QuantumRegister
from qiskit.visualization import plot_histogram
from qiskit import BasicAer
#Definition of quantum register
qr = QuantumRegister(3)
#Definition of quantum circuit
qc = QuantumCircuit(qr)
#Hadamard gate to 0bit
qc.h(0)
# 0bit-CNOT with 1bit
qc.cx(0, 1)
# 1bit-CNOT with 2bit
qc.cx(1, 2)
#Measure all quantum registers
qc.measure_all()
#Show circuit
qc.draw(output='mpl')
#backend settings
backend = BasicAer.get_backend('qasm_simulator')
#Circuit execution
result = execute(qc, backend).result()
#Get counts
counts = result.get_counts()
#plot counts into a histogram
plot_histogram(counts)
You can get beautiful results with the simulator.
We will reproduce the same Noise Model as the actual machine with a simulator.
import
# matplotlib inline
from qiskit import QuantumCircuit, execute
from qiskit import IBMQ, Aer
from qiskit.visualization import plot_histogram
from qiskit.providers.aer.noise import NoiseModel
#Call the IBMQ account.
provider = IBMQ.load_account()
#This time ibmq_Use vigo's Noise Model
backend = provider.get_backend('ibmq_vigo')
noise_model = NoiseModel.from_backend(backend)
#Definition of quantum register
qr = QuantumRegister(3)
#Definition of quantum circuit
qc = QuantumCircuit(qr)
#Hadamard gate to 0bit
qc.h(0)
# 0bit-CNOT with 1bit
qc.cx(0, 1)
# 1bit-CNOT with 2bit
qc.cx(1, 2)
#Measure all quantum registers
qc.measure_all()
#Run
result = execute(qc, Aer.get_backend('qasm_simulator'),
noise_model=noise_model).result()
counts = result.get_counts()
#plot counts into a histogram
plot_histogram(counts)
in this way$ |000>
There seem to be various other options, so I would like to investigate.
Recommended Posts