code: def suggest(
      new_ids,
      domain,
      trials,
      seed,
      prior_weight=_default_prior_weight,
      n_startup_jobs=_default_n_startup_jobs,
      n_EI_candidates=_default_n_EI_candidates,
      gamma=_default_gamma,
      linear_forgetting=_default_linear_forgetting,
  ):
      new_id = new_ids[0]
  
      t0 = time.time()
      (
          s_prior_weight,
          observed,
          observed_loss,
          specs,
          opt_idxs,
          opt_vals,
      ) = tpe_transform(domain, prior_weight, gamma)
      tt = time.time() - t0
      logger.info("tpe_transform took %f seconds" % tt)
  
      best_docs = dict()
      best_docs_loss = dict()
      for doc in trials.trials:
          # get either this docs own tid or the one that it's from
          tid = doc["misc"].get("from_tid", doc["tid"])
          loss = domain.loss(doc["result"], doc["spec"])
          if loss is None:
              # -- associate infinite loss to new/running/failed jobs
              loss = float("inf")
          else:
              loss = float(loss)
          best_docs_loss.setdefault(tid, loss)
          if loss <= best_docs_loss[tid]:
              best_docs_loss[tid] = loss
              best_docs[tid] = doc
  
      tid_docs = list(best_docs.items())
      # -- sort docs by order of suggestion
      #    so that linear_forgetting removes the oldest ones
      tid_docs.sort()
      losses = [best_docs_loss[k] for k, v in tid_docs]
      tids = [k for k, v in tid_docs]
      docs = [v for k, v in tid_docs]
  
      if docs:
          logger.info(
              "TPE using %i/%i trials with best loss %f"
              % (len(docs), len(trials), min(best_docs_loss.values()))
          )
      else:
          logger.info("TPE using 0 trials")
  
      if len(docs) < n_startup_jobs:
          # N.B. THIS SEEDS THE RNG BASED ON THE new_id
          return rand.suggest(new_ids, domain, trials, seed)
  
      #    Sample and compute log-probability.
      if tids:
          # -- the +2 co-ordinates with an assertion above
          #    to ensure that fake ids are used during sampling
          fake_id_0 = max(max(tids), new_id) + 2
      else:
          # -- weird - we're running the TPE algo from scratch
          assert n_startup_jobs <= 0
          fake_id_0 = new_id + 2
  
      fake_ids = list(range(fake_id_0, fake_id_0 + n_EI_candidates))
  
      # -- this dictionary will map pyll nodes to the values
      #    they should take during the evaluation of the pyll program
      memo = {
          domain.s_new_ids: fake_ids,
          domain.s_rng: np.random.RandomState(seed),
      }
  
      o_idxs_d, o_vals_d = miscs_to_idxs_vals(
          [d["misc"] for d in docs], keys=list(domain.params.keys())
      )
      memo[observed["idxs"]] = o_idxs_d
      memo[observed["vals"]] = o_vals_d
  
      memo[observed_loss["idxs"]] = tids
      memo[observed_loss["vals"]] = losses
  
      idxs, vals = pyll.rec_eval(
          [opt_idxs, opt_vals], memo=memo, print_node_on_error=False
      )
  
      # -- retrieve the best of the samples and form the return tuple
      # the build_posterior makes all specs the same
  
      rval_specs = [None]  # -- specs are deprecated
      rval_results = [domain.new_result()]
      rval_miscs = [
          dict(tid=new_id, cmd=domain.cmd, workdir=domain.workdir)
      ]
  
      miscs_update_idxs_vals(
          rval_miscs,
          idxs,
          vals,
          idxs_map={fake_ids[0]: new_id},
          assert_all_vals_used=False,
      )
      rval_docs = trials.new_trial_docs(
          [new_id], rval_specs, rval_results, rval_miscs
      )
  
      return rval_docs
  
imports: from __future__ import print_function
  from __future__ import absolute_import
  from __future__ import division
  from builtins import str
  from builtins import map
  from builtins import zip
  from builtins import range
  from past.utils import old_div
  import logging
  import time
  import numpy
  from scipy.special import erf
  from .None import pyll
  from .pyll import scope
  from .pyll.stochastic import implicit_stochastic
  from .base import miscs_to_idxs_vals
  from .base import miscs_update_idxs_vals
  from .None import rand
label_desc: Use image node_id 31 for calling a global function with example usage: suggest(new_ids, domain, trials, seed, prior_weight, n_startup_jobs, n_EI_candidates, gamma, linear_forgetting) and returns: rval_docs, rand