code: def fmin(self, fn, space, **kw):
      # TODO: all underscore variables are completely unused throughout.
      algo = kw.get("algo")
      max_evals = kw.get("max_evals")
      rstate = kw.get("rstate", None)
      _allow_trials_fmin = (True,)
      _pass_expr_memo_ctrl = (None,)
      _catch_eval_exceptions = (False,)
      verbose = kw.get("verbose", 0)
      _return_argmin = (True,)
      wait = (True,)
      pass_expr_memo_ctrl = (None,)
  
      if rstate is None:
          rstate = np.random
  
      # -- used in test_ipy
      self._testing_fmin_was_called = True
  
      if pass_expr_memo_ctrl is None:
          try:
              pass_expr_memo_ctrl = fn.pass_expr_memo_ctrl
          except AttributeError:
              pass_expr_memo_ctrl = False
  
      domain = Domain(fn, space, None, pass_expr_memo_ctrl=False)
  
      last_print_time = 0
  
      while len(self._dynamic_trials) < max_evals:
          self.refresh()
  
          if verbose and last_print_time + 1 < time():
              print(
                  "fmin: %4i/%4i/%4i/%4i  %f"
                  % (
                      self.count_by_state_unsynced(JOB_STATE_NEW),
                      self.count_by_state_unsynced(JOB_STATE_RUNNING),
                      self.count_by_state_unsynced(JOB_STATE_DONE),
                      self.count_by_state_unsynced(JOB_STATE_ERROR),
                      min(
                          [float("inf")]
                          + [l for l in self.losses() if l is not None]
                      ),
                  )
              )
              last_print_time = time()
  
          idles = [
              eid
              for (eid, (p, tt)) in list(self.job_map.items())
              if p is None
          ]
  
          if idles:
              new_ids = self.new_trial_ids(len(idles))
              new_trials = algo(
                  new_ids, domain, self, rstate.randint(2**31 - 1)
              )
              if len(new_trials) == 0:
                  break
              else:
                  assert len(idles) >= len(new_trials)
                  for eid, new_trial in zip(idles, new_trials):
                      now = coarse_utcnow()
                      new_trial["book_time"] = now
                      new_trial["refresh_time"] = now
                      (tid,) = self.insert_trial_docs([new_trial])
                      promise = call_domain(
                          domain,
                          spec_from_misc(new_trial["misc"]),
                          Ctrl(self, current_trial=new_trial),
                          new_trial,
                          self._clientlbv,
                          eid,
                          tid,
                      )
  
                      # -- XXX bypassing checks because 'ar'
                      # is not ok for SONify... but should check
                      # for all else being SONify
  
                      tt = self._dynamic_trials[-1]
                      assert tt["tid"] == tid
                      self.job_map[eid] = (promise, tt)
                      tt["state"] = JOB_STATE_RUNNING
  
      if wait:
          if verbose:
              print("fmin: Waiting on remaining jobs...")
          self.wait(verbose=verbose)
  
      return self.argmin
  
imports: from __future__ import print_function
  from __future__ import absolute_import
  from builtins import zip
  from builtins import str
  from builtins import object
  from time import sleep, time
  import numpy
  from .base import Trials
  from .base import Domain
  from .base import JOB_STATE_NEW
  from .base import JOB_STATE_RUNNING
  from .base import JOB_STATE_DONE
  from .base import JOB_STATE_ERROR
  from .base import spec_from_misc
  from .base import Ctrl
  from .utils import coarse_utcnow
  import sys
label_desc: Use image node_id 4 for calling the IPythonTrials obj's underlying member method code with example usage: obj.fmin(fn, space) and returns: self