I am trying to perform a simulation using Qasm in order to see how the readout error actually affects my circuit. The circuit I am implementing is a trivial one, the three qubit one that implements the GHZ state: https://qiskit.org/documentation/tutorials/circuits/01_circuit_basics.html
Below I attach the code:
import numpy as np from qiskit import QuantumCircuit circ = QuantumCircuit(3) circ.h(0) circ.cx(0, 1) circ.cx(0, 2) # Create a Quantum Circuit meas = QuantumCircuit(3, 3) meas.barrier(range(3)) # map the quantum measurement to the classical bits meas.measure(range(3), range(3)) # The Qiskit circuit object supports composition. # Here the meas has to be first and front=True (putting it before) # as compose must put a smaller circuit into a larger one. qc = meas.compose(circ, range(3), front=True) #drawing the circuit qc.draw('mpl');
Next, I create the Readout Error model:
from qiskit.providers.aer.noise import NoiseModel from qiskit.providers.aer.noise import QuantumError, ReadoutError # Create noise model readout_noise_model = NoiseModel() # Create the readout error matrix P = np.array([[0.9,0.02,0.02,0.02,0.02,0.01,0.01,0.0], [0.02,0.9,0.02,0.02,0.02,0.01,0.01,0.0], [0.02,0.02,0.9,0.02,0.02,0.01,0.01,0.0], [0.02,0.02,0.02,0.9,0.02,0.01,0.01,0.0], [0.02,0.02,0.02,0.02,0.9,0.01,0.01,0.0], [0.02,0.02,0.02,0.01,0.01,0.9,0.01,0.01], [0.01,0.02,0.02,0.02,0.03,0.04,0.84,0.02], [0.02,0.02,0.02,0.02,0.04,0.04,0.04,0.8]]) # Add readout error to the qubits readout_noise_model.add_readout_error(P,[0,1,2]) print(readout_noise_model)
And now run the simulation:
from qiskit import transpile from qiskit.providers.aer import AerSimulator backend = AerSimulator() # First we have to transpile the quantum circuit # to the low-level QASM instructions used by the # backend qc_compiled = transpile(qc, backend) # Execute the circuit on the qasm simulator. # We've set the number of repeats of the circuit # to be 1024, which is the default. job_sim = backend.run(qc_compiled, shots=1024, noise_model=readout_noise_model) # Grab the results from the job. result_sim = job_sim.result() counts = result_sim.get_counts(qc_compiled) print(counts)
And obtain the histogram:
from qiskit.visualization import plot_histogram plot_histogram(counts);
Now, without noise I would expect indeed, as in the Qiskit link provided, that about 50% of the times I get the first state and about 50% the other one. For example something like this:
However, I would assume that since I am biasing the noise (observe the last two or three rows of the P matrix) I should get slightly offset result. I do not seem to get offset results favoring the $|000\rangle$ state for example (of the opposite).
My questions are:
- Is my Readout Error properly implemented?
- How can I force a bias in such a circuit?