Skip to content

Commit

Permalink
Attempt no ipie import.
Browse files Browse the repository at this point in the history
  • Loading branch information
fdmalone committed Dec 9, 2023
1 parent 30e887f commit 9e7558a
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 58 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: [ '3.8', '3.9', '3.10' ]
python-version: [ '3.10' ]
mpi:
- openmpi
runs-on: ubuntu-latest
Expand Down Expand Up @@ -67,7 +67,7 @@ jobs:
timeout-minutes: 10
run: |
# mpiexec -n 2 python -m pytest ipie/legacy/walkers/tests/test_handler.py
mpiexec -n 6 python -m pytest ipie/estimators/tests/test_generic_chunked.py
mpiexec -n 6 python ipie/estimators/tests/test_generic_chunked.py
# mpiexec -n 6 python -m pytest ipie/propagation/tests/test_generic_chunked.py
# pytest-no_mpi:
# runs-on: ubuntu-latest
Expand Down
114 changes: 58 additions & 56 deletions ipie/estimators/tests/test_generic_chunked.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,22 @@
#

import numpy
import pytest

from ipie.config import MPI
from ipie.estimators.local_energy_sd import local_energy_single_det_batch
from ipie.estimators.local_energy_sd_chunked import local_energy_single_det_uhf_batch_chunked
from ipie.hamiltonians.generic import Generic as HamGeneric
from ipie.propagation.phaseless_generic import PhaselessGenericChunked
from ipie.systems.generic import Generic
from ipie.trial_wavefunction.single_det import SingleDet
from ipie.utils.misc import dotdict
from ipie.utils.mpi import get_shared_array, MPIHandler
from ipie.utils.pack_numba import pack_cholesky
from ipie.utils.testing import generate_hamiltonian, get_random_nomsd
from ipie.walkers.walkers_dispatch import UHFWalkersTrial

# from ipie.walkers.walkers_dispatch import UHFWalkersTrial
from mpi4py import MPI

# from ipie.config import MPI
# from ipie.estimators.local_energy_sd import local_energy_single_det_batch
# from ipie.estimators.local_energy_sd_chunked import local_energy_single_det_uhf_batch_chunked
# from ipie.hamiltonians.generic import Generic as HamGeneric
# from ipie.propagation.phaseless_generic import PhaselessGenericChunked
# from ipie.systems.generic import Generic
# from ipie.trial_wavefunction.single_det import SingleDet
# from ipie.utils.misc import dotdict
# from ipie.utils.mpi import get_shared_array, MPIHandler
# from ipie.utils.pack_numba import pack_cholesky
# from ipie.utils.testing import generate_hamiltonian, get_random_nomsd


comm = MPI.COMM_WORLD
size = comm.Get_size()
Expand All @@ -40,72 +42,72 @@
skip = comm.size == 1


@pytest.mark.unit
@pytest.mark.skipif(skip, reason="Test should be run on multiple cores.")
def test_generic_chunked():
nwalkers = 50
nsteps = 20
numpy.random.seed(7)
nmo = 24
nelec = (4, 2)
h1e, chol, enuc, eri = generate_hamiltonian(nmo, nelec, cplx=False)
# h1e, chol, enuc, eri = generate_hamiltonian(nmo, nelec, cplx=False)
h1e = numpy.random.normal(size=(nmo, nmo))
eri = numpy.random.normal(size=(nmo,) * 4)
print(comm.rank, comm.size)

h1e = comm.bcast(h1e)
chol = comm.bcast(chol)
enuc = comm.bcast(enuc)
eri = comm.bcast(eri)
print(comm.rank, eri.shape)

chol = chol.reshape((-1, nmo * nmo)).T.copy()
# chol = chol.reshape((-1, nmo * nmo)).T.copy()

nchol = chol.shape[-1]
chol = chol.reshape((nmo, nmo, nchol))
# nchol = chol.shape[-1]
# chol = chol.reshape((nmo, nmo, nchol))

idx = numpy.triu_indices(nmo)
cp_shape = (nmo * (nmo + 1) // 2, chol.shape[-1])
# chol_packed = numpy.zeros(cp_shape, dtype = chol.dtype)
chol_packed = get_shared_array(comm, cp_shape, chol.dtype)
# idx = numpy.triu_indices(nmo)
# cp_shape = (nmo * (nmo + 1) // 2, chol.shape[-1])
# # chol_packed = numpy.zeros(cp_shape, dtype = chol.dtype)
# chol_packed = get_shared_array(comm, cp_shape, chol.dtype)

if comm.rank == 0:
pack_cholesky(idx[0], idx[1], chol_packed, chol)
# if comm.rank == 0:
# pack_cholesky(idx[0], idx[1], chol_packed, chol)

chol = chol.reshape((nmo * nmo, nchol))
# chol = chol.reshape((nmo * nmo, nchol))

system = Generic(nelec=nelec)
ham = HamGeneric(h1e=numpy.array([h1e, h1e]), chol=chol, ecore=enuc)
_, wfn = get_random_nomsd(system.nup, system.ndown, ham.nbasis, ndet=1, cplx=False)
trial = SingleDet(wfn[0], nelec, nmo)
trial.half_rotate(ham)
# system = Generic(nelec=nelec)
# ham = HamGeneric(h1e=numpy.array([h1e, h1e]), chol=chol, ecore=enuc)
# _, wfn = get_random_nomsd(system.nup, system.ndown, ham.nbasis, ndet=1, cplx=False)
# trial = SingleDet(wfn[0], nelec, nmo)
# trial.half_rotate(ham)

trial.calculate_energy(system, ham)
# trial.calculate_energy(system, ham)

qmc = dotdict({"dt": 0.005, "nstblz": 5, "batched": True, "nwalkers": nwalkers})
# qmc = dotdict({"dt": 0.005, "nstblz": 5, "batched": True, "nwalkers": nwalkers})

mpi_handler = MPIHandler(nmembers=3, verbose=(rank == 0))
if comm.rank == 0:
print("# Chunking hamiltonian.")
ham.chunk(mpi_handler)
if comm.rank == 0:
print("# Chunking trial.")
trial.chunk(mpi_handler)
# mpi_handler = MPIHandler(nmembers=3, verbose=(rank == 0))
# if comm.rank == 0:
# print("# Chunking hamiltonian.")
# ham.chunk(mpi_handler)
# if comm.rank == 0:
# print("# Chunking trial.")
# trial.chunk(mpi_handler)

prop = PhaselessGenericChunked(time_step=qmc["dt"])
prop.build(ham, trial, mpi_handler=mpi_handler)
# prop = PhaselessGenericChunked(time_step=qmc["dt"])
# prop.build(ham, trial, mpi_handler=mpi_handler)

init_walker = numpy.hstack([trial.psi0a, trial.psi0b])
walkers = UHFWalkersTrial(
trial, init_walker, system.nup, system.ndown, ham.nbasis, nwalkers, mpi_handler
)
walkers.build(trial)
# init_walker = numpy.hstack([trial.psi0a, trial.psi0b])
# walkers = UHFWalkersTrial(
# trial, init_walker, system.nup, system.ndown, ham.nbasis, nwalkers, mpi_handler
# )
# walkers.build(trial)

for i in range(nsteps):
prop.propagate_walkers(walkers, ham, trial, trial.energy)
walkers.reortho()
# for i in range(nsteps):
# prop.propagate_walkers(walkers, ham, trial, trial.energy)
# walkers.reortho()

energies = local_energy_single_det_batch(system, ham, walkers, trial)
# energies = local_energy_single_det_batch(system, ham, walkers, trial)

energies_chunked = local_energy_single_det_uhf_batch_chunked(system, ham, walkers, trial)
# energies_chunked = local_energy_single_det_uhf_batch_chunked(system, ham, walkers, trial)

assert numpy.allclose(energies, energies_chunked)
# assert numpy.allclose(energies, energies_chunked)


if __name__ == "__main__":
Expand Down

0 comments on commit 9e7558a

Please sign in to comment.