gpu4pyscf
gpu4pyscf copied to clipboard
Compute Hamilton from smiles
Hi, guys! Thanks for your work! It's really awesome and I'm trying to compute Hamilton from smiles. However, the gpu computed results is nan while the cpu can compute the right results. Here's my code:
from rdkit import Chem
from rdkit.Chem import AllChem
from pyscf import gto, dft
def get_mol_info(mol):
mol = Chem.AddHs(mol)
# compute 3D coordinates
AllChem.EmbedMolecule(mol)
AllChem.MMFFOptimizeMolecule(mol)
conformer = mol.GetConformer()
coords = [conformer.GetAtomPosition(i) for i in range(mol.GetNumAtoms())]
positions = [[coord.x, coord.y, coord.z] for coord in coords]
# get atomic numbers
atoms = mol.GetAtoms()
atomic_numbers = [atom.GetAtomicNum() for atom in atoms]
# get atom number
atom_number = mol.GetNumAtoms()
# compute hamiltonian
mol_hf = gto.Mole()
mol_hf.build(
verbose=4,
atom=[[atomic_numbers[i], positions[i]] for i in range(len(atomic_numbers))],
# basis='6-31g',
basis='def2-SVP',
unit='ang'
)
mf_hf = dft.RKS(mol_hf).to_gpu()
mf_hf.xc = 'b3lyp'
mf_hf.kernel()
hamiltonian = mf_hf.get_fock().get()
return atom_number, atomic_numbers, positions, hamiltonian
atoms = Chem.MolFromSmiles('O=S(=O)(Nc1cccc(-c2cnc3ccccc3n2)c1)c1cccs1')
atom_number, atomic_numbers, positions, hamiltonian = get_mol_info(atoms)
And the results computed by gpu is here:
******** <class 'gpu4pyscf.dft.rks.RKS'> ********
method = RKS
initial guess = minao
damping factor = 0
level_shift factor = 0
DIIS = <class 'gpu4pyscf.scf.diis.CDIIS'>
diis_start_cycle = 1
diis_space = 8
diis_damp = 0
SCF conv_tol = 1e-09
SCF conv_tol_grad = None
SCF max_cycles = 50
direct_scf = True
direct_scf_tol = 1e-13
chkfile to save SCF result = [/tmp/tmpdgebvox5](https://vscode-remote+ssh-002dremote-
002b7b22686f73744e616d65223a22413430227d.vscode-resource.vscode-cdn.net/tmp/tmpdgebvox5)
max_memory 4000 MB (current use 495 MB)
Set gradient conv threshold to 3.16228e-05
Initial guess from minao.
tot grids = 489472
init E= nan
cycle= 1 E= nan delta_E= nan |ddm|= nan
cycle= 2 E= nan delta_E= nan |ddm|= nan
cycle= 3 E= nan delta_E= nan |ddm|= nan
cycle= 4 E= nan delta_E= nan |ddm|= nan
cycle= 5 E= nan delta_E= nan |ddm|= nan
cycle= 6 E= nan delta_E= nan |ddm|= nan
cycle= 7 E= nan delta_E= nan |ddm|= nan
cycle= 8 E= nan delta_E= nan |ddm|= nan
cycle= 9 E= nan delta_E= nan |ddm|= nan
Any suggestions?
I am not able to reproduce the nan issue on my side. Let us collect more information of your environment. Can you save the log file, using the following script?
mol_hf.build(
verbose=7,
output='pyscf.log',
atom=[[atomic_numbers[i], positions[i]] for i in range(len(atomic_numbers))],
# basis='6-31g',
basis='def2-SVP',
unit='ang'
)
And can you also print gpu4pyscf.__config__.props?
Thank you wxj6000! I test the same code the other day, however, this time the code can produce the right outputs. It's very strange that it sometimes outputs nan and after some time it can output the correct result. I guess it's because of the random number? I will put more information if the nan problem happen again. Thank you very much wxj6000!
Hi @Maximilian1794 I am not aware of any random number is used. We certainly need to take care of the issue even though it is random. My best guess is the environment, such as possible package conflict, CUDA toolkit version, and so on. Please let us know if you have any evidence.
Hi, @wxj6000, the same problem happens again. And I collect the information as you mentioned. The dft output log is here: https://drive.google.com/file/d/1aLA4kN6vHWu-qv-tJWYd1ZcgMwEPEGAe/view?usp=share_link My output of gpu4pyscf.config.props is:
name b'NVIDIA A40'
totalGlobalMem 47622258688
sharedMemPerBlock 49152
regsPerBlock 65536
warpSize 32
maxThreadsPerBlock 1024
maxThreadsDim (1024, 1024, 64)
maxGridSize (2147483647, 65535, 65535)
clockRate 1740000
totalConstMem 65536
major 8
minor 6
textureAlignment 512
texturePitchAlignment 32
multiProcessorCount 84
kernelExecTimeoutEnabled 1
integrated 0
canMapHostMemory 1
computeMode 0
maxTexture1D 131072
maxTexture2D (131072, 65536)
maxTexture3D (16384, 16384, 16384)
concurrentKernels 1
ECCEnabled 1
pciBusID 59
pciDeviceID 0
pciDomainID 0
tccDriver 0
memoryClockRate 7251000
memoryBusWidth 384
l2CacheSize 6291456
maxThreadsPerMultiProcessor 1536
isMultiGpuBoard 0
cooperativeLaunch 1
cooperativeMultiDeviceLaunch 1
deviceOverlap 1
maxTexture1DMipmap 32768
maxTexture1DLinear 268435456
maxTexture1DLayered (32768, 2048)
maxTexture2DMipmap (32768, 32768)
maxTexture2DLinear (131072, 65000, 2097120)
maxTexture2DLayered (32768, 32768, 2048)
maxTexture2DGather (32768, 32768)
maxTexture3DAlt (8192, 8192, 32768)
maxTextureCubemap 32768
maxTextureCubemapLayered (32768, 2046)
maxSurface1D 32768
maxSurface1DLayered (32768, 2048)
maxSurface2D (131072, 65536)
maxSurface2DLayered (32768, 32768, 2048)
maxSurface3D (16384, 16384, 16384)
maxSurfaceCubemap 32768
maxSurfaceCubemapLayered (32768, 2046)
surfaceAlignment 512
asyncEngineCount 2
unifiedAddressing 1
streamPrioritiesSupported 1
globalL1CacheSupported 1
localL1CacheSupported 1
sharedMemPerMultiprocessor 102400
regsPerMultiprocessor 65536
managedMemory 1
multiGpuBoardGroupID 0
hostNativeAtomicSupported 0
singleToDoublePrecisionPerfRatio 32
pageableMemoryAccess 0
concurrentManagedAccess 1
computePreemptionSupported 1
canUseHostPointerForRegisteredMem 1
sharedMemPerBlockOptin 101376
pageableMemoryAccessUsesHostPageTables 0
directManagedMemAccessFromHost 0
uuid b'\xb3k\x06\xd7\xc9\xce\x1c\x8f\xcd\xbd\xcb\xae\xe4\xdd\xe0n'
luid b''
luidDeviceNodeMask 0
persistingL2CacheMaxSize 4325376
maxBlocksPerMultiProcessor 16
accessPolicyMaxWindowSize 134213632
reservedSharedMemPerBlock 1024
I'll close this issue for now since the problem cannot be reproduced. Please feel free to reopen it if it occurs again.