View source on GitHub |
Uses qm: QubitManager
to map all CleanQubit
/BorrowableQubit
s to system qubits.
cirq.map_clean_and_borrowable_qubits(
circuit: 'cirq.AbstractCircuit',
*,
qm: Optional['cirq.QubitManager'] = None
) -> 'cirq.Circuit'
CleanQubit
and BorrowableQubit
are internal qubit types that are used as placeholder qubits
to record a clean / dirty ancilla allocation request.
This transformer uses the QubitManager
provided in the input to:
- Allocate clean ancilla qubits by delegating to
qm.qalloc
for allCleanQubit
s. - Allocate dirty qubits for all
BorrowableQubit
types via the following two steps:- First analyse the input circuit and check if there are any suitable system qubits
that can be borrowed, i.e. ones which do not have any overlapping operations
between circuit[start_index : end_index] where
(start_index, end_index)
is the lifespan of temporary borrowable qubit under consideration. If yes, borrow the system qubits to replace the temporaryBorrowableQubit
. - If no system qubits can be borrowed, delegate the request to
qm.qborrow
.
- First analyse the input circuit and check if there are any suitable system qubits
that can be borrowed, i.e. ones which do not have any overlapping operations
between circuit[start_index : end_index] where
Notes | |
---|---|
|
allocated clean ancilla qubits in step-1 before delegating to qm.borrow
, but this
optimization is left as a future improvement.
2. As of now, the transformer does not preserve moment structure and defaults to
inserting all mapped operations in a resulting circuit using EARLIEST strategy. The reason
is that preserving moment structure forces additional constraints on the qubit allocation
strategy (i.e. if two operations op1
and op2
are in the same moment, then we cannot
reuse ancilla across op1
and op2
). We leave it up to the user to force such constraints
using the qubit manager instead of making it part of the transformer.
3. However, for borrowable system qubits managed by the transformer, we do not reuse qubits
within the same moment.
4. Since this is not implemented using the cirq transformers infrastructure, we currently
do not support recursive mapping within sub-circuits and that is left as a future
Args | |
---|---|
circuit
|
Input cirq.Circuit containing temporarily allocated
CleanQubit /BorrowableQubit s.
|
qm
|
An instance of cirq.QubitManager specifying the strategy to use for allocating /
/ deallocating new ancilla qubits to replace the temporary qubits.
|
Returns | |
---|---|
An updated cirq.Circuit with all CleanQubit /BorrowableQubit mapped to either existing
system qubits or new ancilla qubits allocated using the qm qubit manager.
|