-
Notifications
You must be signed in to change notification settings - Fork 283
Description
The ResourceCounter backend in ProjectQ appears to calculate the circuit width based on the maximum number of simultaneously active qubits. However, it seems to reuse the indices of qubits that have been deallocated. This behavior can lead to an underestimation of the total number of unique qubits required to run an entire algorithm, even if they are not all active at the same time.
Consider the following sub-circuit, which allocates and then deallocates an ancilla qubit:
def op1_circuit(eng, control1, control2, target):
ancilla = eng.allocate_qureg(1)
H | target
CNOT | (control2, ancilla[0])
CNOT | (target, control1)
CNOT | (control2, ancilla[0])
H | target
S | target
eng.deallocate_qubit(ancilla[0])
return
If we call this sub-circuit sequentially, my expectation is that each call should use a logically distinct ancilla qubit, thus increasing the total number of required qubit indices.
When I run the following code:
‘’‘
circuit_backend = _resource.ResourceCounter()
eng = MainEngine(backend=circuit_backend)
State = eng.allocate_qureg(6)
op1_circuit(eng, State[0], State[1], State[2])
op1_circuit(eng, State[3], State[4], State[5])
eng.flush()
’‘’
Return: the reported max_width is 7.
The result of 7 indicates that the backend is reusing the qubit index for the ancilla. However, the total depth will keep the same with only one subcircuit 'op1_circuit(eng, State[0], State[1], State[2])'. Therefore, it might not count the ancilla in reusing the qubit but omit the deallocate qubit.
So, my question is, is this the correct and intended way to use dynamic allocation and deallocation in ProjectQ?
My goal is to estimate the total number of unique physical qubits required to run the entire algorithm from start to finish.