def _run(self, **kwargs): if self.with_df: self._pyscf = self._pyscf.density_fit() self._pyscf.with_df.auxbasis = self.auxbasis self._pyscf.run(**kwargs) if self.check_stability: for niter in range(1, self.stability_cycles + 1): stability = self.stability() if isinstance(stability, tuple): internal, external = stability else: internal = stability if np.allclose(internal, self._pyscf.mo_coeff): if niter == self.stability_cycles: if mpi.rank: log.warn('Internal stability in HF not resolved.') break else: rdm1 = self._pyscf.make_rdm1(internal, self._pyscf.mo_occ) self._pyscf.scf(dm0=rdm1) if not self.with_df: self._eri_ao = util.restore(1, self.mol._pyscf.intor('int2e'), self.nao) else: self._eri_ao = lib.unpack_tril(self._pyscf.with_df._cderi)
def dgemm(a, b, c=None, alpha=1.0, beta=0.0): ''' Performs dgemm in Fortran memory alignment without copying. Input matrix should be contiguous (either F or C). Parameters ---------- a : array input matrix a b : array input matrix b c : array, optional output matrix c, if None then it is allocated inside the function, default None alpha : float, optional scalar factor for matrix a beta : float, optional scalar factor for matrix c Returns ------- c : ndarray output matrix ''' #FIXME: this needs testing better - currently this should only be # used where it has been tested against np.dot specifically for # that use case! if (not _is_contiguous(a)) or (not _is_contiguous(b)): log.warn('DGEMM called on non-contiguous data') m, k = a.shape n = b.shape[1] assert k == b.shape[0] a, ta = _reorder_fortran(a) b, tb = _reorder_fortran(b) if c is None: c = np.zeros((m, n), dtype=np.float64, order='C') if m == 0 or n == 0 or k == 0: return c c, tc = _reorder_fortran(c) c = blas.dgemm(alpha=alpha, a=b, b=a, c=c, beta=beta, trans_a=not tb, trans_b=not ta) c, tc = _reorder_c(c) return c
def __init__(self, uhf, **kwargs): super().__init__(uhf, **kwargs) self.options = _set_options(self.options, **kwargs) if mpi.mpi is None: log.warn( 'No MPI4Py installation detected, OptUAGF2 will therefore run in serial.' ) self.setup()
def zgemm(a, b, c=None, alpha=1.0 + 0.0j, beta=0.0 + 0.0j): ''' Performs zgemm in Fortran memory alignment without copying. Input matrix should be contiguous (either F or C). Parameters ---------- a : array input matrix a b : array input matrix b c : array, optional output matrix c, if None then it is allocated inside the function, default None alpha : complex, optional scalar factor for matrix a beta : float, optional scalar factor for matrix c Returns ------- c : ndarray output matrix ''' if (not _is_contiguous(a)) or (not _is_contiguous(b)): log.warn('ZGEMM called on non-contiguous data') m, k = a.shape n = b.shape[1] assert k == b.shape[0] a, ta = _reorder_fortran(a) b, tb = _reorder_fortran(b) if c is None: c = np.zeros((m, n), dtype=np.complex128, order='C') if m == 0 or n == 0 or k == 0: return c c, tc = _reorder_fortran(c) c = blas.zgemm(alpha=alpha, a=b, b=a, c=c, beta=beta, trans_a=not tb, trans_b=not ta) c, tc = _reorder_c(c) return c
def run(self, **kwargs): if self.disable_omp: with lib.with_omp_threads(1): self._run(**kwargs) else: self._run(**kwargs) if not self._pyscf.converged: if mpi.rank: log.warn('%s did not converge.' % self.__class__.__name__) return self
def cholesky_qr(a): ''' Performs the Cholesky QR decomposition. This can be unstable. ''' try: x = np.dot(a.T, a) r = np.linalg.cholesky(x).T q = np.dot(a, np.linalg.inv(r)) except np.linalg.LinAlgError: # pragma: no cover if mpi.rank: log.warn('Matrix not positive definite in Cholesky step of ' 'util.linalg.qholesky_qr - falling back to numpy.') return np.linalg.qr(a) return q, r
def davidson(se, h_phys, chempot=0.0, nroots=1, which='SM', tol=1e-14, maxiter=None, ntrial=None): ''' Diagonalise the auxiliary + physical space via a Davidson iterative eigensolver. ''' _check_dims(se, h_phys) ndim = se.nphys + se.naux if maxiter is None: maxiter = 10 * ndim if ntrial is None: ntrial = min(ndim, max(2*nroots+1, 20)) abs_op = np.absolute if which in ['SM', 'LM'] else lambda x: x order = 1 if which in ['SM', 'SA'] else -1 matvec = lambda x : se.dot(h_phys, np.asarray(x)) diag = np.concatenate([np.diag(h_phys), se.e]) guess = [np.zeros((ndim)) for n in range(nroots)] mask = np.argsort(abs_op(diag))[::order] for i in range(nroots): guess[i][mask[i]] = 1 def pick(w, v, nroots, callback): mask = np.argsort(abs_op(w)) mask = mask[::order] w = w[mask] v = v[:,mask] return w, v, 0 conv, w, v = util.davidson(matvec, guess, diag, tol=tol, nroots=nroots, max_space=ntrial, max_cycle=maxiter, pick=pick) if not np.all(conv): log.warn('Davidson solver did not converge.') return w, v
def test_warn(self): with self.assertWarns(Warning): log.warn('This is a test')