Skip to content
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

Error: cannot reshape array size ... #8

Open
steto123 opened this issue Nov 20, 2024 · 2 comments
Open

Error: cannot reshape array size ... #8

steto123 opened this issue Nov 20, 2024 · 2 comments

Comments

@steto123
Copy link

Dear devs.

I use a simple script for calculating nmr shieldings:

xyzin="propanol-g_opt1.xyz" # running

xyzin ="clprop1-g_opt1.xyz"
logfile="nmrtest2.log"

import pyscf

from pyscf import gto, dft

from gpu4pyscf.dft import rks
from pyscf.prop import nmr

mol = pyscf.M(atom=xyzin, basis='6-31g*', output=logfile)

mf = dft.RKS(mol)
mf.xc = 'b3lyp'
mf.run()

nmr.RKS(mf).kernel()

Using the optimized geometry for 2-chloropropen fails in this calculation (with and without gpu support):


ValueError Traceback (most recent call last)
Cell In[9], line 24
21 mf.xc = 'b3lyp'
22 mf.run()
---> 24 nmr.RKS(mf).kernel()

File ~/.conda/envs/mycuda11/lib/python3.12/site-packages/pyscf/prop/nmr/rhf.py:287, in NMR.kernel(self, mo1)
286 def kernel(self, mo1=None):
--> 287 return self.shielding(mo1)

File ~/.conda/envs/mycuda11/lib/python3.12/site-packages/pyscf/prop/nmr/rhf.py:297, in NMR.shielding(self, mo1)
294 msc_dia = self.dia(self.gauge_orig)
296 if mo1 is None:
--> 297 self.mo10, self.mo_e10 = self.solve_mo1()
298 mo1 = self.mo10
299 msc_para, para_vir, para_occ = self.para(mo10=mo1)

File ~/.conda/envs/mycuda11/lib/python3.12/site-packages/pyscf/prop/nmr/rks.py:151, in solve_mo1(nmrobj, mo_energy, mo_coeff, mo_occ, h1, s1, with_cphf)
149 libxc = nmrobj._scf._numint.libxc
150 with_cphf = with_cphf and libxc.is_hybrid_xc(nmrobj._scf.xc)
--> 151 return rhf_nmr.solve_mo1(nmrobj, mo_energy, mo_coeff, mo_occ,
152 h1, s1, with_cphf)

File ~/.conda/envs/mycuda11/lib/python3.12/site-packages/pyscf/prop/nmr/rhf.py:209, in solve_mo1(nmrobj, mo_energy, mo_coeff, mo_occ, h1, s1, with_cphf)
207 else:
208 vind = gen_vind(nmrobj._scf, mo_coeff, mo_occ)
--> 209 mo10, mo_e10 = cphf.solve(vind, mo_energy, mo_occ, h1, s1,
210 nmrobj.max_cycle_cphf, nmrobj.conv_tol,
211 verbose=log)
212 else:
213 mo10, mo_e10 = _solve_mo1_uncoupled(mo_energy, mo_occ, h1, s1)

File ~/.conda/envs/mycuda11/lib/python3.12/site-packages/pyscf/scf/cphf.py:48, in solve(fvind, mo_energy, mo_occ, h1, s1, max_cycle, tol, hermi, verbose, level_shift)
45 return solve_nos1(fvind, mo_energy, mo_occ, h1,
46 max_cycle, tol, hermi, verbose, level_shift)
47 else:
---> 48 return solve_withs1(fvind, mo_energy, mo_occ, h1, s1,
49 max_cycle, tol, hermi, verbose, level_shift)

File ~/.conda/envs/mycuda11/lib/python3.12/site-packages/pyscf/scf/cphf.py:130, in solve_withs1(fvind, mo_energy, mo_occ, h1, s1, max_cycle, tol, hermi, verbose, level_shift)
128 v[:,occidx,:] = 0
129 return v.reshape(-1, nmonocc)
--> 130 mo1 = lib.krylov(vind_vo, mo1base.reshape(-1, nmo
nocc),
131 tol=tol, max_cycle=max_cycle, hermi=hermi, verbose=log)
132 mo1 = mo1.reshape(-1, nmo, nocc)
133 mo1[:,occidx] = mo1base[:,occidx]

File ~/.conda/envs/mycuda11/lib/python3.12/site-packages/pyscf/lib/linalg_helper.py:1307, in krylov(aop, b, x0, tol, max_cycle, dot, lindep, callback, hermi, max_memory, verbose)
1305 max_cycle = min(max_cycle, ndim)
1306 for cycle in range(max_cycle):
-> 1307 axt = aop(x1)
1308 if axt.ndim == 1:
1309 axt = axt.reshape(1,ndim)

File ~/.conda/envs/mycuda11/lib/python3.12/site-packages/pyscf/scf/cphf.py:124, in solve_withs1..vind_vo(mo1)
122 def vind_vo(mo1):
123 mo1 = mo1.reshape(-1, nmo, nocc)
--> 124 v = fvind(mo1).reshape(-1, nmo, nocc)
125 if level_shift != 0:
126 v -= mo1 * level_shift

File ~/.conda/envs/mycuda11/lib/python3.12/site-packages/pyscf/prop/nmr/rhf.py:241, in gen_vind..vind(mo1)
239 def vind(mo1):
240 dm1 = [reduce(numpy.dot, (mo_coeff, x*2, orbo.T.conj()))
--> 241 for x in mo1.reshape(3,nmo,nocc)]
242 dm1 = numpy.asarray([d1-d1.conj().T for d1 in dm1])
243 v1mo = lib.einsum('xpq,pi,qj->xij', vresp(dm1), mo_coeff.conj(), orbo)

ValueError: cannot reshape array of size 2800 into shape (3,70,20)

The same calculation for 1-propanol is finished without any errors.

Can anybody help?

@fishjojo
Copy link
Collaborator

It seems like you are using an earlier version of the code. This issue should be fixed in commit 4eee5a4.

@steto123
Copy link
Author

Many thanks for your fast answer. I have installed pyscf and gpu4pyscf two days before in a fresh conda environment. This environment uses cuda11.
Using a other conda environment after (!) deinstalling gpu4pyscf and cutensor, the following code works:

`
xyzin ="clprop1-g_opt1.xyz"
logfile="clprop1_g.log"

import pyscf
from pyscf import gto, dft, prop
from pyscf.prop import nmr

mol = pyscf.M(atom=xyzin, basis='6-31g*', output=logfile)

mf = dft.RKS(mol)
mf.xc = 'b3lyp'
mf.run()

nmr.RKS(mf).kernel()

`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants