Repository: facebookresearch/nevergrad

Issue:
Optimizer always trying the same points 
## Steps to reproduce

  1. Set up an optimizer with a parametrization
  2. Run optimizer.minimize()
  3. Print values being tested

## Observed Results

  * What happened?  This could be a description, log output, etc.
The argument of the objective function are always the same

## Expected Results

  * What did you expect to happen?
The optimizer tries new values
## Relevant Code

  ```
from concurrent import futures

import nevergrad as ng
import numpy as np


class myobj:
    def __init__(self):
        self.params = ng.p.Dict(
            kernel=ng.p.Log(lower=3, upper=2000).set_integer_casting()
        )

    def get_optimizer(self, parametrization, dictA):
        optimizer = ng.optimizers.NGO(
            parametrization=parametrization,
            budget=dictA["budget"],
            num_workers=dictA["workers"],
        )
        return optimizer

    def fn(self, params, dictA, X, Y):
        print(params)
        kvalue = params['kernel']
        print(kvalue)
        return kvalue * np.mean((Y - X)**2)

    def optimize_params(self, dictA, X, Y):
        # breakpoint()
        parametrization = ng.p.Instrumentation(
            self.params, dictA=dictA, X=X, Y=Y
        )
        optimizer = self.get_optimizer(parametrization, dictA)
        with futures.ThreadPoolExecutor(
            max_workers=optimizer.num_workers
        ) as executor:
            r = optimizer.minimize(
                self.fn, executor=executor, batch_mode=False
            )
        return r


obj = myobj()
dictA = {'budget':5, 'workers':2}
recom = obj.optimize_params(dictA, np.zeros(3), np.ones(3))
print('recommendation: ')
print(*recom.args)

  ```

I am sure I am doing something wrong, but I can not detect what. Any helpful hand is welcome.

<!--- In any case, don't hesitate to join and ask questions if you need on Nevergrad users Facebook group https://www.facebook.com/groups/nevergradusers/ -->



Discussion:

Resolving patch:
diff --git a/nevergrad/optimization/mutations.py b/nevergrad/optimization/mutations.py
--- a/nevergrad/optimization/mutations.py
+++ b/nevergrad/optimization/mutations.py
@@ -52,6 +52,8 @@ def portfolio_discrete_mutation(self, parent: ArrayLike, u: Optional[int] = None
         dimension = len(parent)
         if u is None:
             u = 1 if dimension == 1 else int(self.random_state.randint(1, dimension))
+        if dimension == 1:  # corner case.
+            return self.random_state.normal(0., 1., size=1)  # type: ignore
         boolean_vector = [True for _ in parent]
         while all(boolean_vector) and dimension != 1:
             boolean_vector = [self.random_state.rand() > (float(u) / dimension) for _ in parent]


Test patch:
diff --git a/nevergrad/optimization/test_optimizerlib.py b/nevergrad/optimization/test_optimizerlib.py
--- a/nevergrad/optimization/test_optimizerlib.py
+++ b/nevergrad/optimization/test_optimizerlib.py
@@ -423,5 +423,7 @@ def test_optimizer_sequence() -> None:
 
 def test_shiwa_dim1() -> None:
     param = ng.p.Log(lower=1, upper=1000).set_integer_casting()
-    optimizer = optlib.Shiwa(param, budget=10)
-    optimizer.minimize(np.abs)
+    init = param.value
+    optimizer = optlib.Shiwa(param, budget=40)
+    recom = optimizer.minimize(np.abs)
+    assert recom.value < init