Exemplo n.º 1
0
def test_timecontrol():
    strings = ("3.0+0.03", "7.0+0.0")
    result = TimeControl.from_strings(*strings)
    expected = (Decimal("3.0"), Decimal("0.03"), Decimal(7), Decimal(0))
    assert result == expected

    assert result.to_strings() == strings
Exemplo n.º 2
0
 def to_tuple(self):
     return TimeControl(
         engine1_time=self.engine1_time,
         engine1_increment=self.engine1_increment,
         engine2_time=self.engine2_time,
         engine2_increment=self.engine2_increment,
     )
Exemplo n.º 3
0
 def adjust_time_control(self, time_control, lc0_nodes, sf_nodes):
     lc0_ratio = lc0_nodes / self.lc0_benchmark
     sf_ratio = sf_nodes / self.sf_benchmark
     new_tc = TimeControl(
         engine1_time=float(time_control.engine1_time) * lc0_ratio,
         engine1_increment=float(time_control.engine1_increment) * lc0_ratio,
         engine2_time=float(time_control.engine2_time) * sf_ratio,
         engine2_increment=float(time_control.engine2_increment) * sf_ratio,
     )
     return new_tc
Exemplo n.º 4
0
    def __init__(self, experiment_path, dbconfig_path, **kwargs):
        self.logger = logging.getLogger("TuningServer")
        self.experiment_path = experiment_path
        if os.path.isfile(dbconfig_path):
            with open(dbconfig_path, "r") as config_file:
                config = config_file.read().replace("\n", "")
                self.logger.debug(f"Reading DB config:\n{config}")
                self.connect_params = json.loads(config)
        else:
            raise ValueError("No dbconfig file found at provided path")

        self.engine = create_sqlalchemy_engine(self.connect_params)
        Base.metadata.create_all(self.engine)
        sm = sessionmaker(bind=self.engine)
        self.sessionmaker = get_session_maker(sm)

        if os.path.isfile(experiment_path):
            with open(experiment_path, "r+") as experiment_file:
                exp = experiment_file.read().replace("\n", "")
                self.logger.debug(f"Reading experiment config:\n{exp}")
                self.experiment = json.loads(exp)
                self.logger.debug(f"self.experiment = \n{self.experiment}")
        else:
            raise ValueError(
                "No experiment config file found at provided path")
        self.time_controls = [
            TimeControl.from_strings(*x)
            for x in self.experiment["time_controls"]
        ]
        self.rng = np.random.RandomState(
            self.experiment.get("random_seed", 123))
        self.setup_tuner()

        try:
            os.makedirs("experiments")
        except FileExistsError:
            pass
        # TODO: in principle after deleting all jobs from the database,
        #       this could be problematic:
        self.pos = None
        self.chain = None
        if "tune_id" in self.experiment:
            self.resume_tuning()