class_docstr: Subclass of argparse ArgumentParser which adds optional calls to sample from lists or ranges
  Also enables running optimizations across parallel processes
class_docstr_tok: ["Subclass","of","argparse","ArgumentParser","which","adds","optional","calls","to","sample","from","lists","or","ranges","Also","enables","running","optimizations","across","parallel","processes"]
code: def optimize_parallel(
      self,
      train_function,
      nb_trials,
      nb_parallel=4,
  ):
      self.trials = strategies.generate_trials(
          strategy=self.strategy,
          flat_params=self.__flatten_params(self.opt_args),
          nb_trials=nb_trials,
      )
  
      # nb of runs through all parallel systems
      fork_batches = [
          self.trials[i : i + nb_parallel]
          for i in range(0, len(self.trials), nb_parallel)
      ]
  
      for fork_batch in fork_batches:
          children = []
  
          # run n parallel forks
          for parallel_nb, trial in enumerate(fork_batch):
              # q up the trial and convert to a namespace
              ns = self.__namespace_from_trial(trial)
  
              # split new fork
              pid = os.fork()
  
              # when the process is a parent
              if pid:
                  children.append(pid)
  
              # when process is a child
              else:
                  # slight delay to make sure we don't overwrite over test tube log versions
                  sleep(parallel_nb * 0.5)
                  train_function(ns, parallel_nb)
                  os._exit(0)
  
          for i, child in enumerate(children):
              os.waitpid(child, 0)
  
imports: import argparse
  import json
  import math
  import os
  import random
  import re
  import traceback
  from argparse import ArgumentParser
  from copy import deepcopy
  from gettext import gettext
  from multiprocessing import Pool, Queue
  from time import sleep
  import numpy
  from .hyper_opt_utils import strategies
label_desc: Use image node_id 18 for calling the HyperOptArgumentParser obj's underlying member method code with example usage: obj.optimize_parallel(train_function, nb_trials, nb_parallel) without return types