import cma, numpy as np
def grad(x): return 2.0 * (x - 1.0)
opts = {"fixed_variables": {0: 0.0}, "verbose": -9}
es = cma.CMAEvolutionStrategy([0.1, 0.1], 0.5, opts)
es.ask(gradf=grad)
Traceback (most recent call last):
File "<python-input-15>", line 5, in <module>
es.ask(gradf=grad) # currently raises ValueError later, not
~~~~~~^^^^^^^^^^^^
File "/Users/francesco/Downloads/pycma/cma/evolution_strategy.py", line 1759, in ask
v = self.sm.D * np.dot(self.sm.B.T, self.sigma_vec * grad_at_mean)
~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: shapes (1,1) and (2,) not aligned: 1 (dim 1) != 2 (dim 0)
While using
gradfI hit a confusingValueError(shape mismatch) instead of the intendedNotImplementedError. The code appears to intend to stop early whenfixed_variablesis set or the gradient length doesn’t matchN, but it instantiatesNotImplementedError(...)without raising it, and then fails later during the matrix multiply.As an example: