• Members 4 posts
    Nov. 1, 2021, 11:40 p.m.

    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
    Nov. 1, 2021, 11:56 p.m.

    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))
    #%%. 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()