1
$\begingroup$

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.

$\endgroup$

1 Answer 1

1
$\begingroup$

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)
$\endgroup$
6
  • $\begingroup$ What is seed_transpiler? Please show me the example of seed_transpiler $\endgroup$
    – 김동민
    Jun 22, 2021 at 2:15
  • $\begingroup$ 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. $\endgroup$
    – KAJ226
    Jun 22, 2021 at 3:05
  • $\begingroup$ Thank you, I found the seed what I need. But I wonder two things. $\endgroup$
    – 김동민
    Jun 23, 2021 at 0:18
  • $\begingroup$ 1. Should I need to set specific seed to get the result that I need? 2. What is seed exactly? $\endgroup$
    – 김동민
    Jun 23, 2021 at 3:53
  • $\begingroup$ 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 $\endgroup$
    – KAJ226
    Jun 23, 2021 at 4:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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