Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
216 changes: 152 additions & 64 deletions docs/fqe/guide/introduction.ipynb

Large diffs are not rendered by default.

123 changes: 78 additions & 45 deletions docs/fqe/tutorials/diagonal_coulomb_evolution.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,20 @@
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"metadata": {
"id": "b000658d0d2b"
},
"source": [
"##### Copyright 2020 The OpenFermion Developers"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"cellView": "form",
"id": "906e07f6e562"
},
"outputs": [],
"source": [
"#@title Licensed under the Apache License, Version 2.0 (the \"License\");\n",
Expand All @@ -28,14 +33,18 @@
},
{
"cell_type": "markdown",
"metadata": {},
"metadata": {
"id": "7cac3ba4e0b6"
},
"source": [
"# FQE vs OpenFermion vs Cirq: Diagonal Coulomb Operators"
]
},
{
"cell_type": "markdown",
"metadata": {},
"metadata": {
"id": "194e5ebc2e40"
},
"source": [
"<table class=\"tfo-notebook-buttons\" align=\"left\">\n",
" <td>\n",
Expand All @@ -55,15 +64,19 @@
},
{
"cell_type": "markdown",
"metadata": {},
"metadata": {
"id": "027a78b74a41"
},
"source": [
"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."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"id": "1b44f1bf44c3"
},
"outputs": [],
"source": [
"try:\n",
Expand All @@ -75,7 +88,9 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"id": "a623fa4c377a"
},
"outputs": [],
"source": [
"from itertools import product\n",
Expand All @@ -92,7 +107,9 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"id": "07eb37e66cea"
},
"outputs": [],
"source": [
"#Utility function\n",
Expand Down Expand Up @@ -151,7 +168,9 @@
},
{
"cell_type": "markdown",
"metadata": {},
"metadata": {
"id": "4f4ed62f910c"
},
"source": [
"The first example we will perform is diagonal Coulomb evolution on the Hartree-Fock state. The diagonal Coulomb operator is defined as\n",
"\n",
Expand All @@ -170,7 +189,9 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"id": "2d22924fcb4e"
},
"outputs": [],
"source": [
"norbs = 4\n",
Expand All @@ -192,15 +213,19 @@
},
{
"cell_type": "markdown",
"metadata": {},
"metadata": {
"id": "f4b8c93472be"
},
"source": [
"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"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"id": "56aa8604a016"
},
"outputs": [],
"source": [
"tei_compressed = np.random.randn(tedim**2).reshape((tedim, tedim))\n",
Expand All @@ -221,15 +246,19 @@
},
{
"cell_type": "markdown",
"metadata": {},
"metadata": {
"id": "5270f0939273"
},
"source": [
"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\". "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"id": "d7ee0994bdc2"
},
"outputs": [],
"source": [
"alpha_occs = [list(range(fci_graph.nalpha()))]\n",
Expand All @@ -251,15 +280,19 @@
},
{
"cell_type": "markdown",
"metadata": {},
"metadata": {
"id": "9797ff1de370"
},
"source": [
"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."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"id": "7a26d169c115"
},
"outputs": [],
"source": [
"norbs = 6\n",
Expand All @@ -278,15 +311,19 @@
},
{
"cell_type": "markdown",
"metadata": {},
"metadata": {
"id": "89354765d52a"
},
"source": [
"We need to build our Diagoanl Coulomb operator For this bigger system."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"id": "eec8fa7be891"
},
"outputs": [],
"source": [
"tei_compressed = np.random.randn(tedim**2).reshape((tedim, tedim))\n",
Expand All @@ -307,15 +344,19 @@
},
{
"cell_type": "markdown",
"metadata": {},
"metadata": {
"id": "0bab89d13edf"
},
"source": [
"Now we can convert our wavefunction to a cirq wavefunction, evolve under the diagonal_coulomb operator we constructed and then compare the outputs."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"id": "e28ac36062b7"
},
"outputs": [],
"source": [
"cirq_wfn = fqe.to_cirq(fqe_wfn).reshape((-1, 1))\n",
Expand All @@ -327,7 +368,9 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"id": "5a1a81b3c86a"
},
"outputs": [],
"source": [
"fqe_wfn = fqe_wfn.time_evolve(1, dc_ham)\n",
Expand All @@ -338,7 +381,9 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"id": "866925b171a5"
},
"outputs": [],
"source": [
"print(\"From Cirq Evolution\")\n",
Expand All @@ -350,15 +395,19 @@
},
{
"cell_type": "markdown",
"metadata": {},
"metadata": {
"id": "7108f16f2401"
},
"source": [
"Finally, we can compare against evolving each term of $V$ individually."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"id": "8a5588d11373"
},
"outputs": [],
"source": [
"fqe_wfn = fqe.Wavefunction([[n_elec, sz, norbs]])\n",
Expand All @@ -372,34 +421,18 @@
" fqe_wfn.get_coeff((n_elec, sz)))\n",
"print(\"Individual term evolution is equivalent\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"colab": {
"name": "diagonal_coulomb_evolution.ipynb",
"toc_visible": true
},
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.8"
}
},
"nbformat": 4,
"nbformat_minor": 4
"nbformat_minor": 0
}
Loading