Created
December 5, 2019 09:39
-
-
Save sparverius/a5b5cf8614adfabc4777c4ee19e1dcfc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from qiskit import Aer, IBMQ, execute, QuantumCircuit, QuantumRegister, ClassicalRegister | |
from qiskit.transpiler import CouplingMap | |
from qiskit.tools.monitor import job_monitor | |
from qiskit.providers.aer import noise | |
from qiskit.providers.aer.noise.errors import depolarizing_error | |
# Construct quantum circuit | |
qr = QuantumRegister(3, 'qr') | |
cr = ClassicalRegister(3, 'cr') | |
circ = QuantumCircuit(qr, cr) | |
circ.h(qr[0]) | |
circ.cx(qr[0], qr[1]) | |
circ.cx(qr[1], qr[2]) | |
circ.measure(qr, cr) | |
# Select the QasmSimulator from the Aer provider | |
simulator = Aer.get_backend('qasm_simulator') | |
# Execute and get counts | |
result = execute(circ, simulator).result() | |
counts = result.get_counts(circ) | |
print(counts); | |
noise_model = noise.NoiseModel(['h', 'cx']) | |
# print('noise_model before', noise_model.to_dict()) | |
error2 = depolarizing_error(0.1, 2) | |
noise_model.add_all_qubit_quantum_error(error2, ['cx']) | |
print('noise_model after', noise_model.to_dict()) | |
# Get the basis gates for the noise model | |
basis_gates = noise_model.basis_gates | |
# Select the QasmSimulator from the Aer provider | |
simulator = Aer.get_backend('qasm_simulator') | |
cm = CouplingMap([[0,1], [0,2], [1,2]]) | |
# Execute noisy simulation and get counts | |
result_noise = execute(circ, simulator, | |
noise_model=noise_model, | |
coupling_map=cm, | |
basis_gates=basis_gates).result() | |
counts_noise = result_noise.get_counts(circ) | |
print(counts_noise) | |
bar = [{'key': k, 'prob': v/1024} for k,v in counts_noise.items()] | |
print (sorted(bar, key = lambda i: i['key'])) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment