Beispiel #1
0
def mergeXY(sets, foreach=[]):
    foreach_sets = {}
    for iset in pyalps.flatten(sets):
        fe_par_set = tuple((iset.props[m] for m in foreach))

        if fe_par_set in foreach_sets:
            foreach_sets[fe_par_set].append(iset)
        else:
            foreach_sets[fe_par_set] = [iset]

    for k, v in foreach_sets.items():
        common_props = pyalps.dict_intersect([q.props for q in v])
        res = pyalps.DataSet()
        res.props = common_props
        for im in range(0, len(foreach)):
            m = foreach[im]
            res.props[m] = k[im]
        for data in v:
            if len(res.x) > 0 and len(res.y) > 0:
                res.x = np.concatenate((res.x, data.x))
                res.y = np.concatenate((res.y, data.y))
            else:
                res.x = data.x
                res.y = data.y

        order = np.argsort(res.x, kind='mergesort')
        res.x = res.x[order]
        res.y = res.y[order]
        res.props['label'] = ''
        for im in range(0, len(foreach)):
            res.props['label'] += '%s = %s ' % (foreach[im], k[im])

        foreach_sets[k] = res
    return foreach_sets.values()
Beispiel #2
0
def plot(fname):

    ret = pydmrg.LoadDMRGSweeps([fname],['TruncatedWeight'])

    sweeps = []
    for sw in ret[0]:
        sweeps += list(sw[0].y)

    print "total number of values in sweep", len(sweeps)

    # Get length of 1 sweep
    props = ret[0][0][0].props
    L = props['L']
    swl = 2*(L-1)

    xdata = np.arange(len(sweeps), dtype=np.float64)/swl
    ydata = np.array(sweeps)

    pdata = pyalps.DataSet()
    pdata.x = xdata
    pdata.y = ydata
    pdata.props['label'] = "Truncated weight"

    fig = plt.figure()
    plt.ylabel('Truncated weight')
    plt.xlabel('sweep')
    pyalps.plot.plot(pdata)
    plt.legend()

    for ax in fig.axes:
        ax.callbacks.connect('xlim_changed', plotutil.on_xlim_changed)

    plt.show()
Beispiel #3
0
 def evaluate(self, xval=0, degree=1, num_points=None):
     q = pyalps.DataSet()
     q.props = deepcopy(self.props)
     q.props[self.xname] = xval
     q.x = self.obsx
     q.y = np.array([ self.fit_at(x=self.xdata, y=y, degree=degree, xval=xval, num_points=num_points) for y in self.ydata ])
     
     return q
Beispiel #4
0
 def fit_data(self, xval=0, degree=1, ii=0, num_points=None, verbose=False):
     q = pyalps.DataSet()
     q.props = deepcopy(self.props)
     q.x = self.xdata
     q.y = self.ydata[ii]
     q.props['ylabel'] = self.props['observable']
     q.props['xlabel'] = self.xname
     
     q.props['fitting_degree']     = degree
     q.props['fitting_num_points'] = num_points
     q.props['fitted_x']           = xval
     q.props['fitted_bonddims']    = deepcopy(self.bonddims)
     q.props['fitted_value'] = self.fit_at(x=q.x, y=q.y, degree=degree, xval=xval, num_points=num_points, verbose=verbose)
     
     return q
Beispiel #5
0
def plot(fnames):

    ret = pydmrg.LoadDMRGSweeps(fnames, ['Energy'])

    plot_data = []
    for i, f in enumerate(ret):
        sweeps = []
        for sw in f:
            sweeps += list(sw[0].y)

        print "total number of sweep values", len(sweeps)
        props = f[0][0].props
        L = props['L']
        print "L", L
        swl = 2.0 * (L - 1)
        xdata = np.arange(len(sweeps)) / swl
        ydata = np.array(sweeps)

        #print ydata
        print "Minimum energy:", np.min(ydata), "\n"

        pdata = pyalps.DataSet()
        pdata.x = xdata
        pdata.y = ydata
        pdata.props['label'] = "Energy " + props["resultfile"]
        plot_data.append(pdata)

    fig = plt.figure()
    plt.xlabel('Sweeps')
    plt.ylabel('Energy')
    pyalps.plot.plot(plot_data)

    #locs,labels = plt.xticks()
    #plt.xticks(locs, map(lambda x: "%g" % x, locs))
    #locs,labels = plt.yticks()
    #plt.yticks(locs, map(lambda x: "%.4f" % x, locs))

    #plt.gca().set_yticklabels(plt.gca().get_yticks())
    #plt.gca().ticklabel_format(useOffset=False)
    plt.legend()

    for ax in fig.axes:
        ax.callbacks.connect('xlim_changed', plotutil.on_xlim_changed)

    plt.show()
Beispiel #6
0
def ReadMeasurements(ar, measurements, path, props):
    ret = []
    if measurements is None:
        measurements = ar.list_children(path)

    for meas in measurements:
        if meas in ar.list_children(path):
            try:
                d = pyalps.DataSet()
                d.props = deepcopy(props)
                d.props['observable'] = meas
                d.props['hdf5_path'] = path + '/' + meas
                d.y = ar[d.props['hdf5_path'] + '/mean/value']
                if 'labels' in ar.list_children(d.props['hdf5_path']):
                    d.x = parse_labels(ar[d.props['hdf5_path'] + '/labels'])
                else:
                    d.x = range(len(d.y))
                ret.append(d)
            except Exception, e:
                print "Could not load " + meas
                print e
                pass
plotdata = pyalps.collectXY(data, 'T', '|Magnetization|')
plt.figure()
pyalps.plot.plot(plotdata)
plt.xlim(0, 3)
plt.ylim(0, 1)
plt.title('Ising model')
plt.show()

# convert the data to text file for plotting using another tool
print(pyalps.plot.convertToText(plotdata))

# convert the data to grace file for plotting using xmgrace
print(pyalps.plot.makeGracePlot(plotdata))

# convert the data to gnuplot file for plotting using gnuplot
print(pyalps.plot.makeGnuplotPlot(plotdata))

#calculate the Binder cumulants using jackknife-analysis
binder = pyalps.DataSet()
binder.props = pyalps.dict_intersect([d[0].props for d in data])
binder.x = [d[0].props['T'] for d in data]
binder.y = [d[1].y[0] / (d[0].y[0] * d[0].y[0]) for d in data]
print(binder)

# ... and plot them
plt.figure()
pyalps.plot.plot(binder)
plt.xlabel('T')
plt.ylabel('Binder cumulant')
plt.show()
Beispiel #8
0
# extract the ground state energies over all momenta for every simulation
for sim in data:
    l = int(sim[0].props['L'])
    if l not in lengths: lengths.append(l)
    sz = int(sim[0].props['Sz_total'])
    s = float(sim[0].props['local_S'])
    all_energies = []
    for sec in sim:
        all_energies += list(sec.y)
    min_energies[(l, s, sz)] = np.min(all_energies)

# make a plot of the triplet gap as function of system size
plt.figure()
for s in [0.5, 1]:
    gapplot = pyalps.DataSet()
    gapplot.x = 1. / np.sort(lengths)
    gapplot.y = [
        min_energies[(l, s, 1)] - min_energies[(l, s, 0)]
        for l in np.sort(lengths)
    ]
    gapplot.props['xlabel'] = '$1/L$'
    gapplot.props['ylabel'] = 'Triplet gap $\Delta/J$'
    gapplot.props['label'] = 'S=' + str(s)
    pyalps.plot.plot(gapplot)

plt.legend()
plt.xlim(0, 0.25)
plt.ylim(0, 1.0)
plt.show()
Beispiel #9
0
            print 'beta =', beta
            sim = Simulation(beta, l)
            sim.run(N / 2, N)
            sim.save('ising.L_' + str(l) + 'beta_' + str(beta) + '.h5')

    #how to calculate the Binder Ratio within Python:
    infiles = pyalps.getResultFiles(pattern='ising.L')

    data = pyalps.loadMeasurements(pyalps.getResultFiles(pattern='ising.L*'),
                                   ['E', 'm^2', 'm^4'])
    m2 = pyalps.collectXY(data, x='BETA', y='m^2', foreach=['L'])
    m4 = pyalps.collectXY(data, x='BETA', y='m^4', foreach=['L'])

    u = []
    for i in range(len(m2)):
        d = pyalps.DataSet()
        d.propsylabel = 'U4'
        d.props = m2[i].props
        d.x = m2[i].x
        d.y = m4[i].y / m2[i].y / m2[i].y
        u.append(d)

    plt.figure()
    pyalps.plot.plot(u)
    plt.xlabel('Inverse Temperature $\\beta$')
    plt.ylabel('Binder Cumulant U4 $g$')
    plt.title('2D Ising model')
    plt.legend()
    plt.savefig('alps.pdf')

    print('Accepted moves:', sim.accepted)
Beispiel #10
0
        'Sz_total': 0
    })

#write the input file and run the simulation
input_file = pyalps.writeInputFiles('parm_ladder', parms)
res = pyalps.runApplication('sparsediag', input_file)

#load all measurements for all states
data = pyalps.loadSpectra(pyalps.getResultFiles(prefix='parm_ladder'))

# collect spectra over all momenta for every simulation
spectra = {}
for sim in data:
    l = int(sim[0].props['L'])
    all_energies = []
    spectrum = pyalps.DataSet()
    for sec in sim:
        all_energies += list(sec.y)
        spectrum.x = np.concatenate(
            (spectrum.x,
             np.array([sec.props['TOTAL_MOMENTUM']
                       for i in range(len(sec.y))])))
        spectrum.y = np.concatenate((spectrum.y, sec.y))
    spectrum.y -= np.min(all_energies)
    spectrum.props['line'] = 'scatter'
    spectrum.props['label'] = 'L=' + str(l)
    spectra[l] = spectrum

# plot
plt.figure()
pyalps.plot.plot(spectra.values())
Beispiel #11
0
#print the observables stored in those files:
print("The files contain the following mesurements:", end=' ')
print(pyalps.loadObservableList(result_files))

#load a selection of measurements:
data = pyalps.loadMeasurements(result_files,
                               ['|Magnetization|', 'Magnetization^2'])

obschoose = lambda d, o: np.array(d)[np.nonzero(
    [xx.props['observable'] == o for xx in d])]
binder = []
for dd in data:
    magn2 = obschoose(dd, 'Magnetization^2')[0]
    magnabs = obschoose(dd, '|Magnetization|')[0]

    res = pyalps.DataSet()
    res.props = pyalps.dict_intersect([d.props for d in dd])
    res.x = np.array([magnabs.props['T']])
    res.y = np.array([magn2.y[0] / (magnabs.y[0] * magnabs.y[0])])
    res.props['observable'] = 'Binder cumulant'
    binder.append(res)

binder = pyalps.collectXY(binder, 'T', 'Binder cumulant')

# ... and plot them
plt.figure()
pyalps.plot.plot(binder)
plt.xlabel('T')
plt.ylabel('Binder cumulant')
plt.show()