Skip to content

Commit e8ab4b6

Browse files
committed
fix: define pennylane functions inside decorator job
1 parent 5240025 commit e8ab4b6

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

examples/pennylane/3_Hydrogen_Molecule_geometry_with_VQE/3_Hydrogen_Molecule_geometry_with_VQE.ipynb

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,7 @@
526526
},
527527
{
528528
"cell_type": "code",
529-
"execution_count": 16,
529+
"execution_count": null,
530530
"metadata": {},
531531
"outputs": [],
532532
"source": [
@@ -543,6 +543,22 @@
543543
"def run_large_vqe(iterations):\n",
544544
" task_tracker = Tracker().start() # track Braket quantum tasks costs\n",
545545
"\n",
546+
" dev = qml.device(\"lightning.qubit\", wires=qubits)\n",
547+
" params = np.random.normal(0, np.pi, len(singles) + len(doubles))\n",
548+
"\n",
549+
" @qml.qnode(dev)\n",
550+
" def energy_expval(params):\n",
551+
" circuit(params, wires)\n",
552+
" return qml.expval(h)\n",
553+
"\n",
554+
" @qml.qnode(dev)\n",
555+
" def S2_expval(params):\n",
556+
" circuit(params, wires)\n",
557+
" return qml.expval(S2)\n",
558+
"\n",
559+
" def spin(params):\n",
560+
" return -0.5 + np.sqrt(1 / 4 + S2_expval(params))\n",
561+
"\n",
546562
" energies, spins = run_vqe(energy_expval, spin, opt, params, iterations)\n",
547563
"\n",
548564
" return {\n",
@@ -567,7 +583,7 @@
567583
},
568584
{
569585
"cell_type": "code",
570-
"execution_count": 17,
586+
"execution_count": null,
571587
"metadata": {},
572588
"outputs": [
573589
{
@@ -579,7 +595,7 @@
579595
}
580596
],
581597
"source": [
582-
"job = run_large_vqe(iterations=30)\n",
598+
"job = run_large_vqe(iterations=15)\n",
583599
"print(job)"
584600
]
585601
},

0 commit comments

Comments
 (0)