code: def test_run_with_error() -> None:
      func = ArtificialFunction(name="sphere", block_dimension=2)
      xp = xpbase.Experiment(
          func, optimizer="OnePlusOne", budget=300, num_workers=1
      )
      with patch(
          "nevergrad.optimization.base.Optimizer.minimize"
      ) as run:
          run.side_effect = ValueError("test error string")
          with contextlib.redirect_stderr(sys.stdout):
              summary = xp.run()
      testing.assert_set_equal(summary.keys(), DESCRIPTION_KEYS)
      np.testing.assert_equal(summary["error"], "ValueError")
      assert xp._optimizer is not None
      np.testing.assert_equal(
          xp._optimizer.num_tell, 0
      )  # make sure optimizer is kept in case we need to restart (eg.: KeyboardInterrupt)
      assert not np.isnan(
          summary["loss"]
      ), "Loss should be recorded with the current recommendation"
  
imports: import sys
  import contextlib
  from unittest.mock import patch
  import numpy
  import nevergrad.common.typing
  from nevergrad.common import testing
  from nevergrad.optimization import test_base
  from nevergrad.functions import ArtificialFunction
  from nevergrad.functions.base import MultiExperiment
  from nevergrad.functions.test_base import ExampleFunction
  from nevergrad.functions.test_functionlib import DESCRIPTION_KEYS
  from .None import xpbase
label_desc: Use image node_id 4 for calling a global function with example usage: test_run_with_error() without return types