9. Hartree-Fock trial wavefunctions with autoHF#

This example covers generating a Hartree-Fock trial wavefunction using autoHF on a Hubbard model Hamiltonian on square lattice as a test case. We note that autohf can handle general lattice model Hamiltonians just as SAFIRE can.

A lattice model Hamiltonian can be generated using afqmctools and a toml-based input file. Below is a sample input file, which we name input.toml, for a Hubbard model on a 2x3 square lattice with periodic boundary conditions.

[hamiltonian]
t = 1.0 # defaults to 1.0
U = 2.0 

[lattice]
L1 = 2
L2 = 3
boundary1 = "PBC" # or "open" for open boundaries
boundary2 = "PBC" # or "open" for open boundaries

[misc_params]
nelec = [2,2]

if no “type” is specified in the “lattice” section, then a square lattice is used.

autohf and afqmctools can be invoked within a Python script as

from afqmctools.hamiltonian.model.director import HamiltonianDirector
import afqmctools.utils.io as io
from autohf import lattice_hf

infile = "input.toml"

# Build and save a lattice model Hamiltonian
hamiltonian_dir = HamiltonianDirector(source=infile)
lattice = hamiltonian_dir.builder.lattice
hamiltonian = hamiltonian_dir.build()


nelec = io.read_input_params(infile)["misc_params"]["nelec"]
io.write_model_hamiltion(
    hamiltonian=hamiltonian,
    fname="afqmc.h5",
    nelec=nelec
)

settings = dict(
    ansatz = 'SD_ROT',
    numSteps = 100,
    output = "afqmc.h5",
    nelec = nelec,
    numTrials = 10,
    seed = 42
)

lattice_hf(
    hamiltonian=hamiltonian,
    lattice=lattice,
    settings=settings
)

If the sample Python script is run above with the sample input file, the following should be present at the end of the output.

    -----------------------
    - ╔═╗ ------- ╖ ╓╔═╕ --
    - ╠═╣ ╖╖╒╦╕╔╗ ╠═╣╠╕ ---
    - ╜ ╙ ╚╝ ╜ ╚╝ ╜ ╙╨ ----
    -----------------------


===== AutoHF Settings =====

        inputfile                                          input.toml
        noncollinear                                            False
        gpu                                                     False
        approx_expm                                             False
        force_complex                                           False
        ansatz                                                 SD_ROT
        opt_method                                               grad
        seed                                                       42
        eta                                                       0.1
        numSteps                                                  100
        numTrials                                                  10
        plot                                                    False
        verbose                                                 False
        output                                               afqmc.h5
adding flags
[CpuDevice(id=0)]
Reading hopping from spin sector 0
Running in Rotation Mode
Reference HF Energy = -8.5
-8.318047983610533 [-7.82925573 -8.20826297 -7.97682551 -8.01490856 -8.26554431 -7.91850185
-7.54061017 -8.31804798 -7.89857215 -8.16534917]
-8.216382828465095 [-8.09432829 -8.03639054 -8.21638283 -8.07122962 -8.08131579 -8.0877504
-8.15180574 -7.90370033 -8.03161958 -7.78665886]
-8.309509210823176 [-8.07796612 -8.23148944 -8.14454047 -8.19486768 -8.21127767 -8.14004973
-7.96349082 -8.30950921 -8.08577293 -8.23131568]
-8.42258947787306 [-8.31234952 -8.38186672 -8.23707628 -8.35201197 -8.3870684  -8.24290277
-8.16963877 -8.38787803 -8.21464329 -8.42258948]
-8.37393911026142 [-8.37369695 -8.36710946 -8.37393911 -8.37211044 -8.33817992 -8.27254769
-8.30869812 -8.2690715  -8.34041827 -8.21421307]
-8.41389112501501 [-8.31473792 -8.37839445 -8.39627521 -8.40260742 -8.34289539 -8.34189717
-8.30698777 -8.27405296 -8.41389113 -8.19060455]
-8.492547277749024 [-8.31313947 -8.46129363 -8.35305729 -8.49254728 -8.41077511 -8.42622465
-8.29794613 -8.37983532 -8.39457372 -8.35449406]
-8.577874773427446 [-8.40165866 -8.57051177 -8.36321772 -8.57787477 -8.47496182 -8.45799948
-8.34331097 -8.45355054 -8.37880087 -8.45478449]
-8.63588229193564 [-8.52256023 -8.63588229 -8.41571435 -8.62866277 -8.52710558 -8.45092217
-8.4141163  -8.4472473  -8.4639819  -8.41866965]
-8.668559605563079 [-8.60629238 -8.66192164 -8.47208393 -8.66855961 -8.56647378 -8.47865507
-8.44829411 -8.4176252  -8.61176947 -8.36275384]
-8.720722189166914 [-8.62810503 -8.70342147 -8.513561   -8.71615093 -8.60643184 -8.56374697
-8.44436454 -8.4250876  -8.72072219 -8.39087125]
-8.765161793576562 [-8.62702655 -8.76516179 -8.53656143 -8.75977414 -8.66585119 -8.67068667
-8.45726989 -8.47041286 -8.73631855 -8.47093654]
-8.80817153120551 [-8.66135234 -8.80817153 -8.55478639 -8.78225936 -8.74410322 -8.74459399
-8.51428437 -8.5266867  -8.71036115 -8.51743901]
-8.807235481196024 [-8.73602286 -8.79875683 -8.59457016 -8.78464375 -8.80723548 -8.76274037
-8.59639098 -8.57440165 -8.71881122 -8.51289505]
-8.824336471080956 [-8.8029217  -8.75441532 -8.66525359 -8.77763826 -8.82433647 -8.75434706
-8.66942778 -8.61065845 -8.76582716 -8.51295165]
-8.818561955352388 [-8.81856196 -8.72663455 -8.74322607 -8.76690228 -8.80435733 -8.75854338
-8.71633426 -8.64732851 -8.79991518 -8.56179194]
-8.79661826134404 [-8.7889052  -8.73552711 -8.79661826 -8.75382356 -8.7743701  -8.78143319
-8.74088694 -8.69301934 -8.78985725 -8.6427688 ]
-8.81218925447062 [-8.75779947 -8.75730229 -8.81218925 -8.74206082 -8.75122428 -8.79921796
-8.75407235 -8.74637302 -8.7552585  -8.71070041]
-8.803390810430187 [-8.75361762 -8.7661832  -8.80339081 -8.74024605 -8.74102333 -8.79112612
-8.76677335 -8.79824626 -8.73068125 -8.74541631]
-8.831423759321522 [-8.76552098 -8.76457514 -8.792077   -8.7545535  -8.74465207 -8.76257731
-8.78843817 -8.83142376 -8.7284805  -8.76388248]
-8.833883032710625 [-8.76802224 -8.77068068 -8.7883441  -8.77724103 -8.756405   -8.73697464
-8.8149654  -8.83388303 -8.74124183 -8.78828803]
-8.825496363451144 [-8.75657675 -8.79108298 -8.78741578 -8.79190976 -8.76928432 -8.73307889
-8.82549636 -8.81163287 -8.76009712 -8.81736215]
-8.831941420216824 [-8.75137392 -8.81552884 -8.77888655 -8.7947793  -8.78153731 -8.75236605
-8.80587147 -8.78524277 -8.77918649 -8.83194142]
-8.832299092688784 [-8.76875627 -8.83229909 -8.76286652 -8.80002176 -8.79628505 -8.78026954
-8.77104643 -8.77226655 -8.79340278 -8.82054934]
-8.836805660039474 [-8.79988143 -8.83680566 -8.75204902 -8.81691243 -8.81497224 -8.79973136
-8.7510589  -8.77160574 -8.8021593  -8.79418545]
-8.83587014237844 [-8.821902   -8.83088159 -8.75699643 -8.83587014 -8.8321621  -8.80724205
-8.75761634 -8.77136634 -8.81182682 -8.77386069]
-8.842710654649819 [-8.82566049 -8.82237775 -8.77584274 -8.84271065 -8.84039231 -8.81247533
-8.7768003  -8.76766042 -8.82696329 -8.76939173]
-8.841133059037613 [-8.82353906 -8.81952943 -8.79860403 -8.83678865 -8.83816005 -8.82297072
-8.78997257 -8.76807199 -8.84113306 -8.77481204]
-8.843348073896056 [-8.82754754 -8.82214008 -8.81674562 -8.82863472 -8.8303006  -8.83532303
-8.79389418 -8.77874908 -8.84334807 -8.78025536]
-8.841351940867009 [-8.83418726 -8.82407911 -8.82759134 -8.82515658 -8.82294425 -8.84135194
-8.79795055 -8.79691843 -8.83247845 -8.78356733]
-8.837799047908929 [-8.83553228 -8.82325765 -8.83314607 -8.82509508 -8.81964276 -8.83779905
-8.8078389  -8.81618113 -8.82010492 -8.78972709]
-8.836771989937315 [-8.83096557 -8.82344167 -8.83677199 -8.82550455 -8.82039846 -8.82907054
-8.8202511  -8.83227847 -8.81681521 -8.80240923]
-8.842373766878918 [-8.82535253 -8.82807517 -8.83994352 -8.82634868 -8.82325029 -8.82258771
-8.83046389 -8.84237377 -8.82106104 -8.81920678]
-8.844665114952045 [-8.82377339 -8.83611166 -8.84056505 -8.82884448 -8.82675248 -8.82211036
-8.83770442 -8.84466511 -8.82495643 -8.8340971 ]
-8.843215864122868 [-8.82709641 -8.84321586 -8.83599102 -8.83242434 -8.83066521 -8.82544057
-8.84210949 -8.8411883  -8.82585578 -8.84247688]
-8.845876910032523 [-8.83077118 -8.84587691 -8.82811513 -8.83557322 -8.83527149 -8.8285748
-8.84247346 -8.83677453 -8.82766043 -8.84410013]
-8.844386445261337 [-8.83175861 -8.84438645 -8.82245326 -8.8388165  -8.84060152 -8.8306794
-8.83913977 -8.83390252 -8.8332412  -8.84210714]
-8.84530194405395 [-8.83351293 -8.84202875 -8.82270281 -8.84337118 -8.84530194 -8.83362707
-8.83511701 -8.83128734 -8.84048683 -8.83938473]
-8.847419337242542 [-8.83902515 -8.84160252 -8.82796587 -8.84741934 -8.8471537  -8.83831428
-8.83279723 -8.82774839 -8.84565852 -8.83636999]
-8.847855785468413 [-8.84505952 -8.84243862 -8.83439163 -8.84785579 -8.84574668 -8.84353209
-8.83188012 -8.82526742 -8.84735063 -8.83281019]
-8.847551243572742 [-8.84755124 -8.84213907 -8.83910366 -8.84531705 -8.84313653 -8.8473508
-8.83162769 -8.82717404 -8.84648787 -8.83004254]
-8.84824636408363 [-8.8465588  -8.84087088 -8.84231641 -8.84343691 -8.84144466 -8.84824636
-8.83284597 -8.83356346 -8.8445446  -8.82990719]
-8.846260176718571 [-8.84427514 -8.8411329  -8.84517673 -8.84353941 -8.84119351 -8.84626018
-8.83601654 -8.84044813 -8.84274311 -8.832351  ]
-8.847395422653776 [-8.84290789 -8.84383049 -8.84739542 -8.84395868 -8.8418331  -8.84356508
-8.83949755 -8.84455998 -8.84183777 -8.83559696]
-8.848101559743798 [-8.84339576 -8.8469672  -8.84810156 -8.84378856 -8.84283382 -8.84235893
-8.84165531 -8.84651741 -8.84185582 -8.83855305]
-8.848300011185962 [-8.84425847 -8.84830001 -8.84728607 -8.84393865 -8.84405964 -8.842612
-8.84322233 -8.84794753 -8.84238874 -8.84173631]
-8.848589952112295 [-8.84404375 -8.8480439  -8.84550897 -8.84491955 -8.84555708 -8.84315564
-8.8455593  -8.84858995 -8.8432725  -8.84544857]
-8.848499976506448 [-8.84386482 -8.84798219 -8.84337599 -8.84620002 -8.84727358 -8.84372478
-8.84800307 -8.84769719 -8.84458372 -8.84849998]
-8.849459274618873 [-8.84514493 -8.8485761  -8.84193345 -8.8475181  -8.84880626 -8.84476026
-8.84885881 -8.84576801 -8.84616807 -8.84945927]
-8.849499266469234 [-8.84718062 -8.84862901 -8.84235363 -8.84889802 -8.84949927 -8.84635124
-8.84799448 -8.84393831 -8.8477066  -8.84840493]
-8.849775601615313 [-8.84844017 -8.84764714 -8.8444766  -8.8497756  -8.84909837 -8.84802248
-8.84677562 -8.8429883  -8.84895763 -8.84678208]
-8.84959818641765 [-8.84855263 -8.84682173 -8.84675593 -8.84959819 -8.84818667 -8.84910598
-8.84606989 -8.84320011 -8.84956652 -8.84575003]
-8.849432259669197 [-8.84846539 -8.84726822 -8.84801689 -8.84886309 -8.84761755 -8.84943226
-8.84576864 -8.84451258 -8.84927358 -8.84536832]
-8.849447962724913 [-8.84892231 -8.84851328 -8.8485396  -8.8485258  -8.84758344 -8.84944796
-8.84580627 -8.84640299 -8.84854967 -8.84523804]
-8.849385998009748 [-8.84933964 -8.849386   -8.84924794 -8.84872988 -8.84776492 -8.8492816
-8.84629839 -8.84804229 -8.84818626 -8.84526378]
-8.850118172776424 [-8.84899439 -8.84953952 -8.85011817 -8.84884964 -8.84810558 -8.84865911
-8.84696113 -8.84910536 -8.84822157 -8.84575826]
-8.850173201306426 [-8.84830163 -8.84950765 -8.8501732  -8.84866712 -8.8486837  -8.84794791
-8.84746946 -8.84985045 -8.84816416 -8.84693687]
-8.850233928630155 [-8.84807231 -8.84982153 -8.84914263 -8.84870263 -8.84937405 -8.84789388
-8.84806653 -8.85023393 -8.84807715 -8.84843885]
-8.850286477225653 [-8.84855989 -8.85028648 -8.84802693 -8.84917796 -8.85002296 -8.84847304
-8.84900501 -8.84995484 -8.8484486  -8.84954984]
-8.850404477669167 [-8.84931374 -8.85021906 -8.84780819 -8.84970816 -8.85040448 -8.84911004
-8.84985537 -8.8492348  -8.84922572 -8.84993193]
-8.85030439277758 [-8.84970058 -8.84959879 -8.84838749 -8.85013541 -8.85030439 -8.84952539
-8.85008557 -8.84862075 -8.8498798  -8.84993291]
-8.850480446926873 [-8.8498103  -8.84925087 -8.84904671 -8.85048045 -8.84990563 -8.84983689
-8.84986085 -8.84834451 -8.85019423 -8.8499354 ]
-8.850485449467445 [-8.85007586 -8.84959809 -8.84942446 -8.85048545 -8.84963522 -8.85021061
-8.84967316 -8.84837985 -8.85030757 -8.84980811]
-8.850504114533546 [-8.85031671 -8.85013699 -8.84972356 -8.85017961 -8.84965114 -8.85050411
-8.84961728 -8.84873439 -8.85028514 -8.84938367]
-8.850436606700075 [-8.85023852 -8.85032599 -8.85020545 -8.850054   -8.84975016 -8.85043661
-8.84953075 -8.84936145 -8.85015164 -8.84896042]
-8.850666344748236 [-8.85000833 -8.8502625  -8.85066634 -8.85022689 -8.84980884 -8.85013336
-8.84944589 -8.8499798  -8.85000813 -8.8489299 ]
-8.850686727112048 [-8.84991036 -8.85032198 -8.85068673 -8.85030105 -8.84999163 -8.84994565
-8.84947532 -8.85032943 -8.84987343 -8.84924001]
-8.850572271811458 [-8.85006375 -8.85057227 -8.85031309 -8.85012147 -8.85035239 -8.8499389
-8.84958088 -8.85050182 -8.84975167 -8.84958294]
-8.850712823561885 [-8.85024728 -8.85071282 -8.84997875 -8.85004014 -8.85065727 -8.85001421
-8.84973844 -8.85061687 -8.84981294 -8.84986181]
-8.850709885058869 [-8.85019998 -8.85053529 -8.84991561 -8.85030421 -8.85070989 -8.85012508
-8.85001251 -8.85052016 -8.85013176 -8.85016524]
-8.850634210576377 [-8.85016692 -8.85028232 -8.85000626 -8.85063421 -8.85056494 -8.85025336
-8.85032955 -8.85020477 -8.85045656 -8.85048658]
-8.850715349715756 [-8.85040109 -8.85029032 -8.85009937 -8.85071535 -8.85041267 -8.85042684
-8.85050087 -8.84996995 -8.85056849 -8.8506616 ]
-8.850649325099305 [-8.8506472  -8.85049657 -8.85022194 -8.85064933 -8.85036911 -8.85063061
-8.85050598 -8.84996357 -8.85057567 -8.85058116]
-8.850751299030883 [-8.85066297 -8.85062323 -8.85043842 -8.85063233 -8.85040405 -8.8507513
-8.85047567 -8.85007882 -8.85062264 -8.85038117]
-8.850729746244145 [-8.85056081 -8.85061236 -8.85067238 -8.85066588 -8.85043884 -8.85072975
-8.85045987 -8.85022914 -8.85063824 -8.85029034]
-8.850784452564803 [-8.85053605 -8.85062425 -8.85078445 -8.85068582 -8.85047621 -8.85062004
-8.85043863 -8.85041108 -8.85054145 -8.8503263 ]
-8.85075573162677 [-8.85059012 -8.85072639 -8.85075573 -8.85065164 -8.85057884 -8.85052973
-8.85043112 -8.85060141 -8.85042103 -8.85032362]
-8.850798221450999 [-8.85057872 -8.85079822 -8.8506697  -8.85057949 -8.85072518 -8.85053189
-8.85043138 -8.85072965 -8.85040117 -8.85026643]
-8.850796785158476 [-8.85051491 -8.85075032 -8.85059338 -8.8505725  -8.85079679 -8.85057893
-8.85040193 -8.85076285 -8.85048611 -8.85032157]
-8.850750083162698 [-8.85054839 -8.85066169 -8.85054789 -8.85067484 -8.85075008 -8.8506037
-8.85039785 -8.85072461 -8.85058669 -8.85052328]
-8.850773489474516 [-8.85067425 -8.8506424  -8.85053855 -8.85077349 -8.85067558 -8.85063458
-8.85049873 -8.85063288 -8.85064304 -8.85069986]
-8.850783952283729 [-8.85075123 -8.85069279 -8.85057584 -8.85078395 -8.85064985 -8.85070353
-8.85063694 -8.85054308 -8.85068212 -8.85073647]
-8.8507791631027 [-8.85072957 -8.85074478 -8.85064642 -8.85077261 -8.85066638 -8.85077916
-8.85069342 -8.85052546 -8.85073292 -8.85070617]
-8.850818922374689 [-8.85070592 -8.85076002 -8.85072515 -8.85079865 -8.8506865  -8.85081892
-8.85068198 -8.85056007 -8.85075307 -8.85070206]
-8.850819147925257 [-8.85073793 -8.85076794 -8.85079958 -8.85081915 -8.85069684 -8.85081016
-8.85067976 -8.85060682 -8.85071655 -8.85070722]
-8.850841826816568 [-8.85076058 -8.85080171 -8.85084183 -8.85079958 -8.85072592 -8.850777
-8.85069305 -8.85067333 -8.85067827 -8.8506729 ]
-8.850828947591111 [-8.85073832 -8.85082895 -8.85082549 -8.85077419 -8.85077907 -8.85075165
-8.85069744 -8.85075117 -8.85067646 -8.85062295]
-8.850814312441978 [-8.85071396 -8.85081431 -8.8507813  -8.8507696  -8.85081385 -8.85074508
-8.85069392 -8.85080145 -8.85068371 -8.85061992]
-8.850807064800572 [-8.85072724 -8.85078444 -8.85075836 -8.8507754  -8.85080267 -8.85075377
-8.85068127 -8.85080706 -8.85068813 -8.85066735]
-8.8507967868308 [-8.85075965 -8.85077586 -8.85075497 -8.85079679 -8.85077382 -8.85076944
-8.85066433 -8.85078667 -8.85070869 -8.85071381]
-8.850829183632866 [-8.85076886 -8.85078974 -8.85075334 -8.85082918 -8.85076419 -8.8507893
-8.85067203 -8.85075668 -8.85074019 -8.85073776]
-8.850838622270116 [-8.85077616 -8.85080806 -8.85076134 -8.85083862 -8.85077032 -8.85081732
-8.85070886 -8.85072913 -8.8507642  -8.85076505]
-8.85084240088267 [-8.8508028  -8.85081774 -8.85079141 -8.85083354 -8.85077747 -8.8508424
-8.85074155 -8.85072213 -8.85077628 -8.85079785]
-8.850846544507528 [-8.85081272 -8.85082552 -8.85083179 -8.85084326 -8.85078358 -8.85084654
-8.85075374 -8.85073443 -8.85077427 -8.85080331]
-8.85085661657257 [-8.85079829 -8.85083756 -8.85085662 -8.85085299 -8.8507937  -8.85083583
-8.85075698 -8.85075545 -8.85076395 -8.85077926]
-8.850855426798793 [-8.85078645 -8.85084258 -8.85085543 -8.85084409 -8.85081032 -8.85082811
-8.85075928 -8.8507832  -8.85075959 -8.85076095]
-8.850840763614364 [-8.85079073 -8.85083678 -8.85084076 -8.85083078 -8.8508239  -8.85082617
-8.85076312 -8.85081056 -8.85075796 -8.85076171]
-8.850830994280757 [-8.85079902 -8.85082955 -8.85083099 -8.85083079 -8.85082299 -8.85082425
-8.85076817 -8.85082445 -8.85075197 -8.85076466]
-8.850839901609366 [-8.85079786 -8.85082657 -8.85082912 -8.8508399  -8.85081279 -8.8508236
-8.85076499 -8.85082191 -8.85075483 -8.85076488]
-8.850847759374995 [-8.85080281 -8.8508298  -8.85082597 -8.85084776 -8.85080847 -8.85083094
-8.85075413 -8.85081273 -8.8507709  -8.85077429]
Variational energy of final HF state: -8.850853114414434

See the examples in Running SAFIRE for how to run AFQMC.