Skip to content

Commit 6fd7b59

Browse files
committed
fixed control with variable in both arguments issue
1 parent ca97853 commit 6fd7b59

File tree

4 files changed

+66
-48
lines changed

4 files changed

+66
-48
lines changed

applications/finance/option_pricing/option_pricing.ipynb

Lines changed: 21 additions & 20 deletions
Large diffs are not rendered by default.

applications/finance/option_pricing/option_pricing.qmod

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,13 @@ qfunc payoff_linear(asset: qnum, ind: qbit) {
5656
}
5757

5858
qfunc payoff(asset: qnum, ind: qbit) {
59-
control (asset >= ceiling(12.9502500662)) {
60-
payoff_linear(asset, ind);
59+
aux: qbit;
60+
within {
61+
aux = asset >= ceiling(12.9502500662);
62+
} apply {
63+
control (aux) {
64+
payoff_linear(asset, ind);
65+
}
6166
}
6267
}
6368

applications/finance/option_pricing/option_pricing.synthesis_options.json

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,36 +8,38 @@
88
"machine_precision": 8,
99
"custom_hardware_settings": {
1010
"basis_gates": [
11-
"sx",
12-
"rx",
11+
"id",
12+
"cx",
1313
"u",
14-
"z",
15-
"cz",
16-
"y",
17-
"s",
18-
"u1",
14+
"sdg",
15+
"t",
1916
"p",
20-
"r",
21-
"cy",
17+
"u1",
2218
"ry",
23-
"rz",
19+
"z",
2420
"x",
25-
"h",
26-
"t",
27-
"sxdg",
2821
"tdg",
29-
"cx",
30-
"id",
22+
"y",
23+
"cz",
3124
"u2",
32-
"sdg"
25+
"sxdg",
26+
"rx",
27+
"s",
28+
"rz",
29+
"cy",
30+
"sx",
31+
"r",
32+
"h"
3333
],
3434
"is_symmetric_connectivity": true
3535
},
3636
"debug_mode": true,
37+
"synthesize_all_separately": false,
38+
"optimization_level": 3,
3739
"output_format": ["qasm"],
3840
"pretty_qasm": true,
3941
"transpilation_option": "auto optimize",
4042
"timeout_seconds": 300,
41-
"random_seed": -1
43+
"random_seed": 4290148293
4244
}
4345
}

tutorials/workshops/QMOD_workshop/QMOD_Workshop_Part_2.ipynb

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -678,18 +678,24 @@
678678
},
679679
{
680680
"cell_type": "code",
681-
"execution_count": 18,
681+
"execution_count": 1,
682682
"metadata": {
683683
"ExecuteTime": {
684684
"end_time": "2024-10-07T13:39:26.331226Z",
685685
"start_time": "2024-10-07T13:39:26.326156Z"
686686
}
687687
},
688-
"outputs": [],
688+
"outputs": [
689+
{
690+
"name": "stdout",
691+
"output_type": "stream",
692+
"text": [
693+
"Opening: https://nightly.platform.classiq.io/circuit/6fec16d5-72a1-49bf-ab24-3287255c3391?version=0.64.0.dev0\n"
694+
]
695+
}
696+
],
689697
"source": [
690698
"# Solution to Exercise 9:\n",
691-
"\n",
692-
"\n",
693699
"from classiq import *\n",
694700
"\n",
695701
"\n",
@@ -699,10 +705,14 @@
699705
" allocate(3, x)\n",
700706
" hadamard_transform(x)\n",
701707
"\n",
702-
" control(\n",
703-
" x < 0.5,\n",
704-
" stmt_block=lambda: inplace_xor(2.0 * x + 1.0, res),\n",
705-
" else_block=lambda: inplace_xor(1.0 * x + 0.5, res),\n",
708+
" aux = QBit(\"aux\")\n",
709+
" within_apply(\n",
710+
" lambda: assign(x < 0.5, aux),\n",
711+
" lambda: control(\n",
712+
" aux,\n",
713+
" stmt_block=lambda: inplace_xor(2.0 * x + 1.0, res),\n",
714+
" else_block=lambda: inplace_xor(1.0 * x + 0.5, res),\n",
715+
" ),\n",
706716
" )\n",
707717
"\n",
708718
"\n",
@@ -773,7 +783,7 @@
773783
"name": "python",
774784
"nbconvert_exporter": "python",
775785
"pygments_lexer": "ipython3",
776-
"version": "3.11.9"
786+
"version": "3.11.4"
777787
},
778788
"vscode": {
779789
"interpreter": {

0 commit comments

Comments
 (0)