Ejemplo n.º 1
0
 def save_cache(self, filename, to_save, use_pickle=False):
     """ Save data to cache."""
     fullpath = os.path.join(self.cache_dir, filename)
     if use_pickle or type(to_save) == dict:
         with open(fullpath + '.pkl', 'wb') as f:
             pickle.dump(to_save, f, protocol=pickle.HIGHEST_PROTOCOL)
     else:
         save_array(fullpath + '.bcolz', to_save)
Ejemplo n.º 2
0
    J = 1.

    H = 'TFI'  # XXZ

    if H == 'TFI':
        dir_path = 'data/1d_TFI_g%.1f/' % (g)
    elif H == 'XXZ':
        dir_path = 'data/1d_XXZ_g%.1f/' % (g)

    if not os.path.exists(dir_path):
        os.makedirs(dir_path)

    filename = 'exact_energy.csv'
    path = dir_path + filename

    # Try to load file
    # If data return
    E_dict = {}
    try:
        E_array = misc.load_array(path)
        E_dict = misc.nparray_2_dict(E_array)
        assert L in E_dict.keys()
        print("Found data")
    except Exception as error:
        print(error)
        energy = ed.get_E_exact(g, J, L, H)
        E_dict[L] = energy
        misc.save_array(path, misc.dict_2_nparray(E_dict))
        # If no data --> generate data
        print("Save new data")