Skip to content

Commit c1cf6e1

Browse files
committed
simplify
1 parent 8c2d0c3 commit c1cf6e1

3 files changed

Lines changed: 11 additions & 18 deletions

File tree

‎pyscf/dh/grad/dfdh.py‎

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,19 @@
1919
#
2020

2121
from __future__ import annotations
22-
# dh import
2322
from pyscf.dh.resp import RDHRespMixin
2423
from pyscf.dh.resp import _r_get_eri_cpks, _u_get_eri_cpks
25-
from pyscf.dh.resp import _get_Y_mo, _prepare_pt2_r, _prepare_pt2_u
24+
from pyscf.dh.resp import _get_Y_mo
2625
from pyscf.dh.dh import DHBase
2726
from pyscf.dh.dhutil import calc_batch_size, gen_batch, gen_shl_batch, timing, as_scanner_grad, available_memory
28-
# pyscf import
2927
from pyscf import gto, lib, df
3028
from pyscf.df.grad.rhf import _int3c_wrapper as int3c_wrapper
31-
# other import
3229
import numpy as np
3330

3431
einsum = lib.einsum
3532

3633

3734
def kernel(mf_dh: Gradients, **kwargs):
38-
# unrestricted method requires dump t_ijab_αβ to disk; controling αβ and SS dumping is too hard for me
3935
dump_t_ijab = mf_dh.with_t_ijab
4036

4137
mf_dh.base.build()
@@ -68,10 +64,7 @@ def kernel(mf_dh: Gradients, **kwargs):
6864
mf_dh.tensors.consume(Y_mo).consume(eri)
6965

7066
mf_dh.prepare_xc_kernel()
71-
if mf_dh.D.ndim == 2:
72-
pt2_res, eng_bi = _prepare_pt2_r(mf_dh, dump_t_ijab=dump_t_ijab)
73-
else:
74-
pt2_res, eng_bi = _prepare_pt2_u(mf_dh, dump_t_ijab=dump_t_ijab)
67+
pt2_res, eng_bi = mf_dh._prepare_pt2(dump_t_ijab=dump_t_ijab)
7568
mf_dh.tensors.consume(pt2_res)
7669
if mf_dh.base.eng_tot is None and eng_bi is not None:
7770
DHBase.kernel(mf_dh.base, eng_bi=(None,) + tuple(eng_bi))

‎pyscf/dh/polar/rdfdh.py‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
# dh import
2323
from pyscf.dh.resp import RDHRespMixin
2424
from pyscf.dh.resp import _r_get_eri_cpks, _u_get_eri_cpks
25-
from pyscf.dh.resp import _get_Y_mo, _prepare_pt2_r, _prepare_pt2_u
25+
from pyscf.dh.resp import _get_Y_mo
2626
from pyscf.dh.dh import DHBase
2727
from pyscf.dh.dhutil import gen_batch, get_rho_from_dm_gga, restricted_biorthogonalize, hermi_sum_last2dim
2828
from pyscf.dh.xccode import xc_equal
@@ -55,10 +55,7 @@ def kernel(mf: Polar):
5555
mf.tensors.consume(Y_mo).consume(eri)
5656

5757
mf.prepare_xc_kernel()
58-
if mf.D.ndim == 2:
59-
pt2_res, eng_bi = _prepare_pt2_r(mf, dump_t_ijab=True)
60-
else:
61-
pt2_res, eng_bi = _prepare_pt2_u(mf, dump_t_ijab=True)
58+
pt2_res, eng_bi = mf._prepare_pt2(dump_t_ijab=True)
6259
mf.tensors.consume(pt2_res)
6360
if mf.base.eng_tot is None and eng_bi is not None:
6461
DHBase.kernel(mf.base, eng_bi=(None,) + tuple(eng_bi))

‎pyscf/dh/resp.py‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -370,10 +370,7 @@ def make_rdm1_relaxed(self, ao_repr=False):
370370
self.nocc, self.cx, self._incore_Y_mo, self.max_memory)
371371
self.tensors.consume(Y_mo).consume(eri)
372372
self.prepare_xc_kernel()
373-
if self.D.ndim == 2:
374-
pt2_res, _ = _prepare_pt2_r(self, dump_t_ijab=True)
375-
else:
376-
pt2_res, _ = _prepare_pt2_u(self, dump_t_ijab=True)
373+
pt2_res, _ = self._prepare_pt2(dump_t_ijab=True)
377374
self.tensors.consume(pt2_res)
378375
self.prepare_lagrangian()
379376
self.prepare_D_r()
@@ -449,6 +446,9 @@ def build(sI, t_ijab, g_ijab):
449446
class RDHRespMixin(RespMixin):
450447
"""Restricted response mixin: Ax0_*, prepare_lagrangian."""
451448

449+
def _prepare_pt2(self, dump_t_ijab=True):
450+
return _prepare_pt2_r(self, dump_t_ijab=dump_t_ijab)
451+
452452
def Ax0_Core_HF(self, si, sa, sj, sb, cx=None):
453453
Y_mo_jk = self.tensors["Y_mo_jk"]
454454
cx = cx if cx else self.cx
@@ -605,6 +605,9 @@ def _prepare_pt2_u(mf, dump_t_ijab=True):
605605
class UDHRespMixin(RespMixin):
606606
"""Unrestricted response mixin: Ax0_*, prepare_lagrangian."""
607607

608+
def _prepare_pt2(self, dump_t_ijab=True):
609+
return _prepare_pt2_u(self, dump_t_ijab=dump_t_ijab)
610+
608611
def Ax0_Core_HF(self, si, sa, sj, sb, cx=None):
609612
Y_mo_jk = [self.tensors["Y_mo_jk" + str(σ)] for σ in (α, β)]
610613
cx = cx if cx else self.cx

0 commit comments

Comments
 (0)