Skip to content

Commit 5ff4de7

Browse files
committed
ci: npdms
1 parent 5106394 commit 5ff4de7

File tree

3 files changed

+55
-14
lines changed

3 files changed

+55
-14
lines changed

.github/workflows/build.yml

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -101,13 +101,14 @@ jobs:
101101
- name: build gtest (linux emscripten)
102102
if: matrix.os == 'ubuntu-24.04' && matrix.plat == 'wasm'
103103
env:
104-
GTESTROOT: ~/gtest
104+
GTESTROOT: /home/runner/work/gtest
105105
run: |
106106
source emsdk/emsdk_env.sh
107107
git clone -b release-1.8.0 https://github.com/google/googletest
108108
cd googletest
109109
export GTEST_ROOT=$PWD/googletest/install
110-
CC=emcc CXX=em++ emcmake cmake CMakeLists.txt -DCMAKE_INSTALL_PREFIX=${GTESTROOT} -Dgtest_disable_pthreads=ON
110+
CC=emcc CXX=em++ emcmake cmake CMakeLists.txt -DCMAKE_INSTALL_PREFIX=${GTESTROOT} -Dgtest_disable_pthreads=ON \
111+
-DCMAKE_POLICY_VERSION_MINIMUM=3.5
111112
emmake make -j 4
112113
emmake make install
113114
@@ -128,7 +129,8 @@ jobs:
128129
Get-WmiObject -Class Win32_Processor
129130
git clone -b release-1.8.0 https://github.com/google/googletest.git
130131
cd googletest
131-
cmake -G "Visual Studio 17 2022" -S . -B . -DCMAKE_CXX_FLAGS="-D_SILENCE_TR1_NAMESPACE_DEPRECATION_WARNING" -Dgtest_force_shared_crt=ON
132+
cmake -G "Visual Studio 17 2022" -S . -B . -DCMAKE_CXX_FLAGS="-D_SILENCE_TR1_NAMESPACE_DEPRECATION_WARNING" `
133+
-Dgtest_force_shared_crt=ON -DCMAKE_POLICY_VERSION_MINIMUM="3.5"
132134
cmake --build . -j 2 --config Release
133135
cmake --install . --prefix $env:GTEST_ROOT
134136
@@ -167,7 +169,7 @@ jobs:
167169
run: |
168170
git clone -b release-1.8.0 https://github.com/google/googletest
169171
cd googletest
170-
cmake CMakeLists.txt
172+
cmake CMakeLists.txt -DCMAKE_POLICY_VERSION_MINIMUM=3.5
171173
make
172174
make install
173175
brew update
@@ -177,12 +179,12 @@ jobs:
177179
- name: build gtest (macos)
178180
if: matrix.os == 'macos-14'
179181
env:
180-
GTESTROOT: ~/gtest
182+
GTESTROOT: /Users/runner/work/gtest
181183
HOMEBREW_NO_INSTALLED_DEPENDENTS_CHECK: 1
182184
run: |
183185
git clone -b release-1.8.0 https://github.com/google/googletest
184186
cd googletest
185-
cmake CMakeLists.txt -DCMAKE_INSTALL_PREFIX=${GTESTROOT}
187+
cmake CMakeLists.txt -DCMAKE_POLICY_VERSION_MINIMUM=3.5 -DCMAKE_INSTALL_PREFIX=${GTESTROOT}
186188
make
187189
make install
188190
brew update
@@ -317,15 +319,15 @@ jobs:
317319
- name: build test (serial, linux emscripten)
318320
if: matrix.parallel == 'serial' && matrix.os == 'ubuntu-24.04' && matrix.plat == 'wasm'
319321
env:
320-
GTESTROOT: ~/gtest
322+
GTESTROOT: /home/runner/work/gtest
321323
run: |
322324
source emsdk/emsdk_env.sh
323325
export BLAS_ROOT=$PWD/xbuildenv/pyodide-root/packages/.libs
324326
mkdir build_test
325327
cd build_test
326328
cmake --version
327329
CC=emcc CXX=em++ cmake .. -DUSE_MKL=OFF -DARCH_EMSCRIPTEN=ON -DF77UNDERSCORE=ON -DBUILD_TEST=ON \
328-
-DGTEST_ROOT=${GTESTROOT} -DLARGE_BOND=ON -DUSE_COMPLEX=OFF -DUSE_DMRG=ON \
330+
-DGTest_ROOT=${GTESTROOT} -DLARGE_BOND=ON -DUSE_COMPLEX=OFF -DUSE_DMRG=ON \
329331
-DSIMPLE_TEST=ON -DCMAKE_BUILD_TYPE=Release -DOMP_LIB=NONE
330332
emmake make -j 2
331333
@@ -357,15 +359,15 @@ jobs:
357359
- name: build test (serial, macos-arm64)
358360
if: matrix.parallel == 'serial' && matrix.os == 'macos-14'
359361
env:
360-
GTESTROOT: ~/gtest
362+
GTESTROOT: /Users/runner/work/gtest
361363
MACOSX_DEPLOYMENT_TARGET: '11.0'
362364
run: |
363365
mkdir build_test
364366
cd build_test
365367
cmake --version
366368
export OMPROOT=$(brew --prefix libomp)
367369
cmake .. -DUSE_MKL=OFF -DARCH_ARM64=ON -DCMAKE_CXX_FLAGS=-I${OMPROOT}/include -DBUILD_TEST=ON -DOMP_LIB=OMP \
368-
-DLARGE_BOND=ON -DUSE_COMPLEX=ON -DUSE_SINGLE_PREC=OFF -DUSE_SG=ON -DGTEST_ROOT=${GTESTROOT} \
370+
-DLARGE_BOND=ON -DUSE_COMPLEX=ON -DUSE_SINGLE_PREC=OFF -DUSE_SG=ON -DGTest_ROOT=${GTESTROOT} \
369371
-DFORCE_LIB_ABS_PATH=OFF -DSIMPLE_TEST=ON
370372
make -j 2
371373

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
CMAKE_MINIMUM_REQUIRED(VERSION 3.0)
1+
CMAKE_MINIMUM_REQUIRED(VERSION 3.5)
22

33
FIND_PROGRAM(CMAKE_C_COMPILER NAMES $ENV{CC} gcc PATHS ENV PATH NO_DEFAULT_PATH)
44
FIND_PROGRAM(CMAKE_CXX_COMPILER NAMES $ENV{CXX} g++ PATHS ENV PATH NO_DEFAULT_PATH)

pyblock2/uc/ci.py

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,8 @@ def diag(self) -> np.ndarray:
159159
pkcis, pket = [np.ones((len(ket0 ^ 0),))], ket0 ^ 0
160160
self.e_hf = np.dot(pkcis[0], Hamiltonian(big, pket) @ pkcis[0]) + ecore
161161
self.e_corr = 0
162+
self.big = big
163+
self.ridx = np.argsort(idx)
162164
conv = False
163165
for n in range(2, self.ci_order + 1):
164166
ket = ket0 ^ n
@@ -209,15 +211,52 @@ def diag(self) -> np.ndarray:
209211

210212
return conv, self.e_corr + self.e_hf, self.ci
211213

214+
def make_npdm(self, npdm_order):
215+
is_rhf = self.mo_coeff is None or (
216+
isinstance(self.mo_coeff, np.ndarray)
217+
and self.mo_coeff.ndim == 2
218+
and self.mo_coeff.shape[0] == self.mol.nao
219+
)
220+
221+
if is_rhf:
222+
expr = "(C+D)0"
223+
for _ in range(1, npdm_order):
224+
expr = "((C+%s)1+D)0" % expr
225+
npdm = np.array(self.big.build_npdm(expr, self.ci, self.ci)[0]) * (2 ** 0.5) ** npdm_order
226+
for i in range(npdm.ndim):
227+
npdm = npdm[(slice(None),) * i + (self.ridx,)]
228+
npdm = npdm.transpose(tuple(range(npdm_order)) + tuple(range(npdm_order, npdm_order * 2))[::-1])
229+
return npdm.transpose(tuple(j for i in range(npdm_order) for j in [i, i + npdm_order]))
230+
else:
231+
exprs, npdms = ["cd", "CD"], []
232+
for _ in range(1, npdm_order):
233+
exprs = ["c%sd" % x for x in exprs] + ["C%sD" % exprs[-1]]
234+
for expr in exprs:
235+
npdm = np.array(self.big.build_npdm(expr, self.ci, self.ci)[0])
236+
for i in range(npdm.ndim):
237+
npdm = npdm[(slice(None),) * i + (self.ridx,)]
238+
npdm = npdm.transpose(tuple(range(npdm_order)) + tuple(range(npdm_order, npdm_order * 2))[::-1])
239+
npdms.append(npdm.transpose(tuple(j for i in range(npdm_order) for j in [i, i + npdm_order])))
240+
return tuple(npdms)
241+
242+
make_rdm1 = lambda self: self.make_npdm(npdm_order=1)
243+
make_rdm2 = lambda self: self.make_npdm(npdm_order=2)
212244

213245
if __name__ == "__main__":
214246

215247
from pyscf import gto, scf, ci
216248

217249
mol = gto.M(atom="N 0 0 0; N 0 0 1.1", basis="ccpvdz", symmetry="d2h", verbose=3)
218-
mf = scf.RHF(mol).run(conv_tol=1e-14)
219-
ci.CISD(mf).run()
220-
CI(mf, ci_order=2).run()
250+
mf = scf.RHF(mol).run(conv_tol=1E-14)
251+
mcx = ci.CISD(mf).run(conv_tol=1E-14)
252+
mci = CI(mf, ci_order=2).run()
253+
254+
pdm1 = mci.make_rdm1()
255+
pdm2 = mci.make_rdm2()
256+
ref_pdm1 = mcx.make_rdm1()
257+
ref_pdm2 = mcx.make_rdm2()
258+
print(np.linalg.norm(pdm1 - ref_pdm1))
259+
print(np.linalg.norm(pdm2 - ref_pdm2))
221260

222261
mol = gto.M(atom="N 0 0 0; N 0 0 1.1", basis="ccpvdz", symmetry="c1", verbose=3, spin=2)
223262
mf = scf.RHF(mol).run(conv_tol=1e-14)

0 commit comments

Comments
 (0)