Skip to content

Commit

Permalink
fixed control with variable in both arguments issue
Browse files Browse the repository at this point in the history
  • Loading branch information
orsa-classiq committed Dec 24, 2024
1 parent ca97853 commit 6fd7b59
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 48 deletions.
41 changes: 21 additions & 20 deletions applications/finance/option_pricing/option_pricing.ipynb

Large diffs are not rendered by default.

9 changes: 7 additions & 2 deletions applications/finance/option_pricing/option_pricing.qmod
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,13 @@ qfunc payoff_linear(asset: qnum, ind: qbit) {
}

qfunc payoff(asset: qnum, ind: qbit) {
control (asset >= ceiling(12.9502500662)) {
payoff_linear(asset, ind);
aux: qbit;
within {
aux = asset >= ceiling(12.9502500662);
} apply {
control (aux) {
payoff_linear(asset, ind);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,36 +8,38 @@
"machine_precision": 8,
"custom_hardware_settings": {
"basis_gates": [
"sx",
"rx",
"id",
"cx",
"u",
"z",
"cz",
"y",
"s",
"u1",
"sdg",
"t",
"p",
"r",
"cy",
"u1",
"ry",
"rz",
"z",
"x",
"h",
"t",
"sxdg",
"tdg",
"cx",
"id",
"y",
"cz",
"u2",
"sdg"
"sxdg",
"rx",
"s",
"rz",
"cy",
"sx",
"r",
"h"
],
"is_symmetric_connectivity": true
},
"debug_mode": true,
"synthesize_all_separately": false,
"optimization_level": 3,
"output_format": ["qasm"],
"pretty_qasm": true,
"transpilation_option": "auto optimize",
"timeout_seconds": 300,
"random_seed": -1
"random_seed": 4290148293
}
}
28 changes: 19 additions & 9 deletions tutorials/workshops/QMOD_workshop/QMOD_Workshop_Part_2.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -678,18 +678,24 @@
},
{
"cell_type": "code",
"execution_count": 18,
"execution_count": 1,
"metadata": {
"ExecuteTime": {
"end_time": "2024-10-07T13:39:26.331226Z",
"start_time": "2024-10-07T13:39:26.326156Z"
}
},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Opening: https://nightly.platform.classiq.io/circuit/6fec16d5-72a1-49bf-ab24-3287255c3391?version=0.64.0.dev0\n"
]
}
],
"source": [
"# Solution to Exercise 9:\n",
"\n",
"\n",
"from classiq import *\n",
"\n",
"\n",
Expand All @@ -699,10 +705,14 @@
" allocate(3, x)\n",
" hadamard_transform(x)\n",
"\n",
" control(\n",
" x < 0.5,\n",
" stmt_block=lambda: inplace_xor(2.0 * x + 1.0, res),\n",
" else_block=lambda: inplace_xor(1.0 * x + 0.5, res),\n",
" aux = QBit(\"aux\")\n",
" within_apply(\n",
" lambda: assign(x < 0.5, aux),\n",
" lambda: control(\n",
" aux,\n",
" stmt_block=lambda: inplace_xor(2.0 * x + 1.0, res),\n",
" else_block=lambda: inplace_xor(1.0 * x + 0.5, res),\n",
" ),\n",
" )\n",
"\n",
"\n",
Expand Down Expand Up @@ -773,7 +783,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.9"
"version": "3.11.4"
},
"vscode": {
"interpreter": {
Expand Down

0 comments on commit 6fd7b59

Please sign in to comment.