class_docstr: Experimental helper to perform optimization using torch
  workflow with a nevergrad optimizer
  
  Parameters
  ----------
  parameters: iterable
      module parameters which need to be optimized
  cls: Optimizer-like object
      name of a nevergrad optimizer, or nevergrad optimizer class, or ConfiguredOptimizer instance
  bound: float
      values are clipped to [-bound, bound]
  
  Notes
  -----
  - This is experimental, the API may evolve
  - This does not support parallelization (multiple asks).
  
  
  Example
  -------
  ..code::python
  
      module = ...
      optimizer = helpers.TorchOptimizer(module.parameters(), "OnePlusOne")
      for x, y in batcher():
          loss = compute_loss(module(x), y)
          optimizer.step(loss)
code: def __init__(
      self,
      parameters: tp.Iterable[tp.Any],  # torch is not typed
      cls: tp.Union[str, Optim],
      bound: float = 20.0,
  ) -> None:
      self.parameters = list(parameters)
      if isinstance(cls, str):
          cls = optimizerlib.registry[cls]
      elif not isinstance(cls, base.ConfiguredOptimizer):
          if not (
              inspect.isclass(cls) and issubclass(cls, base.Optimizer)
          ):
              raise TypeError(
                  '"cls" must be a str, a ConfiguredOptimizer instance, or an Optimizer class'
              )
      args = (
          ng.p.Array(init=np.array(p.data, dtype=np.float_)).set_bounds(
              -bound, bound, method="clipping"
          )
          for p in self.parameters
      )  # bounded to avoid overflows
      self.optimizer = cls(
          ng.p.Tuple(*args), budget=None, num_workers=1
      )
      self.candidate = self.optimizer.ask()
  
file_path: nevergrad/nevergrad/optimization/helpers.py
imports: import inspect
  import typing
  import numpy
  import nevergrad
  from nevergrad.common.tools import pytorch_import_fix
  from .None import base
  from .None import optimizerlib
label_desc: Use image node_id 1 to create a new TorchOptimizer object  with example: obj = TorchOptimizer(parameters, cls, bound)