From 996606e410490be0306980307db8afdfe67a2626 Mon Sep 17 00:00:00 2001 From: Basil Ibrahim Date: Thu, 11 Apr 2024 16:16:14 +0100 Subject: [PATCH 1/7] More comments --- examples/ewf/molecules/65-callback-solver.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/examples/ewf/molecules/65-callback-solver.py b/examples/ewf/molecules/65-callback-solver.py index dabfb557..58093165 100644 --- a/examples/ewf/molecules/65-callback-solver.py +++ b/examples/ewf/molecules/65-callback-solver.py @@ -8,6 +8,8 @@ from vayesta.misc.molecules import ring # User defined FCI solver - takes pyscf mf as input and returns RDMs +# The mf argment contains the hamiltonain in the orthonormal cluster basis +# Pyscf or other solvers may be used to solve the cluster problem and may return RDMs, CIID amplitudes or CCSD amplitudes def solver(mf): h1e = mf.get_hcore() h2e = mf._eri From 561d0e11ab464529e81a2c3d5b43850212099580 Mon Sep 17 00:00:00 2001 From: Basil Ibrahim Date: Thu, 11 Apr 2024 17:50:35 +0100 Subject: [PATCH 2/7] Add option to use DMET energy (democratic partitioning) in EWF --- vayesta/ewf/ewf.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/vayesta/ewf/ewf.py b/vayesta/ewf/ewf.py index 53ec5c0d..af8ee878 100644 --- a/vayesta/ewf/ewf.py +++ b/vayesta/ewf/ewf.py @@ -315,6 +315,8 @@ def get_e_corr(self, functional=None, **kwargs): return self.get_dm_corr_energy(t_as_lambda=True, **kwargs) if functional == "dm": return self.get_dm_corr_energy(**kwargs) + if functional == 'dmet': + return self.get_dmet_energy(**kwargs) raise ValueError("Unknown energy functional: '%s'" % functional) @mpi.with_allreduce() From ae1fded828f1a0c61eed8c68f1cf640a29a0e857 Mon Sep 17 00:00:00 2001 From: Basil Ibrahim Date: Thu, 11 Apr 2024 17:52:58 +0100 Subject: [PATCH 3/7] Add dyson callback solver example --- examples/ewdmet/65-callback-solver-dyson.py | 67 +++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 examples/ewdmet/65-callback-solver-dyson.py diff --git a/examples/ewdmet/65-callback-solver-dyson.py b/examples/ewdmet/65-callback-solver-dyson.py new file mode 100644 index 00000000..aa53c668 --- /dev/null +++ b/examples/ewdmet/65-callback-solver-dyson.py @@ -0,0 +1,67 @@ +import numpy as np +import pyscf +import pyscf.gto +import pyscf.scf +import pyscf.fci +import vayesta +import vayesta.ewf +from vayesta.misc.molecules import ring +from dyson import FCI + + +# User defined FCI solver - takes pyscf mf as input and returns RDMs +# The mf argment contains the hamiltonain in the orthonormal cluster basis +# Pyscf or other solvers may be used to solve the cluster problem and may return RDMs, CIID amplitudes or CCSD amplitudes +def solver(mf): + fci_1h = FCI["1h"](mf) + fci_1p = FCI["1p"](mf) + + # Use MBLGF + nmom_max = 4 + th = fci_1h.build_gf_moments(nmom_max) + tp = fci_1p.build_gf_moments(nmom_max) + + norb = mf.mo_coeff.shape[-1] + nelec = mf.mol.nelec + civec= fci_1h.c_ci + dm1, dm2 = pyscf.fci.direct_spin0.make_rdm12(civec, norb, nelec) + results = dict(dm1=dm1, dm2=dm2, hole_moments=th, particle_moments=tp, converged=True) + return results + +natom = 10 +mol = pyscf.gto.Mole() +mol.atom = ring("H", natom, 1.5) +mol.basis = "sto-3g" +mol.output = "pyscf.out" +mol.verbose = 5 +mol.symmetry = True +mol.build() + +# Hartree-Fock +mf = pyscf.scf.RHF(mol) +mf.kernel() + +# Vayesta options +use_sym = True +nfrag = 1 +bath_opts = dict(bathtype="ewdmet", order=1, max_order=1) + +# Run vayesta with user defined solver +emb = vayesta.ewf.EWF(mf, solver="CALLBACK", energy_functional='dmet', bath_options=bath_opts, solver_options=dict(callback=solver)) +emb.qpewdmet_scmf(proj=2, maxiter=10) +# Set up fragments +with emb.iao_fragmentation() as f: + if use_sym: + # Add rotational symmetry + with f.rotational_symmetry(order=natom//nfrag, axis=[0, 0, 1]): + f.add_atomic_fragment(range(nfrag)) + else: + # Add all atoms as separate fragments + f.add_all_atomic_fragments() +emb.kernel() + +print("Hartree-Fock energy : %s"%mf.e_tot) +print("DMET energy : %s"%emb.get_dmet_energy(part_cumulant=False, approx_cumulant=False)) +print("DMET energy (part-cumulant): %s"%emb.get_dmet_energy(part_cumulant=True, approx_cumulant=False)) +print("DMET energy (approx-cumulant): %s"%emb.get_dmet_energy(part_cumulant=True, approx_cumulant=True)) + From 78ae86f321ab8035360623748100aefc5e9e2866 Mon Sep 17 00:00:00 2001 From: Basil Ibrahim Date: Thu, 11 Apr 2024 17:53:21 +0100 Subject: [PATCH 4/7] Some comments for energy functionals --- vayesta/ewf/ewf.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/vayesta/ewf/ewf.py b/vayesta/ewf/ewf.py index af8ee878..1fdbb1f1 100644 --- a/vayesta/ewf/ewf.py +++ b/vayesta/ewf/ewf.py @@ -310,12 +310,16 @@ def get_e_corr(self, functional=None, **kwargs): self.log.warning("functional='projected' is deprecated; use functional='wf' instead.") functional = "wf" if functional == "wf": + # CCSD projected energy expression return self.get_wf_corr_energy(**kwargs) if functional == "dm-t2only": + # Builds density matrices from projected amplitudes return self.get_dm_corr_energy(t_as_lambda=True, **kwargs) if functional == "dm": + # Builds density matrices from projected amplitudes return self.get_dm_corr_energy(**kwargs) if functional == 'dmet': + # Uses projected denisty matrices return self.get_dmet_energy(**kwargs) raise ValueError("Unknown energy functional: '%s'" % functional) From 5927da9a817ed100c3d09e44e2a432c670c3e9f2 Mon Sep 17 00:00:00 2001 From: basilib Date: Fri, 12 Apr 2024 13:35:05 +0100 Subject: [PATCH 5/7] Updates comments --- examples/ewdmet/65-callback-solver-dyson.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/examples/ewdmet/65-callback-solver-dyson.py b/examples/ewdmet/65-callback-solver-dyson.py index aa53c668..93404d2b 100644 --- a/examples/ewdmet/65-callback-solver-dyson.py +++ b/examples/ewdmet/65-callback-solver-dyson.py @@ -11,7 +11,8 @@ # User defined FCI solver - takes pyscf mf as input and returns RDMs # The mf argment contains the hamiltonain in the orthonormal cluster basis -# Pyscf or other solvers may be used to solve the cluster problem and may return RDMs, CIID amplitudes or CCSD amplitudes +# Pyscf or other solvers may be used to solve the cluster problem and may return RDMs, CISD amplitudes or CCSD amplitudes +# Green's function moments are also supported, and in are calculated via Dyson in this example. def solver(mf): fci_1h = FCI["1h"](mf) fci_1p = FCI["1p"](mf) From 6ccf11a9e1b4b331873347a6204b718d4fd205a4 Mon Sep 17 00:00:00 2001 From: basilib Date: Fri, 12 Apr 2024 13:36:22 +0100 Subject: [PATCH 6/7] Fix typo --- examples/ewf/molecules/65-callback-solver.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/ewf/molecules/65-callback-solver.py b/examples/ewf/molecules/65-callback-solver.py index 58093165..85a67726 100644 --- a/examples/ewf/molecules/65-callback-solver.py +++ b/examples/ewf/molecules/65-callback-solver.py @@ -9,7 +9,7 @@ # User defined FCI solver - takes pyscf mf as input and returns RDMs # The mf argment contains the hamiltonain in the orthonormal cluster basis -# Pyscf or other solvers may be used to solve the cluster problem and may return RDMs, CIID amplitudes or CCSD amplitudes +# Pyscf or other solvers may be used to solve the cluster problem and may return RDMs, CISD amplitudes or CCSD amplitudes def solver(mf): h1e = mf.get_hcore() h2e = mf._eri From 40407e669b5cf2e341c4021aa561f7780552f336 Mon Sep 17 00:00:00 2001 From: basilib Date: Fri, 12 Apr 2024 13:38:09 +0100 Subject: [PATCH 7/7] Update 65-callback-solver-dyson.py --- examples/ewdmet/65-callback-solver-dyson.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/ewdmet/65-callback-solver-dyson.py b/examples/ewdmet/65-callback-solver-dyson.py index 93404d2b..2354da4d 100644 --- a/examples/ewdmet/65-callback-solver-dyson.py +++ b/examples/ewdmet/65-callback-solver-dyson.py @@ -12,7 +12,7 @@ # User defined FCI solver - takes pyscf mf as input and returns RDMs # The mf argment contains the hamiltonain in the orthonormal cluster basis # Pyscf or other solvers may be used to solve the cluster problem and may return RDMs, CISD amplitudes or CCSD amplitudes -# Green's function moments are also supported, and in are calculated via Dyson in this example. +# Returning the cluster Green's function moments is also supported. They are calculated with Dyson in this example. def solver(mf): fci_1h = FCI["1h"](mf) fci_1p = FCI["1p"](mf)