Skip to content

Commit d2d6fdb

Browse files
orsa-classiqDi Fang
andcommitted
Added the time-marching differential equations solver example
Co-authored-by: Di Fang <[email protected]>
1 parent 68deba4 commit d2d6fdb

File tree

6 files changed

+1227
-0
lines changed

6 files changed

+1227
-0
lines changed

algorithms/differential_equations/time_marching/time_marching.ipynb

Lines changed: 1066 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": "Time Marching Based Quantum Solver",
3+
"description": "Solving time-dependent linear equations using a Time-Marching based strategy and QSVT",
4+
"problem_domain_tags": ["linear equation"],
5+
"qmod_type": ["algorithms"],
6+
"level": ["advanced"]
7+
}
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
qstruct TimeDependentBE {
2+
index: qnum<2>;
3+
time: qnum<2>;
4+
block: qbit;
5+
}
6+
7+
qstruct MagnusBE {
8+
time_dependent: TimeDependentBE;
9+
qsvt_exp_aux: qbit;
10+
qsvt_exp_lcu: qbit;
11+
}
12+
13+
qstruct LongSliceBE {
14+
magnus: MagnusBE;
15+
qsvt_amplification_aux: qbit;
16+
}
17+
18+
qstruct FullBE {
19+
time_slice: LongSliceBE;
20+
counter: qnum<3.0>;
21+
}
22+
23+
qfunc magnus_projector(qbe: MagnusBE, is_in_block: qbit) {
24+
is_in_block ^= ((qbe.time_dependent.block == 0) and (qbe.time_dependent.time == 0)) and ((qbe.qsvt_exp_aux == 0) and (qbe.qsvt_exp_lcu == 0));
25+
}
26+
27+
qfunc time_dependent_projector(qbe: TimeDependentBE, is_in_block: qbit) {
28+
is_in_block ^= (qbe.block == 0) and (qbe.time == 0);
29+
}
30+
31+
qfunc block_encode_time_dependent_A(a: real, b: real, qbe: TimeDependentBE) {
32+
linear_pauli_rotations([Pauli::Y], [
33+
(((b - a) * 2) / (2 ** qbe.time.size))
34+
], [(2 * a)], qbe.time, qbe.block);
35+
linear_pauli_rotations([Pauli::Y], [2], [0], qbe.index, qbe.block);
36+
}
37+
38+
qfunc short_time_summation(a: real, b: real, qbe: TimeDependentBE) {
39+
within {
40+
hadamard_transform(qbe.time);
41+
} apply {
42+
block_encode_time_dependent_A(a, b, qbe);
43+
}
44+
}
45+
46+
qfunc short_time_magnus(a: real, b: real, qbe_st: MagnusBE) {
47+
within {
48+
H(qbe_st.qsvt_exp_lcu);
49+
} apply {
50+
qsvt_lcu([
51+
4.7085,
52+
3.0195,
53+
0.0547,
54+
4.7904,
55+
0.0547,
56+
3.0195,
57+
(-17.2827)
58+
], [
59+
4.5651,
60+
0.2495,
61+
6.6887,
62+
(-0.1862),
63+
6.097,
64+
0.4056,
65+
0.2495,
66+
(-20.5676)
67+
], time_dependent_projector, time_dependent_projector, lambda(x) {
68+
short_time_summation(a, b, x);
69+
}, qbe_st.time_dependent, qbe_st.qsvt_exp_aux, qbe_st.qsvt_exp_lcu);
70+
}
71+
}
72+
73+
qfunc long_slice_evolution(a: real, b: real, qbe: LongSliceBE) {
74+
qsvt([
75+
4.1801,
76+
2.3715,
77+
4.6112,
78+
4.5273,
79+
(-1.7559),
80+
4.6112,
81+
8.6546,
82+
(-20.9526)
83+
], magnus_projector, magnus_projector, lambda(x) {
84+
short_time_magnus(a, b, x);
85+
}, qbe.magnus, qbe.qsvt_amplification_aux);
86+
}
87+
88+
qfunc long_time_integrator_step(a: real, b: real, qbe_full: FullBE) {
89+
long_slice_evolution(a, b, qbe_full.time_slice);
90+
control ((((qbe_full.time_slice.magnus.time_dependent.block == 0) and (qbe_full.time_slice.magnus.time_dependent.time == 0)) and ((qbe_full.time_slice.magnus.qsvt_exp_aux == 0) and (qbe_full.time_slice.magnus.qsvt_exp_lcu == 0))) and (qbe_full.time_slice.qsvt_amplification_aux == 0)) {
91+
qbe_full.counter += -1;
92+
}
93+
}
94+
95+
qfunc long_time_integrator(T: real, num_slices: int, qbe_full: FullBE) {
96+
inplace_prepare_int(num_slices, qbe_full.counter);
97+
repeat (i: num_slices) {
98+
long_time_integrator_step((i * T) / num_slices, ((i + 1) * T) / num_slices, qbe_full);
99+
}
100+
}
101+
102+
qfunc main(output qbe: FullBE) {
103+
allocate(qbe.size, qbe);
104+
hadamard_transform(qbe.time_slice.magnus.time_dependent.index);
105+
long_time_integrator(2, 4, qbe);
106+
}
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+
"machine_precision": 8,
8+
"custom_hardware_settings": {
9+
"basis_gates": [
10+
"cx",
11+
"u2",
12+
"y",
13+
"ry",
14+
"t",
15+
"rx",
16+
"cy",
17+
"r",
18+
"sxdg",
19+
"cz",
20+
"tdg",
21+
"x",
22+
"sdg",
23+
"u1",
24+
"u",
25+
"h",
26+
"sx",
27+
"z",
28+
"p",
29+
"id",
30+
"s",
31+
"rz"
32+
],
33+
"is_symmetric_connectivity": true
34+
},
35+
"debug_mode": true,
36+
"synthesize_all_separately": false,
37+
"optimization_level": 0,
38+
"output_format": ["qasm"],
39+
"pretty_qasm": true,
40+
"transpilation_option": "auto optimize",
41+
"timeout_seconds": 300,
42+
"random_seed": 590453799
43+
}
44+
}

requirements_tests.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@ testbook
55
torch
66
torchvision
77
galois
8+
cvxpy
9+
pyqsp==0.1.6

tests/resources/timeouts.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ algorithms/deutsch_jozsa/simple_deutsch_jozsa.qmod: 16
2525
algorithms/differential_equations/discrete_poisson_solver/discrete_poisson_solver.ipynb: 300
2626
algorithms/differential_equations/discrete_poisson_solver/discrete_poisson_solver.qmod: 300
2727
algorithms/differential_equations/hhl_jungle/hhl_jungle.ipynb: 450
28+
algorithms/differential_equations/time_marching/time_marching.ipynb: 500
29+
algorithms/differential_equations/time_marching/time_marching.qmod: 500
2830
algorithms/grover/3_sat_grover/3_sat_grover.ipynb: 36
2931
algorithms/grover/3_sat_grover/3_sat_grover.qmod: 48
3032
algorithms/grover/3_sat_grover/3_sat_grover_large.qmod: 10

0 commit comments

Comments
 (0)