def generate_npz(fname):
    print(fname)
    base = fname[:-8]
    if os.path.exists(fname + 'diag.npz'):
        pass
    method = base[:base.find('-')]

    energy_boundaries, mean_e, my_lnw, my_system, p_exc = compute.read_file(
        base)

    # Create a function for the entropy
    l_function, eee, sss = compute.linear_entropy(energy_boundaries, mean_e,
                                                  my_lnw)
    S = normalize_S(l_function(E))

    T, C = heat_capacity.data(l_function, fname=fname)

    plt.figure('fraction-well')
    mean_which = np.loadtxt(f'{base}-which.dat')

    if os.path.exists(f'{base}-histogram.dat'):
        hist = np.loadtxt(f'{base}-histogram.dat')
    else:
        hist = []

    errors_S = []
    errors_C = []
    moves = []
    for frame_fname in sorted(glob.glob(f'{base}/*-lnw.dat')):
        frame_base = frame_fname[:-8]

        frame_moves = int(frame_fname[len(base) + 1:-8])
        if frame_moves < 1e4:
            continue
        energy_boundaries, mean_e, my_lnw, my_system, p_exc = compute.read_file(
            frame_base)
        l_function, eee, sss = compute.linear_entropy(energy_boundaries,
                                                      mean_e, my_lnw)
        moves.append(frame_moves)
        err = np.max(
            np.abs(
                normalize_S(l_function(E[indices_for_err])) -
                correct_S_for_err))
        errors_S.append(err)
        T_conv, C_conv = heat_capacity.data(l_function, fname=fname)
        C_mask = [t >= lowest_interestng_T for t in T_conv]
        errors_C.append(np.max(np.abs(correct_C[C_mask] - C_conv[C_mask])))

    np.savez(os.path.join(base) + 'diag.npz',
             E=E,
             T=T,
             mean_e=mean_e,
             mean_which=mean_which,
             hist=hist,
             S=S,
             C=C,
             moves=moves,
             errors_S=errors_S,
             errors_C=errors_C)
示例#2
0
        print(f'working on {base} with moves {mymove} which is {f}')

        energy_b = np.loadtxt(f+'-energy-boundaries.dat')
        mean_e = np.loadtxt(f+'-mean-energy.dat')
        my_lnw = np.loadtxt(f+'-lnw.dat')
        
        if energy_b.ndim == 0: #in case of a single value
            energy_b = np.array([energy_b.item()])

        if energy_b[0] < energy_b[-1]:
            energy_b = np.flip(energy_b)
            mean_e = np.flip(mean_e)
            my_lnw = np.flip(my_lnw)

        # Create a function for the entropy based on this number of moves:
        l_function, _, _ = compute.linear_entropy(energy_b, mean_e, my_lnw)
        # l_function, _, _ = compute.step_entropy(energy_b, mean_e, my_lnw)
        
        entropy_here = l_function(E)
        plt.clf()
        if 'erfinv' in base:
            plt.plot(E, entropy_here, label=f)
            plt.plot(E, exact_entropy, '--', label='exact')
            plt.ylabel('$S(E)$')
        else:
            plt.plot(E, np.exp(entropy_here), label=f)
            plt.plot(E, np.exp(exact_entropy), '--', label='exact')
            plt.ylabel('density of states')
        plt.xlabel('E')
        # plt.ylim(bottom=0)
        plt.legend(loc='best')
frames = set()
bases = []
print('base', args.base)
#each file has different path (including extension) so concatenating is easy
for base in args.base:
    if '.cbor' in base or '.yaml' in base:
        base = base[:-5]
    print(base)
    bases.append(base)
    for f in glob.glob(base+'/*.cbor'):
        f = os.path.splitext(os.path.basename(f))[0]
        if float(f) > 1e7:
            frames.add(f)

best_energy_boundaries, best_mean_energy, best_lnw, best_system = compute.read_file(args.base[0])
unscaled_best_function, best_energy, best_entropy = compute.linear_entropy(best_energy_boundaries, best_mean_energy, best_lnw)
if args.intensive:
    scale = 1/best_system['N']
    best_energy = scale*best_energy
    best_entropy = scale*best_entropy
    best_function = lambda e: scale*unscaled_best_function(e/scale)
else:
    best_function = unscaled_best_function
energies_to_compare = np.array(best_mean_energy)
energies_reference = best_function(energies_to_compare)
# Only compare energies below the energy with max entropy
# nhi = energies_reference.argmax()
# energies_to_compare = energies_to_compare[nhi:-1]
# energies_reference = energies_reference[nhi:-1]

sigma = 1
示例#4
0
for base in bases:
    print('reading', base)

    energy_boundaries = np.loadtxt(base+'-energy-boundaries.dat')
    de = abs(np.diff(energy_boundaries))
    lnw = np.loadtxt(base+'-lnw.dat')
    mean_e = np.loadtxt(base+'-mean-energy.dat')
    s_estimate = lnw[1:-1] - np.log(de)
    peak_e = mean_e[np.argmax(s_estimate)]

    if energy_boundaries[0] < energy_boundaries[-1]:
        energy_boundaries = np.flip(energy_boundaries)
        mean_e = np.flip(mean_e)
        lnw = np.flip(lnw)
    reference_function, reference_energy, reference_entropy = compute.linear_entropy(energy_boundaries, mean_e, lnw)
    unscaled_reference_function = reference_function
    if args.intensive:
        energy_boundaries, mean_e, _, system, p_exc_reference = compute.read_file(base)
        reference_N = system['N']
        N = reference_N
        reference_energy /= reference_N
        reference_entropy /= reference_N
        # energy_boundaries /= reference_N
        # lnw /= reference_N
        # peak_e /= reference_N
        # s_estimate /= reference_N
        # de /= reference_N
        # mean_e /= reference_N
        reference_function = lambda e: unscaled_reference_function(reference_N*e)/reference_N
        pressure_reference, T_reference = compute.pressure_temperature(system['density'], energy_boundaries, mean_e, p_exc_reference)
示例#5
0
        base = base[:-5]
    bases.append(base)

for base in bases:
    print('reading', base)

    energy_boundaries = np.loadtxt(base+'-energy-boundaries.dat')
    de = abs(np.diff(energy_boundaries))
    lnw = np.loadtxt(base+'-lnw.dat')
    mean_e = np.loadtxt(base+'-mean-energy.dat')

    if energy_boundaries[0] < energy_boundaries[-1]:
        energy_boundaries = np.flip(energy_boundaries)
        mean_e = np.flip(mean_e)
        lnw = np.flip(lnw)
    reference_function, _, _ = compute.linear_entropy(
        energy_boundaries, mean_e, lnw)

    energy_boundaries, mean_e, _, system, p_exc_reference = compute.read_file(
        base)

    p_reference, T_reference = compute.pressure_temperature(
        system['density'], energy_boundaries, mean_e, p_exc_reference)

    small_dT = 1/16
    big_dT = 5
    T = np.array(list(np.arange(0.125, 3 + small_dT/2, small_dT)) + list(np.arange(5, 30+big_dT/2, big_dT)))
    p = canonical(T, mean_e, p_reference, reference_function)
    np.savetxt(base+'-p-vs-T.dat',
               np.transpose(np.vstack([T, p])),
               fmt='%.4g')