Skip to content

Commit cfb4d94

Browse files
committed
Run notebooks through nbfmt
Builds are failing on GitHub because some of the notebooks need to be reformatted. Possibly this is a consequence of a version dependency having changed somewhere. (The requirements.txt file does not pin versions, and since the CI workflows use the same requirements.txt, a new version of something there could influence the results.)
1 parent 694523a commit cfb4d94

File tree

4 files changed

+296
-176
lines changed

4 files changed

+296
-176
lines changed

docs/kpz/kpz.ipynb

Lines changed: 91 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
"cell_type": "code",
55
"execution_count": 1,
66
"id": "bfbe98f2",
7-
"metadata": {},
7+
"metadata": {
8+
"id": "a3cdc6c47599"
9+
},
810
"outputs": [],
911
"source": [
1012
"##### Copyright 2023 The Cirq Developers"
@@ -14,7 +16,10 @@
1416
"cell_type": "code",
1517
"execution_count": 2,
1618
"id": "161a0876",
17-
"metadata": {},
19+
"metadata": {
20+
"cellView": "form",
21+
"id": "906e07f6e562"
22+
},
1823
"outputs": [],
1924
"source": [
2025
"#@title Licensed under the Apache License, Version 2.0 (the \"License\");\n",
@@ -33,15 +38,19 @@
3338
{
3439
"cell_type": "markdown",
3540
"id": "9d29cea2",
36-
"metadata": {},
41+
"metadata": {
42+
"id": "d895d2965a7e"
43+
},
3744
"source": [
3845
"# Kardar-Parisi-Zhang Dynamics in the Heisenberg Spin Chain"
3946
]
4047
},
4148
{
4249
"cell_type": "markdown",
4350
"id": "c4a1ff2c",
44-
"metadata": {},
51+
"metadata": {
52+
"id": "c5cb019fcfbc"
53+
},
4554
"source": [
4655
"<table class=\"tfo-notebook-buttons\" align=\"left\">\n",
4756
" <td>\n",
@@ -62,7 +71,9 @@
6271
{
6372
"cell_type": "markdown",
6473
"id": "1de2dd3b",
65-
"metadata": {},
74+
"metadata": {
75+
"id": "70f3cee60e01"
76+
},
6677
"source": [
6778
"Before beginning, we will import the necessary modules into the notebook."
6879
]
@@ -71,7 +82,9 @@
7182
"cell_type": "code",
7283
"execution_count": 3,
7384
"id": "cef7a354",
74-
"metadata": {},
85+
"metadata": {
86+
"id": "68eb3591185f"
87+
},
7588
"outputs": [],
7689
"source": [
7790
"try:\n",
@@ -99,7 +112,9 @@
99112
{
100113
"cell_type": "markdown",
101114
"id": "f4110f55",
102-
"metadata": {},
115+
"metadata": {
116+
"id": "186968984e10"
117+
},
103118
"source": [
104119
"### Motivation and Background\n",
105120
"\n",
@@ -124,7 +139,9 @@
124139
"cell_type": "code",
125140
"execution_count": 4,
126141
"id": "b7477208",
127-
"metadata": {},
142+
"metadata": {
143+
"id": "afd23812124c"
144+
},
128145
"outputs": [],
129146
"source": [
130147
"num_cycles = 2\n",
@@ -139,7 +156,9 @@
139156
{
140157
"cell_type": "markdown",
141158
"id": "af80864e",
142-
"metadata": {},
159+
"metadata": {
160+
"id": "53c75bc5619a"
161+
},
143162
"source": [
144163
"By default, this uses `2*num_cycles` qubits, which is the minimum number of qubits needed for the transferred magnetization to be independent of system size (in the experiment we use 46 qubits and go to cycle 23). The `KPZExperiment` comes with the `num_init_states` initial bitstrings prepared:"
145164
]
@@ -148,7 +167,9 @@
148167
"cell_type": "code",
149168
"execution_count": 5,
150169
"id": "41c5584d",
151-
"metadata": {},
170+
"metadata": {
171+
"id": "4194e9071392"
172+
},
152173
"outputs": [
153174
{
154175
"data": {
@@ -174,7 +195,9 @@
174195
{
175196
"cell_type": "markdown",
176197
"id": "afabba4b",
177-
"metadata": {},
198+
"metadata": {
199+
"id": "b65444f94259"
200+
},
178201
"source": [
179202
"It also prepares the circuits that we need to run. For example, the circuit corresponding to the first initial state is:"
180203
]
@@ -183,7 +206,9 @@
183206
"cell_type": "code",
184207
"execution_count": 6,
185208
"id": "da71a7b2",
186-
"metadata": {},
209+
"metadata": {
210+
"id": "00fc65e3cb43"
211+
},
187212
"outputs": [
188213
{
189214
"data": {
@@ -218,7 +243,9 @@
218243
{
219244
"cell_type": "markdown",
220245
"id": "3fd3828b",
221-
"metadata": {},
246+
"metadata": {
247+
"id": "0be4b1e23a86"
248+
},
222249
"source": [
223250
"To run the experiment, we can either use `KPZExperiment.run_experiment()` or `KPZExperiment.run_experiment_amplitudes()`. In either case, we have to input a Cirq sampler. `run_experiment()` samples bitstrings, closer to what is done in the experiment, whereas `run_experiment_amplitudes()` uses amplitudes from a statevector simulation (and hence requires a `cirq.SimulatesAmplitudes` sampler). In the actual experiment, we apply a post-selection to mitigate against effects of $T_1$; this is not done here because this tutorial uses noiseless simulations.\n",
224251
"\n",
@@ -229,7 +256,9 @@
229256
"cell_type": "code",
230257
"execution_count": 7,
231258
"id": "d3a05a0b",
232-
"metadata": {},
259+
"metadata": {
260+
"id": "1e320cda8aa4"
261+
},
233262
"outputs": [
234263
{
235264
"name": "stderr",
@@ -250,7 +279,9 @@
250279
{
251280
"cell_type": "markdown",
252281
"id": "3df95b0e",
253-
"metadata": {},
282+
"metadata": {
283+
"id": "babe2e86ac00"
284+
},
254285
"source": [
255286
"The measured bitstrings are contained in `res_bitstrings.bitstrs`, which has shape `(num_init_states, reps, num_qubits)`"
256287
]
@@ -259,7 +290,9 @@
259290
"cell_type": "code",
260291
"execution_count": 8,
261292
"id": "b3d73f20",
262-
"metadata": {},
293+
"metadata": {
294+
"id": "f9778320f6a5"
295+
},
263296
"outputs": [
264297
{
265298
"data": {
@@ -327,7 +360,9 @@
327360
{
328361
"cell_type": "markdown",
329362
"id": "944ae2c9",
330-
"metadata": {},
363+
"metadata": {
364+
"id": "b1321a162049"
365+
},
331366
"source": [
332367
"As you can see, the number of excitations is conserved, as expected because fSim gates are number conserving."
333368
]
@@ -336,7 +371,9 @@
336371
"cell_type": "code",
337372
"execution_count": 9,
338373
"id": "0d41941f",
339-
"metadata": {},
374+
"metadata": {
375+
"id": "6271edef408e"
376+
},
340377
"outputs": [],
341378
"source": [
342379
"num_excitations = np.sum(res_bitstrs.bitstrs, axis=2)\n",
@@ -348,7 +385,9 @@
348385
{
349386
"cell_type": "markdown",
350387
"id": "c00b683a",
351-
"metadata": {},
388+
"metadata": {
389+
"id": "9d4e374a5e4d"
390+
},
352391
"source": [
353392
"The transferred magnetization, $\\mathcal{M}$ is computed by counting how many excitations are on the right side of the chain in the final state, contained in `res_bitstrs.num_right_final` (shape `(num_init_states, reps)`), and subtracting the number that were on the right initially, `res_bitstrs.num_right_initial` (shape `(num_init_states,)`), and then multiplying by 2. It is stored in `res_bitstrs.transferred_magnetization` (shape `(num_init_states, reps)`). We can plot a histogram of the transferred magnetization with:"
354393
]
@@ -357,7 +396,9 @@
357396
"cell_type": "code",
358397
"execution_count": 10,
359398
"id": "0627dbd5",
360-
"metadata": {},
399+
"metadata": {
400+
"id": "74bed681e879"
401+
},
361402
"outputs": [
362403
{
363404
"data": {
@@ -387,7 +428,9 @@
387428
{
388429
"cell_type": "markdown",
389430
"id": "a78c9395",
390-
"metadata": {},
431+
"metadata": {
432+
"id": "27f0fda1436d"
433+
},
391434
"source": [
392435
"The same histogram can be obtained without any error from finite `reps` by using `res_amplitudes`:"
393436
]
@@ -396,7 +439,9 @@
396439
"cell_type": "code",
397440
"execution_count": 11,
398441
"id": "18e2234d",
399-
"metadata": {},
442+
"metadata": {
443+
"id": "68ad7583b8e7"
444+
},
400445
"outputs": [
401446
{
402447
"data": {
@@ -426,7 +471,9 @@
426471
{
427472
"cell_type": "markdown",
428473
"id": "6d44c004",
429-
"metadata": {},
474+
"metadata": {
475+
"id": "57f7723b3a54"
476+
},
430477
"source": [
431478
"Finally, we are interested in the mean, variance, skewness, and kurtosis of this distribution. These are stored in `res_amplitudes.mean`, `res_amplitudes.variance`, `res_amplitudes.skewness`, and `res_amplitudes.kurtosis`, and similarly for `res_bitstrs`.\n",
432479
"\n",
@@ -437,7 +484,9 @@
437484
"cell_type": "code",
438485
"execution_count": 12,
439486
"id": "30507cb5",
440-
"metadata": {},
487+
"metadata": {
488+
"id": "245cad3944b5"
489+
},
441490
"outputs": [
442491
{
443492
"name": "stdout",
@@ -460,7 +509,9 @@
460509
{
461510
"cell_type": "markdown",
462511
"id": "d6c84778",
463-
"metadata": {},
512+
"metadata": {
513+
"id": "a1644a042bd2"
514+
},
464515
"source": [
465516
"For the paper, we ran exact density matrix simulations up to cycle 8, which give, for this choice of $t=2$, $\\mu=0.5$, and $(\\theta, \\phi) = (0.4\\pi, 0.8\\pi)$,\n",
466517
"\n",
@@ -479,7 +530,9 @@
479530
"cell_type": "code",
480531
"execution_count": 13,
481532
"id": "e572c635",
482-
"metadata": {},
533+
"metadata": {
534+
"id": "b45b27be9ee3"
535+
},
483536
"outputs": [
484537
{
485538
"name": "stdout",
@@ -636,7 +689,9 @@
636689
{
637690
"cell_type": "markdown",
638691
"id": "decdc752",
639-
"metadata": {},
692+
"metadata": {
693+
"id": "e096bf94b21b"
694+
},
640695
"source": [
641696
"Note that runtime is increasing exponentially $t$. The runtime, beyond $t=13$ or so, can be improved using GPUs if you have access to them, either using [qsim's built-in GPU backend](https://quantumai.google/reference/python/qsimcirq/QSimOptions), or [NVIDIA's cuQuantum](https://docs.nvidia.com/cuda/cuquantum/latest/appliance/cirq.html), the latter of which allows you to pool the resources of multiple GPUs. For instructions on picking hardware, see [this](https://quantumai.google/qsim/choose_hw) page, and for a tutorial on setting up the GPU backends, see [this](https://quantumai.google/qsim/tutorials/gcp_gpu) page. For the paper, we perform simulations to cycle 18 using 8 NVIDIA A100 GPUs.\n",
642697
"\n",
@@ -647,7 +702,9 @@
647702
"cell_type": "code",
648703
"execution_count": 14,
649704
"id": "46514834",
650-
"metadata": {},
705+
"metadata": {
706+
"id": "e01de6de7b3b"
707+
},
651708
"outputs": [
652709
{
653710
"data": {
@@ -700,51 +757,18 @@
700757
"\n",
701758
"plt.tight_layout()"
702759
]
703-
},
704-
{
705-
"cell_type": "code",
706-
"execution_count": null,
707-
"id": "b51f1408",
708-
"metadata": {},
709-
"outputs": [],
710-
"source": []
711-
},
712-
{
713-
"cell_type": "code",
714-
"execution_count": null,
715-
"id": "0cdcec41",
716-
"metadata": {},
717-
"outputs": [],
718-
"source": []
719-
},
720-
{
721-
"cell_type": "code",
722-
"execution_count": null,
723-
"id": "9dd7aa82",
724-
"metadata": {},
725-
"outputs": [],
726-
"source": []
727760
}
728761
],
729762
"metadata": {
763+
"colab": {
764+
"name": "kpz.ipynb",
765+
"toc_visible": true
766+
},
730767
"kernelspec": {
731-
"display_name": "Python 3 (ipykernel)",
732-
"language": "python",
768+
"display_name": "Python 3",
733769
"name": "python3"
734-
},
735-
"language_info": {
736-
"codemirror_mode": {
737-
"name": "ipython",
738-
"version": 3
739-
},
740-
"file_extension": ".py",
741-
"mimetype": "text/x-python",
742-
"name": "python",
743-
"nbconvert_exporter": "python",
744-
"pygments_lexer": "ipython3",
745-
"version": "3.10.10"
746770
}
747771
},
748772
"nbformat": 4,
749-
"nbformat_minor": 5
773+
"nbformat_minor": 0
750774
}

0 commit comments

Comments
 (0)