Skip to content

In EDA, give an error if the output will likely be lost when redirected to one file #460

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion examples/36-amlo_eda.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@

mol_list = [mol1, mol2]

eda_result = eda.eval_ALMO_EDA_2_energies(mol_list, xc = "wB97M-V")
eda_result, dft_result = eda.eval_ALMO_EDA_2_energies(mol_list, xc = "wB97M-V")
print(f"EDA result in dict form: {eda_result}")
print(f"DFT energies of each fragment and the total system: {dft_result}")

### Reference output:
# Fragment 0 energy = -76.4334344665 Hartree
Expand Down
10 changes: 10 additions & 0 deletions gpu4pyscf/properties/eda.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
from gpu4pyscf.lib.diis import DIIS
from gpu4pyscf.lib import logger
import time
import warnings

# np.set_printoptions(linewidth = np.iinfo(np.int32).max, threshold = np.iinfo(np.int32).max, precision = 16, suppress = True)

Expand Down Expand Up @@ -1080,6 +1081,7 @@ def _make_mf(mol, if_kernel = True, dispersion_free_xc = None):
mf.direct_scf_tol = 1e-16
if if_kernel:
energy = mf.kernel()
mf.mol.stdout.flush()
assert mf.converged
return mf, energy
else:
Expand All @@ -1092,9 +1094,17 @@ def _get_gradient(mf):
gradient = grad_obj.kernel()
if isinstance(gradient, cp.ndarray):
gradient = gradient.get()
mf.mol.stdout.flush()
return grad_obj.kernel()

n_frag = len(mol_list)
for i_frag in range(n_frag):
for j_frag in range(i_frag + 1, n_frag):
if mol_list[i_frag].stdout != mol_list[j_frag].stdout:
warnings.warn("The stdout of each mol in mol_list is not consistent. We do not guarantee which stdout to write. "
"Notice if the mol objects share the same \"output\" value, then the same output file is opened "
"more than once, and the outputs of earlier-created mol will be lost.")

mf_list = []
frag_energy_list = []
frag_gradient_list = []
Expand Down
Loading