Skip to content

Commit

Permalink
integration of reviewer modification
Browse files Browse the repository at this point in the history
  • Loading branch information
giacomoRanieri authored and orsa-classiq committed Jun 19, 2024
1 parent f73e035 commit 5a44717
Show file tree
Hide file tree
Showing 8 changed files with 608 additions and 122 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"friendly_name": "Rainbow Options Direct Method",
"description": "Rainbow Options payoff using Direct Method in QAE",
"problem_domain_tags": ["risk analysis"],
"vertical_tags": ["finance"],
"qmod_type": ["application"],
"level": ["advanced"]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
qfunc qmci_oracle(ind: qbit) {
Z(ind);
}

qfunc affine_max(x1: qnum, x2: qnum, output res: qnum) {
res = max(x1 * 1.0, ((x1 * 0.75) + (x2 * 0.75)) + (-1.25));
}

qfunc asset_geq_strike_price(x: qnum, output res: qbit) {
res = x > 1.5;
}

qfunc exponential_amplitude_loading<exp_rate: real>(x: qbit[], aux: qbit[], res: qbit) {
apply_to_all<X>(x);
repeat (index: x.len) {
control (x[index]) {
RY<2 * acos(1 / sqrt(exp(exp_rate * (2 ** index))))>(aux[index]);
}
}
apply_to_all<X>(x);
aux_num: qnum<aux.len, False, 0>;
aux -> aux_num;
control (aux_num == 0) {
X(res);
}
aux_num -> aux;
}

qfunc direct_load_amplitudes(geq_reg: qnum, max_reg: qnum, aux_reg: qnum, ind_reg: qbit) {
control (geq_reg == 1) {
exponential_amplitude_loading<(1 / (2 ** max_reg.fraction_digits)) * 0.4341>(max_reg, aux_reg, ind_reg);
}
control (geq_reg == 0) {
RY<2 * asin(13.784 / sqrt(max(193.97 * exp(((0.4341 * (2 ** (max_reg.size - max_reg.fraction_digits))) * (1 - (1 / (2 ** max_reg.size)))) + (-0.7408)), 190)))>(ind_reg);
}
}

qfunc direct_payoff(max_reg: qnum, aux_reg: qnum, ind_reg: qbit) {
geq_reg: qbit;
within {
asset_geq_strike_price(max_reg, geq_reg);
} apply {
direct_load_amplitudes(geq_reg, max_reg, aux_reg, ind_reg);
}
}

qfunc rainbow_direct(x1: qnum, x2: qnum, aux_reg: qnum, ind_reg: qbit) {
inplace_prepare_state<[
0.0656,
0.4344,
0.4344,
0.0656
], 0>(x1);
inplace_prepare_state<[
0.0656,
0.4344,
0.4344,
0.0656
], 0>(x2);
max_out: qnum;
within {
affine_max(x1, x2, max_out);
} apply {
direct_payoff(max_out, aux_reg, ind_reg);
}
}

qfunc grover_algorithm<k: int, oracle_operand: qfunc (arg0: qbit[]), sp_operand: qfunc (arg0: qbit[])>(x: qbit[]) {
sp_operand(x);
power (k) {
grover_operator<oracle_operand, sp_operand>(x);
}
}

qfunc main<k: int>(output ind_reg: qbit) {
full_reg: qbit[];
allocate<10>(full_reg);
grover_algorithm<k, lambda(arg0) {
qmci_oracle(arg0[arg0.len - 1]);
}, lambda(arg0) {
rainbow_direct(arg0[0:2], arg0[2:4], arg0[4:9], arg0[arg0.len - 1]);
}>(full_reg);
state_reg: qbit[];
full_reg -> {state_reg, ind_reg};
}

cscope ```
iqae_res = iqae(epsilon=0.05, alpha=0.1)
save({'iqae_res': iqae_res})
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"constraints": {
"max_width": 25
}
}
Loading

0 comments on commit 5a44717

Please sign in to comment.