Skip to content

Commit 50b500e

Browse files
authored
docs: format notebooks with tensorflow-docs nbfmt (#1322)
Formats tracked Jupyter notebooks with `tensorflow_docs.tools.nbfmt` (--indent=1). Merge before #1299. Related: #1274.
1 parent a51cdcc commit 50b500e

14 files changed

Lines changed: 642 additions & 456 deletions

docs/fqe/guide/introduction.ipynb

Lines changed: 152 additions & 64 deletions
Large diffs are not rendered by default.

docs/fqe/tutorials/diagonal_coulomb_evolution.ipynb

Lines changed: 78 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,20 @@
22
"cells": [
33
{
44
"cell_type": "markdown",
5-
"metadata": {},
5+
"metadata": {
6+
"id": "b000658d0d2b"
7+
},
68
"source": [
79
"##### Copyright 2020 The OpenFermion Developers"
810
]
911
},
1012
{
1113
"cell_type": "code",
1214
"execution_count": null,
13-
"metadata": {},
15+
"metadata": {
16+
"cellView": "form",
17+
"id": "906e07f6e562"
18+
},
1419
"outputs": [],
1520
"source": [
1621
"#@title Licensed under the Apache License, Version 2.0 (the \"License\");\n",
@@ -28,14 +33,18 @@
2833
},
2934
{
3035
"cell_type": "markdown",
31-
"metadata": {},
36+
"metadata": {
37+
"id": "7cac3ba4e0b6"
38+
},
3239
"source": [
3340
"# FQE vs OpenFermion vs Cirq: Diagonal Coulomb Operators"
3441
]
3542
},
3643
{
3744
"cell_type": "markdown",
38-
"metadata": {},
45+
"metadata": {
46+
"id": "194e5ebc2e40"
47+
},
3948
"source": [
4049
"<table class=\"tfo-notebook-buttons\" align=\"left\">\n",
4150
" <td>\n",
@@ -55,15 +64,19 @@
5564
},
5665
{
5766
"cell_type": "markdown",
58-
"metadata": {},
67+
"metadata": {
68+
"id": "027a78b74a41"
69+
},
5970
"source": [
6071
"Special routines are available for evolving under a diagonal Coulomb operator. This notebook describes how to use these built in routines and how they work."
6172
]
6273
},
6374
{
6475
"cell_type": "code",
6576
"execution_count": null,
66-
"metadata": {},
77+
"metadata": {
78+
"id": "1b44f1bf44c3"
79+
},
6780
"outputs": [],
6881
"source": [
6982
"try:\n",
@@ -75,7 +88,9 @@
7588
{
7689
"cell_type": "code",
7790
"execution_count": null,
78-
"metadata": {},
91+
"metadata": {
92+
"id": "a623fa4c377a"
93+
},
7994
"outputs": [],
8095
"source": [
8196
"from itertools import product\n",
@@ -92,7 +107,9 @@
92107
{
93108
"cell_type": "code",
94109
"execution_count": null,
95-
"metadata": {},
110+
"metadata": {
111+
"id": "07eb37e66cea"
112+
},
96113
"outputs": [],
97114
"source": [
98115
"#Utility function\n",
@@ -151,7 +168,9 @@
151168
},
152169
{
153170
"cell_type": "markdown",
154-
"metadata": {},
171+
"metadata": {
172+
"id": "4f4ed62f910c"
173+
},
155174
"source": [
156175
"The first example we will perform is diagonal Coulomb evolution on the Hartree-Fock state. The diagonal Coulomb operator is defined as\n",
157176
"\n",
@@ -170,7 +189,9 @@
170189
{
171190
"cell_type": "code",
172191
"execution_count": null,
173-
"metadata": {},
192+
"metadata": {
193+
"id": "2d22924fcb4e"
194+
},
174195
"outputs": [],
175196
"source": [
176197
"norbs = 4\n",
@@ -192,15 +213,19 @@
192213
},
193214
{
194215
"cell_type": "markdown",
195-
"metadata": {},
216+
"metadata": {
217+
"id": "f4b8c93472be"
218+
},
196219
"source": [
197220
"Now we can define a random 2-electron operator $V$. To define $V$ we need a $4 \\times 4$ matrix. We will generate this matrix by making a full random two-electron integral matrix and then just take the diagonal elements"
198221
]
199222
},
200223
{
201224
"cell_type": "code",
202225
"execution_count": null,
203-
"metadata": {},
226+
"metadata": {
227+
"id": "56aa8604a016"
228+
},
204229
"outputs": [],
205230
"source": [
206231
"tei_compressed = np.random.randn(tedim**2).reshape((tedim, tedim))\n",
@@ -221,15 +246,19 @@
221246
},
222247
{
223248
"cell_type": "markdown",
224-
"metadata": {},
249+
"metadata": {
250+
"id": "5270f0939273"
251+
},
225252
"source": [
226253
"Evolution under $V$ can be computed by looking at each bitstring, seeing if $n_{p\\alpha}n_{q\\beta}$ is non-zero and then phasing that string by $V_{pq}$. For the Hartree-Fock state we can easily calculate this phase accumulation. The alpha and beta bitstrings are \"0001\" and \"0001\". "
227254
]
228255
},
229256
{
230257
"cell_type": "code",
231258
"execution_count": null,
232-
"metadata": {},
259+
"metadata": {
260+
"id": "d7ee0994bdc2"
261+
},
233262
"outputs": [],
234263
"source": [
235264
"alpha_occs = [list(range(fci_graph.nalpha()))]\n",
@@ -251,15 +280,19 @@
251280
},
252281
{
253282
"cell_type": "markdown",
254-
"metadata": {},
283+
"metadata": {
284+
"id": "9797ff1de370"
285+
},
255286
"source": [
256287
"We can now try this out for more than 2 electrons. Let's reinitialize a wavefunction on 6-orbitals with 4-electrons $S_{z} = 0$ to a random state."
257288
]
258289
},
259290
{
260291
"cell_type": "code",
261292
"execution_count": null,
262-
"metadata": {},
293+
"metadata": {
294+
"id": "7a26d169c115"
295+
},
263296
"outputs": [],
264297
"source": [
265298
"norbs = 6\n",
@@ -278,15 +311,19 @@
278311
},
279312
{
280313
"cell_type": "markdown",
281-
"metadata": {},
314+
"metadata": {
315+
"id": "89354765d52a"
316+
},
282317
"source": [
283318
"We need to build our Diagoanl Coulomb operator For this bigger system."
284319
]
285320
},
286321
{
287322
"cell_type": "code",
288323
"execution_count": null,
289-
"metadata": {},
324+
"metadata": {
325+
"id": "eec8fa7be891"
326+
},
290327
"outputs": [],
291328
"source": [
292329
"tei_compressed = np.random.randn(tedim**2).reshape((tedim, tedim))\n",
@@ -307,15 +344,19 @@
307344
},
308345
{
309346
"cell_type": "markdown",
310-
"metadata": {},
347+
"metadata": {
348+
"id": "0bab89d13edf"
349+
},
311350
"source": [
312351
"Now we can convert our wavefunction to a cirq wavefunction, evolve under the diagonal_coulomb operator we constructed and then compare the outputs."
313352
]
314353
},
315354
{
316355
"cell_type": "code",
317356
"execution_count": null,
318-
"metadata": {},
357+
"metadata": {
358+
"id": "e28ac36062b7"
359+
},
319360
"outputs": [],
320361
"source": [
321362
"cirq_wfn = fqe.to_cirq(fqe_wfn).reshape((-1, 1))\n",
@@ -327,7 +368,9 @@
327368
{
328369
"cell_type": "code",
329370
"execution_count": null,
330-
"metadata": {},
371+
"metadata": {
372+
"id": "5a1a81b3c86a"
373+
},
331374
"outputs": [],
332375
"source": [
333376
"fqe_wfn = fqe_wfn.time_evolve(1, dc_ham)\n",
@@ -338,7 +381,9 @@
338381
{
339382
"cell_type": "code",
340383
"execution_count": null,
341-
"metadata": {},
384+
"metadata": {
385+
"id": "866925b171a5"
386+
},
342387
"outputs": [],
343388
"source": [
344389
"print(\"From Cirq Evolution\")\n",
@@ -350,15 +395,19 @@
350395
},
351396
{
352397
"cell_type": "markdown",
353-
"metadata": {},
398+
"metadata": {
399+
"id": "7108f16f2401"
400+
},
354401
"source": [
355402
"Finally, we can compare against evolving each term of $V$ individually."
356403
]
357404
},
358405
{
359406
"cell_type": "code",
360407
"execution_count": null,
361-
"metadata": {},
408+
"metadata": {
409+
"id": "8a5588d11373"
410+
},
362411
"outputs": [],
363412
"source": [
364413
"fqe_wfn = fqe.Wavefunction([[n_elec, sz, norbs]])\n",
@@ -372,34 +421,18 @@
372421
" fqe_wfn.get_coeff((n_elec, sz)))\n",
373422
"print(\"Individual term evolution is equivalent\")"
374423
]
375-
},
376-
{
377-
"cell_type": "code",
378-
"execution_count": null,
379-
"metadata": {},
380-
"outputs": [],
381-
"source": []
382424
}
383425
],
384426
"metadata": {
427+
"colab": {
428+
"name": "diagonal_coulomb_evolution.ipynb",
429+
"toc_visible": true
430+
},
385431
"kernelspec": {
386432
"display_name": "Python 3",
387-
"language": "python",
388433
"name": "python3"
389-
},
390-
"language_info": {
391-
"codemirror_mode": {
392-
"name": "ipython",
393-
"version": 3
394-
},
395-
"file_extension": ".py",
396-
"mimetype": "text/x-python",
397-
"name": "python",
398-
"nbconvert_exporter": "python",
399-
"pygments_lexer": "ipython3",
400-
"version": "3.6.8"
401434
}
402435
},
403436
"nbformat": 4,
404-
"nbformat_minor": 4
437+
"nbformat_minor": 0
405438
}

0 commit comments

Comments
 (0)