class_docstr: Recast optimizer where points to evaluate are provided in batches
  and stored by the optimizer to be asked and told on. The fake_callable
  is only brought into action every 'batch size' number of asks and tells
  instead of every ask and tell. This opens up the optimizer to
  parallelism.
  
  Note
  ----
  You have to complete a batch before you start a new one so parallelism
  is only possible within batches i.e. if a batch size is 100 and you have
  done 100 asks, you must do 100 tells before you ask again but you could do
  those 100 asks and tells in parallel. To find out if you can perform an ask
  at any given time call self.can_ask.
class_docstr_tok: ["Recast","optimizer","where","points","to","evaluate","are","provided","in","batches","and","stored","by","the","optimizer","to","be","asked","and","told","on",".","The","fake_callable","is","only","brought","into","action","every","'batch","size","'","number","of","asks","and","tells","instead","of","every","ask","and","tell",".","This","opens","up","the","optimizer","to","parallelism",".","Note","--","--","You","have","to","complete","a","batch","before","you","start","a","new","one","so","parallelism","is","only","possible","within","batches","i.e",".","if","a","batch","size","is","100","and","you","have","done","100","asks",",","you","must","do","100","tells","before","you","ask","again","but","you","could","do","those","100","asks","and","tells","in","parallel",".","To","find","out","if","you","can","perform","an","ask","at","any","given","time","call","self.can_ask","."]
docstr: Reads messages from the thread in which the underlying optimization function is running
  New messages are sent as "ask".
docstr_tok: ["Reads","messages","from","the","thread","in","which","the","underlying","optimization","function","is","running","New","messages","are","sent","as","``","ask","''","."]
code: def _internal_ask_candidate(self) -> p.Parameter:
      """Reads messages from the thread in which the underlying optimization function is running
      New messages are sent as "ask".
      """
      if self._messaging_thread is None:
          self._messaging_thread = MessagingThread(
              self.get_optimization_function()
          )
      if self._current_batch:
          return self._current_batch.pop()
      # if there are any points in the previous batch that haven't been told on, you cannot update the current batch.
      if not self.can_ask():
          raise TooManyAskError(
              "You can't get a new batch until the old one has been fully told on. See docstring for more info."
          )
      alive = self._messaging_thread.is_alive()
      # wait for a message
      if alive:
          points = self._messaging_thread.messages_ask.get()
          if isinstance(points, Exception):
              raise points
      if (
          not alive or points is None
      ):  # In case the algorithm stops before the budget is elapsed.
          warnings.warn(
              "Underlying optimizer has already converged, returning random points",
              base.errors.FinishedUnderlyingOptimizerWarning,
          )
          self._check_error()
          data = self._rng.normal(0, 1, self.dimension)
          return (
              self.parametrization.spawn_child().set_standardized_data(
                  data
              )
          )
  
      # We have a new batch
      self.batch_size = len(points)
      self._current_batch = [
          self.parametrization.spawn_child().set_standardized_data(
              point
          )
          for point in points
      ]
      self._batch_losses = [None] * len(points)  # type: ignore
      # map each point to an index in preparation to build loss array in tell
      self.indices = {
          candidate.uid: i
          for i, candidate in enumerate(self._current_batch)
      }
      return self._current_batch.pop()
  
imports: import warnings
  import threading
  import queue
  import numpy
  import nevergrad.common.typing
  from nevergrad.common.errors import NevergradError
  from nevergrad.parametrization import parameter
  from .None import base
  from .base import IntOrParameter
label_desc: Use image node_id 2 for calling the BatchRecastOptimizer obj's underlying member method code with example usage: obj._internal_ask_candidate() and returns: self, self, self