Skip to content

Commit 98fba83

Browse files
authored
Merge pull request #264 from jcmgray/circuit-updates
Circuit updates: gate by gate sampling, and efficient local expectation cals for MPS
2 parents f627b4e + 71bbea9 commit 98fba83

26 files changed

+1965
-117929
lines changed

docs/_static/amplitude.png

103 KB
Loading

docs/_static/branching.png

126 KB
Loading

docs/_static/compute_marginal.png

189 KB
Loading

docs/_static/local_expectation.png

123 KB
Loading

docs/_static/partial_trace.png

108 KB
Loading

docs/_static/sample.png

215 KB
Loading

docs/_static/sample_chaotic.png

73.7 KB
Loading

docs/_static/sample_gate_by_gate.png

149 KB
Loading

docs/_static/to_dense.png

35.1 KB
Loading

docs/basics.ipynb

Lines changed: 48 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"cells": [
33
{
44
"cell_type": "markdown",
5+
"id": "0b054e8d-d0bb-4613-bddd-81b37f3d2a8e",
56
"metadata": {
67
"raw_mimetype": "text/restructuredtext"
78
},
@@ -21,6 +22,7 @@
2122
{
2223
"cell_type": "code",
2324
"execution_count": 1,
25+
"id": "a30d59e4-ebf6-417d-9adf-16de0b1bbbe1",
2426
"metadata": {
2527
"raw_mimetype": "text/restructuredtext"
2628
},
@@ -32,6 +34,7 @@
3234
},
3335
{
3436
"cell_type": "markdown",
37+
"id": "1f139c32-2483-406f-8a4c-399cf1945a34",
3538
"metadata": {},
3639
"source": [
3740
"Kets are column vectors, i.e. with shape ``(d, 1)``:"
@@ -40,6 +43,7 @@
4043
{
4144
"cell_type": "code",
4245
"execution_count": 2,
46+
"id": "69b02c9c-37c3-427d-99de-b480b7ea4d6d",
4347
"metadata": {},
4448
"outputs": [
4549
{
@@ -61,6 +65,7 @@
6165
},
6266
{
6367
"cell_type": "markdown",
68+
"id": "4a731dcf-13e7-4888-a7d1-e7defb06edd3",
6469
"metadata": {},
6570
"source": [
6671
"The ``normalized=True`` option can be used to ensure a normalized output.\n",
@@ -71,6 +76,7 @@
7176
{
7277
"cell_type": "code",
7378
"execution_count": 3,
79+
"id": "0770dcd6-e29b-4b92-9072-2b4ade641268",
7480
"metadata": {},
7581
"outputs": [
7682
{
@@ -90,6 +96,7 @@
9096
},
9197
{
9298
"cell_type": "markdown",
99+
"id": "f2ab8914-8431-4dad-bb4b-7a6c400c60df",
93100
"metadata": {},
94101
"source": [
95102
"And operators are square matrices, i.e. have shape ``(d, d)``:"
@@ -98,12 +105,13 @@
98105
{
99106
"cell_type": "code",
100107
"execution_count": 4,
108+
"id": "6a3a349c-8648-4934-8000-66d3ddf16805",
101109
"metadata": {},
102110
"outputs": [
103111
{
104112
"data": {
105113
"text/plain": [
106-
"[[ 1.+0.j 0.-2.j -3.+0.j]\n",
114+
"[[ 1.+0.j 0.-2.j -3.-0.j]\n",
107115
" [ 0.+2.j 4.+0.j 0.-6.j]\n",
108116
" [-3.+0.j 0.+6.j 9.+0.j]]"
109117
]
@@ -119,6 +127,7 @@
119127
},
120128
{
121129
"cell_type": "markdown",
130+
"id": "fb452078-ab1c-4ba5-81e0-799af6ef0f76",
122131
"metadata": {},
123132
"source": [
124133
"Which can also be sparse:"
@@ -127,13 +136,14 @@
127136
{
128137
"cell_type": "code",
129138
"execution_count": 5,
139+
"id": "24cab7c2-7dd3-46a7-9acf-f1d3e0cbe5d3",
130140
"metadata": {},
131141
"outputs": [
132142
{
133143
"data": {
134144
"text/plain": [
135-
"<3x3 sparse matrix of type '<class 'numpy.complex128'>'\n",
136-
"\twith 9 stored elements in Compressed Sparse Row format>"
145+
"<Compressed Sparse Row sparse matrix of dtype 'complex128'\n",
146+
"\twith 9 stored elements and shape (3, 3)>"
137147
]
138148
},
139149
"execution_count": 5,
@@ -147,6 +157,7 @@
147157
},
148158
{
149159
"cell_type": "markdown",
160+
"id": "a10ffe96-9bc3-4e4e-ace8-0098d0e29564",
150161
"metadata": {
151162
"raw_mimetype": "text/restructuredtext"
152163
},
@@ -173,6 +184,7 @@
173184
{
174185
"cell_type": "code",
175186
"execution_count": 6,
187+
"id": "7bebe19b-bb7e-4d5d-a55c-63340574aba4",
176188
"metadata": {},
177189
"outputs": [
178190
{
@@ -197,6 +209,7 @@
197209
{
198210
"cell_type": "code",
199211
"execution_count": 7,
212+
"id": "0cb44044-6832-4365-a4b0-5f6ed7b940c4",
200213
"metadata": {},
201214
"outputs": [
202215
{
@@ -216,6 +229,7 @@
216229
},
217230
{
218231
"cell_type": "markdown",
232+
"id": "9389db86-974f-47a7-94e0-729a34436be2",
219233
"metadata": {
220234
"raw_mimetype": "text/restructuredtext"
221235
},
@@ -231,6 +245,7 @@
231245
{
232246
"cell_type": "code",
233247
"execution_count": 8,
248+
"id": "ccb3c8b1-3673-496b-9efe-d15e13e15c45",
234249
"metadata": {},
235250
"outputs": [
236251
{
@@ -253,6 +268,7 @@
253268
{
254269
"cell_type": "code",
255270
"execution_count": 9,
271+
"id": "21c148d7-a55c-44cb-bbf3-8de4c9b33f41",
256272
"metadata": {},
257273
"outputs": [
258274
{
@@ -273,6 +289,7 @@
273289
{
274290
"cell_type": "code",
275291
"execution_count": 10,
292+
"id": "6916a93e-bbfa-4b37-92f3-a7816d58af28",
276293
"metadata": {},
277294
"outputs": [
278295
{
@@ -295,6 +312,7 @@
295312
{
296313
"cell_type": "code",
297314
"execution_count": 11,
315+
"id": "ad4186dc-309d-44b9-abed-5d6af268746a",
298316
"metadata": {},
299317
"outputs": [
300318
{
@@ -314,6 +332,7 @@
314332
},
315333
{
316334
"cell_type": "markdown",
335+
"id": "ba59088e-d798-455f-95b8-179512b0874f",
317336
"metadata": {
318337
"raw_mimetype": "text/restructuredtext"
319338
},
@@ -327,12 +346,13 @@
327346
{
328347
"cell_type": "code",
329348
"execution_count": 12,
349+
"id": "4012d11b-f4b9-4dd5-af69-96f51299839d",
330350
"metadata": {},
331351
"outputs": [
332352
{
333353
"data": {
334354
"text/plain": [
335-
"1.0"
355+
"np.float64(1.0)"
336356
]
337357
},
338358
"execution_count": 12,
@@ -347,12 +367,13 @@
347367
{
348368
"cell_type": "code",
349369
"execution_count": 13,
370+
"id": "a67c2946-6e4b-40e6-91ff-f47c17e5f0d7",
350371
"metadata": {},
351372
"outputs": [
352373
{
353374
"data": {
354375
"text/plain": [
355-
"0j"
376+
"np.complex128(0j)"
356377
]
357378
},
358379
"execution_count": 13,
@@ -366,6 +387,7 @@
366387
},
367388
{
368389
"cell_type": "markdown",
390+
"id": "cd62be41-0bf5-422e-b5b5-8cb9a37174d6",
369391
"metadata": {},
370392
"source": [
371393
"Here's an example for a much larger (20 qubit), sparse operator expecation,\n",
@@ -375,13 +397,14 @@
375397
{
376398
"cell_type": "code",
377399
"execution_count": 14,
400+
"id": "425bae86-798a-4d9d-a7e0-2690ea7a219b",
378401
"metadata": {},
379402
"outputs": [
380403
{
381404
"data": {
382405
"text/plain": [
383-
"<1048576x1048576 sparse matrix of type '<class 'numpy.complex128'>'\n",
384-
"\twith 11534268 stored elements in Compressed Sparse Row format>"
406+
"<Compressed Sparse Row sparse matrix of dtype 'complex128'\n",
407+
"\twith 11534284 stored elements and shape (1048576, 1048576)>"
385408
]
386409
},
387410
"execution_count": 14,
@@ -398,12 +421,13 @@
398421
{
399422
"cell_type": "code",
400423
"execution_count": 15,
424+
"id": "4198dbc2-d143-4514-9563-8785ef1395f4",
401425
"metadata": {},
402426
"outputs": [
403427
{
404428
"data": {
405429
"text/plain": [
406-
"0.9998770131258168"
430+
"np.float64(1.0004858170636874)"
407431
]
408432
},
409433
"execution_count": 15,
@@ -418,13 +442,14 @@
418442
{
419443
"cell_type": "code",
420444
"execution_count": 16,
445+
"id": "bda59aa7-95c5-4dbf-9b63-95a3635f1ec9",
421446
"metadata": {},
422447
"outputs": [
423448
{
424449
"name": "stdout",
425450
"output_type": "stream",
426451
"text": [
427-
"59 ms ± 3.85 ms per loop (mean ± std. dev. of 7 runs, 10 loops each)\n"
452+
"55.1 ms ± 3.82 ms per loop (mean ± std. dev. of 7 runs, 10 loops each)\n"
428453
]
429454
}
430455
],
@@ -435,6 +460,7 @@
435460
},
436461
{
437462
"cell_type": "markdown",
463+
"id": "e68195b9-331c-4e07-b3b2-a1276beb808e",
438464
"metadata": {
439465
"raw_mimetype": "text/restructuredtext"
440466
},
@@ -464,12 +490,13 @@
464490
":::\n",
465491
"\n",
466492
"Often one wants to sandwich an operator with many identities,\n",
467-
"{func}`~quimb.core.ikron` can be used for this:\n"
493+
"{func}`~quimb.core.ikron` can be used for this:"
468494
]
469495
},
470496
{
471497
"cell_type": "code",
472498
"execution_count": 17,
499+
"id": "bf597230-30d7-4d54-b876-e93967891fc7",
473500
"metadata": {},
474501
"outputs": [
475502
{
@@ -492,6 +519,7 @@
492519
},
493520
{
494521
"cell_type": "markdown",
522+
"id": "5b7a4905-ee44-4a82-89f1-6e1a612c021b",
495523
"metadata": {
496524
"raw_mimetype": "text/restructuredtext"
497525
},
@@ -503,6 +531,7 @@
503531
{
504532
"cell_type": "code",
505533
"execution_count": 18,
534+
"id": "ed53d5cc-a2e7-4acb-b867-cb1e61951d3f",
506535
"metadata": {},
507536
"outputs": [
508537
{
@@ -532,6 +561,7 @@
532561
},
533562
{
534563
"cell_type": "markdown",
564+
"id": "753aebb7-8d79-491b-8add-9b2497e6d81a",
535565
"metadata": {
536566
"raw_mimetype": "text/restructuredtext"
537567
},
@@ -553,15 +583,16 @@
553583
{
554584
"cell_type": "code",
555585
"execution_count": 19,
586+
"id": "5c6f0168-e595-4472-b78e-e7c551089e31",
556587
"metadata": {},
557588
"outputs": [
558589
{
559590
"data": {
560591
"text/plain": [
561-
"[[ 0.256+0.j -0.013-0.007j 0.02 +0.008j -0.014+0.007j]\n",
562-
" [-0.013+0.007j 0.263+0.j -0.011+0.008j 0.016+0.004j]\n",
563-
" [ 0.02 -0.008j -0.011-0.008j 0.231+0.j 0.01 +0.008j]\n",
564-
" [-0.014-0.007j 0.016-0.004j 0.01 -0.008j 0.25 +0.j ]]"
592+
"[[ 0.279+0.j 0.003-0.005j 0.012+0.009j 0.018-0.009j]\n",
593+
" [ 0.003+0.005j 0.239+0.j -0.005+0.007j -0.005-0.002j]\n",
594+
" [ 0.012-0.009j -0.005-0.007j 0.24 +0.j -0.015-0.014j]\n",
595+
" [ 0.018+0.009j -0.005+0.002j -0.015+0.014j 0.242+0.j ]]"
565596
]
566597
},
567598
"execution_count": 19,
@@ -579,6 +610,7 @@
579610
},
580611
{
581612
"cell_type": "markdown",
613+
"id": "5ea15f65-79d4-40a1-993a-82b011dc77e1",
582614
"metadata": {
583615
"raw_mimetype": "text/restructuredtext"
584616
},
@@ -590,7 +622,7 @@
590622
"metadata": {
591623
"celltoolbar": "Raw Cell Format",
592624
"kernelspec": {
593-
"display_name": "Python 3.10.8 ('numpy')",
625+
"display_name": "py312",
594626
"language": "python",
595627
"name": "python3"
596628
},
@@ -604,12 +636,7 @@
604636
"name": "python",
605637
"nbconvert_exporter": "python",
606638
"pygments_lexer": "ipython3",
607-
"version": "3.10.8 (main, Nov 4 2022, 13:48:29) [GCC 11.2.0]"
608-
},
609-
"vscode": {
610-
"interpreter": {
611-
"hash": "39c10650315d977fb13868ea1402e99f3e10e9885c2c202e692ae90b8995050d"
612-
}
639+
"version": "3.12.6"
613640
}
614641
},
615642
"nbformat": 4,

0 commit comments

Comments
 (0)