class_docstr: Helper class to retry a function until it succeeds.
  
  Typical use case is to retry random sampling until a non-duplicate / valid sample is found.
  
  Parameters
  ----------
  retries
      Number of retries.
  exception_types
      Exception types to catch.
  raise_last
      Whether to raise the last exception if all retries failed.
class_docstr_tok: ["Helper","class","to","retry","a","function","until","it","succeeds",".","Typical","use","case","is","to","retry","random","sampling","until","a","non-duplicate","\/","valid","sample","is","found",".","Parameters","--","--","--","--","--","retries","Number","of","retries",".","exception_types","Exception","types","to","catch",".","raise_last","Whether","to","raise","the","last","exception","if","all","retries","failed","."]
code: def retry(self, func: Callable[..., T], *args, **kwargs) -> T | None:
      for retry in range(self.retries):
          try:
              return func(*args, **kwargs)
          except self.exception_types as e:
              if retry in [0, 10, 100, 1000]:
                  _logger.debug(
                      "Sampling failed. %d retries so far. Exception caught: %r",
                      retry,
                      e,
                  )
              if retry >= self.retries - 1 and self.raise_last:
                  _logger.warning(
                      "Sampling failed after %d retries. Giving up and raising the last exception.",
                      self.retries,
                  )
                  raise
  
      _logger.warning(
          "Sampling failed after %d retires. Giving up and returning None.",
          self.retries,
      )
      return None
  
file_path: nni/nni/nas/strategy/utils.py
imports: from __future__ import annotations
  import logging
  from typing import Any, Type, TypeVar, Callable
  from nni.mutable import SampleValidationError
label_desc: Use image node_id 2 for calling the RetrySamplingHelper obj's underlying member method code with example usage: obj.retry(func) and returns: None, func