How to use the smac.utils.io.traj_logging.TrajLogger function in smac

To help you get started, we’ve selected a few smac examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github automl / SMAC3 / test / test_utils / io / test_traj_logging.py View on Github external
def test_init(self):
        scen = Scenario(scenario={'run_obj': 'quality', 'cs': self.cs,
                                  'output_dir': ''})
        stats = Stats(scen)
        TrajLogger(output_dir='./tmp_test_folder', stats=stats)
        self.assertFalse(os.path.exists('smac3-output'))
        self.assertTrue(os.path.exists('tmp_test_folder'))
github automl / SMAC3 / test / test_initial_design / test_single_config_initial_design.py View on Github external
def test_single_default_config_design(self):
        stats = Stats(scenario=self.scenario)
        stats.start_timing()
        self.ta.stats = stats
        tj = TrajLogger(output_dir=None, stats=stats)
        rh = RunHistory(aggregate_func=average_cost)

        dc = DefaultConfiguration(
            tae_runner=self.ta,
            scenario=self.scenario,
            stats=stats,
            traj_logger=tj,
            rng=np.random.RandomState(seed=12345),
            runhistory=rh,
            intensifier=None,
            aggregate_func=average_cost,
        )

        inc = dc.run()
        self.assertTrue(stats.ta_runs==1)
        self.assertTrue(len(rh.data)==0)
github automl / SMAC3 / test / test_intensify / test_intensify.py View on Github external
def test_compare_configs_chall(self):
        '''
            challenger is better
        '''
        intensifier = Intensifier(
            tae_runner=None, stats=self.stats,
            traj_logger=TrajLogger(output_dir=None, stats=self.stats),
            rng=None,
            instances=[1])

        self.rh.add(config=self.config1, cost=1, time=2,
                    status=StatusType.SUCCESS, instance_id=1,
                    seed=None,
                    additional_info=None)

        self.rh.add(config=self.config2, cost=0, time=1,
                    status=StatusType.SUCCESS, instance_id=1,
                    seed=None,
                    additional_info=None)

        conf = intensifier._compare_configs(incumbent=self.config1,
                                            challenger=self.config2,
                                            run_history=self.rh,
github automl / SMAC3 / test / test_intensify / test_successive_halving.py View on Github external
def test_init_1(self):
        """
            test parameter initializations for successive halving - instance as budget
        """
        intensifier = SuccessiveHalving(
            tae_runner=None, stats=self.stats,
            traj_logger=TrajLogger(output_dir=None, stats=self.stats),
            rng=np.random.RandomState(12345), deterministic=False, run_obj_time=False,
            instances=[1, 2, 3], n_seeds=2, initial_budget=None, max_budget=None, eta=2)

        self.assertEqual(len(intensifier.inst_seed_pairs), 6)  # since instance-seed pairs
        self.assertEqual(len(intensifier.instances), 3)
        self.assertEqual(intensifier.initial_budget, 1)
        self.assertEqual(intensifier.max_budget, 6)
        self.assertListEqual(intensifier.n_configs_in_stage, [4.0, 2.0, 1.0])
        self.assertTrue(intensifier.instance_as_budget)
        self.assertTrue(intensifier.repeat_configs)
github automl / SMAC3 / smac / smac_cli.py View on Github external
def restore_state_after_output_dir(self, scen, stats, traj_list_aclib,
                                       traj_list_old):
        """Finish processing files for state-restoration. Trajectory
        is read in, but needs to be written to new output-folder. Therefore, the
        output-dir is created. This needs to be considered in the SMAC-facade."""
        # write trajectory-list
        traj_path_aclib = os.path.join(scen.output_dir, "traj_aclib2.json")
        traj_path_old = os.path.join(scen.output_dir, "traj_old.csv")
        with open(traj_path_aclib, 'w') as traj_fn:
            traj_fn.writelines(traj_list_aclib)
        with open(traj_path_old, 'w') as traj_fn:
            traj_fn.writelines(traj_list_old)
        # read trajectory to retrieve incumbent
        # TODO replace this with simple traj_path_aclib?
        trajectory = TrajLogger.read_traj_aclib_format(fn=traj_path_aclib, cs=scen.cs)
        incumbent = trajectory[-1]["incumbent"]
        self.logger.debug("Restored incumbent %s from %s", incumbent,
                          traj_path_aclib)
        return incumbent
github automl / SMAC3 / smac / facade / experimental / epils_facade.py View on Github external
# initialize empty runhistory
        if runhistory is None:
            runhistory = RunHistory(aggregate_func=aggregate_func)
        # inject aggr_func if necessary
        if runhistory.aggregate_func is None:
            runhistory.aggregate_func = aggregate_func

        # initial random number generator
        num_run, rng = self._get_rng(rng=rng)

        # reset random number generator in config space to draw different
        # random configurations with each seed given to SMAC
        scenario.cs.seed(rng.randint(MAXINT))

        # initial Trajectory Logger
        traj_logger = TrajLogger(
            output_dir=self.output_dir, stats=self.stats)

        # initial EPM
        types, bounds = get_types(scenario.cs, scenario.feature_array)
        if model is None:
            model = RandomForestWithInstances(
                configspace=scenario.cs,
                types=types,
                bounds=bounds,
                instance_features=scenario.feature_array,
                seed=rng.randint(MAXINT),
                pca_components=scenario.PCA_DIM,
                num_trees=scenario.rf_num_trees,
                do_bootstrapping=scenario.rf_do_bootstrapping,
                ratio_features=scenario.rf_ratio_features,
                min_samples_split=scenario.rf_min_samples_split,
github automl / SMAC3 / scripts / aggregate_traj_by_best.py View on Github external
def save_traj(traj, save_dn:str):
    '''
        save trajectory to disk
        using the TrajLogger
        
        Arguments
        ---------
        traj: typing.List
            trajectory 
        save_dn: str
            directory name to save the trajectory into it
    '''
    
    tj = TrajLogger(output_dir=save_dn, stats=None)
    
    for id_, entry in enumerate(traj):
        tj._add_in_old_format(train_perf=entry["cost"], 
                              incumbent_id=id_+1, 
                              incumbent=entry["incumbent"], 
                              ta_time_used=entry["cpu_time"], 
                              wallclock_time=entry["wallclock_time"])
        tj._add_in_aclib_format(train_perf=entry["cost"], 
                              incumbent_id=id_+1, 
                              incumbent=entry["incumbent"], 
                              ta_time_used=entry["cpu_time"], 
                              wallclock_time=entry["wallclock_time"],
                              evaluations=entry["evaluations"])