def observe(total, cmdargs): if total < 3: print(" ".join(str(x) for x in cmdargs)) raise ValueError('Missing arguments') inputname = cmdargs[1] observname = cmdargs[2] outputname = "dataObserve.hdf5" if total == 4: outputname = cmdargs[3] # --------------------------------------------------------------- para = Parameter(inputname) Lat = Lattice(para) ob = Observ(Lat) print(Lat.Model) dof = Dofs("SpinHalf") # default spin-1/2 if Lat.Model == "AKLT": dof = Dofs("SpinOne") # ------- Read dataSpec file ------- rfile = h5py.File('dataSpec.hdf5', 'r') evalset = rfile["3.Eigen"]["Eigen Values"] evecset = rfile["3.Eigen"]["Wavefunctions"] # extract eigen value and eigen vector from HDF5 rfile print(dof.hilbsize ** Lat.Nsite) evals = np.zeros(para.Nstates, dtype=float) evecs = np.zeros((dof.hilbsize ** Lat.Nsite, para.Nstates), dtype=complex) evalset.read_direct(evals) evecset.read_direct(evecs) rfile.close() # ------- Calculate spin response S(\omega) & write to HDF5--------- if observname == "spin_response": print("Calculating S(omega)...") tic = time.perf_counter() SpinRes = ob.SpRe(evals, evecs, dof.type) toc = time.perf_counter() print(f"time = {toc-tic:0.4f} sec") wfile = h5py.File(outputname, 'a') if "Spin Response" in list(wfile.keys()): wfile.__delitem__("Spin Response") # over write if existed wfile.create_dataset("Spin Response", data=SpinRes) wfile["Spin Response"].attrs["time"] = toc - tic wfile.close() # ------- Calculate spin conductivity & write to HDF5--------- elif observname == "spin_cond": pass # ------- Calculate energy conductivity & write to HDF5--------- elif observname == "energy_cond": pass # ------- Calculate Single-Magnon DOS & write to HDF5--------- elif observname == "singlemagnon": print("Calculating Single-Magnon DOS...") tic = time.perf_counter() SMag = ob.SingleMagnon(evals, evecs, dof.type) toc = time.perf_counter() print(f"time = {toc-tic:0.4f} sec") wfile = h5py.File(outputname, 'a') if "Single-Magnon DOS" in list(wfile.keys()): wfile.__delitem__("Single-Magnon DOS") # over write if existed wfile.create_dataset("Single-Magnon DOS", data=SMag) wfile["Single-Magnon DOS"].attrs["time"] = toc - tic wfile.close() # ------- Calculate SzSz DOS & write to HDF5--------- elif observname == "szsz": print("Calculating SzSz spectrum...") tic = time.perf_counter() SZSZ = ob.SzSz(evals, evecs, dof.type) toc = time.perf_counter() print(f"time = {toc-tic:0.4f} sec") wfile = h5py.File(outputname, 'a') if "SzSz" in list(wfile.keys()): wfile.__delitem__("SzSz") # over write if existed wfile.create_dataset("SzSz", data=SZSZ) wfile["SzSz"].attrs["time"] = toc - tic wfile.close() # ------- Calculate SpSm DOS & write to HDF5--------- elif observname == "spsm": print("Calculating SpSm spectrum...") tic = time.perf_counter() SPSM = ob.SpSm(evals, evecs, dof.type) toc = time.perf_counter() print(f"time = {toc - tic:0.4f} sec") wfile = h5py.File(outputname, 'a') if "SpSm" in list(wfile.keys()): wfile.__delitem__("SpSm") # over write if existed wfile.create_dataset("SpSm", data=SPSM) wfile["SpSm"].attrs["time"] = toc - tic wfile.close() # ------- Calculate energy current of TFIM & write to HDF5--------- elif observname == "ecurrent1": site = 2 if para.Model != "TFIM": raise ValueError("ecurrent1 is designed for TFIM exclusively") print("Calculating energy current of TFIM...") tic = time.perf_counter() mEcurr = ob.ecurrent1(evals, evecs, site) toc = time.perf_counter() print(f"time = {toc - tic:0.4f} sec") print("Current at site=", site, "is ", mEcurr) else: raise ValueError("Observable not supported yet")
2000: (2.5312e3, 0.284779, None), 2300: (2.5312e3, 0.284779, None), 2600: (2.5312e3, 0.284779, None), } param.z3 = MultiFreqImpType() param.z3.rlc_s = { 1700: (0.1, 4.2e-3, None), 2000: (0.1, 4.2e-3, None), 2300: (0.1, 4.2e-3, None), 2600: (0.1, 4.2e-3, None), } param.zc = MultiFreqImpType() param.zc.rlc_s = { 1700: (None, None, 2.35e-3), 2000: (None, None, 2.35e-3), 2300: (None, None, 2.35e-3), 2600: (None, None, 2.35e-3), } param.n = { 1700: 13.5, 2000: 13.5, 2300: 12, 2600: 12, } Parameter.param_dict_to_pkl(param_dict) pass
def main(total, cmdargs): if total != 2: print(" ".join(str(x) for x in cmdargs)) raise ValueError('Missing arguments') inputname = cmdargs[1] sys.stdout = Logger() # for exporting the logfile # ----------------------- Build and Diagonalize --------------------------------- para = Parameter(inputname) # import parameters from input.inp Lat = Lattice(para) # Build lattice ob = Observ(Lat) # initialize observables tic = time.perf_counter() Hamil = Hamiltonian(Lat) # Build Hamiltonian ham = Hamil.Ham # Hamiltonian as sparse matrix toc = time.perf_counter() print(f"Hamiltonian construction time = {toc - tic:0.4f} sec") tic = time.perf_counter() evals, evecs = primme.eigsh(ham, para.Nstates, tol=1e-12, which='SA') evals, evecs = sort(evals, evecs) toc = time.perf_counter() evals = np.round(evals, 10) print("\n-----------Beg of Eigen Values-----------\n", *evals, sep='\n') print("\n-----------End of Eigen Values-----------") print(f"Diagonalization time = {toc - tic:0.4f} sec \n\n") # -------------- Entanglement properties of GS ----------- if para.Option is not None: if "EE" in para.Option: EntS, Entvec = ob.EntSpec( evecs[:, 0]) # Entanglement spectrum and vector EntS = np.round(EntS, decimals=10) EntS_log = np.zeros(len(EntS)) for i in range(len(EntS)): if EntS[i] <= 0: EntS_log[i] = 0 else: EntS_log[i] = math.log(EntS[i]) EE = -np.around(np.dot(EntS, EntS_log), decimals=8) print("Entanglement Spectrum=\n", EntS) print("Entanglement Entropy=", EE) # ------------------------ Ascii Ostream for EE-------- file = open("entspec.dat", "w") # For a U-scan of Bose-Hubbard model if para.Model == "Bose_Hubbard": for i in range(EntS.size): file.write(str(abs(para.U)) + " " + str(EntS[i])) file.write("\n") else: for i in range(EntS.size): file.write(str(abs(para.Hx)) + " " + str(EntS[i])) file.write("\n") # ------------------------ Hdf5 Ostream (Big Data Storage) ------------------------------ # ------------------------ Hdf5 Ostream (Big Data Storage) ------------------------------ # ------------------------ Hdf5 Ostream (Big Data Storage) ------------------------------ tic = time.perf_counter() file = h5py.File('dataSpec.hdf5', 'w') file.attrs["LLX"] = para.LLX file.attrs["LLY"] = para.LLY file.attrs["IsPeriodicX"] = para.IsPeriodicX file.attrs["IsPeriodicY"] = para.IsPeriodicY file.attrs["Kx"] = para.Kxx file.attrs["Ky"] = para.Kyy file.attrs["Kz"] = para.Kzz file.attrs["Hx"] = para.Hz file.attrs["Hy"] = para.Hy file.attrs["Hz"] = para.Hz file.attrs["#States2Keep"] = para.Nstates file.attrs["Model"] = para.Model file.attrs["Nsites"] = Lat.Nsite LatGrp = file.create_group("1.Lattice") LatGrp.create_dataset("Mesh", data=Lat.mesh_) LatGrp.create_dataset("Nearest Neighbors", data=Lat.nn_) ConnGrp = file.create_group("2.Connectors") if para.Model == "Heisenberg_Square" or para.Model == "Kitaev": ConnGrp.create_dataset("KxxGraph", data=Hamil.KxxGraph_) ConnGrp.create_dataset("KyyGraph", data=Hamil.KyyGraph_) ConnGrp.create_dataset("KzzGraph", data=Hamil.KzzGraph_) elif para.Model == "AKLT": ConnGrp.create_dataset("Kxx1Graph", data=Hamil.Kxx1Graph_) ConnGrp.create_dataset("Kyy1Graph", data=Hamil.Kyy1Graph_) ConnGrp.create_dataset("Kzz1Graph", data=Hamil.Kzz1Graph_) ConnGrp.create_dataset("Kxx2Graph", data=Hamil.Kxx2Graph_) ConnGrp.create_dataset("Kyy2Graph", data=Hamil.Kyy2Graph_) ConnGrp.create_dataset("Kzz2Graph", data=Hamil.Kzz2Graph_) elif para.Model == "Bose_Hubbard": ConnGrp.create_dataset("tGraph", data=Hamil.tGraph_) EigGrp = file.create_group("3.Eigen") EigGrp.create_dataset("Eigen Values", data=evals) EigGrp.create_dataset("Wavefunctions", data=evecs) if para.Option is not None: if "EE" in para.Option: EigGrp = file.create_group("4.Entanglment") EigGrp.create_dataset("ES", data=EntS) EigGrp.create_dataset("ESlog", data=EntS_log) EigGrp.create_dataset("EE", data=EE) file.close() toc = time.perf_counter() print(f"\nHDF5 time = {toc - tic:0.4f} sec")