|
2 | 2 | "cells": [ |
3 | 3 | { |
4 | 4 | "cell_type": "markdown", |
5 | | - "metadata": { |
6 | | - "id": "b000658d0d2b" |
7 | | - }, |
| 5 | + "metadata": {}, |
8 | 6 | "source": [ |
9 | 7 | "##### Copyright 2020 The OpenFermion Developers" |
10 | 8 | ] |
11 | 9 | }, |
12 | 10 | { |
13 | 11 | "cell_type": "code", |
14 | 12 | "execution_count": null, |
15 | | - "metadata": { |
16 | | - "cellView": "form", |
17 | | - "id": "906e07f6e562" |
18 | | - }, |
| 13 | + "metadata": {}, |
19 | 14 | "outputs": [], |
20 | 15 | "source": [ |
21 | 16 | "#@title Licensed under the Apache License, Version 2.0 (the \"License\");\n", |
|
33 | 28 | }, |
34 | 29 | { |
35 | 30 | "cell_type": "markdown", |
36 | | - "metadata": { |
37 | | - "id": "7cac3ba4e0b6" |
38 | | - }, |
| 31 | + "metadata": {}, |
39 | 32 | "source": [ |
40 | 33 | "# FQE vs OpenFermion vs Cirq: Diagonal Coulomb Operators" |
41 | 34 | ] |
42 | 35 | }, |
43 | 36 | { |
44 | 37 | "cell_type": "markdown", |
45 | | - "metadata": { |
46 | | - "id": "194e5ebc2e40" |
47 | | - }, |
| 38 | + "metadata": {}, |
48 | 39 | "source": [ |
49 | 40 | "<table class=\"tfo-notebook-buttons\" align=\"left\">\n", |
50 | 41 | " <td>\n", |
|
64 | 55 | }, |
65 | 56 | { |
66 | 57 | "cell_type": "markdown", |
67 | | - "metadata": { |
68 | | - "id": "027a78b74a41" |
69 | | - }, |
| 58 | + "metadata": {}, |
70 | 59 | "source": [ |
71 | 60 | "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." |
72 | 61 | ] |
73 | 62 | }, |
74 | 63 | { |
75 | 64 | "cell_type": "code", |
76 | 65 | "execution_count": null, |
77 | | - "metadata": { |
78 | | - "id": "1b44f1bf44c3" |
79 | | - }, |
| 66 | + "metadata": {}, |
80 | 67 | "outputs": [], |
81 | 68 | "source": [ |
82 | 69 | "try:\n", |
|
88 | 75 | { |
89 | 76 | "cell_type": "code", |
90 | 77 | "execution_count": null, |
91 | | - "metadata": { |
92 | | - "id": "a623fa4c377a" |
93 | | - }, |
| 78 | + "metadata": {}, |
94 | 79 | "outputs": [], |
95 | 80 | "source": [ |
96 | 81 | "from itertools import product\n", |
|
107 | 92 | { |
108 | 93 | "cell_type": "code", |
109 | 94 | "execution_count": null, |
110 | | - "metadata": { |
111 | | - "id": "07eb37e66cea" |
112 | | - }, |
| 95 | + "metadata": {}, |
113 | 96 | "outputs": [], |
114 | 97 | "source": [ |
115 | 98 | "#Utility function\n", |
|
168 | 151 | }, |
169 | 152 | { |
170 | 153 | "cell_type": "markdown", |
171 | | - "metadata": { |
172 | | - "id": "4f4ed62f910c" |
173 | | - }, |
| 154 | + "metadata": {}, |
174 | 155 | "source": [ |
175 | 156 | "The first example we will perform is diagonal Coulomb evolution on the Hartree-Fock state. The diagonal Coulomb operator is defined as\n", |
176 | 157 | "\n", |
|
189 | 170 | { |
190 | 171 | "cell_type": "code", |
191 | 172 | "execution_count": null, |
192 | | - "metadata": { |
193 | | - "id": "2d22924fcb4e" |
194 | | - }, |
| 173 | + "metadata": {}, |
195 | 174 | "outputs": [], |
196 | 175 | "source": [ |
197 | 176 | "norbs = 4\n", |
|
213 | 192 | }, |
214 | 193 | { |
215 | 194 | "cell_type": "markdown", |
216 | | - "metadata": { |
217 | | - "id": "f4b8c93472be" |
218 | | - }, |
| 195 | + "metadata": {}, |
219 | 196 | "source": [ |
220 | 197 | "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" |
221 | 198 | ] |
222 | 199 | }, |
223 | 200 | { |
224 | 201 | "cell_type": "code", |
225 | 202 | "execution_count": null, |
226 | | - "metadata": { |
227 | | - "id": "56aa8604a016" |
228 | | - }, |
| 203 | + "metadata": {}, |
229 | 204 | "outputs": [], |
230 | 205 | "source": [ |
231 | 206 | "tei_compressed = np.random.randn(tedim**2).reshape((tedim, tedim))\n", |
|
246 | 221 | }, |
247 | 222 | { |
248 | 223 | "cell_type": "markdown", |
249 | | - "metadata": { |
250 | | - "id": "5270f0939273" |
251 | | - }, |
| 224 | + "metadata": {}, |
252 | 225 | "source": [ |
253 | 226 | "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\". " |
254 | 227 | ] |
255 | 228 | }, |
256 | 229 | { |
257 | 230 | "cell_type": "code", |
258 | 231 | "execution_count": null, |
259 | | - "metadata": { |
260 | | - "id": "d7ee0994bdc2" |
261 | | - }, |
| 232 | + "metadata": {}, |
262 | 233 | "outputs": [], |
263 | 234 | "source": [ |
264 | 235 | "alpha_occs = [list(range(fci_graph.nalpha()))]\n", |
|
280 | 251 | }, |
281 | 252 | { |
282 | 253 | "cell_type": "markdown", |
283 | | - "metadata": { |
284 | | - "id": "9797ff1de370" |
285 | | - }, |
| 254 | + "metadata": {}, |
286 | 255 | "source": [ |
287 | 256 | "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." |
288 | 257 | ] |
289 | 258 | }, |
290 | 259 | { |
291 | 260 | "cell_type": "code", |
292 | 261 | "execution_count": null, |
293 | | - "metadata": { |
294 | | - "id": "7a26d169c115" |
295 | | - }, |
| 262 | + "metadata": {}, |
296 | 263 | "outputs": [], |
297 | 264 | "source": [ |
298 | 265 | "norbs = 6\n", |
|
311 | 278 | }, |
312 | 279 | { |
313 | 280 | "cell_type": "markdown", |
314 | | - "metadata": { |
315 | | - "id": "89354765d52a" |
316 | | - }, |
| 281 | + "metadata": {}, |
317 | 282 | "source": [ |
318 | 283 | "We need to build our Diagoanl Coulomb operator For this bigger system." |
319 | 284 | ] |
320 | 285 | }, |
321 | 286 | { |
322 | 287 | "cell_type": "code", |
323 | 288 | "execution_count": null, |
324 | | - "metadata": { |
325 | | - "id": "eec8fa7be891" |
326 | | - }, |
| 289 | + "metadata": {}, |
327 | 290 | "outputs": [], |
328 | 291 | "source": [ |
329 | 292 | "tei_compressed = np.random.randn(tedim**2).reshape((tedim, tedim))\n", |
|
344 | 307 | }, |
345 | 308 | { |
346 | 309 | "cell_type": "markdown", |
347 | | - "metadata": { |
348 | | - "id": "0bab89d13edf" |
349 | | - }, |
| 310 | + "metadata": {}, |
350 | 311 | "source": [ |
351 | 312 | "Now we can convert our wavefunction to a cirq wavefunction, evolve under the diagonal_coulomb operator we constructed and then compare the outputs." |
352 | 313 | ] |
353 | 314 | }, |
354 | 315 | { |
355 | 316 | "cell_type": "code", |
356 | 317 | "execution_count": null, |
357 | | - "metadata": { |
358 | | - "id": "e28ac36062b7" |
359 | | - }, |
| 318 | + "metadata": {}, |
360 | 319 | "outputs": [], |
361 | 320 | "source": [ |
362 | 321 | "cirq_wfn = fqe.to_cirq(fqe_wfn).reshape((-1, 1))\n", |
|
368 | 327 | { |
369 | 328 | "cell_type": "code", |
370 | 329 | "execution_count": null, |
371 | | - "metadata": { |
372 | | - "id": "5a1a81b3c86a" |
373 | | - }, |
| 330 | + "metadata": {}, |
374 | 331 | "outputs": [], |
375 | 332 | "source": [ |
376 | 333 | "fqe_wfn = fqe_wfn.time_evolve(1, dc_ham)\n", |
|
381 | 338 | { |
382 | 339 | "cell_type": "code", |
383 | 340 | "execution_count": null, |
384 | | - "metadata": { |
385 | | - "id": "866925b171a5" |
386 | | - }, |
| 341 | + "metadata": {}, |
387 | 342 | "outputs": [], |
388 | 343 | "source": [ |
389 | 344 | "print(\"From Cirq Evolution\")\n", |
|
395 | 350 | }, |
396 | 351 | { |
397 | 352 | "cell_type": "markdown", |
398 | | - "metadata": { |
399 | | - "id": "7108f16f2401" |
400 | | - }, |
| 353 | + "metadata": {}, |
401 | 354 | "source": [ |
402 | 355 | "Finally, we can compare against evolving each term of $V$ individually." |
403 | 356 | ] |
404 | 357 | }, |
405 | 358 | { |
406 | 359 | "cell_type": "code", |
407 | 360 | "execution_count": null, |
408 | | - "metadata": { |
409 | | - "id": "8a5588d11373" |
410 | | - }, |
| 361 | + "metadata": {}, |
411 | 362 | "outputs": [], |
412 | 363 | "source": [ |
413 | 364 | "fqe_wfn = fqe.Wavefunction([[n_elec, sz, norbs]])\n", |
|
421 | 372 | " fqe_wfn.get_coeff((n_elec, sz)))\n", |
422 | 373 | "print(\"Individual term evolution is equivalent\")" |
423 | 374 | ] |
| 375 | + }, |
| 376 | + { |
| 377 | + "cell_type": "code", |
| 378 | + "execution_count": null, |
| 379 | + "metadata": {}, |
| 380 | + "outputs": [], |
| 381 | + "source": [] |
424 | 382 | } |
425 | 383 | ], |
426 | 384 | "metadata": { |
427 | | - "colab": { |
428 | | - "name": "diagonal_coulomb_evolution.ipynb", |
429 | | - "toc_visible": true |
430 | | - }, |
431 | 385 | "kernelspec": { |
432 | 386 | "display_name": "Python 3", |
| 387 | + "language": "python", |
433 | 388 | "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" |
434 | 401 | } |
435 | 402 | }, |
436 | 403 | "nbformat": 4, |
437 | | - "nbformat_minor": 0 |
| 404 | + "nbformat_minor": 4 |
438 | 405 | } |
0 commit comments