qrisp.view_LCU#
- view_LCU(operand_prep, state_prep, unitaries, num_unitaries=None)[source]#
Generate and return the quantum circuit for the LCU algorithm without utilizing the Repeat-Until-Success (RUS) protocol.
This function constructs the LCU primitive and returns the corresponding quantum circuit representation. It’s useful for visualization and analysis of the underlying quantum circuit implementing the LCU algorithm.
- Parameters:
- operand_prepcallable
A function preparing the input state \(\ket{\psi}\). This function must return a QuantumVariable (the
operand
).- state_prepcallable
A function preparing the coefficient state from the \(\ket{0}\) state. This function receives a QuantumFloat with \(\lceil\log_2m\rceil\) qubits for \(m\) unitiaries \(U_0,\dotsc,U_{m-1}\) as argument and applies
\[\text{PREPARE}\ket{0} = \sum_i\sqrt{\frac{\alpha_i}{\lambda}}\ket{i}\]- unitarieslist[callable] or callable
- Either:
A list of functions performing some in-place operation on
operand
, orA function
unitaries(i, operand)
performing some in-place operation onoperand
depending on a nonnegative integer indexi
specifying the case.
- num_unitariesint, optional
Required when
unitaries
is a callable to specify the number \(m\) of unitaries.
- Returns:
- QuantumCircuit
Quantum circuit object showing the LCU implementation details.
Examples
from qrisp import * def U0(operand): y(operand) def U1(operand): x(operand) unitaries = [U0, U1] def state_prep(case): h(case) def operand_prep(): operand = QuantumVariable(1) y(operand) return operand qc = view_LCU(operand_prep, state_prep, unitaries)
>>> print(qc) ┌───┐ ┌───┐ » qb_287: ┤ Y ├─────────────────────┤ Y ├────────────────────────» ├───┤┌───────────────────┐└─┬─┘┌──────────────────────┐» qb_288: ┤ H ├┤0 ├──┼──┤0 ├» └───┘│ jasp_balauca_mcx │ │ │ jasp_balauca_mcx_dg │» qb_289: ─────┤1 ├──■──┤1 ├» └───────────────────┘ └──────────────────────┘» « ┌───┐ «qb_287: ─────────────────────┤ X ├───────────────────────────── « ┌───────────────────┐└─┬─┘┌──────────────────────┐┌───┐ «qb_288: ┤0 ├──┼──┤0 ├┤ H ├ « │ jasp_balauca_mcx │ │ │ jasp_balauca_mcx_dg │└───┘ «qb_289: ┤1 ├──■──┤1 ├───── « └───────────────────┘ └──────────────────────┘
We can see that the operand and case variables are prepared, the unitaries for the two cases (i.e., X and Y) are executed, and the inverse preparation (H gate) of the case variable is applied. The inner workings of the circuit can be further analyzed by calling
qc.transpile(level: int)
.