LineManager#
qualtran.drawing.LineManager
View source on GitHub
|
Methods to manage allocation and de-allocation of lines representing a register of qubits.
qualtran.drawing.LineManager(
max_n_lines: int = 100
)
Methods#
new_y
new_y(
binst: qualtran.BloqInstance,
reg: qualtran.Register,
idx=None
)
Allocate a new y position (i.e. a new qubit or register).
reserve_n
reserve_n(
n: int, until
)
Reserve n lines until further notice.
To have fine-grained control over the vertical layout of HLines, consider
overriding maybe_reserve which can call this method to reserve lines
depending on the musical score context.
unreserve
unreserve(
binst: qualtran.BloqInstance,
reg: qualtran.Register
)
Go through our reservations and rescind them depending on the until predicate.
maybe_reserve
maybe_reserve(
binst: Union[qualtran.DanglingT, qualtran.BloqInstance],
reg: qualtran.Register,
idx: Tuple[int, ...]
)
Override this method to provide custom control over line allocation.
After a new y position is allocated and after a y position is freed, this method
is called with the current binst, reg, idx. You can inspect these elements to
determine whether you want to continue allocating lines first-come-first-serve by
returning without doing anything;
or you can call self.reserve_n(n, until) to keep the next n lines unavailable
until the until callback predicate evaluates to True.
Whenever a new register is encountered, we first go through existing reservations
and call the until predicate on binst, reg.
new
new(
binst: qualtran.BloqInstance,
reg: qualtran.Register,
seq_x: int,
topo_gen: int
) -> Union[RegPosition, NDArray[RegPosition]]
Allocate a position or positions for reg.
binst and reg can optionally modify the allocation strategy.
seq_x and topo_gen are passed through.
finish_hline
finish_hline(
y: int, seq_x_end: int
)
Update self.hlines once we know where an HLine ends.
free
free(
binst: Union[qualtran.DanglingT, qualtran.BloqInstance],
reg: qualtran.Register,
arr: Union[RegPosition, NDArray[RegPosition]]
)
De-allocate a position or positions for reg.
This will free the position for future allocation. This will find the in-progress
HLine associate with reg and update it to indicate the end point.
View source on GitHub