Skip to content

Commit 3cd05e0

Browse files
committed
icmr frozen
1 parent 70eb4d7 commit 3cd05e0

File tree

9 files changed

+71
-52
lines changed

9 files changed

+71
-52
lines changed

.github/workflows/build.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,13 @@ jobs:
576576

577577
steps:
578578
- uses: actions/checkout@v4
579-
- if: matrix.os == 'macos-13' || matrix.os == 'macos-14' || matrix.os == 'windows-2022'
579+
580+
- if: matrix.os == 'windows-2022' && matrix.python == '3.13t'
581+
uses: actions/setup-python@v5
582+
with:
583+
python-version: '3.13.3t'
584+
585+
- if: matrix.os == 'macos-13' || matrix.os == 'macos-14' || (matrix.os == 'windows-2022' && matrix.python != '3.13t')
580586
uses: actions/setup-python@v5
581587
with:
582588
python-version: ${{ matrix.python }}

pyblock2/icmr/eri_helper.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,35 +59,40 @@ class _ChemistsERIs:
5959
def __init__(self, mol=None):
6060
self.mol = mol
6161

62-
def _common_init_(self, mc, mo_coeff=None):
62+
def _common_init_(self, mc, mo_coeff=None, frozen=0):
6363
if mo_coeff is None:
6464
mo_coeff = mc.mo_coeff
65-
self.ncore = mc.ncore
65+
self.ncore = mc.ncore - frozen
6666
self.ncas = mc.ncas
6767
self.nocc = self.ncore + self.ncas
68-
ncore = mc.ncore
69-
dmcore = np.dot(mo_coeff[:,:ncore], mo_coeff[:,:ncore].T)
68+
dmcore = np.dot(mo_coeff[:, :mc.ncore], mo_coeff[:, :mc.ncore].T)
7069
vj, vk = mc._scf.get_jk(mc.mol, dmcore)
7170
vhfcore = mo_coeff.conj().T @ (vj * 2 - vk) @ mo_coeff
7271
self.h1eff = mo_coeff.conj().T @ mc.get_hcore() @ mo_coeff + vhfcore
72+
self.h1eff = self.h1eff[frozen:, frozen:]
7373

7474
get_chem = get_chem_eri
7575
get_phys = get_phys_eri
7676
get_h1 = get_h1_eri
7777
get_h1eff = get_h1eff_eri
7878

79-
def init_eris(mc, mo_coeff=None, mrci=False):
79+
def init_eris(mc, mo_coeff=None, mrci=False, frozen=0):
8080
from pyscf import ao2mo, lib
8181
if mo_coeff is None:
8282
mo_coeff = mc.mo_coeff
83-
nmo, ncore, ncas = mo_coeff.shape[1], mc.ncore, mc.ncas
83+
nmo, ncore, ncas = mo_coeff.shape[1] - frozen, mc.ncore - frozen, mc.ncas
8484
nocc = ncore + ncas
8585
nvir = nmo - nocc
8686
eris = _ChemistsERIs()
87-
eris._common_init_(mc, mo_coeff)
87+
eris._common_init_(mc, mo_coeff, frozen=frozen)
8888
if mrci:
89-
h1e = mo_coeff.conj().T @ mc._scf.get_hcore() @ mo_coeff
90-
g2e = ao2mo.restore(1, ao2mo.kernel(mc._scf.mol, mo_coeff), nmo)
89+
hveff_ao = 0
90+
if frozen != 0:
91+
core_dmao = 2 * mo_coeff[:, :frozen] @ mo_coeff[:, :frozen].T.conj()
92+
vj, vk = mc._scf.get_jk(mc.mol, core_dmao)
93+
hveff_ao = vj - 0.5 * vk
94+
h1e = mo_coeff[:, frozen:].conj().T @ (mc._scf.get_hcore() + hveff_ao) @ mo_coeff[:, frozen:]
95+
g2e = ao2mo.restore(1, ao2mo.kernel(mc._scf.mol, mo_coeff[:, frozen:]), nmo)
9196
eris.known = ['vvca', 'aaca', 'cvca', 'cvaa', 'cvcv', 'caac', 'avaa',
9297
'vacc', 'aacc', 'avva', 'avcv', 'accc', 'vaca', 'vvaa',
9398
'aaaa', 'vvvv', 'vccc', 'vvva', 'vvvc', 'cccc', 'vvcc']
@@ -104,6 +109,7 @@ def init_eris(mc, mo_coeff=None, mrci=False):
104109
nwav = nmo - ncore # w = a + v
105110
if mc._scf._eri is None:
106111
mc._scf._eri = mc._scf.mol.intor('int2e', aosym='s8')
112+
mo_coeff = mo_coeff[:, frozen:]
107113
pwxx = ao2mo.incore.half_e1(mc._scf._eri,
108114
(mo_coeff[:, :nocc], mo_coeff[:, ncore:]), compact=False)
109115
pwxx = pwxx.reshape((nocc, nwav, -1))

pyblock2/icmr/icmrcisd_full.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,14 +150,14 @@ def kernel(ic, mc=None, mo_coeff=None, pdms=None, eris=None, nroots=1):
150150
if pdms is None:
151151
pdms = eri_helper.init_pdms(mc=mc, pdm_eqs=pdm_eqs)
152152
if eris is None:
153-
eris = eri_helper.init_eris(mc=mc, mo_coeff=mo_coeff, mrci=True)
153+
eris = eri_helper.init_eris(mc=mc, mo_coeff=mo_coeff, mrci=True, frozen=ic.frozen)
154154
ic.eris = eris
155155
assert isinstance(eris, eri_helper._ChemistsERIs)
156156
E1, E2, E3, E4 = pdms
157-
ncore = mc.ncore
157+
ncore = mc.ncore - ic.frozen
158158
ncas = mc.ncas
159159
nocc = ncore + ncas
160-
nvirt = len(ic.mo_energy) - nocc
160+
nvirt = len(ic.mo_energy) - nocc - ic.frozen
161161
mdict = {
162162
"E1": E1, "E2": E2, "E3": E3, "E4": E4,
163163
"deltaII": np.eye(ncore), "deltaEE": np.eye(nvirt),
@@ -250,14 +250,15 @@ def kernel(ic, mc=None, mo_coeff=None, pdms=None, eris=None, nroots=1):
250250
ic.__class__.__name__, ic.e_tot + ic.de_dav_q, ic.e_corr + ic.de_dav_q)
251251

252252
class WickICMRCISD(lib.StreamObject):
253-
def __init__(self, mc):
253+
def __init__(self, mc, frozen=0):
254254
self._mc = mc
255255
self._scf = mc._scf
256256
self.mol = self._scf.mol
257257
self.verbose = self.mol.verbose
258258
self.stdout = self.mol.stdout
259259
self.e_corr = None
260260
self.mrci_thrds = 1E-10
261+
self.frozen = frozen
261262

262263
@property
263264
def e_tot(self):

pyblock2/icmr/icmrrept2_full.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -184,15 +184,15 @@ def kernel(ic, mc=None, mo_coeff=None, pdms=None, eris=None, root=None):
184184
tpdms = time.perf_counter() - t
185185
if eris is None:
186186
t = time.perf_counter()
187-
eris = eri_helper.init_eris(mc=mc, mo_coeff=mo_coeff, mrci=True)
187+
eris = eri_helper.init_eris(mc=mc, mo_coeff=mo_coeff, mrci=True, frozen=ic.frozen)
188188
teris = time.perf_counter() - t
189189
ic.eris = eris
190190
assert isinstance(eris, eri_helper._ChemistsERIs)
191191
E1, E2, E3, E4 = pdms
192-
ncore = mc.ncore
192+
ncore = mc.ncore - ic.frozen
193193
ncas = mc.ncas
194194
nocc = ncore + ncas
195-
nvirt = len(ic.mo_energy) - nocc
195+
nvirt = len(ic.mo_energy) - nocc - ic.frozen
196196
mdict = {
197197
"E1": E1, "E2": E2, "E3": E3, "E4": E4,
198198
"deltaII": np.eye(ncore), "deltaEE": np.eye(nvirt),
@@ -290,7 +290,7 @@ def kernel(ic, mc=None, mo_coeff=None, pdms=None, eris=None, root=None):
290290
" | ".join(["%s = %7.2f" % (k, v) for k, v in ic.sub_times.items()]))
291291

292292
class WickICMRREPT2(lib.StreamObject):
293-
def __init__(self, mc):
293+
def __init__(self, mc, frozen=0):
294294
self._mc = mc
295295
assert mc.canonicalization
296296
self._scf = mc._scf
@@ -299,6 +299,7 @@ def __init__(self, mc):
299299
self.stdout = self.mol.stdout
300300
self.e_corr = None
301301
self.trunc_thrds = 1E-4
302+
self.frozen = frozen
302303

303304
@property
304305
def e_tot(self):

pyblock2/icmr/icmrrept2_ortho.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -224,15 +224,15 @@ def kernel(ic, mc=None, mo_coeff=None, pdms=None, eris=None, root=None, iprint=N
224224
tpdms = time.perf_counter() - t
225225
if eris is None:
226226
t = time.perf_counter()
227-
eris = eri_helper.init_eris(mc=mc, mo_coeff=mo_coeff, mrci=True)
227+
eris = eri_helper.init_eris(mc=mc, mo_coeff=mo_coeff, mrci=True, frozen=ic.frozen)
228228
teris = time.perf_counter() - t
229229
ic.eris = eris
230230
assert isinstance(eris, eri_helper._ChemistsERIs)
231231
E1, E2, E3, E4 = pdms
232-
ncore = mc.ncore
232+
ncore = mc.ncore - ic.frozen
233233
ncas = mc.ncas
234234
nocc = ncore + ncas
235-
nvirt = len(ic.mo_energy) - nocc
235+
nvirt = len(ic.mo_energy) - nocc - ic.frozen
236236
mdict = {
237237
"E1": E1, "E2": E2, "E3": E3, "E4": E4,
238238
"deltaII": np.eye(ncore), "deltaEE": np.eye(nvirt),
@@ -288,7 +288,7 @@ def kernel(ic, mc=None, mo_coeff=None, pdms=None, eris=None, root=None, iprint=N
288288
sw, su = np.linalg.eigh(ss.reshape((ns * 2, ns * 2)))
289289
idx = sw > ic.trunc_thrds
290290
sf = su[:, idx] * (sw[idx] ** (-0.5))
291-
sf = sf.reshape((2, *s.shape[:len(s.shape) // 2], -1))
291+
sf = sf.reshape((2, *s.shape[:len(s.shape) // 2], sf.shape[-1]))
292292
exec(pt2_beqs, globals(), { "b": b, "b2": b2, **mdict })
293293
def trans_forth(g, sf=sf):
294294
return np.einsum("v%s,v%sx->x" % (rkey, rkey), g, sf, optimize=True)
@@ -309,7 +309,7 @@ def axop(ppx, eqs=pt2_axeqs, xid=xindex):
309309
sw, su = np.linalg.eigh(s.reshape((ns, ns)))
310310
idx = sw > ic.trunc_thrds
311311
sf = su[:, idx] * (sw[idx] ** (-0.5))
312-
sf = sf.reshape((*s.shape[:len(s.shape) // 2], -1))
312+
sf = sf.reshape((*s.shape[:len(s.shape) // 2], sf.shape[-1]))
313313
exec(pt2_beqs, globals(), { "b": b, **mdict })
314314
def trans_forth(g, sf=sf):
315315
return np.einsum("%s,%sx->x" % (rkey, rkey), g, sf, optimize=True)
@@ -341,7 +341,7 @@ def axop(px, eqs=pt2_axeqs, xid=xindex):
341341
" | ".join(["%s = %7.2f" % (k, v) for k, v in ic.sub_times.items()]))
342342

343343
class WickICMRREPT2(lib.StreamObject):
344-
def __init__(self, mc):
344+
def __init__(self, mc, frozen=0):
345345
self._mc = mc
346346
assert mc.canonicalization
347347
self._scf = mc._scf
@@ -350,6 +350,7 @@ def __init__(self, mc):
350350
self.stdout = self.mol.stdout
351351
self.e_corr = None
352352
self.trunc_thrds = 1E-4
353+
self.frozen = frozen
353354

354355
@property
355356
def e_tot(self):

pyblock2/icmr/icnevpt2.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -245,17 +245,17 @@ def kernel(ic, mc=None, mo_coeff=None, pdms=None, eris=None, root=None, iprint=N
245245
tpdms = time.perf_counter() - t
246246
if eris is None:
247247
t = time.perf_counter()
248-
eris = eri_helper.init_eris(mc=mc, mo_coeff=ic.mo_coeff)
248+
eris = eri_helper.init_eris(mc=mc, mo_coeff=ic.mo_coeff, frozen=ic.frozen)
249249
teris = time.perf_counter() - t
250250
ic.eris = eris
251251
assert isinstance(eris, eri_helper._ChemistsERIs)
252252
E1, E2, E3, E4 = pdms
253-
ncore = mc.ncore
253+
ncore = mc.ncore - ic.frozen
254254
ncas = mc.ncas
255255
nocc = ncore + ncas
256-
nvirt = len(ic.mo_energy) - nocc
257-
orbeI = ic.mo_energy[:ncore]
258-
orbeE = ic.mo_energy[nocc:]
256+
nvirt = len(ic.mo_energy) - nocc - ic.frozen
257+
orbeI = ic.mo_energy[ic.frozen:ic.frozen + ncore]
258+
orbeE = ic.mo_energy[ic.frozen + nocc:]
259259
wkeys = ["wAAAA", "wEAAA", "wEAIA", "wEAAI", "wAAIA",
260260
"wEEIA", "wEAII", "wEEAA", "wAAII", "wEEII"]
261261
mdict = {
@@ -351,14 +351,15 @@ def axop(x, eqs=pt2_axeqs, xid=xindex, ridx=ridx):
351351
" | ".join(["%s = %7.2f" % (k, v) for k, v in ic.sub_times.items()]))
352352

353353
class WickICNEVPT2(lib.StreamObject):
354-
def __init__(self, mc):
354+
def __init__(self, mc, frozen=0):
355355
self._mc = mc
356356
self._scf = mc._scf
357357
self.mol = self._scf.mol
358358
self.verbose = self.mol.verbose
359359
self.stdout = self.mol.stdout
360360
self.canonicalized = False
361361
self.e_corr = None
362+
self.frozen = frozen
362363

363364
@property
364365
def e_tot(self):

pyblock2/icmr/icnevpt2_full.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -211,17 +211,17 @@ def kernel(ic, mc=None, mo_coeff=None, pdms=None, eris=None, root=None):
211211
tpdms = time.perf_counter() - t
212212
if eris is None:
213213
t = time.perf_counter()
214-
eris = eri_helper.init_eris(mc=mc, mo_coeff=ic.mo_coeff)
214+
eris = eri_helper.init_eris(mc=mc, mo_coeff=ic.mo_coeff, frozen=ic.frozen)
215215
teris = time.perf_counter() - t
216216
ic.eris = eris
217217
assert isinstance(eris, eri_helper._ChemistsERIs)
218218
E1, E2, E3, E4 = pdms
219-
ncore = mc.ncore
219+
ncore = mc.ncore - ic.frozen
220220
ncas = mc.ncas
221221
nocc = ncore + ncas
222-
nvirt = len(ic.mo_energy) - nocc
223-
orbeI = ic.mo_energy[:ncore]
224-
orbeE = ic.mo_energy[nocc:]
222+
nvirt = len(ic.mo_energy) - nocc - ic.frozen
223+
orbeI = ic.mo_energy[ic.frozen:ic.frozen + ncore]
224+
orbeE = ic.mo_energy[ic.frozen + nocc:]
225225
wkeys = ["wAAAA", "wEAAA", "wEAIA", "wEAAI", "wAAIA",
226226
"wEEIA", "wEAII", "wEEAA", "wAAII", "wEEII"]
227227
mdict = {
@@ -316,14 +316,15 @@ def kernel(ic, mc=None, mo_coeff=None, pdms=None, eris=None, root=None):
316316
" | ".join(["%s = %7.2f" % (k, v) for k, v in ic.sub_times.items()]))
317317

318318
class WickICNEVPT2(lib.StreamObject):
319-
def __init__(self, mc):
319+
def __init__(self, mc, frozen=0):
320320
self._mc = mc
321321
self._scf = mc._scf
322322
self.mol = self._scf.mol
323323
self.verbose = self.mol.verbose
324324
self.stdout = self.mol.stdout
325325
self.canonicalized = False
326326
self.e_corr = None
327+
self.frozen = frozen
327328

328329
@property
329330
def e_tot(self):

pyblock2/icmr/icnevpt2_ortho.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -266,17 +266,17 @@ def kernel(ic, mc=None, mo_coeff=None, pdms=None, eris=None, root=None, iprint=N
266266
tpdms = time.perf_counter() - t
267267
if eris is None:
268268
t = time.perf_counter()
269-
eris = eri_helper.init_eris(mc=mc, mo_coeff=ic.mo_coeff)
269+
eris = eri_helper.init_eris(mc=mc, mo_coeff=ic.mo_coeff, frozen=ic.frozen)
270270
teris = time.perf_counter() - t
271271
ic.eris = eris
272272
assert isinstance(eris, eri_helper._ChemistsERIs)
273273
E1, E2, E3, E4 = pdms
274-
ncore = mc.ncore
274+
ncore = mc.ncore - ic.frozen
275275
ncas = mc.ncas
276276
nocc = ncore + ncas
277-
nvirt = len(ic.mo_energy) - nocc
278-
orbeI = ic.mo_energy[:ncore]
279-
orbeE = ic.mo_energy[nocc:]
277+
nvirt = len(ic.mo_energy) - nocc - ic.frozen
278+
orbeI = ic.mo_energy[ic.frozen:ic.frozen + ncore]
279+
orbeE = ic.mo_energy[ic.frozen + nocc:]
280280
wkeys = ["wAAAA", "wEAAA", "wEAIA", "wEAAI", "wAAIA",
281281
"wEEIA", "wEAII", "wEEAA", "wAAII", "wEEII"]
282282
mdict = {
@@ -340,8 +340,8 @@ def kernel(ic, mc=None, mo_coeff=None, pdms=None, eris=None, root=None, iprint=N
340340
idx = sw > ic.trunc_thrds
341341
sf = su[:, idx] * (sw[idx] ** (-0.5))
342342
sb = su[:, idx] * (sw[idx] ** 0.5)
343-
sf = sf.reshape((2, *s.shape[:len(s.shape) // 2], -1))
344-
sb = sb.reshape((2, *s.shape[:len(s.shape) // 2], -1))
343+
sf = sf.reshape((2, *s.shape[:len(s.shape) // 2], sf.shape[-1]))
344+
sb = sb.reshape((2, *s.shape[:len(s.shape) // 2], sb.shape[-1]))
345345
exec(pt2_beqs, globals(), { "b": b, "b2": b2, **mdict })
346346
def trans_forth(g, sf=sf):
347347
return np.einsum("v%s,v%sx->%sx" % (rkey, key[4 - l:-1], key[:9 - l]), g, sf, optimize=True)
@@ -364,8 +364,8 @@ def axop(ppx, eqs=pt2_axeqs, xid=xindex):
364364
idx = sw > ic.trunc_thrds
365365
sf = su[:, idx] * (sw[idx] ** (-0.5))
366366
sb = su[:, idx] * (sw[idx] ** 0.5)
367-
sf = sf.reshape((*s.shape[:len(s.shape) // 2], -1))
368-
sb = sb.reshape((*s.shape[:len(s.shape) // 2], -1))
367+
sf = sf.reshape((*s.shape[:len(s.shape) // 2], sf.shape[-1]))
368+
sb = sb.reshape((*s.shape[:len(s.shape) // 2], sb.shape[-1]))
369369
exec(pt2_beqs, globals(), { "b": b, **mdict })
370370
def trans_forth(g, sf=sf):
371371
return np.einsum("%s,%sx->%sx" % (rkey, key[4 - l:-1], key[:9 - l]), g, sf, optimize=True)
@@ -408,7 +408,7 @@ def axop(px, eqs=pt2_axeqs, xid=xindex, ridx=ridx):
408408
" | ".join(["%s = %7.2f" % (k, v) for k, v in ic.sub_times.items()]))
409409

410410
class WickICNEVPT2(lib.StreamObject):
411-
def __init__(self, mc):
411+
def __init__(self, mc, frozen=0):
412412
self._mc = mc
413413
self._scf = mc._scf
414414
self.mol = self._scf.mol
@@ -417,6 +417,7 @@ def __init__(self, mc):
417417
self.e_corr = None
418418
self.canonicalized = False
419419
self.trunc_thrds = 1E-4
420+
self.frozen = frozen
420421

421422
@property
422423
def e_tot(self):

pyblock2/icmr/scnevpt2.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -150,17 +150,17 @@ def kernel(ic, mc=None, mo_coeff=None, pdms=None, eris=None, root=None):
150150
tpdms = time.perf_counter() - t
151151
if eris is None:
152152
t = time.perf_counter()
153-
eris = eri_helper.init_eris(mc=mc, mo_coeff=ic.mo_coeff)
153+
eris = eri_helper.init_eris(mc=mc, mo_coeff=ic.mo_coeff, frozen=ic.frozen)
154154
teris = time.perf_counter() - t
155155
ic.eris = eris
156156
assert isinstance(eris, eri_helper._ChemistsERIs)
157157
E1, E2, E3, E4 = pdms
158-
ncore = mc.ncore
158+
ncore = mc.ncore - ic.frozen
159159
ncas = mc.ncas
160160
nocc = ncore + ncas
161-
nvirt = len(ic.mo_energy) - nocc
162-
orbeI = ic.mo_energy[:ncore]
163-
orbeE = ic.mo_energy[nocc:]
161+
nvirt = len(ic.mo_energy) - nocc - ic.frozen
162+
orbeI = ic.mo_energy[ic.frozen:ic.frozen + ncore]
163+
orbeE = ic.mo_energy[ic.frozen + nocc:]
164164
wkeys = ["wAAAA", "wEAAA", "wEAIA", "wEAAI", "wAAIA",
165165
"wEEIA", "wEAII", "wEEAA", "wAAII", "wEEII"]
166166
wdict = { k: eris.get_phys(k[1:]) for k in wkeys }
@@ -210,14 +210,15 @@ def kernel(ic, mc=None, mo_coeff=None, pdms=None, eris=None, root=None):
210210
" | ".join(["%s = %7.2f" % (k, v) for k, v in ic.sub_times.items()]))
211211

212212
class WickSCNEVPT2(lib.StreamObject):
213-
def __init__(self, mc):
213+
def __init__(self, mc, frozen=0):
214214
self._mc = mc
215215
self._scf = mc._scf
216216
self.mol = self._scf.mol
217217
self.verbose = self.mol.verbose
218218
self.stdout = self.mol.stdout
219219
self.canonicalized = False
220220
self.e_corr = None
221+
self.frozen = frozen
221222

222223
@property
223224
def e_tot(self):

0 commit comments

Comments
 (0)