コード例 #1
0
def main():
    ############################################################
    # read command line parameters
    ############################################################
    parser = argparse.ArgumentParser(
        description="Get information about the PT exchanges and make plots showing replica paths through "
                    "temperature space, replica diffusion, and exchange probabilities, and occupation probabilities."
                    "The exchange information is read from file exchanges.permutations.  If this file does not exist"
                    "I try to get the exchange information from GMIN_out.1.  "
                    "Some of these routines can be quite slow when done in pure python, so there is an extension module"
                    "written in c.  This must to be compiled.  "
                    "Furthermore, by default the analysis is done in parallel with 4 cores.  This can be turned off with the options"
                    )
    parser.add_argument("basedir", type=str, nargs="*", help="The simulation directories.  It is possible to specify"
                        " multiple base directories in order to accommodate resumed simulations."
                        "  The default is the working directory."
                        , default=["."])
    parser.add_argument("--serial", action="store_true", help="Do the computations in serial, not in parallel.")
    args = parser.parse_args()
    print args
    
    for d in args.basedir:
        assert os.path.isdir(d)
        
    dirlist = args.basedir
    for i in range(len(dirlist)):
        if dirlist[i].endswith('/'):
            dirlist[i] = dirlist[i][:-1]


    temps = utils.getTemperatures(dirlist[0])

    # read the permutations from disc and change the formatting into replica paths.
    permutations, paths, replicas, times, ex_freq = getReplicaPath(dirlist=dirlist, makeplots=True)
    
    # set up the parallel computation
    if not args.serial:
        ncores = 4
        print "making a pool of workers"
        pool = mp.Pool(processes=ncores)
        myapply = pool.apply_async
    else:
        myapply = apply
        ncores = 1
    
    # make some plots and do some calculations on the replica paths
    myapply(makeplot_exchanges, (paths, times, ex_freq, temps))
    
    myapply(makeplot_hist, (permutations, temps))
    myapply(calculate_occupation_probability, (paths,))
    myapply(calculateDiffusion, (paths,))

    if ncores > 1:
        print "finished submitting all the jobs in parallel"
        pool.close()
        pool.join()
コード例 #2
0
def main():
    ############################################################
    # read command line parameters
    ############################################################
    parser = argparse.ArgumentParser(
        description=
        "Get information about the PT exchanges and make plots showing replica paths through "
        "temperature space, replica diffusion, and exchange probabilities, and occupation probabilities."
        "The exchange information is read from file exchanges.permutations.  If this file does not exist"
        "I try to get the exchange information from GMIN_out.1.  "
        "Some of these routines can be quite slow when done in pure python, so there is an extension module"
        "written in c.  This must to be compiled.  "
        "Furthermore, by default the analysis is done in parallel with 4 cores.  This can be turned off with the options"
    )
    parser.add_argument(
        "basedir",
        type=str,
        nargs="*",
        help="The simulation directories.  It is possible to specify"
        " multiple base directories in order to accommodate resumed simulations."
        "  The default is the working directory.",
        default=["."])
    parser.add_argument("--serial",
                        action="store_true",
                        help="Do the computations in serial, not in parallel.")
    args = parser.parse_args()
    print args

    for d in args.basedir:
        assert os.path.isdir(d)

    dirlist = args.basedir
    for i in range(len(dirlist)):
        if dirlist[i].endswith('/'):
            dirlist[i] = dirlist[i][:-1]

    temps = utils.getTemperatures(dirlist[0])

    # read the permutations from disc and change the formatting into replica paths.
    permutations, paths, replicas, times, ex_freq = getReplicaPath(
        dirlist=dirlist, makeplots=True)

    # set up the parallel computation
    if not args.serial:
        ncores = 4
        print "making a pool of workers"
        pool = mp.Pool(processes=ncores)
        myapply = pool.apply_async
    else:
        myapply = apply
        ncores = 1

    # make some plots and do some calculations on the replica paths
    myapply(makeplot_exchanges, (paths, times, ex_freq, temps))

    myapply(makeplot_hist, (permutations, temps))
    myapply(calculate_occupation_probability, (paths, ))
    myapply(calculateDiffusion, (paths, ))

    if ncores > 1:
        print "finished submitting all the jobs in parallel"
        pool.close()
        pool.join()
コード例 #3
0
def getReplicaPath(fname="GMIN_out.1", dirlist=["."], makeplots=True):
    """
    get the paths of the replicas from file fname

    the replicas are undergoing permutations and are moving around between the temperature
    bins.  some definitions::

        position      : the index of the temperature bin
        replica label : the label of a replica

    Returns
    -------
    permutations : array, shape(nexchanges, nreplicas)
        permutations[t, i] is the previous position of the replica curently at
        position i at time t
    paths : array, shape(nexchanges, nreplicas)
        paths[t, r] is the position of replica r at time t
    replicas : array, shape(nexchanges, nreplicas)
        replicas[t, i] is the replica at position i at time t
    """
    temps = utils.getTemperatures()
    nreps = len(temps)
    readclass = ReadPermutations(nreps, dirlist=dirlist)
    readclass.readAll()
    #permutations, times = getPermutations(nreps, fname)
    permutations = np.array(readclass.permutations)
    times = np.array(readclass.times)
    nperm = len(permutations[:, 0])
    print "nperm", nperm
    if True:
        #get `paths` and `replicas` from `permutations`
        try:
            from src.exch_tools import path_from_permutations
            paths, replicas, exchanges_counts = path_from_permutations(
                permutations)
        except ImportError:
            exchanges_counts = np.zeros(nreps, np.integer)
            opos = np.array(range(nreps))
            paths = np.zeros(np.shape(permutations), np.integer)
            replicas = np.zeros(np.shape(permutations), np.integer)
            paths[0, :] = range(nreps)
            replicas[0, :] = range(nreps)
            print "using slow python version of get paths"
            for i in range(1, nperm):
                perm = permutations[i - 1, :]
                replicas[i, :] = replicas[i - 1, perm]
                for pos, rep in enumerate(replicas[i, :]):
                    paths[i, rep] = pos
                exchanges_counts += (perm != opos)

    if True:
        """
        find how many round trips each replica made
        """
        print "calculating round trips"
        ndownup = np.zeros(nreps, np.integer)
        nupdown = np.zeros(nreps, np.integer)
        last_visit = np.zeros(nreps, np.integer)
        up = 1
        down = -1
        for i in range(nperm):
            iup = replicas[i, 0]
            if last_visit[iup] == down:
                ndownup[iup] += 1
            last_visit[iup] = up

            idown = replicas[i, -1]
            if last_visit[idown] == up:
                nupdown[idown] += 1
            last_visit[idown] = down
        with open("exchanges.round_trips", "w") as fout:
            fout.write("#complete trips up and down\n")
            fout.write("#replica n_down_up n_up_down\n")
            for rep in range(nreps):
                print "complete trips up, down for replica %3d: %4d %4d" % (
                    rep, ndownup[rep], nupdown[rep])
                fout.write("%d %d %d\n" % (rep, ndownup[rep], nupdown[rep]))

    if not makeplots:
        print "not making plots"

    print "exchange frequency"
    ex_freq = exchanges_counts.astype(float) / nperm
    #permutations = np.array(permutations)
    #paths = np.array(paths)
    print exchanges_counts
    print ex_freq

    nperm = len(permutations[:, 0])
    if False:
        with open("exchanges.perms", "w") as fout:
            print "writing file exchanges.perms"
            for i in range(nperm):
                ostr = ' '.join([str(n) for n in permutations[i, :]])
                fout.write(ostr + "\n")
    print "writing file exchanges.paths"
    np.savetxt("exchanges.paths", paths, fmt="%d")

    return permutations, paths, replicas, times, ex_freq
コード例 #4
0
def plotVisits(nfiles=5, basedirlist=['.']):

    if False:
        dirlist = getDirList()
        print dirlist

        files = listVisitsFiles(dirlist[0])
        files = reduce_list(files, nfiles)

        file = files[-1]

        allvisits = []
        for dir in dirlist:
            allvisits.append(listVisitsFiles(dir))

    #get all visits files
    Vcollection = utils.VisitsHisCollection(basedirlist)
    Vcollection.check_data()

    #we don't want to plot them all, so select nfiles objects
    indices = Vcollection.get_equispaced_indices(nfiles)
    Vcollection.reduce(indices)
    Vcollection.check_data()
    indices = list(reversed(range(Vcollection.get_nvisits())))
    allvisits = Vcollection.vseries_list

    print "indices", indices

    if True:
        pp = PdfPages("Visits.his.pdf")

        plt.xlabel("energy")
        plt.ylabel("visits")
        for visits in allvisits:
            myvis = visits[-1]
            #n,fname = file
            #myvis = utils.VisitsHis(fname, dir)
            myvis.read()
            e, counts = myvis.getHis()
            plt.plot((e), (counts), '-')
        pp.savefig()
        plt.clf()

        plt.xlabel("energy")
        plt.ylabel("log_10 visits")
        for visits in allvisits:
            myvis = visits[-1]
            #n,fname = file
            #myvis = utils.VisitsHis(fname, dir)
            myvis.read()
            e, counts = myvis.getHis()
            plt.plot((e), np.log10(counts), '-')
        pp.savefig()
        plt.clf()

        plt.xlabel("energy")
        plt.ylabel("visits")
        for visits in allvisits:
            myvis = visits[-1]
            oldvis = visits[len(visits) / 2]
            title = "%g - %g = %g" % (myvis.time, oldvis.time,
                                      myvis.time - oldvis.time)
            #n,fname = file
            #myvis = utils.VisitsHis(fname, dir)
            myvis.read()
            oldvis.read()
            e, counts = myvis.getHisDiff(oldvis)
            plt.plot((e), (counts), '-')
        plt.title(title)
        pp.savefig()
        plt.clf()

        plt.xlabel("energy")
        plt.ylabel("log_10 visits")
        for visits in allvisits:
            myvis = visits[-1]
            oldvis = visits[len(visits) / 2]
            title = "%g - %g = %g" % (myvis.time, oldvis.time,
                                      myvis.time - oldvis.time)
            #n,fname = file
            #myvis = utils.VisitsHis(fname, dir)
            myvis.read()
            oldvis.read()
            e, counts = myvis.getHisDiff(oldvis)
            plt.plot((e), np.log10(counts), '-')
        plt.title(title)
        pp.savefig()
        plt.clf()

        plt.ylabel("log density of states")
        plt.xlabel("log energy")
        Tlist = np.genfromtxt("temperatures")
        for T, visits in izip(Tlist, allvisits):
            myvis = visits[-1]
            oldvis = visits[len(visits) / 2]
            title = "%g - %g = %g" % (myvis.time, oldvis.time,
                                      myvis.time - oldvis.time)
            #n,fname = file
            #myvis = utils.VisitsHis(fname, dir)
            myvis.read()
            oldvis.read()
            e, counts = myvis.getHisDiff(oldvis)
            log_dos = np.log(counts) + e / T
            plt.plot(e, log_dos, '-')
        pp.savefig()
        plt.clf()

        pp.close()

    Tlist = utils.getTemperatures()

    pp = PdfPages("Visits.his.all.pdf")
    plt.clf()
    rep = 0
    for T, visits in izip(Tlist, allvisits):
        rep += 1
        visits = reduce_list(visits, nfiles)
        finalvis = visits[-1]
        finalvis.read()
        for myvis in reversed(visits[:-1]):
            title = "replica %d, T = %f" % (rep, T)
            plt.title(title)

            myvis.read()

            #e, counts = utils.read_Visits(fname)
            e, counts = finalvis.getHisDiffNorm(myvis)
            label = "%g - %g = %g" % (finalvis.time, myvis.time,
                                      finalvis.time - myvis.time)
            label = "%g" % (finalvis.time - myvis.time)
            plt.ylabel("log_{10} Num. Visits")
            plt.plot(e, np.log10(counts), '-', label=label)
        plt.legend(loc="lower left")
        pp.savefig()
        plt.clf()
    pp.close()
コード例 #5
0
def getReplicaPath(fname = "GMIN_out.1", dirlist=["."], makeplots=True):
    """
    get the paths of the replicas from file fname

    the replicas are undergoing permutations and are moving around between the temperature
    bins.  some definitions::

        position      : the index of the temperature bin
        replica label : the label of a replica

    Returns
    -------
    permutations : array, shape(nexchanges, nreplicas)
        permutations[t, i] is the previous position of the replica curently at
        position i at time t
    paths : array, shape(nexchanges, nreplicas)
        paths[t, r] is the position of replica r at time t
    replicas : array, shape(nexchanges, nreplicas)
        replicas[t, i] is the replica at position i at time t
    """
    temps = utils.getTemperatures()
    nreps = len(temps)
    readclass = ReadPermutations( nreps, dirlist=dirlist )
    readclass.readAll()
    #permutations, times = getPermutations(nreps, fname)
    permutations = np.array(readclass.permutations)
    times = np.array(readclass.times)
    nperm = len(permutations[:,0])
    print "nperm", nperm
    if True:
        #get `paths` and `replicas` from `permutations`
        try:
            from src.exch_tools import path_from_permutations
            paths, replicas, exchanges_counts = path_from_permutations(permutations)
        except ImportError:
            exchanges_counts = np.zeros(nreps, np.integer)
            opos = np.array(range(nreps))
            paths = np.zeros(np.shape(permutations), np.integer)
            replicas = np.zeros(np.shape(permutations), np.integer)
            paths[0,:] = range(nreps)
            replicas[0,:] = range(nreps)
            print "using slow python version of get paths"
            for i in range(1,nperm):
                perm = permutations[i-1,:]
                replicas[i,:] = replicas[i-1, perm]
                for pos,rep in enumerate(replicas[i,:]):
                    paths[i,rep] = pos
                exchanges_counts += (perm != opos)

    if True:
        """
        find how many round trips each replica made
        """
        print "calculating round trips"
        ndownup = np.zeros(nreps, np.integer)
        nupdown = np.zeros(nreps, np.integer)
        last_visit = np.zeros( nreps, np.integer)
        up = 1
        down = -1
        for i in range(nperm):
            iup = replicas[i,0]
            if last_visit[iup] == down:
                ndownup[iup] += 1
            last_visit[iup] = up

            idown = replicas[i,-1]
            if last_visit[idown] == up:
                nupdown[idown] += 1
            last_visit[idown] = down
        with open("exchanges.round_trips", "w") as fout:
            fout.write("#complete trips up and down\n")
            fout.write("#replica n_down_up n_up_down\n")
            for rep in range(nreps):
                print "complete trips up, down for replica %3d: %4d %4d" % ( rep, ndownup[rep], nupdown[rep])
                fout.write("%d %d %d\n" % (rep, ndownup[rep], nupdown[rep]))

    if not makeplots:
        print "not making plots"

    print "exchange frequency"
    ex_freq = exchanges_counts.astype(float) / nperm
    #permutations = np.array(permutations)
    #paths = np.array(paths)
    print exchanges_counts
    print ex_freq
    
    
    nperm = len(permutations[:,0])
    if False:
        with open("exchanges.perms", "w") as fout:
            print "writing file exchanges.perms"
            for i in range(nperm):
                ostr = ' '.join( [str(n) for n in permutations[i,:] ])
                fout.write(ostr + "\n")
    print "writing file exchanges.paths"
    np.savetxt("exchanges.paths", paths, fmt="%d")
        
    return permutations, paths, replicas, times, ex_freq
コード例 #6
0
def plotVisits(nfiles=5, basedirlist = ['.']):

    if False:
        dirlist = getDirList()
        print dirlist

        files = listVisitsFiles(dirlist[0])
        files = reduce_list(files, nfiles)

        file = files[-1]

        allvisits = []
        for dir in dirlist:
            allvisits.append( listVisitsFiles( dir ) )

    #get all visits files
    Vcollection = utils.VisitsHisCollection(basedirlist)
    Vcollection.check_data()

    #we don't want to plot them all, so select nfiles objects
    indices = Vcollection.get_equispaced_indices(nfiles)
    Vcollection.reduce(indices)
    Vcollection.check_data()
    indices = list(reversed(range(Vcollection.get_nvisits())))
    allvisits = Vcollection.vseries_list

    print "indices", indices

    if True:
        pp=PdfPages("Visits.his.pdf")

        plt.xlabel("energy")
        plt.ylabel("visits")
        for visits in allvisits:
            myvis = visits[-1]
            #n,fname = file
            #myvis = utils.VisitsHis(fname, dir)
            myvis.read()
            e, counts = myvis.getHis()
            plt.plot((e), (counts), '-')
        pp.savefig()
        plt.clf()
        
        plt.xlabel("energy")
        plt.ylabel("log_10 visits")
        for visits in allvisits:
            myvis = visits[-1]
            #n,fname = file
            #myvis = utils.VisitsHis(fname, dir)
            myvis.read()
            e, counts = myvis.getHis()
            plt.plot((e), np.log10(counts), '-')
        pp.savefig()
        plt.clf()

        plt.xlabel("energy")
        plt.ylabel("visits")
        for visits in allvisits:
            myvis = visits[-1]
            oldvis = visits[ len(visits)/2 ]
            title = "%g - %g = %g"%(myvis.time, oldvis.time, myvis.time - oldvis.time)
            #n,fname = file
            #myvis = utils.VisitsHis(fname, dir)
            myvis.read()
            oldvis.read()
            e, counts = myvis.getHisDiff(oldvis)
            plt.plot((e), (counts), '-')
        plt.title(title)
        pp.savefig()
        plt.clf()
        
        plt.xlabel("energy")
        plt.ylabel("log_10 visits")
        for visits in allvisits:
            myvis = visits[-1]
            oldvis = visits[ len(visits)/2 ]
            title = "%g - %g = %g"%(myvis.time, oldvis.time, myvis.time - oldvis.time)
            #n,fname = file
            #myvis = utils.VisitsHis(fname, dir)
            myvis.read()
            oldvis.read()
            e, counts = myvis.getHisDiff(oldvis)
            plt.plot((e), np.log10(counts), '-')
        plt.title(title)
        pp.savefig()
        plt.clf()

        plt.ylabel("log density of states")
        plt.xlabel("log energy")
        Tlist = np.genfromtxt("temperatures")
        for T, visits in izip(Tlist, allvisits):
            myvis = visits[-1]
            oldvis = visits[ len(visits)/2 ]
            title = "%g - %g = %g"%(myvis.time, oldvis.time, myvis.time - oldvis.time)
            #n,fname = file
            #myvis = utils.VisitsHis(fname, dir)
            myvis.read()
            oldvis.read()
            e, counts = myvis.getHisDiff(oldvis)
            log_dos = np.log(counts) + e / T 
            plt.plot(e, log_dos, '-')
        pp.savefig()
        plt.clf()
        
        
        pp.close()




    Tlist = utils.getTemperatures()

    pp=PdfPages("Visits.his.all.pdf")
    plt.clf()
    rep = 0
    for T, visits in izip(Tlist, allvisits):
        rep += 1
        visits = reduce_list( visits, nfiles)
        finalvis = visits[-1]
        finalvis.read()
        for myvis in reversed(visits[:-1]):
            title = "replica %d, T = %f" % (rep, T)
            plt.title( title)

            myvis.read()

            #e, counts = utils.read_Visits(fname)
            e, counts = finalvis.getHisDiffNorm(myvis)
            label = "%g - %g = %g"%(finalvis.time, myvis.time, finalvis.time - myvis.time)
            label = "%g"%(finalvis.time - myvis.time)
            plt.ylabel("log_{10} Num. Visits")
            plt.plot(e, np.log10(counts), '-', label=label)
        plt.legend(loc="lower left")
        pp.savefig()
        plt.clf()
    pp.close()