Suppose one of my functions create some ancillary qubits and reset them. Then, another function wants to create a larger number of ancillary qubits. So, I'd like to reuse the first set of qubits and add the difference two them. Is there any efficient way to achieve the goal?
def function1(qc): r = 3 ancillas = QuantumRegister(r, 'ancillas') qc.add(sum_q) # use the ancillas return ancillas def function2(qc, partial_ancillas): r = 5 diff = r - len(partial_ancillas) if diff > 0: # something like ancillas = partial_ancillas.add(diff) # or maybe ancillas = partial_ancillas + QuantumRegister(diff) else: ancillas = partial_ancillas return ancillas qc = QuantumCircuit() anc = function1(qc) anc = function2(qc, anc)