qp.select_thc_wires¶
- select_thc_wires(M, N, beth, num_batches=1)[source]¶
Return the wire counts required by
SelectTHC.- Parameters:
M (int) – the THC rank.
N (int) – the number of spin orbitals.
beth (int) – bits of precision per Givens angle. The realised grid is the odd multiples of \(\pi / 2^{\mathrm{beth}}\), so the spacing is \(2\pi / 2^{\mathrm{beth}}\).
num_batches (int) – the number of batches the Givens angles are loaded in. The default of
1loads all of them at once. See the note below.
- Returns:
{"system_wires": n_system, "index_wires": n_index, "flag_wires": n_flag, "gradient_wires": n_gradient, "work_wires": n_work}.system_wires(N): the spin orbitals, theN/2spin-down spatial orbitals followed by theN/2spin-up ones.index_wires(2 * ceil(log2(M + 1))): \(\mu\) followed by \(\nu\), as produced byPREPARE. The+ 1inside the logarithm leaves room for the one-body sentinel value \(\nu = M\).flag_wires(5): the success flag, the one-body sentinel flag (\(\nu = M\)), the qubit that controls the \(\mu \leftrightarrow \nu\) swap, and the two spin flags.gradient_wires(beth + 1): the phase gradient register. See the note below.work_wires(ceil((N/2 - 1) / num_batches) * beth + max(ceil(log2(M + 1)), beth)): the minimum clean scratch, returned to \(\lvert 0 \rangle\). Zero whenN/2 == 1, where the sandwich is a lone \(Z_1\) and no angles are loaded.
- Return type:
dict
- Raises:
ValueError – if
M,N,bethornum_batchesis not a positive integer, ifNis odd, or if the one-body block does not fit the index register.
Note
Only
work_wiresis a minimum; the other four are exact and must be matched. Extra work wires are forwarded to the internalQROM, which splits them between the unary iteration of itsSelectand theSelectSwapspace-time trade-off. Which split it picks depends onM,Nandbeth, so extra wires do not necessarily lower the gate count.Note
gradient_wiresmust be prepared by the caller in the phase gradient state\[\lvert \phi \rangle = \frac{1}{\sqrt{2^{\mathrm{beth}+1}}} \sum_{k=0}^{2^{\mathrm{beth}+1} - 1} e^{-2 \pi i k / 2^{\mathrm{beth}+1}} \lvert k \rangle ,\]which can be done with
PhaseGradientStatePrep. TheSELECToracle leaves it unchanged, so it is deliberately not allocated internally: one register is prepared once and shared byPREPAREandSELECT.Example
>>> import pennylane as qp >>> qp.select_thc_wires(M=3, N=4, beth=4) {'system_wires': 4, 'index_wires': 4, 'flag_wires': 5, 'gradient_wires': 5, 'work_wires': 8}