I am reading a book named Learn Quantum Computing with Python and IBM Quantum Experience authored by Robert Loredo. When I tried to run the code on Chapter 11, I followed the instruction and wroted down the code:

# Import plot and match libraries
import matplotlib.pyplot as plt

# Import the noise models and some standard error methods
from qiskit.providers.aer.noise import NoiseModel
# from qiskit.providers.aer.noise.errors.standard_errors import amplitude_damping_error, phase_damping_error
from qiskit.providers.aer.noise import amplitude_damping_error, phase_damping_error

# Import all three coherence circuits generators and fitters
from qiskit.ignis.characterization.coherence import t1_circuits, t2_circuits, t2star_circuits
from qiskit.ignis.characterization.coherence import T1Fitter, T2Fitter, T2StarFitter

# Generate the T1 test circuits

# Generate a list of number of gates to add to each circuit
# using np.linspace so that the number of gates increases linearly
# and append with a large span at the end of the list (200-4000)

num_of_gates = np.append((np.linspace(1, 100, 12)).astype(int),
                         np.array([200, 400, 800, 1000, 2000, 4000]))

# Define the gate time for each Idnentity gate
gate_time = 0.1

# Select the first qubit as the one we wish to measure T1
qubits = [0]

# Generate the test circuits given the above parameters
test_circuits, delay_times = t1_circuits(num_of_gates,
                                        gate_time, qubits)
# The number of I gates appended for each circuit
print('Number of gates per test circuit: \n', num_of_gates, '\n')

# The gate time of each circuit (number of I gate * gate_time)
print('Delay times for each test circuit created, respectively: \n',

After I successfully generate the circuits, I added the amplitude damping error like:

# Set the simulator with amplitude damping noise

# Set the amplitude damping noise channel parameters T1 and Lambda
t1 = 20
lam = np.exp(-gate_time/t1)

# Generate the amplitude damping error channel
error = amplitude_damping_error(1 - lam)
noise_model = NoiseModel()

# Set the dampling error to the ID gate on qubit 0.
noise_model.add_quantum_error(error, 'id', [0])

Then I tried to execute this circuit on a simulator like:

# Run the simulator with the generated noise model
from qiskit import execute
backend = Aer.get_backend('qasm_simulator')
shots = 200
backend_result = execute(test_circuits, backend, shots = shots,
                         noise_model = noise_model).result()

Then the results are plotted:

# Plot the noisy results of the largest (last in the list) circuit

The graph I got is like: enter image description here Howerver, the correct one should be like: enter image description here

It seems to me the amplitude damping error was NOT added to the NoiseModel successfully. I wonder if anyone can help me to figure out the solution to this problem.


1 Answer 1


Actually, the amplitude damping error added to the NoiseModel successfully. The issue happens because the noisy gates are removed from your circuits before sending them to the backend.

When calling execute function without specifying the optimization level, level $1$ will be chosen by default[1]. That will make the transpiler remove the I gates from the circuit. For more details see this answer.

So, you need to set optimization_level to $0$ while calling execute:

backend_result = execute(test_circuits, backend, shots = shots,
                        optimization_level = 0,
                        noise_model = noise_model).result()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.