def test_select_strs1(self): myci = selected_ci.SCI() myci.select_cutoff = .1 myci.ci_coeff_cutoff = .01 eri1 = ao2mo.restore(1, eri, norb) eri_pq_max = abs(eri1.reshape(norb**2,-1)).max(axis=1).reshape(norb,norb) civec_a_max = abs(ci_coeff).max(axis=1) civec_b_max = abs(ci_coeff).max(axis=0) strs_add0 = select_strs(myci, eri1, eri_pq_max, civec_a_max, ci_strs[0], norb, nelec//2) strs_add1 = selected_ci.select_strs(myci, eri1, eri_pq_max, civec_a_max, ci_strs[0], norb, nelec//2) self.assertTrue(numpy.all(strs_add0 == strs_add1)) strs_add0 = select_strs(myci, eri1, eri_pq_max, civec_b_max, ci_strs[1], norb, nelec//2) strs_add1 = selected_ci.select_strs(myci, eri1, eri_pq_max, civec_b_max, ci_strs[1], norb, nelec//2) self.assertTrue(numpy.all(strs_add0 == strs_add1))
def test_select_strs(self): myci = selected_ci.SCI() myci.select_cutoff = 1e-3 norb, nelec = 10, 4 strs = cistring.make_strings(range(norb), nelec) numpy.random.seed(11) mask = numpy.random.random(len(strs)) > .8 strs = strs[mask] nn = norb*(norb+1)//2 eri = (numpy.random.random(nn*(nn+1)//2)-.2)**3 eri[eri<.1] *= 3e-3 eri = ao2mo.restore(1, eri, norb) eri_pq_max = abs(eri.reshape(norb**2,-1)).max(axis=1).reshape(norb,norb) civec_max = numpy.random.random(len(strs)) strs_add0 = select_strs(myci, eri, eri_pq_max, civec_max, strs, norb, nelec) strs_add1 = selected_ci.select_strs(myci, eri, eri_pq_max, civec_max, strs, norb, nelec) self.assertTrue(numpy.all(strs_add0 == strs_add1))
def enlarge_space(myci, civec_strs, eri, norb, nelec): if isinstance(civec_strs, (tuple, list)): nelec, (strsa, strsb) = selected_ci._unpack(civec_strs[0], nelec)[1:] ci_coeff = lib.asarray(civec_strs) else: ci_coeff, nelec, (strsa, strsb) = selected_ci._unpack(civec_strs, nelec) na = nb = len(strsa) ci0 = ci_coeff.reshape(-1, na, nb) abs_ci = abs(ci0).max(axis=0) eri = ao2mo.restore(1, eri, norb) eri_pq_max = abs(eri.reshape(norb**2, -1)).max(axis=1).reshape(norb, norb) civec_a_max = abs_ci.max(axis=1) ci_aidx = numpy.where(civec_a_max > myci.ci_coeff_cutoff)[0] civec_a_max = civec_a_max[ci_aidx] strsa = strsa[ci_aidx] strsa_add = selected_ci.select_strs(myci, eri, eri_pq_max, civec_a_max, strsa, norb, nelec[0]) strsa = numpy.append(strsa, strsa_add) aidx = numpy.argsort(strsa) strsa = strsa[aidx] aidx = numpy.where(aidx < len(ci_aidx))[0] ci_bidx = ci_aidx strsb = strsa bidx = aidx ma = mb = len(strsa) cs = [] for i in range(ci0.shape[0]): ci1 = numpy.zeros((ma, mb)) tmp = lib.take_2d(ci0[i], ci_aidx, ci_bidx) lib.takebak_2d(ci1, tmp, aidx, bidx) cs.append(selected_ci._as_SCIvector(ci1, (strsa, strsb))) if ci_coeff[0].ndim == 0 or ci_coeff[0].shape[-1] != nb: cs = [c.ravel() for c in cs] if (isinstance(ci_coeff, numpy.ndarray) and ci_coeff.shape[0] == na or ci_coeff.shape[0] == na * nb): cs = cs[0] return cs
def enlarge_space(myci, civec_strs, eri, norb, nelec): if isinstance(civec_strs, (tuple, list)): nelec, (strsa, strsb) = selected_ci._unpack(civec_strs[0], nelec)[1:] ci_coeff = lib.asarray(civec_strs) else: ci_coeff, nelec, (strsa, strsb) = selected_ci._unpack(civec_strs, nelec) na = nb = len(strsa) ci0 = ci_coeff.reshape(-1,na,nb) abs_ci = abs(ci0).max(axis=0) eri = ao2mo.restore(1, eri, norb) eri_pq_max = abs(eri.reshape(norb**2,-1)).max(axis=1).reshape(norb,norb) civec_a_max = abs_ci.max(axis=1) ci_aidx = numpy.where(civec_a_max > myci.ci_coeff_cutoff)[0] civec_a_max = civec_a_max[ci_aidx] strsa = strsa[ci_aidx] strsa_add = selected_ci.select_strs(myci, eri, eri_pq_max, civec_a_max, strsa, norb, nelec[0]) strsa = numpy.append(strsa, strsa_add) aidx = numpy.argsort(strsa) strsa = strsa[aidx] aidx = numpy.where(aidx < len(ci_aidx))[0] ci_bidx = ci_aidx strsb = strsa bidx = aidx ma = mb = len(strsa) cs = [] for i in range(ci0.shape[0]): ci1 = numpy.zeros((ma,mb)) tmp = lib.take_2d(ci0[i], ci_aidx, ci_bidx) lib.takebak_2d(ci1, tmp, aidx, bidx) cs.append(selected_ci._as_SCIvector(ci1, (strsa,strsb))) if ci_coeff[0].ndim == 0 or ci_coeff[0].shape[-1] != nb: cs = [c.ravel() for c in cs] if (isinstance(ci_coeff, numpy.ndarray) and ci_coeff.shape[0] == na or ci_coeff.shape[0] == na*nb): cs = cs[0] return cs