Skip to content

Commit a0f25fc

Browse files
OriRothClassiqNadav Ben Ami
authored andcommitted
Update qmods
1 parent 37ec88c commit a0f25fc

File tree

10 files changed

+83
-83
lines changed

10 files changed

+83
-83
lines changed

algorithms/differential_equations/discrete_poisson_solver/discrete_poisson_solver.qmod

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@ qfunc qsct_2d(xy_variable: qnum[2]) {
33
qct_type2(xy_variable[1]);
44
}
55

6-
qfunc powered_hamiltonian_evolution(hamiltonian: PauliTerm[], scaling: real, p: int, qba: qbit[]) {
7-
suzuki_trotter(hamiltonian, p * ((-6.28318530718) * scaling), 1, 1, qba);
8-
}
9-
106
qfunc inverse_amplitude_load(prefactor: real, phase: qnum, ind: qbit) {
117
ind *= prefactor / phase;
128
}
@@ -22,6 +18,10 @@ qfunc matrix_inversion_HHL(prefactor: real, my_unitary: qfunc (int, qbit[]), sta
2218
}
2319
}
2420

21+
qfunc powered_hamiltonian_evolution(hamiltonian: PauliTerm[], scaling: real, p: int, qba: qbit[]) {
22+
suzuki_trotter(hamiltonian, p * ((-6.28318530718) * scaling), 1, 1, qba);
23+
}
24+
2525
qfunc main(output x_variable: qnum<3, False, 0>, output y_variable: qnum<3, False, 0>, output phase: qnum, output indicator: qbit) {
2626
xy_variable: qnum<3, False, 0>[2];
2727
prepare_amplitudes([

algorithms/oblivious_amplitude_amplification/oblivious_amplitude_amplification.qmod

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
qfunc check_block(b: qnum, res: qbit) {
2+
res ^= b == 0;
3+
}
4+
5+
qfunc oblivious_amplitude_amplification(reps: int, block_encoding: qfunc (qnum, qbit[]), block: qnum, data: qbit[]) {
6+
block_encoding(data, block);
7+
repeat (index: reps) {
8+
grover_operator(lambda(b) {
9+
phase_oracle(lambda(x, res) {
10+
check_block(x, res);
11+
}, b);
12+
}, lambda(b) {
13+
block_encoding(data, b);
14+
}, block);
15+
}
16+
}
17+
118
qfunc apply_pauli_term(pauli_string: Pauli[], x: qbit[]) {
219
repeat (index: x.len) {
320
switch(pauli_string[index], [lambda() {
@@ -24,23 +41,6 @@ qfunc block_encode(pauli_list: Pauli[][], data: qbit[], block: qnum) {
2441
}
2542
}
2643

27-
qfunc check_block(b: qnum, res: qbit) {
28-
res ^= b == 0;
29-
}
30-
31-
qfunc oblivious_amplitude_amplification(reps: int, block_encoding: qfunc (qnum, qbit[]), block: qnum, data: qbit[]) {
32-
block_encoding(data, block);
33-
repeat (index: reps) {
34-
grover_operator(lambda(b) {
35-
phase_oracle(lambda(x, res) {
36-
check_block(x, res);
37-
}, b);
38-
}, lambda(b) {
39-
block_encoding(data, b);
40-
}, block);
41-
}
42-
}
43-
4444
qfunc main(output data: qnum, output block: qnum) {
4545
allocate(2, block);
4646
prepare_amplitudes([

algorithms/simon/simon_example.qmod

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
qfunc simon_qfunc_simple(s: int, x: qnum, output res: qnum) {
2-
res = min(x, x ^ s);
3-
}
4-
51
qfunc simon_qfunc(f_qfunc: qfunc (qnum, output qnum), x: qnum) {
62
res: qnum;
73
hadamard_transform(x);
84
f_qfunc(x, res);
95
hadamard_transform(x);
106
}
117

8+
qfunc simon_qfunc_simple(s: int, x: qnum, output res: qnum) {
9+
res = min(x, x ^ s);
10+
}
11+
1212
qfunc main(output x: qnum) {
1313
allocate(5, x);
1414
simon_qfunc(lambda(x, res) {

algorithms/simon/simon_shallow_example.qmod

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
qfunc simon_qfunc(f_qfunc: qfunc (qnum, output qnum), x: qnum) {
2+
res: qnum;
3+
hadamard_transform(x);
4+
f_qfunc(x, res);
5+
hadamard_transform(x);
6+
}
7+
18
qfunc simon_qfunc_with_bipartite_s(partition_index: int, x: qbit[], output res: qbit[]) {
29
allocate(x.len, res);
310
repeat (i: x.len - partition_index) {
@@ -9,13 +16,6 @@ qfunc simon_qfunc_with_bipartite_s(partition_index: int, x: qbit[], output res:
916
}
1017
}
1118

12-
qfunc simon_qfunc(f_qfunc: qfunc (qnum, output qnum), x: qnum) {
13-
res: qnum;
14-
hadamard_transform(x);
15-
f_qfunc(x, res);
16-
hadamard_transform(x);
17-
}
18-
1919
qfunc main(output x: qnum) {
2020
allocate(6, x);
2121
simon_qfunc(lambda(x, res) {

algorithms/vqls/lcu_vqls/vqls_with_lcu.qmod

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
qfunc block_encoding_vqls(ansatz: qfunc (), block_encoding: qfunc (), prepare_b_state: qfunc ()) {
2+
ansatz();
3+
block_encoding();
4+
invert {
5+
prepare_b_state();
6+
}
7+
}
8+
19
qfunc apply_ry_on_all(params: real[], io: qbit[]) {
210
repeat (index: io.len) {
311
RY(params[index], io[index]);
@@ -60,14 +68,6 @@ qfunc prepare_ca(pauli_terms_list: PauliTerm[], system_qubits: qbit[], ancillary
6068
}
6169
}
6270

63-
qfunc block_encoding_vqls(ansatz: qfunc (), block_encoding: qfunc (), prepare_b_state: qfunc ()) {
64-
ansatz();
65-
block_encoding();
66-
invert {
67-
prepare_b_state();
68-
}
69-
}
70-
7171
qfunc main(params: real[9], output ancillary_qubits: qnum, output system_qubits: qnum) {
7272
allocate(2, ancillary_qubits);
7373
allocate(3, system_qubits);

applications/cybersecurity/whitebox_fuzzing/whitebox_fuzzing.qmod

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ qfunc my_sp(x: qnum, y: qnum) {
33
hadamard_transform(y);
44
}
55

6-
qfunc my_predicate(x: qnum, y: qnum, res: qbit) {
7-
res ^= ((x + y) < 9) and (((x * y) % 4) == 1);
6+
qfunc my_grover_operator(oracle_operand: qfunc (), diffuser_operand: qfunc ()) {
7+
oracle_operand();
8+
diffuser_operand();
89
}
910

1011
qfunc prep_minus(output out: qbit) {
@@ -22,6 +23,10 @@ qfunc my_oracle(predicate: qfunc (qbit)) {
2223
}
2324
}
2425

26+
qfunc my_predicate(x: qnum, y: qnum, res: qbit) {
27+
res ^= ((x + y) < 9) and (((x * y) % 4) == 1);
28+
}
29+
2530
qfunc zero_predicate(x: qnum, y: qnum, res: qbit) {
2631
joined: qnum<x.size + y.size, False, 0>;
2732
{x, y} -> joined;
@@ -43,11 +48,6 @@ qfunc my_diffuser(sp_operand: qfunc (qnum, qnum), x: qnum, y: qnum) {
4348
}
4449
}
4550

46-
qfunc my_grover_operator(oracle_operand: qfunc (), diffuser_operand: qfunc ()) {
47-
oracle_operand();
48-
diffuser_operand();
49-
}
50-
5151
qfunc main(output x: qnum, output y: qnum) {
5252
allocate_num(6, False, 0, x);
5353
allocate_num(6, False, 0, y);

applications/finance/option_pricing/option_pricing.qmod

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@ qstruct OptionPricingState {
33
ind: qbit;
44
}
55

6+
qfunc iqae_algorithm(k: int, oracle_operand: qfunc (qbit[]), sp_operand: qfunc (qbit[]), x: qbit[]) {
7+
sp_operand(x);
8+
power (k) {
9+
grover_operator(oracle_operand, sp_operand, x);
10+
}
11+
}
12+
613
qfunc iqae_oracle(state: OptionPricingState) {
714
Z(state.ind);
815
}
@@ -59,13 +66,6 @@ qfunc european_call_state_preparation(state: OptionPricingState) {
5966
payoff(state.asset, state.ind);
6067
}
6168

62-
qfunc iqae_algorithm(k: int, oracle_operand: qfunc (qbit[]), sp_operand: qfunc (qbit[]), x: qbit[]) {
63-
sp_operand(x);
64-
power (k) {
65-
grover_operator(oracle_operand, sp_operand, x);
66-
}
67-
}
68-
6969
qfunc main(k: int, output ind: qbit) {
7070
state: OptionPricingState;
7171
asset: qbit[];

tutorials/advanced_tutorials/discrete_quantum_walk/quantum_walk_circle_balanced_coin.qmod

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,3 @@
1-
qfunc quantum_step_clockwise(x: qbit[]) {
2-
within {
3-
qft(x);
4-
} apply {
5-
repeat (i: x.len) {
6-
PHASE(((2 * pi) * (2 ** i)) / (2 ** x.len), x[i]);
7-
}
8-
}
9-
}
10-
111
qfunc discrete_quantum_walk(time: int, coin_flip_qfunc: qfunc (qnum), walks_qfuncs: qfunc[] (), coin_state: qnum) {
122
power (time) {
133
coin_flip_qfunc(coin_state);
@@ -19,6 +9,16 @@ qfunc discrete_quantum_walk(time: int, coin_flip_qfunc: qfunc (qnum), walks_qfun
199
}
2010
}
2111

12+
qfunc quantum_step_clockwise(x: qbit[]) {
13+
within {
14+
qft(x);
15+
} apply {
16+
repeat (i: x.len) {
17+
PHASE(((2 * pi) * (2 ** i)) / (2 ** x.len), x[i]);
18+
}
19+
}
20+
}
21+
2222
qfunc main(t: int, output x: qnum) {
2323
coin: qbit;
2424
allocate_num(floor(log(128, 2)), True, 0, x);

tutorials/advanced_tutorials/discrete_quantum_walk/quantum_walk_hypercube.qmod

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
qfunc moving_one_hamming_dist(pos: int, x: qbit[]) {
2-
X(x[pos]);
3-
}
4-
51
qfunc discrete_quantum_walk(time: int, coin_flip_qfunc: qfunc (qnum), walks_qfuncs: qfunc[] (), coin_state: qnum) {
62
power (time) {
73
coin_flip_qfunc(coin_state);
@@ -13,6 +9,10 @@ qfunc discrete_quantum_walk(time: int, coin_flip_qfunc: qfunc (qnum), walks_qfun
139
}
1410
}
1511

12+
qfunc moving_one_hamming_dist(pos: int, x: qbit[]) {
13+
X(x[pos]);
14+
}
15+
1616
qfunc main(t: int, output x: qbit[]) {
1717
allocate(4, x);
1818
coin: qbit[];

tutorials/popular_usage_examples/hamiltonian_simulation/hamiltonian_simulation_with_block_encoding/hamiltonian_simulation_qubitization.qmod

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
qfunc lcu_cheb(coef: real[], generalized_signs: int[], walk_operator: qfunc (qnum, qbit[]), walk_block: qnum, walk_data: qbit[], cheb_block: qnum) {
2+
within {
3+
inplace_prepare_state(coef, 0.0, cheb_block);
4+
} apply {
5+
repeat (k: generalized_signs.len) {
6+
control (cheb_block == k) {
7+
U(0, 0, 0, (pi / 2) * generalized_signs[k], walk_data[0]);
8+
power (k) {
9+
walk_operator(walk_block, walk_data);
10+
}
11+
}
12+
}
13+
}
14+
}
15+
116
qfunc apply_pauli_term(pauli_string: PauliTerm, x: qbit[]) {
217
repeat (index: x.len) {
318
switch(pauli_string.pauli[index], [lambda() {
@@ -52,21 +67,6 @@ qfunc my_walk_operator(block: qbit[], data: qbit[]) {
5267
RY(2 * pi, block[0]);
5368
}
5469

55-
qfunc lcu_cheb(coef: real[], generalized_signs: int[], walk_operator: qfunc (qnum, qbit[]), walk_block: qnum, walk_data: qbit[], cheb_block: qnum) {
56-
within {
57-
inplace_prepare_state(coef, 0.0, cheb_block);
58-
} apply {
59-
repeat (k: generalized_signs.len) {
60-
control (cheb_block == k) {
61-
U(0, 0, 0, (pi / 2) * generalized_signs[k], walk_data[0]);
62-
power (k) {
63-
walk_operator(walk_block, walk_data);
64-
}
65-
}
66-
}
67-
}
68-
}
69-
7070
qfunc main(output ham_block: qnum, output data: qnum, output exp_block: qnum) {
7171
allocate(4, exp_block);
7272
allocate(2, ham_block);

0 commit comments

Comments
 (0)