View source on GitHub |
Greedy allocator that maximizes/minimizes qubit reuse based on a configurable parameter.
Inherits From: QubitManager
cirq.GreedyQubitManager(
prefix: str, *, size: int = 0, maximize_reuse: bool = False
)
GreedyQubitManager can be configured, using maximize_reuse
flag, to work in one of two modes:
- Minimize qubit reuse (maximize_reuse=False): For a fixed width, this mode uses a FIFO (First in First out) strategy s.t. next allocated qubit is one which was freed the earliest.
- Maximize qubit reuse (maximize_reuse=True): For a fixed width, this mode uses a LIFO (Last in First out) strategy s.t. the next allocated qubit is one which was freed the latest.
If the requested qubits are more than the set of free qubits, the qubit manager automatically resizes the size of the managed qubit pool and adds new free qubits, that have their last freed time to be -infinity.
For borrowing qubits, the qubit manager simply delegates borrow requests to self.qalloc
, thus
always allocating new clean qubits.
Methods
qalloc
qalloc(
n: int, dim: int = 2
) -> List['cirq.Qid']
Allocate n
clean qubits, i.e. qubits guaranteed to be in state |0>.
qborrow
qborrow(
n: int, dim: int = 2
) -> List['cirq.Qid']
Allocate n
dirty qubits, i.e. the returned qubits can be in any state.
qfree
qfree(
qubits: Iterable['cirq.Qid']
) -> None
Free pre-allocated clean or dirty qubits managed by this qubit manager.
resize
resize(
new_size: int, dim: int = 2
) -> None