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