# Why qiskit transpiler makes different results everytime? (Non-deterministic)

I tried to do qubit mapping called 'SABRE' and execute transpiled quantum circuit. I use FakeTokyo backend which has some noise because it is mock version of IBMQ 20-Tokyo. I know using this backend makes some noise but will not change final result when I measure my circuit. But, when I transpile my quantum circuit like below code, the result is always different. I wonder why this happens.

Source code:

from qiskit.test.mock import FakeTokyo
from qiskit.circuit.measure import measure
from qiskit.execute_function import execute
from qiskit.circuit.quantumcircuit import QuantumCircuit
from qiskit.compiler import transpile

backend = FakeTokyo()

final_circuit = transpile(circuits=circuit,
backend=backend,
routing_method='sabre',
layout_method='sabre',
basis_gates=['u1', 'u2', 'u3', 'cx', 'id'])

final_circuit.barrier()
final_circuit.measure_all()

results = execute(final_circuit, backend).result()
counts = results.get_counts()
print("result : ", counts)


circuits = circuit means I input list of quantum circuits into transpile function. I really don't know why the results always different.

Set the seed_transpiler. See the documentation for transpiler() here.

from qiskit.test.mock import FakeTokyo
from qiskit.circuit.measure import measure
from qiskit.execute_function import execute
from qiskit.circuit.quantumcircuit import QuantumCircuit
from qiskit.compiler import transpile

backend = FakeTokyo()

final_circuit = transpile(circuits=circuit,
backend=backend,
routing_method='sabre',
layout_method='sabre',
seed_transpiler= 1000,
basis_gates=['u1', 'u2', 'u3', 'cx', 'id'])

final_circuit.barrier()
final_circuit.measure_all()

results = execute(final_circuit, backend).result()
counts = results.get_counts()
print("result : ", counts)

• What is seed_transpiler? Please show me the example of seed_transpiler
– 김동민
Jun 22, 2021 at 2:15
• It sets random seed for the stochastic parts of the transpiler. The transpiler/compiler uses a heuristic approach at decomposing the circuit. If you set the seed to a specific value then the transpiled circuit will be the same each time. If not, then each execution, the transpiler will pick a random seed hence lead to different results. Look at the code I put down... which is the same as the code you had, I just set the seed to a fixed value of 1000. Jun 22, 2021 at 3:05
• Thank you, I found the seed what I need. But I wonder two things.
– 김동민
Jun 23, 2021 at 0:18
• 1. Should I need to set specific seed to get the result that I need? 2. What is seed exactly?
– 김동민
Jun 23, 2021 at 3:53
• 1) You can set it to any specific value you want. But keep it the same through out. 2) See this: en.wikipedia.org/wiki/Random_seed Jun 23, 2021 at 4:27