def get_random(shape, num_charges, dtype=np.float64): R = len(shape) charges = [ BaseCharge(np.random.randint(-5, 6, (num_charges, shape[n])), charge_types=[U1Charge] * num_charges) for n in range(R) ] flows = list(np.full(R, fill_value=False, dtype=np.bool)) indices = [Index(charges[n], flows[n]) for n in range(R)] return BlockSparseTensor.randn(indices=indices, dtype=dtype)
# 0.5 * np.kron(np.eye(2), sZ)) ham_temp = (0.5 * np.kron(np.eye(8), np.kron(ham_s, np.eye(2))) + np.kron(np.eye(4), np.kron(ham_s, np.eye(4))) + 0.5 * np.kron(np.eye(2), np.kron(ham_s, np.eye(8)))) bias_shift = max(LA.eigvalsh(ham_temp)) - min(LA.eigvalsh(ham_temp)) # ham_temp = ham_temp - min(LA.eigvalsh(ham_temp))*np.eye(64,64) ham_init = BT.fromdense([ind_chib1] * 3 + [ind_chib0] * 3, ham_temp.reshape([chi_b] * 6)) if initialize_on: # initialize tensors u = [0] * n_levels w = [0] * n_levels utemp = np.eye(chi_b**2, chi_b**2).reshape(chi_b, chi_b, chi_b, chi_b) u[0] = BT.fromdense([ind_chib1] * 2 + [ind_chib0] * 2, utemp) w[0] = orthog_sym(BT.randn([ind_chib1] * 2 + [ind_chi0], dtype='float64'), pivot=2) for k in range(n_levels - 1): utemp = (np.eye(chi**2, chi_p**2)).reshape(chi, chi, chi_p, chi_p) u[k + 1] = BT.fromdense([ind_chi1] * 2 + [ind_chip0] * 2, utemp) w[k + 1] = orthog_sym(BT.randn([ind_chip1] * 2 + [ind_chi0], dtype='float64'), pivot=2) vtemp = np.random.rand(chi, chi, chi, 1) vtemp = vtemp / LA.norm(vtemp) v = BT.fromdense([ind_chi1] * 3 + [ind_1], vtemp) else: u, w, v, rho, ham = np.load('XXData_temp8.npy', allow_pickle=True) # np.save('XXData_temp12.npy', (u, w, v, rho, ham))
ham_temp = (0.5 * np.kron(np.eye(8), np.kron(ham_s, np.eye(2))) + np.kron(np.eye(4), np.kron(ham_s, np.eye(4))) + 0.5 * np.kron(np.eye(2), np.kron(ham_s, np.eye(8)))) ham_init = BT.fromdense([ind_chib1] * 3 + [ind_chib0] * 3, ham_temp.reshape([chi_b] * 6)) bias_shift = max(LA.eigvalsh(ham_temp)) - min(LA.eigvalsh(ham_temp)) ham = [0] * (n_levels + 1) ham[0] = ham_init.copy() if initialize_on: # initialize tensors u = [0] * n_levels w = [0] * n_levels utemp = np.eye(chi_b**2, chi_b**2).reshape(chi_b, chi_b, chi_b, chi_b) u[0] = BT.fromdense([ind_chib1] * 2 + [ind_chib0] * 2, utemp) w[0] = BT.randn([ind_chib1] * 2 + [ind_chib0], dtype='float64') for k in range(n_levels - 1): utemp = (np.eye(chi**2, chi_p**2)).reshape(chi, chi, chi_p, chi_p) u[k + 1] = BT.fromdense([ind_chi1] * 2 + [ind_chip0] * 2, utemp) w[k + 1] = BT.randn([ind_chip1] * 2 + [ind_chi0], dtype='float64') ####################################### def LiftHam(ham, u, w): tensors = [ ham, u, u, u.conj(), u.conj(), w, w, w, w.conj(), w.conj(),
ham_z0 = BT.fromdense([ind_chib1] * 3 + [ind_chib0] * 3, ham_init.reshape([chib] * 6)) # initialize tensors u = [0] * n_levels w = [0] * n_levels ham = [0] * (n_levels + 1) rho = [0] * (n_levels + 1) # --- Martin: is there a way of directly defining blocksparse `eye` matrices? eye_mat = np.eye(chib**2, chib**2).reshape(chib, chib, chib, chib) u[0] = BT.fromdense([ind_chib1, ind_chib1, ind_chib0, ind_chib0], eye_mat) # ----------------- # --- Martin: is there a way of directly defining blocksparse isometries? w_temp = BT.randn([ind_chib1, ind_chib1, ind_chi0], dtype=np.float64) ut, st, vt = BLA.svd(w_temp.reshape([chib**2, chi]), full_matrices=False) w[0] = (ut @ vt).reshape([chib, chib, chi]) # ----------------- ham_temp = (ham_init - bias * np.eye(chib**3)).reshape([chib] * 6) ham[0] = BT.fromdense([ind_chib1] * 3 + [ind_chib0] * 3, ham_temp) rho[0] = BT.randn([ind_chib0] * 3 + [ind_chib1] * 3, dtype=np.float64) for z in range(1, n_levels): eye_mat = np.eye(chim**2, chi**2).reshape(chi, chi, chim, chim) u[z] = BT.fromdense([ind_chi1, ind_chi1, ind_chim0, ind_chim0], eye_mat) w_temp = BT.randn([ind_chim1, ind_chim1, ind_chi0], dtype=np.float64) ut, st, vt = BLA.svd(w_temp.reshape([chim**2, chi]), full_matrices=False)