class_docstr: Manages distributed hyperparameter optimisation across many gpus.
class_docstr_tok: ["Manages","distributed","hyperparameter","optimisation","across","many","gpus","."]
docstr: Instantiates optimisation manager.
  
  This hyperparameter optimisation pre-generates #search_iterations
  hyperparameter combinations and serialises them
  at the start. At runtime, each worker goes through their own set of
  parameter ranges. The pregeneration
  allows for multiple workers to run in parallel on different machines without
  resulting in parameter overlaps.
  
  Args:
    param_ranges: Discrete hyperparameter range for random search.
    fixed_params: Fixed model parameters per experiment.
    root_model_folder: Folder to store optimisation artifacts.
    worker_number: Worker index defining which set of hyperparameters to
      test.
    search_iterations: Maximum number of random search iterations.
    num_iterations_per_worker: How many iterations are handled per worker.
    clear_serialised_params: Whether to regenerate hyperparameter
      combinations.
docstr_tok: ["Instantiates","optimisation","manager",".","This","hyperparameter","optimisation","pre-generates","#","search_iterations","hyperparameter","combinations","and","serialises","them","at","the","start",".","At","runtime",",","each","worker","goes","through","their","own","set","of","parameter","ranges",".","The","pregeneration","allows","for","multiple","workers","to","run","in","parallel","on","different","machines","without","resulting","in","parameter","overlaps",".","Args",":","param_ranges",":","Discrete","hyperparameter","range","for","random","search",".","fixed_params",":","Fixed","model","parameters","per","experiment",".","root_model_folder",":","Folder","to","store","optimisation","artifacts",".","worker_number",":","Worker","index","defining","which","set","of","hyperparameters","to","test",".","search_iterations",":","Maximum","number","of","random","search","iterations",".","num_iterations_per_worker",":","How","many","iterations","are","handled","per","worker",".","clear_serialised_params",":","Whether","to","regenerate","hyperparameter","combinations","."]
code: def __init__(
      self,
      param_ranges,
      fixed_params,
      root_model_folder,
      worker_number,
      search_iterations=1000,
      num_iterations_per_worker=5,
      clear_serialised_params=False,
  ):
      """Instantiates optimisation manager.
  
      This hyperparameter optimisation pre-generates #search_iterations
      hyperparameter combinations and serialises them
      at the start. At runtime, each worker goes through their own set of
      parameter ranges. The pregeneration
      allows for multiple workers to run in parallel on different machines without
      resulting in parameter overlaps.
  
      Args:
        param_ranges: Discrete hyperparameter range for random search.
        fixed_params: Fixed model parameters per experiment.
        root_model_folder: Folder to store optimisation artifacts.
        worker_number: Worker index defining which set of hyperparameters to
          test.
        search_iterations: Maximum number of random search iterations.
        num_iterations_per_worker: How many iterations are handled per worker.
        clear_serialised_params: Whether to regenerate hyperparameter
          combinations.
      """
  
      max_workers = int(
          np.ceil(search_iterations / num_iterations_per_worker)
      )
  
      # Sanity checks
      if worker_number > max_workers:
          raise ValueError(
              "Worker number ({}) cannot be larger than the total number of workers!".format(
                  max_workers
              )
          )
      if worker_number > search_iterations:
          raise ValueError(
              "Worker number ({}) cannot be larger than the max search iterations ({})!".format(
                  worker_number, search_iterations
              )
          )
  
      print(
          "*** Creating hyperparameter manager for worker {} ***".format(
              worker_number
          )
      )
  
      hyperparam_folder = os.path.join(
          root_model_folder, str(worker_number)
      )
      super().__init__(
          param_ranges,
          fixed_params,
          hyperparam_folder,
          override_w_fixed_params=True,
      )
  
      serialised_ranges_folder = os.path.join(
          root_model_folder, "hyperparams"
      )
      if clear_serialised_params:
          print("Regenerating hyperparameter list")
          if os.path.exists(serialised_ranges_folder):
              shutil.rmtree(serialised_ranges_folder)
  
      utils.create_folder_if_not_exist(serialised_ranges_folder)
  
      self.serialised_ranges_path = os.path.join(
          serialised_ranges_folder,
          "ranges_{}.csv".format(search_iterations),
      )
      self.hyperparam_folder = hyperparam_folder  # override
      self.worker_num = worker_number
      self.total_search_iterations = search_iterations
      self.num_iterations_per_worker = num_iterations_per_worker
      self.global_hyperparam_df = self.load_serialised_hyperparam_df()
      self.worker_search_queue = self._get_worker_search_queue()
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import collections
  import os
  import shutil
  import libs.utils
  import numpy
  import pandas
label_desc: Use image node_id 1 to create a new DistributedHyperparamOptManager object from inherited base classes: HyperparamOptManager with example: obj = DistributedHyperparamOptManager(param_ranges, fixed_params, root_model_folder, worker_number, search_iterations, num_iterations_per_worker, clear_serialised_params)