Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 51 additions & 26 deletions learning/courses/quantum-machine-learning/data-encoding.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -945,42 +945,67 @@
"id": "0f573f85-c2a2-449e-bcd4-74d42072e0db",
"metadata": {},
"source": [
"Up to the first barrier (a point we label $b1$), our states are:\n",
"As we write our state, we will use the Qiskit convention that least-significant qubits are ordered to the far right, as in $|q_2,q_1,q_0\\rangle$ or $|q_2\\rangle\\otimes|q_1\\rangle\\otimes|q_0\\rangle.$ These states can become very complicated very quickly, and this rare example may help explain why such states are seldom written out explicitly.\n",
"\n",
"Our system starts in the state $|00\\rangle.$ Up to the first barrier (a point we label $b1$), our states are:\n",
"\n",
"$$\n",
"|\\psi\\rangle_{b1} = \\left(\\cos(\\theta_0/2)|0\\rangle+\\sin(\\theta_0/2)e^{i\\theta_2}|1\\rangle\\right)\\otimes\\left(\\cos(\\theta_1/2)|0\\rangle+\\sin(\\theta_1/2)e^{i\\theta_3}|1\\rangle\\right)\n",
"|\\psi\\rangle_{b1} = \\left(\\cos\\left(\\frac{\\theta_1}{2}\\right)|0\\rangle+\\sin\\left(\\frac{\\theta_1}{2}\\right)e^{i\\theta_3}|1\\rangle\\right)\\otimes\\left(\\cos\\left(\\frac{\\theta_0}{2}\\right)|0\\rangle+\\sin\\left(\\frac{\\theta_0}{2}\\right)e^{i\\theta_2}|1\\rangle\\right)\n",
"$$\n",
"\n",
"That's just dense encoding, which we've seen before. Now after the CNOT gate, at the second barrier ($b2$), our state is\n",
"\n",
"$$\n",
"|\\psi\\rangle_{b2} = \\left(\\cos(\\theta_0/2)|0\\rangle+\\sin(\\theta_0/2)e^{i\\theta_2}|1\\rangle\\right)\\otimes\\cos(\\theta_1/2)|0\\rangle+\n",
"\\left(\\sin(\\theta_0/2)e^{i\\theta_2}|0\\rangle+\\cos(\\theta_0/2)|1\\rangle\\right)\\otimes\\sin(\\theta_1/2)e^{i\\theta_3}|1\\rangle\n",
"That's just dense encoding, which we've seen before. Now after the CNOT gate, at the second barrier ($b2$), our state is"
]
},
{
"cell_type": "markdown",
"id": "b3008413-246f-459f-b8b3-4f7610e93f2b",
"metadata": {},
"source": [
"$$\n",
"We now apply the last set of rotations to obtain:"
"\\begin{aligned}\n",
"|\\psi\\rangle_{b2} = & \\cos\\left(\\frac{\\theta_1}{2}\\right)\\cos\\left(\\frac{\\theta_0}{2}\\right)|00\\rangle+\\cos\\left(\\frac{\\theta_1}{2}\\right)\\sin\\left(\\frac{\\theta_0}{2}\\right)e^{i\\theta_2}|11\\rangle\\\\\n",
"+ & \\sin\\left(\\frac{\\theta_1}{2}\\right)\\cos\\left(\\frac{\\theta_0}{2}\\right)e^{i\\theta_3}|10\\rangle+\\sin\\left(\\frac{\\theta_1}{2}\\right)\\sin\\left(\\frac{\\theta_0}{2}\\right)e^{i\\theta_2}e^{i\\theta_3}|01\\rangle\n",
"\\end{aligned}\n",
"$$"
]
},
{
"cell_type": "markdown",
"id": "52d99dcf-2cd7-4777-a92b-765f8f8c02c2",
"metadata": {},
"source": [
"We now apply the last set of single-qubit rotations and collect like states to obtain:"
]
},
{
"cell_type": "markdown",
"id": "40307fb4-8001-452b-90cd-bc71b086cdae",
"id": "fae33b09-fc78-42d8-98f0-7fdd6fa0ae5c",
"metadata": {},
"source": [
"$$\n",
"\\begin{align}\n",
"\\nonumber\n",
"|\\psi\\rangle_{\\text{final}} &= \\cos(\\theta_0/2)\n",
"\\left(\\cos(\\theta_4/2)|0\\rangle+\\sin(\\theta_4/2)e^{i\\theta_6}|1\\rangle\\right)\\\\ \\nonumber\n",
"&\\otimes \\left[ \\cos(\\theta_1/2)\n",
" \\left( \\cos(\\theta_5/2)|0\\rangle+\\sin(\\theta_5/2)e^{i \\theta_7}|1\\rangle\\right)\n",
"+\\sin(\\theta_1/2)e^{i\\theta_3}\\left(-\\sin(\\theta_5/2)|0\\rangle+\\cos(\\theta_5/2)e^{i \\theta_7}|1\\rangle\\right)\n",
" \\right]\\\\ \\nonumber\n",
"&+\\sin(\\theta_0/2)e^{i\\theta_2}\n",
"\\left(-\\sin(\\theta_4/2)|0\\rangle+\\cos(\\theta_4/2)e^{i\\theta_6}|1\\rangle\\right)\\\\ \\nonumber\n",
"&\\otimes \\left[\n",
"\\sin(\\theta_1/2)e^{i\\theta_3}\\left(\\cos(\\theta_5/2)|0\\rangle+\\sin(\\theta_5/2)e^{i \\theta_7}|1\\rangle\\right)\n",
"+\\cos(\\theta_1/2)e^{i\\theta_3}\\left(-\\sin(\\theta_5/2)|0\\rangle+\\cos(\\theta_5/2)e^{i \\theta_7}|1\\rangle\\right)\n",
"\\right]\n",
"\\end{align}\n",
"\\begin{align*}\n",
"|\\psi\\rangle_{\\text{final}} = &\n",
"\\left[\\cos\\left(\\frac{\\theta_0}{2}\\right)\\left(\\cos\\left(\\frac{\\theta_1}{2}\\right)\\cos\\left(\\frac{\\theta_5}{2}\\right)-\\sin\\left(\\frac{\\theta_1}{2}\\right)\\sin\\left(\\frac{\\theta_5}{2}\\right)e^{i\\theta_3}\\right)\\cos\\left(\\frac{\\theta_4}{2}\\right)\\right.\\\\\n",
"\n",
"+ & \\left.\\sin\\left(\\frac{\\theta_0}{2}\\right)\\left(\\cos\\left(\\frac{\\theta_1}{2}\\right)\\sin\\left(\\frac{\\theta_5}{2}\\right)-\\sin\\left(\\frac{\\theta_1}{2}\\right)\\cos\\left(\\frac{\\theta_5}{2}\\right)e^{i\\theta_3}\\right)\\sin\\left(\\frac{\\theta_4}{2}\\right)e^{i\\theta_2}\\right]\n",
"|00\\rangle\\\\\n",
"\n",
"+ & \\left[\\cos\\left(\\frac{\\theta_0}{2}\\right)\\left(\\cos\\left(\\frac{\\theta_1}{2}\\right)\\cos\\left(\\frac{\\theta_5}{2}\\right)-\\sin\\left(\\frac{\\theta_1}{2}\\right)\\sin\\left(\\frac{\\theta_5}{2}\\right)e^{i\\theta_3}\\right)\\sin\\left(\\frac{\\theta_4}{2}\\right)\\right.\\\\\n",
"\n",
"+ & \\left.\\sin\\left(\\frac{\\theta_0}{2}\\right)\\left(-\\cos\\left(\\frac{\\theta_1}{2}\\right)\\sin\\left(\\frac{\\theta_5}{2}\\right)+\\sin\\left(\\frac{\\theta_1}{2}\\right)\\cos\\left(\\frac{\\theta_5}{2}\\right)e^{i\\theta_3}\\right)\\cos\\left(\\frac{\\theta_4}{2}\\right)e^{i\\theta_2}\\right]\n",
"e^{i\\theta_6}|01\\rangle\\\\\n",
"\n",
"+ & \\left[\\cos\\left(\\frac{\\theta_0}{2}\\right)\\left(\\cos\\left(\\frac{\\theta_1}{2}\\right)\\sin\\left(\\frac{\\theta_5}{2}\\right)+\\sin\\left(\\frac{\\theta_1}{2}\\right)\\cos\\left(\\frac{\\theta_5}{2}\\right)e^{i\\theta_3}\\right)\\cos\\left(\\frac{\\theta_4}{2}\\right)\\right.\\\\\n",
"\n",
"- & \\left.\\sin\\left(\\frac{\\theta_0}{2}\\right)\\left(\\cos\\left(\\frac{\\theta_1}{2}\\right)\\cos\\left(\\frac{\\theta_5}{2}\\right)+\\sin\\left(\\frac{\\theta_1}{2}\\right)\\sin\\left(\\frac{\\theta_5}{2}\\right)e^{i\\theta_3}\\right)\\sin\\left(\\frac{\\theta_4}{2}\\right)e^{i\\theta_2}\\right]\n",
"e^{i\\theta_7}|10\\rangle\\\\\n",
"\n",
"+ & \\left[\\cos\\left(\\frac{\\theta_0}{2}\\right)\\left(\\cos\\left(\\frac{\\theta_1}{2}\\right)\\sin\\left(\\frac{\\theta_5}{2}\\right)+\\sin\\left(\\frac{\\theta_1}{2}\\right)\\cos\\left(\\frac{\\theta_5}{2}\\right)e^{i\\theta_3}\\right)\\sin\\left(\\frac{\\theta_4}{2}\\right)\\right.\\\\\n",
"\n",
"+ & \\left.\\sin\\left(\\frac{\\theta_0}{2}\\right)\\left(\\cos\\left(\\frac{\\theta_1}{2}\\right)\\cos\\left(\\frac{\\theta_5}{2}\\right)+\\sin\\left(\\frac{\\theta_1}{2}\\right)\\sin\\left(\\frac{\\theta_5}{2}\\right)e^{i\\theta_3}\\right)\\cos\\left(\\frac{\\theta_4}{2}\\right)e^{i\\theta_2}\\right]\n",
"e^{i\\theta_6}e^{i\\theta_7}|11\\rangle\n",
"\n",
"\\end{align*}\n",
"$$"
]
},
Expand All @@ -989,11 +1014,11 @@
"id": "93e9e6ae-85e8-4077-9c25-f947daebe610",
"metadata": {},
"source": [
"At first glance, it may appear that we have loaded so more parameters onto just a few states than makes sense, since the final state can be written as $\\psi_\\text{final} = c_0|00\\rangle+c_1|01\\rangle+c_2|10\\rangle+c_3|11\\rangle$. But note that each prefactor is complex! Written like this:\n",
"This is likely too complicated to parse. But step back and think about how many parameters we loaded onto the state: 8. But we have with just four computational basis states. At first glance, it may appear that we have loaded more parameters than makes sense, since the final state can be written as $\\psi_\\text{final} = c_0|00\\rangle+c_1|01\\rangle+c_2|10\\rangle+c_3|11\\rangle$. But note that each prefactor is complex! Written like this:\n",
"$$\n",
"\\psi_\\text{final} = (a_0+ib_0)|00\\rangle+(a_1+ib_1)|01\\rangle+(a_2+ib_2)|10\\rangle+(a_3+ib_3)|11\\rangle\n",
"$$\n",
"One can see that we do, indeed, have 8 parameters on the state on which to encode our 8 features.\n",
"ne can see that we do, indeed, have 8 parameters on the state on which to encode our 8 features.\n",
"\n",
"By increasing the number of qubits and increasing the number of repetitions of entangling and rotation layers, one can encode much more data. Writing out the wave functions quickly becomes intractable. But we can still see the encoding in action."
]
Expand Down
Loading