class_docstr: Object for conducting search experiments.
class_docstr_tok: ["Object","for","conducting","search","experiments","."]
docstr: Run `self.algo` iteratively (use existing `self.trials` to produce the new
  ones), update, and repeat
  block_until_done  means that the process blocks until ALL jobs in
  trials are not in running or new state
docstr_tok: ["Run","`","self.algo","`","iteratively","(","use","existing","`","self.trials","`","to","produce","the","new","ones",")",",","update",",","and","repeat","block_until_done","means","that","the","process","blocks","until","ALL","jobs","in","trials","are","not","in","running","or","new","state"]
code: def run(self, N, block_until_done=True):
      """
      Run `self.algo` iteratively (use existing `self.trials` to produce the new
      ones), update, and repeat
      block_until_done  means that the process blocks until ALL jobs in
      trials are not in running or new state
  
      """
      trials = self.trials
      algo = self.algo
      n_queued = 0
  
      def get_queue_len():
          return self.trials.count_by_state_unsynced(base.JOB_STATE_NEW)
  
      def get_n_done():
          return self.trials.count_by_state_unsynced(
              base.JOB_STATE_DONE
          )
  
      def get_n_unfinished():
          unfinished_states = [
              base.JOB_STATE_NEW,
              base.JOB_STATE_RUNNING,
          ]
          return self.trials.count_by_state_unsynced(unfinished_states)
  
      stopped = False
      initial_n_done = get_n_done()
      with self.progress_callback(
          initial=initial_n_done, total=self.max_evals
      ) as progress_ctx:
          all_trials_complete = False
          best_loss = float("inf")
          while (
              # more run to Q     || ( block_flag & trials not done )
              (
                  n_queued < N
                  or (block_until_done and not all_trials_complete)
              )
              # no timeout        || < current last time
              and (
                  self.timeout is None
                  or (timer() - self.start_time) < self.timeout
              )
              # no loss_threshold || < current best_loss
              and (
                  self.loss_threshold is None
                  or best_loss >= self.loss_threshold
              )
          ):
              qlen = get_queue_len()
              while (
                  qlen < self.max_queue_len
                  and n_queued < N
                  and not self.is_cancelled
              ):
                  n_to_enqueue = min(
                      self.max_queue_len - qlen, N - n_queued
                  )
                  # get ids for next trials to enqueue
                  new_ids = trials.new_trial_ids(n_to_enqueue)
                  self.trials.refresh()
                  # Based on existing trials and the domain, use `algo` to probe in
                  # new hp points. Save the results of those inspections into
                  # `new_trials`. This is the core of `run`, all the rest is just
                  # processes orchestration
                  new_trials = algo(
                      new_ids,
                      self.domain,
                      trials,
                      self.rstate.integers(2**31 - 1),
                  )
                  assert len(new_ids) >= len(new_trials)
  
                  if len(new_trials):
                      self.trials.insert_trial_docs(new_trials)
                      self.trials.refresh()
                      n_queued += len(new_trials)
                      qlen = get_queue_len()
                  else:
                      stopped = True
                      break
  
              if self.is_cancelled:
                  break
  
              if self.asynchronous:
                  # -- wait for workers to fill in the trials
                  time.sleep(self.poll_interval_secs)
              else:
                  # -- loop over trials and do the jobs directly
                  self.serial_evaluate()
  
              self.trials.refresh()
              if self.trials_save_file != "":
                  pickler.dump(
                      self.trials, open(self.trials_save_file, "wb")
                  )
              if self.early_stop_fn is not None:
                  stop, kwargs = self.early_stop_fn(
                      self.trials, *self.early_stop_args
                  )
                  self.early_stop_args = kwargs
                  if stop:
                      logger.info(
                          "Early stop triggered. Stopping iterations as condition is reach."
                      )
                      stopped = True
              # update progress bar with the min loss among trials with status ok
              losses = [
                  loss
                  for loss in self.trials.losses()
                  if loss is not None and not np.isnan(loss)
              ]
              if losses:
                  best_loss = min(losses)
                  progress_ctx.postfix = "best loss: " + str(best_loss)
  
              n_unfinished = get_n_unfinished()
              if n_unfinished == 0:
                  all_trials_complete = True
  
              n_done = get_n_done()
              n_done_this_iteration = n_done - initial_n_done
              if n_done_this_iteration > 0:
                  progress_ctx.update(n_done_this_iteration)
              initial_n_done = n_done
  
              if stopped:
                  break
  
      if block_until_done:
          self.block_until_done()
          self.trials.refresh()
          logger.info("Queue empty, exiting run.")
      else:
          qlen = get_queue_len()
          if qlen:
              msg = "Exiting run, not waiting for %d jobs." % qlen
              logger.info(msg)
  
imports: import functools
  import inspect
  import logging
  import os
  import sys
  import time
  from timeit import default_timer
  import numpy
  from hyperopt import tpe, exceptions
  from hyperopt.base import validate_timeout, validate_loss_threshold
  from .None import pyll
  from .utils import coarse_utcnow
  from .None import base
  from .None import progress
label_desc: Use image node_id 5 for calling the FMinIter obj's underlying member method code with example usage: obj.run(N, block_until_done) and returns: self, self, self