Skip to content

Commit a2fb4a1

Browse files
ronClassiqnati-erez
authored andcommitted
Add notebook
1 parent e973c1c commit a2fb4a1

File tree

5 files changed

+1191
-0
lines changed

5 files changed

+1191
-0
lines changed

applications/cfd/heat_eq_qsvt/heat_eq_qsvt.ipynb

Lines changed: 1029 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"friendly_name": "Heat Equation QSVT Solver",
3+
"description": "QSVT Algorithm for Solving The 1D Heat Equation",
4+
"problem_domain_tags": ["linear equation"],
5+
"qmod_type": ["application"],
6+
"level": ["advanced"]
7+
}
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
qfunc my_projector_controlled_phase(phase: real, block: qnum, aux: qbit) {
2+
control (block == 0) {
3+
X(aux);
4+
}
5+
RZ(phase, aux);
6+
control (block == 0) {
7+
X(aux);
8+
}
9+
}
10+
11+
qfunc my_qsvt_step(phase1: real, phase2: real, u: qfunc (qbit[], qbit[]), data: qbit[], block: qbit[], qsvt_aux: qbit) {
12+
u(data, block);
13+
my_projector_controlled_phase(phase1, block, qsvt_aux);
14+
invert {
15+
u(data, block);
16+
}
17+
my_projector_controlled_phase(phase2, block, qsvt_aux);
18+
}
19+
20+
qfunc multiplex(qfuncs: qfunc[] (), select: qnum) {
21+
repeat (i: qfuncs.len) {
22+
control (select == i) {
23+
qfuncs[i]();
24+
}
25+
}
26+
}
27+
28+
qfunc my_be(data: qnum<3, UNSIGNED, 0>, block: qbit[4]) {
29+
rotating_qubit: qbit;
30+
del_qubit: qbit;
31+
select: qbit[2.0];
32+
packed: qnum<data.size + del_qubit.size, UNSIGNED, 0>;
33+
within {
34+
block -> {select, rotating_qubit, del_qubit};
35+
{data, del_qubit} -> packed;
36+
inplace_prepare_state([
37+
0.333333333333333,
38+
0.333333333333333,
39+
0.333333333333333,
40+
0
41+
], 0, select);
42+
} apply {
43+
multiplex([lambda() {
44+
RY(3.252761000151628, rotating_qubit);
45+
}, lambda() {
46+
RY(0.0, rotating_qubit);
47+
}, lambda() {
48+
RY(3.252761000151628, rotating_qubit);
49+
}], select);
50+
multiplex([lambda() {
51+
packed += 0;
52+
}, lambda() {
53+
packed += 1;
54+
}, lambda() {
55+
packed += 2;
56+
}], select);
57+
packed += -1;
58+
}
59+
}
60+
61+
qfunc qsvt_inversion_my(qsvt_phases: real[4], block: qnum, data: qnum, qsvt_aux: qbit) {
62+
H(qsvt_aux);
63+
my_projector_controlled_phase(qsvt_phases[0], block, qsvt_aux);
64+
repeat (i: floor((qsvt_phases.len - 1) / 2)) {
65+
my_qsvt_step(qsvt_phases[(2 * i) + 1], qsvt_phases[(2 * i) + 2], lambda(d, b) {
66+
my_be(d, b);
67+
}, data, block, qsvt_aux);
68+
}
69+
H(qsvt_aux);
70+
}
71+
72+
qfunc main(output block: qnum, output data: qnum, output qsvt_aux: qbit) {
73+
allocate(1, qsvt_aux);
74+
allocate(4.0, block);
75+
prepare_amplitudes([
76+
(-0.240746626240615),
77+
(-0.336737859255334),
78+
(-0.330108402561768),
79+
(-0.347888362107992),
80+
(-0.559992716867353),
81+
(-0.482868801572984),
82+
(-0.218588012434707),
83+
(-0.064155783127223)
84+
], 0, data);
85+
qsvt_inversion_my([
86+
(-1.738078501179466),
87+
0.654311402219199,
88+
0.654311402219198,
89+
(-0.16728217438457)
90+
], block, data, qsvt_aux);
91+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
{
2+
"constraints": {
3+
"max_gate_count": {},
4+
"optimization_parameter": "no_opt"
5+
},
6+
"preferences": {
7+
"custom_hardware_settings": {
8+
"basis_gates": [
9+
"u",
10+
"y",
11+
"cz",
12+
"sxdg",
13+
"s",
14+
"sx",
15+
"u2",
16+
"tdg",
17+
"rx",
18+
"ry",
19+
"z",
20+
"x",
21+
"p",
22+
"cx",
23+
"r",
24+
"cy",
25+
"t",
26+
"rz",
27+
"h",
28+
"u1",
29+
"id",
30+
"sdg"
31+
],
32+
"is_symmetric_connectivity": true
33+
},
34+
"debug_mode": true,
35+
"machine_precision": 8,
36+
"optimization_level": 1,
37+
"output_format": ["qasm"],
38+
"pretty_qasm": true,
39+
"random_seed": 2564086545,
40+
"synthesize_all_separately": false,
41+
"timeout_seconds": 300,
42+
"transpilation_option": "auto optimize"
43+
}
44+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from tests.utils_for_testbook import (
2+
validate_quantum_program_size,
3+
validate_quantum_model,
4+
wrap_testbook,
5+
)
6+
from testbook.client import TestbookNotebookClient
7+
8+
9+
@wrap_testbook("heat_eq_qsvt", timeout_seconds=600 * 7)
10+
def test_notebook(tb: TestbookNotebookClient) -> None:
11+
# test quantum programs
12+
validate_quantum_program_size(
13+
tb.ref_pydantic("qprog"),
14+
expected_width=None,
15+
expected_depth=None,
16+
expected_cx_count=None,
17+
)
18+
19+
# test notebook content
20+
pass # Todo

0 commit comments

Comments
 (0)