Suppose I want to implement run several circuits one after another, but they are constructed in a similar fashion. I could reinstantiate a QuantumCircuit
for each iteration, like this:
params = np.linspace(0, 2 * np.pi, num=20)
for p in params:
circ = QuantumCircuit(q, c)
do_stuff(circ, p)
do_other_stuff()
but I'm afraid that creating a bunch of unnecessary circ
objects takes too much memory or too many calls to the garbage collector.
Instead, I would like to remove the gates from the QuantumCircuit
object and build the new circuit in the old object. Is it possible, and if so, is it reasonable?