def create_exp(self,
                   name_suffix: str = None,
                   context_symbol_table: dict = None) -> Experiment:
        # TODO require name suffix
        name = self.base_exp.name
        if name_suffix:
            # Add name suffix to experiment name
            name = name + " - " + name_suffix

        if context_symbol_table:
            self._context_symbol_table = context_symbol_table
        if not self._context_symbol_table:
            self._context_symbol_table = experiment_utils.get_caller_symbol_table(
            )
        exp_copy = Experiment(
            self.base_exp._env,
            name,
            auto_sync=self.base_exp.auto_sync,
            track_file_events=
            False,  # Do not track file events for sub experiments
            upload_code_script=self.base_exp.upload_code_script,
            upload_code_repo=self.base_exp.upload_code_repo,
            redirect_logs=self.base_exp.redirect_logs,
            context_symbol_table=self._context_symbol_table,
            root_folder=self.base_exp.output_path
            if self._use_group_folder else None,
            group_key=self.group_key)

        # Initialize with all input files and artifacts
        exp_copy.exp_metadata.resources.input = self.base_exp.exp_metadata.resources.input
        exp_copy.exp_metadata.resources.artifacts = self.base_exp.exp_metadata.resources.artifacts
        self._experiments.append(exp_copy)
        return exp_copy
 def __init__(self,
              base_exp,
              group_key: str = None,
              maximize_score: bool = True,
              **kwargs):
     super(OptunaOptimizer, self).__init__(
         base_exp,
         group_key,
         context_symbol_table=experiment_utils.get_caller_symbol_table())
     self.maximize_score = maximize_score
     self.optuna_args = kwargs
     self.optuna_study = None
 def __init__(self,
              base_exp,
              group_key: str = None,
              maximize_score: bool = True,
              algo: str = "gp",
              **kwargs):
     super(SkoptOptimizer, self).__init__(
         base_exp,
         group_key,
         context_symbol_table=experiment_utils.get_caller_symbol_table())
     self.maximize_score = maximize_score
     self.skopt_args = kwargs
     self.skopt_algo = algo
 def __init__(self,
              base_exp,
              group_key: str = None,
              maximize_score: bool = True,
              **kwargs):
     super(HyperoptOptimizer, self).__init__(
         base_exp,
         group_key,
         context_symbol_table=experiment_utils.get_caller_symbol_table())
     self.maximize_score = maximize_score
     self.fmin_args = kwargs
     self.hyperopt_trials = None
     self.hyperopt_result = None
示例#5
0
    def create_experiment(self, name: str) -> Experiment:
        """
        Creates a new #Experiment and save it as active experiment.

        # Arguments
            name (string): Short description of the experiment.

        # Returns
        The created #Experiment instance.
        """
        self.active_exp = Experiment(
            self,
            name,
            context_symbol_table=experiment_utils.get_caller_symbol_table())
        return self.active_exp
    def __init__(self,
                 env,
                 name: str,
                 auto_sync: bool = True,
                 track_file_events: bool = True,
                 upload_code_script: bool = True,
                 upload_code_repo: bool = False,
                 redirect_logs: bool = True,
                 context_symbol_table: dict = None,
                 root_folder: dict = None,
                 group_key: str = None,
                 experiment_key: str = None):
        # TODO option to track file events only during run
        # Initialize logger
        self.log = logging.getLogger(__name__)

        # Initialize internal variables -> Lazy initialization
        self._track_file_events = None
        self._running = False
        self._has_run = False
        self._syncing = False
        self._output_path = None
        self._tensorboard_path = None

        # Initialize components -> Lazy initialization
        self._tensorboard_logger = None
        self._stdout_file_redirect = None

        # Initialize internal variables from parameters
        self._root_folder = root_folder
        self._name = name
        self._env = env
        self._context_symbol_table = context_symbol_table

        # Initialize public variables from parameters
        self.auto_sync = auto_sync
        self.redirect_logs = redirect_logs
        self.upload_code_script = upload_code_script
        self.upload_code_repo = upload_code_repo
        self.track_file_events = track_file_events  # use setter to add event listeners
        self.init_time = datetime.datetime.now()
        self._artifacts = {}

        # Initialize internal variables
        self._exp_script_dir = os.getcwd()

        if experiment_key:
            # use provided key
            self._key = experiment_key
        else:
            # Generate key
            timestamp = self.init_time.strftime('%Y-%m-%d-%H-%M-%S')
            self._key = '{}_{}_{}'.format(
                timestamp, text_utils.simplify(self._env.operator),
                text_utils.simplify(self.name))

        # set context (symbol table)
        if not self._context_symbol_table:
            self._context_symbol_table = experiment_utils.get_caller_symbol_table(
            )

        # Initialize experiment metadata
        self._exp_metadata = self._init_default_metadata()

        if group_key:
            self.exp_metadata.group_key = group_key

        # TODO set as active experiment?

        self.log.info("Experiment " + self.name + " is initialized.")
        self.log.debug("Experiment key: " + self.key)

        if not self._env.is_connected():
            self.log.info(
                "Environment is not connected to Lab. Experiment data will only be synced locally."
            )
 def __init__(self, base_exp, group_key: str = None):
     super(GridSearchOptimizer, self).__init__(
         base_exp,
         group_key,
         context_symbol_table=experiment_utils.get_caller_symbol_table())