Skip to content

Commit

Permalink
Merge pull request #264 from jcmgray/circuit-updates
Browse files Browse the repository at this point in the history
Circuit updates: gate by gate sampling, and efficient local expectation cals for MPS
  • Loading branch information
jcmgray authored Oct 22, 2024
2 parents f627b4e + 71bbea9 commit 98fba83
Show file tree
Hide file tree
Showing 26 changed files with 1,965 additions and 117,929 deletions.
Binary file added docs/_static/amplitude.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/_static/branching.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/_static/compute_marginal.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/_static/local_expectation.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/_static/partial_trace.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/_static/sample.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/_static/sample_chaotic.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/_static/sample_gate_by_gate.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/_static/to_dense.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
69 changes: 48 additions & 21 deletions docs/basics.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"cells": [
{
"cell_type": "markdown",
"id": "0b054e8d-d0bb-4613-bddd-81b37f3d2a8e",
"metadata": {
"raw_mimetype": "text/restructuredtext"
},
Expand All @@ -21,6 +22,7 @@
{
"cell_type": "code",
"execution_count": 1,
"id": "a30d59e4-ebf6-417d-9adf-16de0b1bbbe1",
"metadata": {
"raw_mimetype": "text/restructuredtext"
},
Expand All @@ -32,6 +34,7 @@
},
{
"cell_type": "markdown",
"id": "1f139c32-2483-406f-8a4c-399cf1945a34",
"metadata": {},
"source": [
"Kets are column vectors, i.e. with shape ``(d, 1)``:"
Expand All @@ -40,6 +43,7 @@
{
"cell_type": "code",
"execution_count": 2,
"id": "69b02c9c-37c3-427d-99de-b480b7ea4d6d",
"metadata": {},
"outputs": [
{
Expand All @@ -61,6 +65,7 @@
},
{
"cell_type": "markdown",
"id": "4a731dcf-13e7-4888-a7d1-e7defb06edd3",
"metadata": {},
"source": [
"The ``normalized=True`` option can be used to ensure a normalized output.\n",
Expand All @@ -71,6 +76,7 @@
{
"cell_type": "code",
"execution_count": 3,
"id": "0770dcd6-e29b-4b92-9072-2b4ade641268",
"metadata": {},
"outputs": [
{
Expand All @@ -90,6 +96,7 @@
},
{
"cell_type": "markdown",
"id": "f2ab8914-8431-4dad-bb4b-7a6c400c60df",
"metadata": {},
"source": [
"And operators are square matrices, i.e. have shape ``(d, d)``:"
Expand All @@ -98,12 +105,13 @@
{
"cell_type": "code",
"execution_count": 4,
"id": "6a3a349c-8648-4934-8000-66d3ddf16805",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[[ 1.+0.j 0.-2.j -3.+0.j]\n",
"[[ 1.+0.j 0.-2.j -3.-0.j]\n",
" [ 0.+2.j 4.+0.j 0.-6.j]\n",
" [-3.+0.j 0.+6.j 9.+0.j]]"
]
Expand All @@ -119,6 +127,7 @@
},
{
"cell_type": "markdown",
"id": "fb452078-ab1c-4ba5-81e0-799af6ef0f76",
"metadata": {},
"source": [
"Which can also be sparse:"
Expand All @@ -127,13 +136,14 @@
{
"cell_type": "code",
"execution_count": 5,
"id": "24cab7c2-7dd3-46a7-9acf-f1d3e0cbe5d3",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<3x3 sparse matrix of type '<class 'numpy.complex128'>'\n",
"\twith 9 stored elements in Compressed Sparse Row format>"
"<Compressed Sparse Row sparse matrix of dtype 'complex128'\n",
"\twith 9 stored elements and shape (3, 3)>"
]
},
"execution_count": 5,
Expand All @@ -147,6 +157,7 @@
},
{
"cell_type": "markdown",
"id": "a10ffe96-9bc3-4e4e-ace8-0098d0e29564",
"metadata": {
"raw_mimetype": "text/restructuredtext"
},
Expand All @@ -173,6 +184,7 @@
{
"cell_type": "code",
"execution_count": 6,
"id": "7bebe19b-bb7e-4d5d-a55c-63340574aba4",
"metadata": {},
"outputs": [
{
Expand All @@ -197,6 +209,7 @@
{
"cell_type": "code",
"execution_count": 7,
"id": "0cb44044-6832-4365-a4b0-5f6ed7b940c4",
"metadata": {},
"outputs": [
{
Expand All @@ -216,6 +229,7 @@
},
{
"cell_type": "markdown",
"id": "9389db86-974f-47a7-94e0-729a34436be2",
"metadata": {
"raw_mimetype": "text/restructuredtext"
},
Expand All @@ -231,6 +245,7 @@
{
"cell_type": "code",
"execution_count": 8,
"id": "ccb3c8b1-3673-496b-9efe-d15e13e15c45",
"metadata": {},
"outputs": [
{
Expand All @@ -253,6 +268,7 @@
{
"cell_type": "code",
"execution_count": 9,
"id": "21c148d7-a55c-44cb-bbf3-8de4c9b33f41",
"metadata": {},
"outputs": [
{
Expand All @@ -273,6 +289,7 @@
{
"cell_type": "code",
"execution_count": 10,
"id": "6916a93e-bbfa-4b37-92f3-a7816d58af28",
"metadata": {},
"outputs": [
{
Expand All @@ -295,6 +312,7 @@
{
"cell_type": "code",
"execution_count": 11,
"id": "ad4186dc-309d-44b9-abed-5d6af268746a",
"metadata": {},
"outputs": [
{
Expand All @@ -314,6 +332,7 @@
},
{
"cell_type": "markdown",
"id": "ba59088e-d798-455f-95b8-179512b0874f",
"metadata": {
"raw_mimetype": "text/restructuredtext"
},
Expand All @@ -327,12 +346,13 @@
{
"cell_type": "code",
"execution_count": 12,
"id": "4012d11b-f4b9-4dd5-af69-96f51299839d",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"1.0"
"np.float64(1.0)"
]
},
"execution_count": 12,
Expand All @@ -347,12 +367,13 @@
{
"cell_type": "code",
"execution_count": 13,
"id": "a67c2946-6e4b-40e6-91ff-f47c17e5f0d7",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0j"
"np.complex128(0j)"
]
},
"execution_count": 13,
Expand All @@ -366,6 +387,7 @@
},
{
"cell_type": "markdown",
"id": "cd62be41-0bf5-422e-b5b5-8cb9a37174d6",
"metadata": {},
"source": [
"Here's an example for a much larger (20 qubit), sparse operator expecation,\n",
Expand All @@ -375,13 +397,14 @@
{
"cell_type": "code",
"execution_count": 14,
"id": "425bae86-798a-4d9d-a7e0-2690ea7a219b",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<1048576x1048576 sparse matrix of type '<class 'numpy.complex128'>'\n",
"\twith 11534268 stored elements in Compressed Sparse Row format>"
"<Compressed Sparse Row sparse matrix of dtype 'complex128'\n",
"\twith 11534284 stored elements and shape (1048576, 1048576)>"
]
},
"execution_count": 14,
Expand All @@ -398,12 +421,13 @@
{
"cell_type": "code",
"execution_count": 15,
"id": "4198dbc2-d143-4514-9563-8785ef1395f4",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0.9998770131258168"
"np.float64(1.0004858170636874)"
]
},
"execution_count": 15,
Expand All @@ -418,13 +442,14 @@
{
"cell_type": "code",
"execution_count": 16,
"id": "bda59aa7-95c5-4dbf-9b63-95a3635f1ec9",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"59 ms ± 3.85 ms per loop (mean ± std. dev. of 7 runs, 10 loops each)\n"
"55.1 ms ± 3.82 ms per loop (mean ± std. dev. of 7 runs, 10 loops each)\n"
]
}
],
Expand All @@ -435,6 +460,7 @@
},
{
"cell_type": "markdown",
"id": "e68195b9-331c-4e07-b3b2-a1276beb808e",
"metadata": {
"raw_mimetype": "text/restructuredtext"
},
Expand Down Expand Up @@ -464,12 +490,13 @@
":::\n",
"\n",
"Often one wants to sandwich an operator with many identities,\n",
"{func}`~quimb.core.ikron` can be used for this:\n"
"{func}`~quimb.core.ikron` can be used for this:"
]
},
{
"cell_type": "code",
"execution_count": 17,
"id": "bf597230-30d7-4d54-b876-e93967891fc7",
"metadata": {},
"outputs": [
{
Expand All @@ -492,6 +519,7 @@
},
{
"cell_type": "markdown",
"id": "5b7a4905-ee44-4a82-89f1-6e1a612c021b",
"metadata": {
"raw_mimetype": "text/restructuredtext"
},
Expand All @@ -503,6 +531,7 @@
{
"cell_type": "code",
"execution_count": 18,
"id": "ed53d5cc-a2e7-4acb-b867-cb1e61951d3f",
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -532,6 +561,7 @@
},
{
"cell_type": "markdown",
"id": "753aebb7-8d79-491b-8add-9b2497e6d81a",
"metadata": {
"raw_mimetype": "text/restructuredtext"
},
Expand All @@ -553,15 +583,16 @@
{
"cell_type": "code",
"execution_count": 19,
"id": "5c6f0168-e595-4472-b78e-e7c551089e31",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[[ 0.256+0.j -0.013-0.007j 0.02 +0.008j -0.014+0.007j]\n",
" [-0.013+0.007j 0.263+0.j -0.011+0.008j 0.016+0.004j]\n",
" [ 0.02 -0.008j -0.011-0.008j 0.231+0.j 0.01 +0.008j]\n",
" [-0.014-0.007j 0.016-0.004j 0.01 -0.008j 0.25 +0.j ]]"
"[[ 0.279+0.j 0.003-0.005j 0.012+0.009j 0.018-0.009j]\n",
" [ 0.003+0.005j 0.239+0.j -0.005+0.007j -0.005-0.002j]\n",
" [ 0.012-0.009j -0.005-0.007j 0.24 +0.j -0.015-0.014j]\n",
" [ 0.018+0.009j -0.005+0.002j -0.015+0.014j 0.242+0.j ]]"
]
},
"execution_count": 19,
Expand All @@ -579,6 +610,7 @@
},
{
"cell_type": "markdown",
"id": "5ea15f65-79d4-40a1-993a-82b011dc77e1",
"metadata": {
"raw_mimetype": "text/restructuredtext"
},
Expand All @@ -590,7 +622,7 @@
"metadata": {
"celltoolbar": "Raw Cell Format",
"kernelspec": {
"display_name": "Python 3.10.8 ('numpy')",
"display_name": "py312",
"language": "python",
"name": "python3"
},
Expand All @@ -604,12 +636,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.8 (main, Nov 4 2022, 13:48:29) [GCC 11.2.0]"
},
"vscode": {
"interpreter": {
"hash": "39c10650315d977fb13868ea1402e99f3e10e9885c2c202e692ae90b8995050d"
}
"version": "3.12.6"
}
},
"nbformat": 4,
Expand Down
Loading

0 comments on commit 98fba83

Please sign in to comment.