Ejemplo n.º 1
0
    def __init__(self, problem, run, evaluator, **kwargs):
        _args = vars(self.parse_args(''))
        kwargs['problem'] = problem
        kwargs['run'] = run
        kwargs['evaluator'] = evaluator
        _args.update(kwargs)
        _args['problem'] = problem
        _args['run'] = run
        self.args = Namespace(**_args)
        self.problem = util.generic_loader(problem, 'Problem')
        self.run_func = util.generic_loader(run, 'run')
        logger.info('Evaluator will execute the function: ' + run)
        if kwargs.get('cache_key') is None:
            self.evaluator = Evaluator.create(self.run_func, method=evaluator)
        else:
            self.evaluator = Evaluator.create(self.run_func,
                                              method=evaluator,
                                              cache_key=kwargs['cache_key'])
        self.num_workers = self.evaluator.num_workers

        logger.info(f'Options: ' + pformat(self.args.__dict__, indent=4))
        logger.info('Hyperparameter space definition: ' +
                    pformat(self.problem.space, indent=4))
        logger.info(f'Created {self.args.evaluator} evaluator')
        logger.info(f'Evaluator: num_workers is {self.num_workers}')
Ejemplo n.º 2
0
 def __init__(self, comm, problem, run, evaluator, **kwargs):
     """Constructor."""
     self.comm = comm
     self.rank = comm.Get_rank()
     self.problem = util.generic_loader(problem, "Problem")
     self.run_func = util.generic_loader(run, "run")
     self.evaluator = Evaluator.create(self.run_func, method=evaluator)
Ejemplo n.º 3
0
 def setUp(self):
     self.ev = Evaluator.create(run, cache_key=key, method="balsam")
     self.AWAIT_TIMEOUT = 30
     self.launcher = subprocess.Popen(
         "balsam launcher --job-mode=serial --consume-all --num-transition=1",
         shell=True,
     )
Ejemplo n.º 4
0
    def __init__(self, problem, fbest, evaluator, **kwargs):

        if MPI is None:
            self.free_workers = 1
        else:
            nranks = MPI.COMM_WORLD.Get_size()
            if evaluator == 'balsam':
                balsam_launcher_nodes = int(
                    os.environ.get('BALSAM_LAUNCHER_NODES', 1))
                deephyper_workers_per_node = int(
                    os.environ.get('DEEPHYPER_WORKERS_PER_NODE', 1))
                n_free_nodes = balsam_launcher_nodes - nranks  # Number of free nodes
                self.free_workers = n_free_nodes * \
                    deephyper_workers_per_node  # Number of free workers
            else:
                self.free_workers = 1

        _args = vars(self.parse_args(''))
        kwargs['problem'] = problem
        kwargs['p_f_best'] = fbest
        kwargs['evaluator'] = evaluator
        _args.update(kwargs)
        self.args = Namespace(**_args)
        self.problem = util.generic_loader(problem, 'Problem')
        if kwargs.get('cache_key') is None:
            self.evaluator = Evaluator.create(run_function=train,
                                              method=evaluator)
        else:
            self.evaluator = Evaluator.create(run_function=train,
                                              method=evaluator,
                                              cache_key=kwargs['cache_key'])
        self.num_workers = self.evaluator.num_workers

        logger.info(f'Options: ' + pformat(self.args.__dict__, indent=4))
        logger.info('Problem definition: ' +
                    pformat(self.problem.space, indent=4))
        logger.info(f'Created {self.args.evaluator} evaluator')
        logger.info(f'Evaluator: num_workers is {self.num_workers}')
Ejemplo n.º 5
0
    def __init__(self, problem, fbest, evaluator, **kwargs):

        if MPI is None:
            self.free_workers = 1
        else:
            nranks = MPI.COMM_WORLD.Get_size()
            if evaluator == "balsam":
                balsam_launcher_nodes = int(
                    os.environ.get("BALSAM_LAUNCHER_NODES", 1))
                deephyper_workers_per_node = int(
                    os.environ.get("DEEPHYPER_WORKERS_PER_NODE", 1))
                n_free_nodes = balsam_launcher_nodes - nranks  # Number of free nodes
                self.free_workers = (n_free_nodes * deephyper_workers_per_node
                                     )  # Number of free workers
            else:
                self.free_workers = 1

        _args = vars(self.parse_args(""))
        kwargs["problem"] = problem
        kwargs["p_f_best"] = fbest
        kwargs["evaluator"] = evaluator
        _args.update(kwargs)
        self.args = Namespace(**_args)
        self.problem = util.generic_loader(problem, "Problem")
        if kwargs.get("cache_key") is None:
            self.evaluator = Evaluator.create(run_function=train,
                                              method=evaluator)
        else:
            self.evaluator = Evaluator.create(run_function=train,
                                              method=evaluator,
                                              cache_key=kwargs["cache_key"])
        self.num_workers = self.evaluator.num_workers

        logger.info(f"Options: " + pformat(self.args.__dict__, indent=4))
        logger.info("Problem definition: " +
                    pformat(self.problem.space, indent=4))
        logger.info(f"Created {self.args.evaluator} evaluator")
        logger.info(f"Evaluator: num_workers is {self.num_workers}")
Ejemplo n.º 6
0
    def __init__(
        self,
        problem: str,
        run: str,
        evaluator: str,
        max_evals: int = 1000000,
        seed: int = None,
        num_nodes_master: int = 1,
        num_workers: int = None,
        log_dir: int = None,
        **kwargs,
    ):
        kwargs["problem"] = problem
        kwargs["run"] = run
        kwargs["evaluator"] = evaluator
        kwargs["max_evals"] = max_evals  # * For retro compatibility
        kwargs["seed"] = seed

        # Loading problem instance and run function
        self.problem = util.generic_loader(problem, "Problem")
        if self.problem.seed == None:
            self.problem.seed = seed
        else:
            kwargs["seed"] = self.problem.seed
        self.run_func = util.generic_loader(run, "run")

        notice = f"Maximizing the return value of function: {run}"
        logger.info(notice)
        util.banner(notice)

        self.evaluator = Evaluator.create(
            self.run_func,
            method=evaluator,
            num_nodes_master=num_nodes_master,
            num_workers=num_workers,
            **kwargs,
        )
        self.num_workers = self.evaluator.num_workers
        self.max_evals = max_evals
        self.log_dir = os.getcwd() if log_dir is None else log_dir

        # set the random seed
        np.random.seed(self.problem.seed)

        logger.info(f"Options: " + pformat(kwargs, indent=4))
        logger.info("Hyperparameter space definition: " +
                    pformat(self.problem.space, indent=4))
        logger.info(f"Created {evaluator} evaluator")
        logger.info(f"Evaluator: num_workers is {self.num_workers}")
Ejemplo n.º 7
0
 def _on_done(job):  # def _on_done(job, process_data):
     output = job.read_file_in_workdir(f'{job.name}.out')
     # process_data(job)
     #args = job.args
     #args = args.replace("\'", "")
     # with open('test.json', 'w') as f:
     #    f.write(args)
     #
     # with open('test.json', 'r') as f:
     #    args = json.load(f)
     output = Evaluator._parse(output)
     #job.data['reward'] = output
     #job.data['arch_seq'] = args['arch_seq']
     #job.data['id_worker'] = args['w']
     # job.save()
     return output
Ejemplo n.º 8
0
    def __init__(self,
                 problem: str,
                 run: str,
                 evaluator: str,
                 max_evals: int = 100,
                 seed: int = None,
                 **kwargs):
        kwargs['problem'] = problem
        kwargs['run'] = run
        kwargs['evaluator'] = evaluator
        kwargs['max_evals'] = max_evals  # * For retro compatibility
        kwargs['seed'] = seed

        self.problem = util.generic_loader(problem, 'Problem')
        if self.problem.seed == None:
            self.problem.seed = seed
        else:
            kwargs['seed'] = self.problem.seed
        self.run_func = util.generic_loader(run, 'run')
        notice = f'Maximizing the return value of function: {run}'
        logger.info(notice)
        util.banner(notice)

        self.evaluator = Evaluator.create(self.run_func,
                                          method=evaluator,
                                          **kwargs)
        self.num_workers = self.evaluator.num_workers
        self.max_evals = max_evals

        # set the random seed
        np.random.seed(self.problem.seed)

        logger.info(f'Options: ' + pformat(kwargs, indent=4))
        logger.info('Hyperparameter space definition: ' +
                    pformat(self.problem.space, indent=4))
        logger.info(f'Created {evaluator} evaluator')
        logger.info(f'Evaluator: num_workers is {self.num_workers}')
Ejemplo n.º 9
0
 def setUp(self):
     self.ev = Evaluator.create(run, cache_key=key, method='local-lite')
     self.AWAIT_TIMEOUT = 8
Ejemplo n.º 10
0
 def _on_done(job):
     if "dh_objective" in job.data:
         return job.data["dh_objective"]
     output = job.read_file_in_workdir(f"{job.name}.out")
     output = Evaluator._parse(output)
     return output