guppyalgos.primitives.subroutines.ladders¶
Reusable patterns for quantum algorithms.
These are not necessarily algorithmic primitives, but rather patterns that appear in multiple primitives.
Functions
|
Apply the CCX V chain in linear depth with 2n - 1 Toffoli gates. |
Build the CCX V chain in O(n) gates and O(log n) depth, ancilla free. |
|
|
Build a ladder of k C^nX gates in logarithmic depth. |
Count the clean ancillae the log depth cnx ladder needs. |
|
|
Count the clean ancillae the log depth Toffoli ladder needs. |
Classes
Linear depth CX Ladder. |
|
Log depth CX Ladder from https://arxiv.org/abs/2501.16802. |
|
|
Protocol for ladders of gates. |
Linear-depth Toffoli ladder. |
|
Log depth Toffoli ladder from https://arxiv.org/abs/2510.00840 (Algorithm 1). |
- class guppyalgos.primitives.subroutines.ladders.CXLadderLinear¶
Linear depth CX Ladder.
Protocols: Ladder
- class guppyalgos.primitives.subroutines.ladders.CXLadderLog¶
Log depth CX Ladder from https://arxiv.org/abs/2501.16802.
Log-depth increases the gate count.
Protocols: Ladder
- class guppyalgos.primitives.subroutines.ladders.Ladder¶
Protocol for ladders of gates.
The ladder has an orientation, with gates oriented in a consistent way. Here ‘ascending’ means that the ladder has gates oriented on increasing indices, e.g. a linear cx ladder:
- for i in range(n-1):
cx(qs[i], qs[i+1])
descending instead has the ladder oriented the other way.
- class guppyalgos.primitives.subroutines.ladders.ToffoliLadderLinear¶
Linear-depth Toffoli ladder.
Protocols: Ladder
- class guppyalgos.primitives.subroutines.ladders.ToffoliLadderLog¶
Log depth Toffoli ladder from https://arxiv.org/abs/2510.00840 (Algorithm 1).
Log depth increases the gate count.
Protocols: Ladder
- ascending_dagger_with_cca(qs, anc)¶
Apply ascending log depth Toffoli ladder dagger on the given ancillae.
- Return type:
- ascending_with_cca(qs, anc)¶
Apply ascending log depth Toffoli ladder on the given ancillae.
- Return type:
- descending_dagger_with_cca(qs, anc)¶
Apply descending log depth Toffoli ladder dagger on the given ancillae.
- Return type:
- descending_with_cca(qs, anc)¶
Apply descending log depth Toffoli ladder on the given ancillae.
- Return type:
- guppyalgos.primitives.subroutines.ladders.ccx_v_chain(controls_a, controls_b, target)¶
Apply the CCX V chain in linear depth with 2n - 1 Toffoli gates.
- Parameters:
controls_a (array[qubit, n]) – Chain register, restored at the end.
controls_b (array[qubit, n]) – Second control of each Toffoli.
target (qubit) – Qubit flipped by the middle Toffoli.
- guppyalgos.primitives.subroutines.ladders.ccx_v_chain_logdepth(n)¶
Build the CCX V chain in O(n) gates and O(log n) depth, ancilla free.
- Parameters:
n (
int) – Number of (controls_a, controls_b) pairs.- Return type:
- Returns:
A Guppy function implementing the CCX V chain.
- Ref:
Vivien Vandaele, “Asymptotically Optimal Quantum Circuits for Comparators and Incrementers”, https://arxiv.org/abs/2603.12917
- guppyalgos.primitives.subroutines.ladders.cnx_ladder_logdepth(k, n, inverse=False)¶
Build a ladder of k C^nX gates in logarithmic depth.
- Parameters:
- Return type:
- Returns:
A Guppy function implementing the C^nX ladder in logarithmic depth.
- guppyalgos.primitives.subroutines.ladders.cnx_ladder_logdepth_num_ancilla(k)¶
Count the clean ancillae the log depth cnx ladder needs.