Download this notebook (.ipynb + data files)
3. The Square Hubbard Model at Half Filling#
Author: Ryan Levy
import os
# This is in case you have a GPU-enabled JAX but are running on CPU.
os.environ['JAX_PLATFORMS'] = 'cpu'
# Don't preallocate GPU memory, so that several notebooks can share the same GPU
os.environ["XLA_PYTHON_CLIENT_PREALLOCATE"] = "false"
# use x64 numbers
from jax import config
config.update("jax_enable_x64", True)
import matplotlib.pyplot as plt
import numpy as np
# create scratch directory in notebook path
%mkdir -p {_dh[0]}/data
%cd -q {_dh[0]}/data
3.1. Physics Background#
The Hubbard model at half filling (\(n=1\)) has a special symmetry known as particle-hole symmetry, which allows auxiliary-field methods to be sign-free. However, care must be taken to make sure that phaseless/constrained-path AFQMC is used properly to exploit said symmetry.
[1] M. Qin, H. Shi, and S. Zhang, Benchmark study of the two-dimensional Hubbard model with auxiliary-field quantum Monte Carlo method, Phys. Rev. B 94, 085103, published 4 August 2016.
DOI: https://doi.org/10.1103/PhysRevB.94.085103
3.2. Lattice and Hamiltonian Setup#
# taken from 10.1103/PhysRevB.45.10741, U => E_0
E0_n1_lookup = {4 : -13.62185,
8 : -8.46888}
U = 4.0
from safiretools import Lattice
lattice = Lattice.from_type('square', (4, 4), boundaries=('periodic', 'periodic'), twists=(0.0, 0.0))
Ne = lattice.N_sites//2
nelec = (Ne,Ne)
nelec
from safiretools import vis
vis.plot_lattice(lattice)
plt.show()
The Hamiltonian will be
from safiretools import LatticeHamiltonian
hamiltonian = LatticeHamiltonian.from_lattice(lattice, U=U)
hamiltonian_hf = LatticeHamiltonian.from_lattice(
lattice,
U=U, # if you want an effective U, you can change this
)
# get the one-body Hamiltonian
T = hamiltonian_hf.get_one_body().toarray().reshape(2,lattice.N_sites,lattice.N_sites)
3.3. GHF Trial#
Because of the open shell at half filling, we’ll follow Ref. [1] and use a GHF trial with AFM constrained to the X-Y plane (Eq. 14),
where \(M_i= (-1)^i\Delta_i\).
3.3.1. Aside: Custom Hartree-Fock Solver#
We’ll want to optimize \(M\) directly, and to do this we’ll use AutoHF’s custom ansatz support to build a modification of the DIAG ansatz.
To do that we’ll need:
orbitalFunc, which takes astateand produces the orbitalsrdmFunc, which takes astateand produces the rdm \(\langle c^\dagger_{\sigma i}c_{\sigma^\prime j}\rangle\)state0, the initial statestate0_ref, the initial state that should correspond to e.g. \(U=0\)
import jax.numpy as jnp
from autohf import solve_hf, AutoHFHamiltonian
from autohf.solver import sd_to_rdm_noncollinear
# get the (-1)^i which is really the checkerboard pattern for a 4×4
signs = np.array([ (-1)**np.sum(s.coord) for s in lattice.sites])
N = lattice.N_sites
# convert T -> GHF format
TGHF_ = np.block([[T[0],np.zeros_like(T[1])],
[np.zeros_like(T[0]),T[1]]])
TGHF_ = jnp.array(TGHF_)
def orbitalFunc(state):
# take the hopping matrix TGHF, and "set" M on the off-diagonal blocks
TGHF = TGHF_+0.0
TGHF = TGHF.at[N+np.arange(N),np.arange(N)].set(signs*state)
TGHF = TGHF.at[np.arange(N),N+np.arange(N)].set(signs*state)
lams,vecs = jnp.linalg.eigh(TGHF)
return jnp.stack([vecs[:,:2*Ne]])
def rdmFunc(state):
o = orbitalFunc(state)
return sd_to_rdm_noncollinear(o)
def checkPH(state):
'''check that the spectrum of the faux HF state is PH symmetric'''
# take the hopping matrix TGHF, and "set" M on the off-diagonal blocks
TGHF = TGHF_+0.0
TGHF = TGHF.at[N+np.arange(N),np.arange(N)].set(signs*state)
TGHF = TGHF.at[np.arange(N),N+np.arange(N)].set(signs*state)
lams,vecs = jnp.linalg.eigh(TGHF)
# verify symmetry
return np.allclose(lams,-lams[::-1])
hf_settings = {
"verbose": False,
"plot": False,
"steps": 200,
"seed": 1479,
"noncollinear": True,
"gpu": False,
"ansatz": "CUSTOM",
"opt_method": "lbfgs",
"batch_size": 16,
"nelec": nelec,
}
rng = np.random.default_rng(42)
state0_ref = 0.0 * np.arange(N).reshape(N)
state0 = state0_ref + rng.normal(scale=0.01, size=(hf_settings["batch_size"], N))
dataHFC = solve_hf(
hamiltonian=AutoHFHamiltonian(hamiltonian_hf),
settings=hf_settings,
state2orbitals=orbitalFunc,
state2rdm=rdmFunc,
state0=state0,
state0_ref=state0_ref,
)
Let’s check out what \(M\) values we got.
dataHFC[0]["state"]
plt.imshow(dataHFC[0]["state"].reshape(4,4))
Hmm… This looks like we haven’t fully converged into a translationally invariant solution, but it’s close. Let’s increase the precision!
⚠️ Warning This notebook is set up for the CPU; the following cell takes a while (the GPU is a bit faster if you have one).
hf_settings = {
"verbose": False,
"plot": False,
"steps": 2000, # increase
"seed": 149,
"noncollinear": True,
"gpu": False,
"ansatz": "CUSTOM",
"opt_method": "lbfgs",
"batch_size": 16,
"nelec": nelec,
}
rng = np.random.default_rng(42)
state0_ref = 0.0 * np.arange(N).reshape(N)
state0 = state0_ref + rng.normal(scale=0.01, size=(hf_settings["batch_size"], N))
dataHFC2 = solve_hf(
hamiltonian=AutoHFHamiltonian(hamiltonian_hf),
settings=hf_settings,
state2orbitals=orbitalFunc,
state2rdm=rdmFunc,
state0=state0,
state0_ref=state0_ref,
jaxoptargs=dict(tol=1e-8), # tune to get closer to the minimum
)
dataHFC2[0]["state"]
checkPH(dataHFC2[0]["state"])
plt.imshow(dataHFC2[0]["state"].reshape(4,4))
Let’s check that this is a better energy than the previous energy.
dataHFC2[0]["E"] < dataHFC[0]["E"]
Great!
Now let’s check if we can guess a better state by explicitly restoring translation invariance.
uni_state = np.ones(lattice.N_sites)*np.mean(np.abs(dataHFC2[0]["state"]))
np.isclose(dataHFC2[1]["energy_func"](dataHFC2[0]["state"]),dataHFC2[1]["energy_func"](uni_state))
So we see we’ve reached a minimum, and that a constant \(M\) is the same as our nearly constant optimized \(M_i\).
3.3.2. Preparing the SAFIRE Input Files#
Next, we turn the AutoHF orbitals into a SAFIRE trial wavefunction.
from safiretools import Wavefunction
wavefunction = Wavefunction.from_single_determinant(np.array(dataHFC2[0]["orbitals"][0].reshape(2, N, -1)))
from safiretools import write_jobfile
write_jobfile(
"afqmc.json",
{
"execute": {
"wavefunction": wavefunction,
"hamiltonian": hamiltonian,
"timestep": 0.005,
"steps": 20000,
"equilibration_steps": 1000,
"num_walkers": 640,
}
}
)
!mpirun -n 16 $AFQMC_EXEC afqmc.json
from safiretools import Results
results = Results("afqmc.results.h5")
vis.plot_timeseries(results, skip=250)
E_ref = E0_n1_lookup[U]
plt.axhline(E_ref, color="crimson")
3.3.3. For Further Thinking#
What if we didn’t use the correct signs (\(M_i = (-1)^i\Delta_i\)) for the HF ansatz? Could we construct an even more constrained wavefunction?
What do the local spin/charge observables of the optimized ansatz look like?
What happens for \(U=8\)? Do we need a different wavefunction?
What happens if you start from a free-electron state instead of the HF state? (
free_wfn = Wavefunction.from_free_electron(hamiltonian, nelec, spin_symm="nc"); this warns, since the untwisted lattice is open-shell at half filling.)