Пример #1
0
def merge_foreign_data_from_file(
        scenario: Scenario,
        runhistory: RunHistory,
        in_scenario_fn_list: typing.List[str],
        in_runhistory_fn_list: typing.List[str],
        cs: ConfigurationSpace,
        aggregate_func: typing.Callable = average_cost):
    """Extend <scenario> and <runhistory> with runhistory data from another
    <in_scenario> assuming the same pcs, feature space, but different instances

    Parameters
    ---------
    scenario: Scenario
        original scenario -- feature dictionary will be extended
    runhistory: RunHistory
        original runhistory -- will be extended by further data points
    in_scenario_fn_list: typing.List[str]
        input scenario file names
    in_runhistory_fn_list: typing.List[str]
        list filenames of runhistory dumps
    cs: ConfigurationSpace
        parameter configuration space to read runhistory from file
    aggregate_func: typing.Callable
        function to aggregate performance of a configuratoion across instances

    Returns
    -------
    scenario: Scenario
    runhistory: Runhistory
    """

    if not in_scenario_fn_list:
        raise ValueError(
            "To read warmstart data from previous runhistories, the corresponding scenarios are required. Use option --warmstart_scenario"
        )
    scens = [
        Scenario(scenario=scen_fn, cmd_options={"output_dir": ""})
        for scen_fn in in_scenario_fn_list
    ]
    rhs = []
    for rh_fn in in_runhistory_fn_list:
        rh = RunHistory(aggregate_func, file_system=scenario.file_system)
        rh.load_json(rh_fn, cs)
        rhs.append(rh)

    return merge_foreign_data(scenario,
                              runhistory,
                              in_scenario_list=scens,
                              in_runhistory_list=rhs)
Пример #2
0
 def restore_state(self, scen, args_):
     """Read in files for state-restoration: runhistory, stats, trajectory.
     """
     # Check for folder and files
     rh_path = os.path.join(args_.restore_state, "runhistory.json")
     stats_path = os.path.join(args_.restore_state, "stats.json")
     traj_path_aclib = os.path.join(args_.restore_state, "traj_aclib2.json")
     traj_path_old = os.path.join(args_.restore_state, "traj_old.csv")
     scen_path = os.path.join(args_.restore_state, "scenario.txt")
     if not os.path.isdir(args_.restore_state):
        raise FileNotFoundError("Could not find folder from which to restore.")
     # Load runhistory and stats
     rh = RunHistory(aggregate_func=None)
     rh.load_json(rh_path, scen.cs)
     self.logger.debug("Restored runhistory from %s", rh_path)
     stats = Stats(scen)
     stats.load(stats_path)
     self.logger.debug("Restored stats from %s", stats_path)
     with open(traj_path_aclib, 'r') as traj_fn:
         traj_list_aclib = traj_fn.readlines()
     with open(traj_path_old, 'r') as traj_fn:
         traj_list_old = traj_fn.readlines()
     return rh, stats, traj_list_aclib, traj_list_old
Пример #3
0
from dsmac.runhistory.runhistory import RunHistoryDB
from dsmac.runhistory.utils import get_id_of_config
from dsmac.tae.execute_ta_run import StatusType

if __name__ == '__main__':
    from ConfigSpace import ConfigurationSpace
    import joblib
    from dsmac.optimizer.objective import average_cost
    from dsmac.runhistory.runhistory import RunHistory

    runhistory = RunHistory(average_cost,db_args="test.db")
    cs: ConfigurationSpace = joblib.load("/home/tqc/PycharmProjects/auto-pipeline/test/php.bz2")
    runhistory.load_json(
        "/home/tqc/PycharmProjects/auto-pipeline/test/test_runhistory/default_dataset_name/smac_output/runhistory.json",
        cs)
    all_configs = (runhistory.get_all_configs())
    config = all_configs[0]
    config_id = get_id_of_config(config)
    cost = runhistory.get_cost(config)
    db = RunHistoryDB(cs, runhistory, "test.db")
    db.delete_all()
    ans = db.appointment_config(config)
    print(ans)
    db.insert_runhistory(config, cost, 0.1, StatusType.SUCCESS)
    db2 = RunHistoryDB(cs, runhistory, "test.db")
    db2.insert_runhistory(all_configs[1], runhistory.get_cost(all_configs[1]), 0.1, StatusType.SUCCESS)
    db.fetch_new_runhistory()