Ejemplo n.º 1
0
def main(): 
    global nodes
    global cores
    global JOBID
    global nprocmax
    global nprocmin

    # Parse command line arguments
    args = parse_args()

    nxmax = args.nxmax
    nymax = args.nymax
    nzmax = args.nzmax
    nodes = args.nodes
    cores = args.cores
    nprocmin_pernode = args.nprocmin_pernode
    machine = args.machine
    ntask = args.ntask
    nruns = args.nruns
    JOBID = args.jobid
    TUNER_NAME = args.optimization
    TLA = False

    os.environ['MACHINE_NAME'] = machine
    os.environ['TUNER_NAME'] = TUNER_NAME
    # os.system("mkdir -p scalapack-driver/bin/%s; cp ../build/pdqrdriver scalapack-driver/bin/%s/.;" %(machine, machine))

    nprocmax = nodes*cores-1  # YL: there is one proc doing spawning, so nodes*cores should be at least 2
    nprocmin = min(nodes*nprocmin_pernode,nprocmax-1)  # YL: ensure strictly nprocmin<nprocmax, required by the Integer space 

    
    nxmin = 20
    nymin = 20
    nzmin = 20
    nx = Integer(nxmin, nxmax, transform="normalize", name="nx")
    ny = Integer(nymin, nymax, transform="normalize", name="ny")
    nz = Integer(nzmin, nzmax, transform="normalize", name="nz")
    Px = Integer(1, nprocmax, transform="normalize", name="Px")
    Py = Integer(1, nprocmax, transform="normalize", name="Py")
    Nproc = Integer(nprocmin, nprocmax, transform="normalize", name="Nproc")
    strong_threshold = Real(0, 1, transform="normalize", name="strong_threshold")
    trunc_factor =  Real(0, 1, transform="normalize", name="trunc_factor")
    P_max_elmts = Integer(1, 12,  transform="normalize", name="P_max_elmts")
    coarsen_type = Categoricalnorm (['0', '1', '2', '3', '4', '6', '8', '10'], transform="onehot", name="coarsen_type")
    relax_type = Categoricalnorm (['-1', '0', '6', '8', '16', '18'], transform="onehot", name="relax_type")
    smooth_type = Categoricalnorm (['5', '6', '7', '8', '9'], transform="onehot", name="smooth_type")
    smooth_num_levels = Integer(0, 5,  transform="normalize", name="smooth_num_levels")
    interp_type = Categoricalnorm (['0', '3', '4', '5', '6', '8', '12'], transform="onehot", name="interp_type")
    agg_num_levels = Integer(0, 5,  transform="normalize", name="agg_num_levels")
    r = Real(float("-Inf"), float("Inf"), name="r")
    
    IS = Space([nx, ny, nz])
    PS = Space([Px, Py, Nproc, strong_threshold, trunc_factor, P_max_elmts, coarsen_type, relax_type, smooth_type, smooth_num_levels, interp_type, agg_num_levels])
    OS = Space([r])
    
    # Question: how to set constraints
    cst1 = f"Px * Py  <= Nproc"
    cst2 = f"not(coarsen_type=='0' and P_max_elmts==10 and relax_type=='18' and smooth_type=='6' and smooth_num_levels==3 and interp_type=='8' and agg_num_levels==1)"
    constraints = {"cst1": cst1,"cst2": cst2}

    print(IS, PS, OS, constraints)

    problem = TuningProblem(IS, PS, OS, objectives, constraints, None) # no performance model
    computer = Computer(nodes=nodes, cores=cores, hosts=None)

    options = Options()
    options['model_processes'] = 1
    # options['model_threads'] = 1
    options['model_restarts'] = 1
    options['distributed_memory_parallelism'] = False
    options['shared_memory_parallelism'] = False
    # options['mpi_comm'] = None
    options['model_class '] = 'Model_LCM'
    options['verbose'] = False
    options.validate(computer=computer)
    
    
    """ Intialize the tuner with existing data stored as last check point"""
    try:
        data = pickle.load(open('Data_nodes_%d_cores_%d_nxmax_%d_nymax_%d_nzmax_%d_machine_%s_jobid_%d.pkl' % (nodes, cores, nxmax, nymax, nzmax, machine, JOBID), 'rb'))
        giventask = data.I
    except (OSError, IOError) as e:
        data = Data(problem)
        giventask = [[randint(nxmin,nxmax),randint(nymin,nymax),randint(nzmin,nzmax)] for i in range(ntask)]

    # giventask = [[50, 60, 80], [60, 80, 100]]
    # # the following will use only task lists stored in the pickle file
    # data = Data(problem)


    if(TUNER_NAME=='GPTune'):
        gt = GPTune(problem, computer=computer, data=data, options=options, driverabspath=os.path.abspath(__file__))        
        """ Building MLA with the given list of tasks """
        NI = len(giventask)
        NS = nruns
        (data, model, stats) = gt.MLA(NS=NS, NI=NI, Igiven=giventask, NS1=max(NS//2, 1))
        print("stats: ", stats)
        
        """ Dump the data to file as a new check point """
        pickle.dump(data, open('Data_nodes_%d_cores_%d_nxmax_%d_nymax_%d_nzmax_%d_machine_%s_jobid_%d.pkl' % (nodes, cores, nxmax, nymax, nzmax, machine, JOBID), 'wb'))
        
        """ Dump the tuner to file for TLA use """
        pickle.dump(gt, open('MLA_nodes_%d_cores_%d_nxmax_%d_nymax_%d_nzmax_%d_machine_%s_jobid_%d.pkl' % (nodes, cores, nxmax, nymax, nzmax, machine, JOBID), 'wb'))


        """ Print all input and parameter samples """
        for tid in range(NI):
            print("tid: %d" % (tid))
            print("    nx:%d ny:%d nz:%d" % (data.I[tid][0], data.I[tid][1], data.I[tid][2]))
            print("    Ps ", data.P[tid])
            print("    Os ", data.O[tid])
            print('    Popt ', data.P[tid][np.argmin(data.O[tid])], 'Oopt ', min(data.O[tid])[0], 'nth ', np.argmin(data.O[tid]))

        if TLA is True:
            """ Call TLA for 2 new tasks using the constructed LCM model"""
            newtask = [[50, 50, 60], [80, 60, 70]]
            (aprxopts, objval, stats) = gt.TLA1(newtask, NS=None)
            print("stats: ", stats)

            """ Print the optimal parameters and function evaluations"""
            for tid in range(len(newtask)):
                print("new task: %s" % (newtask[tid]))
                print('    predicted Popt: ', aprxopts[tid], ' objval: ', objval[tid])

    
    if(TUNER_NAME=='opentuner'):
        NI = ntask
        NS = nruns
        (data,stats) = OpenTuner(T=giventask, NS=NS, tp=problem, computer=computer, run_id="OpenTuner", niter=1, technique=None)
        print("stats: ", stats)

        """ Print all input and parameter samples """
        for tid in range(NI):
            print("tid: %d" % (tid))
            print("    nx:%d ny:%d nz:%d" % (data.I[tid][0], data.I[tid][1], data.I[tid][2]))
            print("    Ps ", data.P[tid])
            print("    Os ", data.O[tid])
            print('    Popt ', data.P[tid][np.argmin(data.O[tid])], 'Oopt ', min(data.O[tid])[0], 'nth ', np.argmin(data.O[tid]))

    if(TUNER_NAME=='hpbandster'):
        NI = ntask
        NS = nruns
        (data,stats)=HpBandSter(T=giventask, NS=NS, tp=problem, computer=computer, run_id="HpBandSter", niter=1)
        print("stats: ", stats)
        """ Print all input and parameter samples """
        for tid in range(NI):
            print("tid: %d" % (tid))
            print("    nx:%d ny:%d nz:%d" % (data.I[tid][0], data.I[tid][1], data.I[tid][2]))
            print("    Ps ", data.P[tid])
            print("    Os ", data.O[tid].tolist())
            print('    Popt ', data.P[tid][np.argmin(data.O[tid])], 'Oopt ', min(data.O[tid])[0], 'nth ', np.argmin(data.O[tid]))
Ejemplo n.º 2
0
def main_interactive():

    global ROOTDIR
    global nodes
    global cores
    global target

    # Parse command line arguments

    parser = argparse.ArgumentParser()

    # Problem related arguments
    # parser.add_argument('-mmax', type=int, default=-1, help='Number of rows')
    # parser.add_argument('-nmax', type=int, default=-1, help='Number of columns')
    # Machine related arguments
    parser.add_argument('-nodes',
                        type=int,
                        default=1,
                        help='Number of machine nodes')
    parser.add_argument('-cores',
                        type=int,
                        default=1,
                        help='Number of cores per machine node')
    parser.add_argument('-machine',
                        type=str,
                        help='Name of the computer (not hostname)')
    # Algorithm related arguments
    parser.add_argument(
        '-optimization',
        type=str,
        help='Optimization algorithm (opentuner, spearmint, mogpo)')
    parser.add_argument('-ntask', type=int, default=-1, help='Number of tasks')
    parser.add_argument('-nruns', type=int, help='Number of runs per task')
    parser.add_argument('-truns', type=int, help='Time of runs')
    # Experiment related arguments
    parser.add_argument(
        '-jobid', type=int, default=-1,
        help='ID of the batch job')  #0 means interactive execution (not batch)

    args = parser.parse_args()

    # Extract arguments

    # mmax = args.mmax
    # nmax = args.nmax
    ntask = args.ntask
    nodes = args.nodes
    cores = args.cores
    machine = args.machine
    optimization = args.optimization
    nruns = args.nruns
    truns = args.truns
    # JOBID = args.jobid

    os.environ['MACHINE_NAME'] = machine
    os.environ['TUNER_NAME'] = 'GPTune'
    TUNER_NAME = os.environ['TUNER_NAME']

    # YL: for the spaces, the following datatypes are supported:
    # Real(lower, upper, transform="normalize", name="yourname")
    # Integer(lower, upper, transform="normalize", name="yourname")
    # Categoricalnorm(categories, transform="onehot", name="yourname")

    matrices = ["big.rua", "g4.rua", "g20.rua"]
    # matrices = ["Si2.rb", "SiH4.rb", "SiNa.rb", "Na5.rb", "benzene.rb", "Si10H16.rb", "Si5H12.rb", "SiO.rb", "Ga3As3H12.rb", "GaAsH6.rb", "H2O.rb"]

    # Task parameters
    matrix = Categoricalnorm(matrices, transform="onehot", name="matrix")

    # Input parameters
    COLPERM = Categoricalnorm(['2', '4'], transform="onehot", name="COLPERM")
    LOOKAHEAD = Integer(5, 20, transform="normalize", name="LOOKAHEAD")
    nprows = Integer(1, nodes * cores, transform="normalize", name="nprows")
    nproc = Integer(nodes, nodes * cores, transform="normalize", name="nproc")
    NSUP = Integer(30, 300, transform="normalize", name="NSUP")
    NREL = Integer(10, 40, transform="normalize", name="NREL")
    runtime = Real(float("-Inf"),
                   float("Inf"),
                   transform="normalize",
                   name="r")

    IS = Space([matrix])
    PS = Space([COLPERM, LOOKAHEAD, nproc, nprows, NSUP, NREL])
    OS = Space([runtime])

    cst1 = "%d * %d" % (
        nodes, cores
    ) + ">= nproc+2"  # YL: there are at least 2 cores working on other stuff
    cst2 = "NSUP >= NREL"
    cst3 = "nproc >= nprows"  # intrinsically implies "p <= nproc"

    constraints = {"cst1": cst1, "cst2": cst2, "cst3": cst3}
    models = {}

    print(IS, PS, OS, constraints, models)

    # target='memory'
    target = 'time'

    problem = TuningProblem(IS, PS, OS, objective, constraints, None)
    computer = Computer(nodes=nodes, cores=cores, hosts=None)

    options = Options()
    # options['model_processes'] = 1
    # options['model_threads'] = 1
    options['model_restarts'] = 1
    # options['search_multitask_processes'] = 1
    # options['model_restart_processes'] = 1
    options['distributed_memory_parallelism'] = True
    options['shared_memory_parallelism'] = False
    options['model_class '] = 'Model_LCM'
    options['verbose'] = False

    options.validate(computer=computer)
    data = Data(problem)
    gt = GPTune(problem, computer=computer, data=data, options=options)

    # """ Building MLA with NI random tasks """
    # NI = ntask
    # NS = nruns
    # (data, model,stats) = gt.MLA(NS=NS, NI=NI, NS1 = max(NS//2,1))
    # print("stats: ",stats)
    """ Building MLA with the given list of tasks """
    giventask = [["big.rua"], ["g4.rua"], ["g20.rua"]]
    NI = len(giventask)
    NS = nruns
    (data, model, stats) = gt.MLA(NS=NS,
                                  NI=NI,
                                  Tgiven=giventask,
                                  NS1=max(NS // 2, 1))
    print("stats: ", stats)

    for tid in range(NI):
        print("tid: %d" % (tid))
        print("    matrix:%s" % (data.T[tid][0]))
        print("    Xs ", data.X[tid])
        print("    Ys ", data.Y[tid])
        print('    Xopt ', data.X[tid][np.argmin(data.Y[tid])], 'Yopt ',
              min(data.Y[tid])[0])

    newtask = [["big.rua"], ["g4.rua"]]
    (aprxopts, objval, stats) = gt.TLA1(newtask, nruns)
    print("stats: ", stats)

    for tid in range(len(newtask)):
        print("new task: %s" % (newtask[tid]))
        print('    predicted Xopt: ', aprxopts[tid], ' objval: ', objval[tid])
Ejemplo n.º 3
0
def main():

    global ROOTDIR
    global nodes
    global cores
    global JOBID
    global nprocmax
    global nprocmin

    # Parse command line arguments
    args = parse_args()

    mmax = args.mmax
    nmax = args.nmax
    ntask = args.ntask
    nodes = args.nodes
    cores = args.cores
    nprocmin_pernode = args.nprocmin_pernode
    machine = args.machine
    nruns = args.nruns
    truns = args.truns
    JOBID = args.jobid
    TUNER_NAME = args.optimization

    os.environ['MACHINE_NAME'] = machine
    os.environ['TUNER_NAME'] = TUNER_NAME
    os.system(
        "mkdir -p scalapack-driver/bin/%s; cp ../build/pdqrdriver scalapack-driver/bin/%s/.;"
        % (machine, machine))

    nprocmax = nodes * cores - 1  # YL: there is one proc doing spawning, so nodes*cores should be at least 2
    nprocmin = min(
        nodes * nprocmin_pernode, nprocmax - 1
    )  # YL: ensure strictly nprocmin<nprocmax, required by the Integer space

    mmin = 128
    nmin = 128
    m = Integer(mmin, mmax, transform="normalize", name="m")
    n = Integer(nmin, nmax, transform="normalize", name="n")
    mb = Integer(1, 128, transform="normalize", name="mb")
    nb = Integer(1, 128, transform="normalize", name="nb")
    nproc = Integer(nprocmin, nprocmax, transform="normalize", name="nproc")
    p = Integer(0, nprocmax, transform="normalize", name="p")
    r = Real(float("-Inf"), float("Inf"), name="r")

    IS = Space([m, n])
    PS = Space([mb, nb, nproc, p])
    OS = Space([r])
    cst1 = "mb * p <= m"
    cst2 = "nb * nproc <= n * p"
    cst3 = "nproc >= p"
    constraints = {"cst1": cst1, "cst2": cst2, "cst3": cst3}
    print(IS, PS, OS, constraints)

    # problem = TuningProblem(IS, PS, OS, objectives, constraints, models) # use performance models
    problem = TuningProblem(IS, PS, OS, objectives, constraints,
                            None)  # no performance model

    computer = Computer(nodes=nodes, cores=cores, hosts=None)
    """ Set and validate options """
    options = Options()
    options['model_processes'] = 1
    # options['model_threads'] = 1
    options['model_restarts'] = 1
    # options['search_multitask_processes'] = 1
    # options['model_restart_processes'] = 1
    # options['model_restart_threads'] = 1

    # options['objective_evaluation_parallelism'] = True

    options['distributed_memory_parallelism'] = False
    options['shared_memory_parallelism'] = False
    # options['mpi_comm'] = None
    options['model_class'] = 'Model_GPy_LCM'
    options['verbose'] = False

    options.validate(computer=computer)
    # giventask = [[2000, 2000]]
    # giventask = [[randint(mmin,mmax),randint(nmin,nmax)] for i in range(ntask)]
    giventask = [[460, 500], [800, 690]]

    data = Data(problem)
    gt = GPTune(problem,
                computer=computer,
                data=data,
                options=options,
                driverabspath=os.path.abspath(__file__))

    if (TUNER_NAME == 'GPTune'):
        """ Building MLA with the given list of tasks """
        NI = len(giventask)
        NS = nruns
        (data, model, stats) = gt.MLA(NS=NS,
                                      NI=NI,
                                      Igiven=giventask,
                                      NS1=max(NS // 2, 1))
        print("stats: ", stats)
        pickle.dump(
            gt,
            open(
                'MLA_nodes_%d_cores_%d_mmax_%d_nmax_%d_machine_%s_jobid_%d.pkl'
                % (nodes, cores, mmax, nmax, machine, JOBID), 'wb'))
        """ Print all input and parameter samples """
        for tid in range(NI):
            print("tid: %d" % (tid))
            print("    m:%d n:%d" % (data.I[tid][0], data.I[tid][1]))
            print("    Ps ", data.P[tid])
            print("    Os ", data.O[tid])
            print('    Popt ', data.P[tid][np.argmin(data.O[tid])], 'Yopt ',
                  min(data.O[tid])[0], 'nth ', np.argmin(data.O[tid]))
        """ Call TLA for 2 new tasks using the constructed LCM model"""
        newtask = [[400, 500], [800, 600]]
        (aprxopts, objval, stats) = gt.TLA1(newtask, NS=None)
        print("stats: ", stats)
        """ Print the optimal parameters and function evaluations"""
        for tid in range(len(newtask)):
            print("new task: %s" % (newtask[tid]))
            print('    predicted Popt: ', aprxopts[tid], ' objval: ',
                  objval[tid])

    if (TUNER_NAME == 'opentuner'):
        NI = ntask
        NS = nruns
        (data, stats) = OpenTuner(T=giventask,
                                  NS=NS,
                                  tp=problem,
                                  computer=computer,
                                  run_id="OpenTuner",
                                  niter=1,
                                  technique=None)
        print("stats: ", stats)
        """ Print all input and parameter samples """
        for tid in range(NI):
            print("tid: %d" % (tid))
            print("    m:%d n:%d" % (data.I[tid][0], data.I[tid][1]))
            print("    Ps ", data.P[tid])
            print("    Os ", data.O[tid].tolist())
            print('    Popt ', data.P[tid][np.argmin(data.O[tid])], 'Oopt ',
                  min(data.O[tid])[0], 'nth ', np.argmin(data.O[tid]))

    if (TUNER_NAME == 'hpbandster'):
        NI = ntask
        NS = nruns
        (data, stats) = HpBandSter(T=giventask,
                                   NS=NS,
                                   tp=problem,
                                   computer=computer,
                                   run_id="HpBandSter",
                                   niter=1)
        print("stats: ", stats)
        """ Print all input and parameter samples """
        for tid in range(NI):
            print("tid: %d" % (tid))
            print("    m:%d n:%d" % (data.I[tid][0], data.I[tid][1]))
            print("    Ps ", data.P[tid])
            print("    Os ", data.O[tid].tolist())
            print('    Popt ', data.P[tid][np.argmin(data.O[tid])], 'Oopt ',
                  min(data.O[tid])[0], 'nth ', np.argmin(data.O[tid]))
Ejemplo n.º 4
0
def main():
    global nodes
    global cores
    global JOBID
    global nprocmax
    global nprocmin

    # Get arguments from CK-GPTune
    # if not given by CK-GPTune: -nxmax 100 -nymax 100 -nzmax 100 -nodes 1 -cores 32 -nprocmin_pernode 1 -ntask 2 -nrun 5 -machine cori -jobid 0
    nxmax = int(os.environ.get('nxmax','100'))
    nymax = int(os.environ.get('nymax','100'))
    nzmax = int(os.environ.get('nzmax','100'))
    nodes = int(os.environ.get('nodes','1'))
    cores = int(os.environ.get('cores','4'))
    nprocmin_pernode = int(os.environ.get('nprocmin_pernode','1'))
    machine = str(os.environ.get('machine','mymachine'))
    ntask = int(os.environ.get('ntask','2'))
    nruns = int(os.environ.get('nruns','5'))
    JOBID = int(os.environ.get('jobid','0'))
    TUNER_NAME = str(os.environ.get('optimization','GPTune'))
    TLA = False

    print ('run_autotuner arguments\n \
            nxmax: %d\
            nymax: %d\
            nzmax: %d\
            nodes: %d\
            cores: %d\
            nprocmin_pernode: %d\
            machine: %s\
            ntask: %d\
            nruns: %d\
            jobid: %d\
            tuner: %s'
            %(nxmax, nymax, nzmax, nodes, cores, nprocmin_pernode, machine, ntask, nruns, JOBID, TUNER_NAME))

#    # Parse command line arguments
#    args = parse_args()
#
#    nxmax = args.nxmax
#    nymax = args.nymax
#    nzmax = args.nzmax
#    nodes = args.nodes
#    cores = args.cores
#    nprocmin_pernode = args.nprocmin_pernode
#    machine = args.machine
#    ntask = args.ntask
#    nruns = args.nruns
#    JOBID = args.jobid
#    TUNER_NAME = args.optimization
#    TLA = False

    os.environ['MACHINE_NAME'] = machine
    os.environ['TUNER_NAME'] = TUNER_NAME
    # os.system("mkdir -p scalapack-driver/bin/%s; cp ../build/pdqrdriver scalapack-driver/bin/%s/.;" %(machine, machine))

    nprocmax = nodes*cores-1  # YL: there is one proc doing spawning, so nodes*cores should be at least 2
    nprocmin = min(nodes*nprocmin_pernode,nprocmax-1)  # YL: ensure strictly nprocmin<nprocmax, required by the Integer space


    nxmin = 20
    nymin = 20
    nzmin = 20
    nx = Integer(nxmin, nxmax, transform="normalize", name="nx")
    ny = Integer(nymin, nymax, transform="normalize", name="ny")
    nz = Integer(nzmin, nzmax, transform="normalize", name="nz")
    Px = Integer(1, nprocmax, transform="normalize", name="Px")
    Py = Integer(1, nprocmax, transform="normalize", name="Py")
    Nproc = Integer(nprocmin, nprocmax, transform="normalize", name="Nproc")
    strong_threshold = Real(0, 1, transform="normalize", name="strong_threshold")
    trunc_factor =  Real(0, 1, transform="normalize", name="trunc_factor")
    P_max_elmts = Integer(1, 12,  transform="normalize", name="P_max_elmts")
    coarsen_type = Categoricalnorm (['0', '1', '2', '3', '4', '6', '8', '10'], transform="onehot", name="coarsen_type")
    relax_type = Categoricalnorm (['-1', '0', '6', '8', '16', '18'], transform="onehot", name="relax_type")
    smooth_type = Categoricalnorm (['5', '6', '7', '8', '9'], transform="onehot", name="smooth_type")
    smooth_num_levels = Integer(0, 5,  transform="normalize", name="smooth_num_levels")
    interp_type = Categoricalnorm (['0', '3', '4', '5', '6', '8', '12'], transform="onehot", name="interp_type")
    agg_num_levels = Integer(0, 5,  transform="normalize", name="agg_num_levels")
    r = Real(float("-Inf"), float("Inf"), name="r")

    IS = Space([nx, ny, nz])
    PS = Space([Px, Py, Nproc, strong_threshold, trunc_factor, P_max_elmts, coarsen_type, relax_type, smooth_type, smooth_num_levels, interp_type, agg_num_levels])
    OS = Space([r])

    # Question: how to set constraints
    cst1 = f"Px * Py  <= Nproc"
    cst2 = f"not(coarsen_type=='0' and P_max_elmts==10 and relax_type=='18' and smooth_type=='6' and smooth_num_levels==3 and interp_type=='8' and agg_num_levels==1)"
    constraints = {"cst1": cst1,"cst2": cst2}

    print(IS, PS, OS, constraints)

    problem = TuningProblem(IS, PS, OS, objectives, constraints, None) # no performance model
    computer = Computer(nodes=nodes, cores=cores, hosts=None)

    options = Options()
    options['model_processes'] = 1
    # options['model_threads'] = 1
    options['model_restarts'] = 1
    options['distributed_memory_parallelism'] = False
    options['shared_memory_parallelism'] = False
    # options['mpi_comm'] = None
    options['model_class '] = 'Model_LCM'
    options['verbose'] = False
    options.validate(computer=computer)

    data = Data(problem)
    giventask = [[randint(nxmin,nxmax),randint(nymin,nymax),randint(nzmin,nzmax)] for i in range(ntask)]

    if(TUNER_NAME=='GPTune'):
        gt = GPTune(problem, computer=computer, data=data, options=options, driverabspath=os.path.abspath(__file__))
        """ Building MLA with the given list of tasks """
        NI = len(giventask)
        NS = nruns
        (data, model, stats) = gt.MLA(NS=NS, NI=NI, Igiven=giventask, NS1=max(NS//2, 1))
        print("stats: ", stats)

        """ Print all input and parameter samples """
        for tid in range(NI):
            print("tid: %d" % (tid))
            print("    nx:%d ny:%d nz:%d" % (data.I[tid][0], data.I[tid][1], data.I[tid][2]))
            print("    Ps ", data.P[tid])
            print("    Os ", data.O[tid])
            print('    Popt ', data.P[tid][np.argmin(data.O[tid])], 'Oopt ', min(data.O[tid])[0], 'nth ', np.argmin(data.O[tid]))

        if TLA is True:
            """ Call TLA for 2 new tasks using the constructed LCM model"""
            newtask = [[50, 50, 60], [80, 60, 70]]
            (aprxopts, objval, stats) = gt.TLA1(newtask, NS=None)
            print("stats: ", stats)

            """ Print the optimal parameters and function evaluations"""
            for tid in range(len(newtask)):
                print("new task: %s" % (newtask[tid]))
                print('    predicted Popt: ', aprxopts[tid], ' objval: ', objval[tid])


    if(TUNER_NAME=='opentuner'):
        NI = ntask
        NS = nruns
        (data,stats) = OpenTuner(T=giventask, NS=NS, tp=problem, computer=computer, run_id="OpenTuner", niter=1, technique=None)
        print("stats: ", stats)

        """ Print all input and parameter samples """
        for tid in range(NI):
            print("tid: %d" % (tid))
            print("    nx:%d ny:%d nz:%d" % (data.I[tid][0], data.I[tid][1], data.I[tid][2]))
            print("    Ps ", data.P[tid])
            print("    Os ", data.O[tid])
            print('    Popt ', data.P[tid][np.argmin(data.O[tid])], 'Oopt ', min(data.O[tid])[0], 'nth ', np.argmin(data.O[tid]))

    if(TUNER_NAME=='hpbandster'):
        NI = ntask
        NS = nruns
        (data,stats)=HpBandSter(T=giventask, NS=NS, tp=problem, computer=computer, run_id="HpBandSter", niter=1)
        print("stats: ", stats)
        """ Print all input and parameter samples """
        for tid in range(NI):
            print("tid: %d" % (tid))
            print("    nx:%d ny:%d nz:%d" % (data.I[tid][0], data.I[tid][1], data.I[tid][2]))
            print("    Ps ", data.P[tid])
            print("    Os ", data.O[tid].tolist())
            print('    Popt ', data.P[tid][np.argmin(data.O[tid])], 'Oopt ', min(data.O[tid])[0], 'nth ', np.argmin(data.O[tid]))
Ejemplo n.º 5
0
def main():

    global ROOTDIR
    global nodes
    global cores
    global target
    global nprocmax
    global nprocmin

    # Parse command line arguments
    args = parse_args()

    # Extract arguments
    ntask = args.ntask
    nodes = args.nodes
    cores = args.cores
    nprocmin_pernode = args.nprocmin_pernode
    machine = args.machine
    optimization = args.optimization
    nruns = args.nruns
    truns = args.truns
    # JOBID = args.jobid
    TUNER_NAME = args.optimization
    os.environ['MACHINE_NAME'] = machine
    os.environ['TUNER_NAME'] = TUNER_NAME

    nprocmax = nodes * cores - 1  # YL: there is one proc doing spawning, so nodes*cores should be at least 2
    nprocmin = min(
        nodes * nprocmin_pernode, nprocmax - 1
    )  # YL: ensure strictly nprocmin<nprocmax, required by the Integer space
    matrices = ["big.rua", "g4.rua", "g20.rua"]
    # matrices = ["Si2.rb", "SiH4.rb", "SiNa.rb", "Na5.rb", "benzene.rb", "Si10H16.rb", "Si5H12.rb", "SiO.rb", "Ga3As3H12.rb","H2O.rb"]
    # matrices = ["Si2.rb", "SiH4.rb", "SiNa.rb", "Na5.rb", "benzene.rb", "Si10H16.rb", "Si5H12.rb", "SiO.rb", "Ga3As3H12.rb", "GaAsH6.rb", "H2O.rb"]
    # Task parameters
    matrix = Categoricalnorm(matrices, transform="onehot", name="matrix")
    # Input parameters
    COLPERM = Categoricalnorm(['2', '4'], transform="onehot", name="COLPERM")
    LOOKAHEAD = Integer(5, 20, transform="normalize", name="LOOKAHEAD")
    nprows = Integer(1, nprocmax, transform="normalize", name="nprows")
    nproc = Integer(nprocmin, nprocmax, transform="normalize", name="nproc")
    NSUP = Integer(30, 300, transform="normalize", name="NSUP")
    NREL = Integer(10, 40, transform="normalize", name="NREL")
    runtime = Real(float("-Inf"), float("Inf"), name="r")
    IS = Space([matrix])
    PS = Space([COLPERM, LOOKAHEAD, nproc, nprows, NSUP, NREL])
    OS = Space([runtime])
    cst1 = "NSUP >= NREL"
    cst2 = "nproc >= nprows"  # intrinsically implies "p <= nproc"
    constraints = {"cst1": cst1, "cst2": cst2}
    models = {}
    """ Print all input and parameter samples """
    print(IS, PS, OS, constraints, models)

    target = 'memory'
    # target='time'

    problem = TuningProblem(IS, PS, OS, objectives, constraints, None)
    computer = Computer(nodes=nodes, cores=cores, hosts=None)
    """ Set and validate options """
    options = Options()
    options['model_processes'] = 1
    # options['model_threads'] = 1
    options['model_restarts'] = 1
    # options['search_multitask_processes'] = 1
    # options['model_restart_processes'] = 1
    options['distributed_memory_parallelism'] = False
    options['shared_memory_parallelism'] = False
    options['model_class '] = 'Model_LCM'
    options['verbose'] = True
    options.validate(computer=computer)
    """ Intialize the tuner with existing data stored as last check point"""
    try:
        data = pickle.load(
            open(
                'Data_nodes_%d_cores_%d_nprocmin_pernode_%d_tasks_%s_machine_%s.pkl'
                % (nodes, cores, nprocmin_pernode, matrices, machine), 'rb'))
        giventask = data.I
    except (OSError, IOError) as e:
        data = Data(problem)
        giventask = [[np.random.choice(matrices, size=1)[0]]
                     for i in range(ntask)]

    # """ Building MLA with the given list of tasks """
    # giventask = [["big.rua"], ["g4.rua"], ["g20.rua"]]
    # data = Data(problem)

    if (TUNER_NAME == 'GPTune'):
        gt = GPTune(problem,
                    computer=computer,
                    data=data,
                    options=options,
                    driverabspath=os.path.abspath(__file__))

        NI = len(giventask)
        NS = nruns
        (data, model, stats) = gt.MLA(NS=NS,
                                      NI=NI,
                                      Igiven=giventask,
                                      NS1=max(NS // 2, 1))
        print("stats: ", stats)
        """ Dump the data to file as a new check point """
        pickle.dump(
            data,
            open(
                'Data_nodes_%d_cores_%d_nprocmin_pernode_%d_tasks_%s_machine_%s.pkl'
                % (nodes, cores, nprocmin_pernode, matrices, machine), 'wb'))
        """ Dump the tuner to file for TLA use """
        pickle.dump(
            gt,
            open(
                'MLA_nodes_%d_cores_%d_nprocmin_pernode_%d_tasks_%s_machine_%s.pkl'
                % (nodes, cores, nprocmin_pernode, matrices, machine), 'wb'))
        """ Print all input and parameter samples """
        for tid in range(NI):
            print("tid: %d" % (tid))
            print("    matrix:%s" % (data.I[tid][0]))
            print("    Ps ", data.P[tid])
            print("    Os ", data.O[tid])
            print('    Popt ', data.P[tid][np.argmin(data.O[tid])], 'Oopt ',
                  min(data.O[tid])[0])
        """ Call TLA for a new task using the constructed LCM model"""
        newtask = [["big.rua"]]
        # newtask = [["H2O.rb"]]
        (aprxopts, objval, stats) = gt.TLA1(newtask, NS=None)
        print("stats: ", stats)
        """ Print the optimal parameters and function evaluations"""
        for tid in range(len(newtask)):
            print("new task: %s" % (newtask[tid]))
            print('    predicted Popt: ', aprxopts[tid], ' objval: ',
                  objval[tid])

    if (TUNER_NAME == 'opentuner'):
        NI = ntask
        NS = nruns
        (data, stats) = OpenTuner(T=giventask,
                                  NS=NS,
                                  tp=problem,
                                  computer=computer,
                                  run_id="OpenTuner",
                                  niter=1,
                                  technique=None)
        print("stats: ", stats)
        """ Print all input and parameter samples """
        for tid in range(NI):
            print("tid: %d" % (tid))
            print("    matrix:%s" % (data.I[tid][0]))
            print("    Ps ", data.P[tid])
            print("    Os ", data.O[tid])
            print('    Popt ', data.P[tid][np.argmin(data.O[tid])], 'Oopt ',
                  min(data.O[tid])[0])

    if (TUNER_NAME == 'hpbandster'):
        NI = ntask
        NS = nruns
        (data, stats) = HpBandSter(T=giventask,
                                   NS=NS,
                                   tp=problem,
                                   computer=computer,
                                   run_id="HpBandSter",
                                   niter=1)
        print("stats: ", stats)
        """ Print all input and parameter samples """
        for tid in range(NI):
            print("tid: %d" % (tid))
            print("    matrix:%s" % (data.I[tid][0]))
            print("    Ps ", data.P[tid])
            print("    Os ", data.O[tid])
            print('    Popt ', data.P[tid][np.argmin(data.O[tid])], 'Oopt ',
                  min(data.O[tid])[0])
Ejemplo n.º 6
0
def main_interactive():

    global ROOTDIR
    global nodes
    global cores
    global JOBID

    # Parse command line arguments

    parser = argparse.ArgumentParser()

    # Problem related arguments
    parser.add_argument('-mmax', type=int, default=-1, help='Number of rows')
    parser.add_argument('-nmax',
                        type=int,
                        default=-1,
                        help='Number of columns')
    # Machine related arguments
    parser.add_argument('-nodes',
                        type=int,
                        default=1,
                        help='Number of machine nodes')
    parser.add_argument('-cores',
                        type=int,
                        default=1,
                        help='Number of cores per machine node')
    parser.add_argument('-machine',
                        type=str,
                        help='Name of the computer (not hostname)')
    # Algorithm related arguments
    parser.add_argument(
        '-optimization',
        type=str,
        help='Optimization algorithm (opentuner, spearmint, mogpo)')
    parser.add_argument('-ntask', type=int, default=-1, help='Number of tasks')
    parser.add_argument('-nruns', type=int, help='Number of runs per task')
    parser.add_argument('-truns', type=int, help='Time of runs')
    # Experiment related arguments
    parser.add_argument(
        '-jobid', type=int, default=-1,
        help='ID of the batch job')  #0 means interactive execution (not batch)

    args = parser.parse_args()

    # Extract arguments

    mmax = args.mmax
    nmax = args.nmax
    ntask = args.ntask
    nodes = args.nodes
    cores = args.cores
    machine = args.machine
    optimization = args.optimization
    nruns = args.nruns
    truns = args.truns
    JOBID = args.jobid

    os.environ['MACHINE_NAME'] = machine
    os.environ['TUNER_NAME'] = 'GPTune'
    # print(os.environ)

    os.system(
        "mkdir -p scalapack-driver/bin/%s; cp ../build/pdqrdriver scalapack-driver/bin/%s/.;"
        % (machine, machine))

    # YL: for the spaces, the following datatypes are supported:
    # Real(lower, upper, transform="normalize", name="yourname")
    # Integer(lower, upper, transform="normalize", name="yourname")
    # Categoricalnorm(categories, transform="onehot", name="yourname")

    m = Integer(128, mmax, transform="normalize", name="m")
    n = Integer(128, nmax, transform="normalize", name="n")
    mb = Integer(1, 128, transform="normalize", name="mb")
    nb = Integer(1, 128, transform="normalize", name="nb")
    nproc = Integer(nodes,
                    nodes * cores - 1,
                    transform="normalize",
                    name="nproc")  # YL: there are is one proc doing spawning
    p = Integer(1, nodes * cores, transform="normalize", name="p")
    r = Real(float("-Inf"), float("Inf"), name="r")

    IS = Space([m, n])
    PS = Space([mb, nb, nproc, p])
    OS = Space([r])

    #    cst1 = "mb <= int(m / p) if (m / p) >= 1 else False"
    #    cst2 = "nb <= int(n / int(nproc / p)) if (n / int(nproc / p)) >= 1 else False"
    #    #cst3 = "int(nodes * cores / nproc) == (nodes * cores / nproc)"
    #    cst3 = "int(%d * %d / nproc) == (%d * %d / nproc)"%(nodes, cores, nodes, cores)
    #    cst4 = "int(nproc / p) == (nproc / p)" # intrinsically implies "p <= nproc"
    cst1 = "mb * p <= m"
    cst2 = "nb * nproc <= n * p"
    #cst3 = "int(nodes * cores / nproc) == (nodes * cores / nproc)"
    # cst3 = "%d * %d"%(nodes, cores) + ">= nproc+2"
    cst3 = "nproc >= p"  # intrinsically implies "p <= nproc"

    constraints = {"cst1": cst1, "cst2": cst2, "cst3": cst3}
    # constraints = {"cst1" : cst1, "cst2" : cst2, "cst3" : cst3}

    models = {}

    print(IS, PS, OS, constraints, models)

    problem = TuningProblem(IS, PS, OS, objective, constraints, None)
    computer = Computer(nodes=nodes, cores=cores, hosts=None)

    options = Options()
    # options['model_processes'] = 1
    # options['model_threads'] = 1
    options['model_restarts'] = 1
    # options['search_multitask_processes'] = 1
    # options['model_restart_processes'] = 1
    # options['model_restart_threads'] = 1
    options['distributed_memory_parallelism'] = False
    options['shared_memory_parallelism'] = False
    # options['mpi_comm'] = None
    options['model_class '] = 'Model_LCM'
    options['verbose'] = False

    options.validate(computer=computer)
    data = Data(problem)
    gt = GPTune(problem, computer=computer, data=data, options=options)

    # """ Building MLA with NI random tasks """
    # NI = ntask
    # NS = nruns
    # (data, model,stats) = gt.MLA(NS=NS, NI=NI, NS1 = max(NS//2,1))
    # print("stats: ",stats)
    """ Building MLA with the given list of tasks """
    giventask = [[460, 500], [800, 690]]
    NI = len(giventask)
    NS = nruns
    (data, model, stats) = gt.MLA(NS=NS,
                                  NI=NI,
                                  Tgiven=giventask,
                                  NS1=max(NS // 2, 1))
    print("stats: ", stats)

    pickle.dump(
        gt,
        open(
            'MLA_nodes_%d_cores_%d_mmax_%d_nmax_%d_machine_%s_jobid_%d.pkl' %
            (nodes, cores, mmax, nmax, machine, JOBID), 'wb'))

    for tid in range(NI):
        print("tid: %d" % (tid))
        print("    m:%d n:%d" % (data.T[tid][0], data.T[tid][1]))
        print("    Xs ", data.X[tid])
        print("    Ys ", data.Y[tid])
        print('    Xopt ', data.X[tid][np.argmin(data.Y[tid])], 'Yopt ',
              min(data.Y[tid])[0])

    newtask = [[400, 500], [800, 600]]
    (aprxopts, objval, stats) = gt.TLA1(newtask, nruns)
    print("stats: ", stats)

    for tid in range(len(newtask)):
        print("new task: %s" % (newtask[tid]))
        print('    predicted Xopt: ', aprxopts[tid], ' objval: ', objval[tid])