• Members 4 posts

I have a parametrized QAOA circuit, for every iteration, I am plugging in numbers to the variables and it needs to go through the same compilation process. How could I compile parametrized circuit only for the first time and avoid re-compilation in the following iterations?

• Members 22 posts

You will need to transpile the parametrized circuit to the backend before you bind the parameters.

from qiskit import *
from qiskit.circuit import  QuantumCircuit, Parameter

# create parametrized circuit
theta = Parameter('θ')
qc = QuantumCircuit(5)
qc.rz(theta, range(5))
qc.draw()
#%%. set up your backend and transpile the parametrized circuit to the backend
simulator = Aer.get_backend('aer_simulator')
transpiled_qc = transpile(qc, backend=simulator)
# start your iteration and run without transpilation.
for i in range(10):
real_qc = transpiled_qc.bind_parameters({theta: i})
job = simulator.run(real_qc, shots=8192)
result = job.result()