Skip to content

Commit 555d1b6

Browse files
committed
lcu qmod comments
1 parent 9743e43 commit 555d1b6

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

tutorials/basic_tutorials/quantum_primitives/linear_combination_of_unitaries/linear_combination_of_unitaries.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@
336336
" )\n",
337337
"\n",
338338
"\n",
339-
"qmod_2 = create_model(main, out_file=\"linear_combination_of_unitaries\")\n",
339+
"qmod_2 = create_model(main)\n",
340340
"qprog_2 = synthesize(qmod_2)\n",
341341
"\n",
342342
"show(qprog_2)"

tutorials/basic_tutorials/quantum_primitives/linear_combination_of_unitaries/linear_combination_of_unitaries.qmod

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,34 @@
1+
// Linear Combination of Unitaries (LCU)
2+
3+
// The Linear Combination of Unitaries (LCU) technique implements a block encoding
4+
// proportional to a weighted sum of unitaries,
5+
//
6+
// A = Σ_j α_j U_j ,
7+
//
8+
// by coherently selecting between the unitaries U_j using an ancilla variable.
9+
// The ancilla is prepared in a superposition whose amplitudes encode the
10+
// coefficients α_j, and a controlled SELECT operation applies U_j conditioned
11+
// on the ancilla state.
12+
// By uncomputing the ancilla and post-selecting the zero state |0…0⟩, the action of the
13+
// circuit on the data variable becomes proportional to the desired linear
14+
// combination. LCU is a central primitive in quantum algorithms for Hamiltonian
15+
// simulation, quantum signal processing, and quantum linear algebra.
16+
17+
// In this concrete example, the controller encodes three unitaries acting on
18+
// the state psi: the identity, the quantum Fourier transform (QFT), and the
19+
// inverse QFT. The resulting transformation is proportional to
20+
// 0.5 · I + 0.25 · QFT + 0.25 · QFT⁻¹ ,
21+
22+
lcu_amplitudes: real[] = [ 0.5, 0.25, 0.25, 0.0 ];
23+
124
qfunc prepare(controller: qnum) {
2-
inplace_prepare_state([0.5, 0.25, 0.25, 0], 0.01, controller);
25+
inplace_prepare_state(lcu_amplitudes, 0, controller);
326
}
427

528
qfunc select(controller: qnum, psi: qnum) {
29+
// Coherently apply U_j conditioned on the controller value j.
630
control (controller == 0) {
7-
apply_to_all(IDENTITY, psi);
31+
IDENTITY(psi);
832
}
933
control (controller == 1) {
1034
qft(psi);
@@ -14,11 +38,13 @@ qfunc select(controller: qnum, psi: qnum) {
1438
qft(psi);
1539
}
1640
}
41+
// The controller = 3 branch has zero weight and is omitted.
1742
}
1843

1944
qfunc main(output controller: qnum, output psi: qnum) {
2045
allocate(2, psi);
2146
allocate(2, controller);
47+
2248
within {
2349
prepare(controller);
2450
} apply {

0 commit comments

Comments
 (0)