Skip to content

Commit

Permalink
update df trotter tutorial
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinsung committed Nov 6, 2023
1 parent 21d010f commit 7d1c82c
Showing 1 changed file with 36 additions and 17 deletions.
53 changes: 36 additions & 17 deletions docs/tutorials/03-double-factorized.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"\n",
"where $n_{\\sigma, i} = a^\\dagger_{\\sigma, i} a_{\\sigma, i}$ is the occupation number operator and $\\mathbf{J}_{ij}$ is a real symmetric matrix.\n",
"\n",
"In the cell below, we construct the Hamiltonian for a hydrogen molecule at a stretched bond length and then get the double-factorized representation of the Hamiltonian."
"In the cell below, we construct the Hamiltonian for an ethene molecule at a stretched bond length and then get the double-factorized representation of the Hamiltonian."
]
},
{
Expand All @@ -47,14 +47,34 @@
"import pyscf\n",
"import ffsim\n",
"\n",
"# Build an H2 molecule\n",
"# Build a stretched ethene molecule\n",
"bond_distance = 2.678\n",
"a = 0.5 * bond_distance\n",
"b = a + 0.5626\n",
"c = 0.9289\n",
"mol = pyscf.gto.Mole()\n",
"mol.build(atom=[[\"H\", (0, 0, 0)], [\"H\", (0, 0, 1.8)]], basis=\"sto-6g\", symmetry=\"d2h\")\n",
"mol.build(\n",
" atom=[\n",
" [\"C\", (0, 0, a)],\n",
" [\"C\", (0, 0, -a)],\n",
" [\"H\", (0, c, b)],\n",
" [\"H\", (0, -c, b)],\n",
" [\"H\", (0, c, -b)],\n",
" [\"H\", (0, -c, -b)],\n",
" ],\n",
" basis=\"sto-6g\",\n",
" symmetry=\"d2h\",\n",
")\n",
"hartree_fock = pyscf.scf.RHF(mol)\n",
"hartree_fock.kernel()\n",
"\n",
"# Define active space\n",
"active_space = range(mol.nelectron // 2 - 2, mol.nelectron // 2 + 2)\n",
"\n",
"# Get molecular data and molecular Hamiltonian (one- and two-body tensors)\n",
"mol_data = ffsim.MolecularData.from_hartree_fock(hartree_fock)\n",
"mol_data = ffsim.MolecularData.from_hartree_fock(\n",
" hartree_fock, active_space=active_space\n",
")\n",
"norb = mol_data.norb\n",
"nelec = mol_data.nelec\n",
"mol_hamiltonian = mol_data.hamiltonian\n",
Expand All @@ -69,7 +89,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Here, `mol_hamiltonian` is an instance of `MolecularHamiltonian`, a dataclass that stores the one- and two-body tensors, and `df_hamiltonian` is an instance of `DoubleFactorizedHamiltonian`, a dataclass that stores the updated one-body-tensor, diagonal Coulomb matrices, and orbital rotations. In the cell below, we print out the tensors describing the original and double-factorized representations."
"Here, `mol_hamiltonian` is an instance of `MolecularHamiltonian`, a dataclass that stores the one- and two-body tensors, and `df_hamiltonian` is an instance of `DoubleFactorizedHamiltonian`, a dataclass that stores the updated one-body-tensor, diagonal Coulomb matrices, and orbital rotations. In the cell below, we print out the shapes of the tensors describing the original and double-factorized representations."
]
},
{
Expand All @@ -78,26 +98,25 @@
"metadata": {},
"outputs": [],
"source": [
"# Print some information\n",
"print(\"Original representation\")\n",
"print(\"-----------------------\")\n",
"print(\"One-body tensor:\")\n",
"print(mol_hamiltonian.one_body_tensor)\n",
"print(\"One-body tensor shape:\")\n",
"print(mol_hamiltonian.one_body_tensor.shape)\n",
"print()\n",
"print(\"Two-body tensor:\")\n",
"print(mol_hamiltonian.two_body_tensor)\n",
"print(\"Two-body tensor shape:\")\n",
"print(mol_hamiltonian.two_body_tensor.shape)\n",
"print()\n",
"\n",
"print(\"Double-factorized representation\")\n",
"print(\"--------------------------------\")\n",
"print(\"One-body tensor:\")\n",
"print(df_hamiltonian.one_body_tensor)\n",
"print(\"One-body tensor shape:\")\n",
"print(df_hamiltonian.one_body_tensor.shape)\n",
"print()\n",
"print(\"Diagonal Coulomb matrices:\")\n",
"print(df_hamiltonian.diag_coulomb_mats)\n",
"print(\"Diagonal Coulomb matrices shape:\")\n",
"print(df_hamiltonian.diag_coulomb_mats.shape)\n",
"print()\n",
"print(\"Orbital rotations:\")\n",
"print(df_hamiltonian.orbital_rotations)"
"print(\"Orbital rotations shape:\")\n",
"print(df_hamiltonian.orbital_rotations.shape)"
]
},
{
Expand Down Expand Up @@ -263,7 +282,7 @@
"source": [
"import scipy.sparse.linalg\n",
"\n",
"time = 1.0\n",
"time = 5.0\n",
"\n",
"exact_state = scipy.sparse.linalg.expm_multiply(\n",
" -1j * time * hamiltonian,\n",
Expand Down

0 comments on commit 7d1c82c

Please sign in to comment.