Tuli99's picture
Gold / Method: Tuli99 dual-engine Hubbard ED with reproducibility package
6921858 verified
Raw History Blame
6.09 kB
# -*- coding: utf-8 -*-
"""Validate our own ED against the published independent ED reference
(validation/multisize_ED_table_kuku.md, team ku-ku, 2026-10-01).
Checks per point: E0(U=8), GS degeneracy, P_org(U=8), P_org(U=0) [Wick].
Also a brute-force Fock-space check of the Wick 4-operator identity.
Usage: python validate_ed.py [2x4 sqrt8 sqrt10 3x4]
"""
import sys
import numpy as np
import ed_core as ec
# cluster, Nup=Ndn, E0(U=8), deg(U=8), P_org(U=8), P_org(U=0) [ku-ku table]
REF = [
("2x4", 1, -7.51754096, 1, 0.00216029, 0.0),
("2x4", 2, -10.49762201, 1, -0.00363614, 0.0312499),
("2x4", 3, -10.62689735, 1, 0.193846, 0.187500),
("2x4", 4, -7.12671234, 1, 0.0328407, 0.0625000),
("sqrt8", 1, -7.46479305, 1, 0.0, 0.0),
("sqrt8", 2, -6.70043783, 4, 0.0462048, 0.0277777),
("sqrt8", 3, -5.95282782, 4, 0.0151149, 0.0277777),
("sqrt8", 4, -3.78398080, 1, -0.0815632, 0.0),
("sqrt10", 1, -7.59126715, 1, 0.0, 0.0),
("sqrt10", 2, -8.86885383, 5, 0.0321150, 0.0),
("sqrt10", 3, -9.83963907, 1, -0.0370993, 0.0499999),
("sqrt10", 4, -8.11706774, 5, 0.0909946, 0.149999),
("sqrt10", 5, -5.10409191, 1, 0.0359803, 0.300000),
("3x4", 1, -7.67599209, 1, 5.7526378308795875e-05, 0.0),
("3x4", 2, -11.037873924, 1, -0.00649435, 0.0138888),
("3x4", 3, -13.067143245, 1, 0.103875, 0.0833333),
("3x4", 4, -12.64005415, 1, 0.0360609, 0.0868055),
("3x4", 5, -10.76537911, 1, 0.0568266, 0.121527),
("3x4", 6, -5.83348425, 1, 0.0100270, 0.0347222),
("4x4", 1, -7.76409059, 1, 0.0, 0.0),
("4x4", 2, -11.32149713, 3, 0.0120940, 0.0),
("4x4", 3, -14.72354031, 1, -0.0137308, 0.0156250),
("4x4", 4, -16.46062675, 3, 0.0480759, 0.0468749),
("4x4", 5, -17.51036669, 1, 0.0601219, 0.0937500),
("4x4", 6, -14.92531021, 2, 0.00983108, 0.0416666),
("4x4", 7, -11.86883556, 3, 0.0192190, 0.0104166),
("4x4", 8, -8.46887501, 1, 0.00619709, 0.0),
]
TOL_E = 5e-7 # E0 table has 8-9 decimals
TOL_P = 2e-6 # P table truncated to 6-7 significant digits
def test_wick_bf():
"""Brute-force check of wick4 on a Slater determinant (3 sites, 1 up + 1 down)."""
Ns = 4
cl = ec.Cluster((2, 0), (0, 2), "t2x2ring")
H1 = np.zeros((Ns, Ns))
for (p, q) in cl.bonds:
H1[p, q] -= 1.0
H1[q, p] -= 1.0
eps, U = ec.eigh(H1)
occ = np.zeros(Ns)
occ[0] = 1.0 # unique orbital per spin (non-degenerate here)
a = U[:, 0] # orbital coefficients
rho = np.outer(a, a)
# Fock vector over (up_mask, dn_mask): single particle per spin
amp = {}
for x in range(Ns):
for y in range(Ns):
amp[(1 << x) | (1 << (Ns + y))] = a[x] * a[y]
def apply(st, site, spin, create):
m, sgn = st, 1.0
bit = site + (Ns if spin == 1 else 0)
occ_bit = (m >> bit) & 1
if create:
if occ_bit:
return None, 0.0
sgn = 1 - 2 * (bin(m & ((1 << bit) - 1)).count("1") & 1)
return m | (1 << bit), float(sgn)
if not occ_bit:
return None, 0.0
sgn = 1 - 2 * (bin(m & ((1 << bit) - 1)).count("1") & 1)
return m ^ (1 << bit), float(sgn)
import itertools
worst = 0.0
for P in itertools.product(range(Ns), [0, 1]):
for Q in itertools.product(range(Ns), [0, 1]):
for R in itertools.product(range(Ns), [0, 1]):
for S in itertools.product(range(Ns), [0, 1]):
tot = 0.0
for st0, a0 in amp.items():
m1, s1 = apply(st0, S[0], S[1], False) # c_S
if m1 is None:
continue
m2, s2 = apply(m1, R[0], R[1], False) # c_R
if m2 is None:
continue
m3, s3 = apply(m2, Q[0], Q[1], True) # c^+_Q
if m3 is None:
continue
m4, s4 = apply(m3, P[0], P[1], True) # c^+_P
if m4 is None:
continue
tot += a0 * s1 * s2 * s3 * s4 * amp.get(m4, 0.0)
ref = ec.wick4(rho, rho, P, Q, R, S)
worst = max(worst, abs(tot - ref))
return worst
def main():
which = sys.argv[1:] or ["2x4", "sqrt8", "sqrt10", "3x4"]
w = test_wick_bf()
print(f"[wick4 brute-force] max |diff| = {w:.3e} ->", "PASS" if w < 1e-12 else "FAIL")
npass = nfail = 0
for (cname, ne, e0_ref, deg_ref, p8_ref, p0_ref) in REF:
if cname not in which:
continue
cl = ec.CLUSTERS[cname]()
ed = ec.SectorED(cl, ne, U=8.0)
E0, vecs = ed.solve_gs()
deg = vecs.shape[1]
pops = ec.PairOps(ed)
p8, npair = pops.pd_at_R(vecs, cl.rmax)
p0, _ = ec.wick_u0(cl, ne, cl.rmax)
rows = [
("dim", ed.dim, ""),
("E0", E0, e0_ref),
("deg", deg, deg_ref),
("P_org U=8", p8, p8_ref),
("P_org U=0", p0, p0_ref),
]
ok = (abs(E0 - e0_ref) < TOL_E and deg == deg_ref
and abs(p8 - p8_ref) < TOL_P and abs(p0 - p0_ref) < TOL_P)
npass += ok
nfail += (not ok)
print(f"\n== {cname} Ne={ne} (n={2*ne/cl.Ns:.4f}) Rmax={cl.rmax:.4f} npairs={npair} "
f"{'PASS' if ok else 'FAIL'}")
for (k, got, ref) in rows:
rs = f"{ref:.8f}" if isinstance(ref, float) else str(ref)
d = f" diff={got-ref:+.2e}" if isinstance(ref, float) and k != "dim" else ""
print(f" {k:12s} got={got!r:22} ref={rs}{d}")
print(f"\n==== {npass} PASS / {nfail} FAIL ====")
sys.exit(0 if nfail == 0 and npass > 0 and w < 1e-12 else 1)
if __name__ == "__main__":
main()