Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NoiseHandler not work in parallel_mode=True #281

Open
Landau1908 opened this issue Nov 18, 2024 · 1 comment
Open

NoiseHandler not work in parallel_mode=True #281

Landau1908 opened this issue Nov 18, 2024 · 1 comment

Comments

@Landau1908
Copy link

Hi,
The code and outputs are as follows.
Regards

import numpy as np
import cma

def fun(x,a):
    return sum(x)

if __name__ == "__main__":    
    nprocesses = 1
    args = (0,)
    parallel = Parallel(fitness_function=fun, num_processes=nprocesses)
    es = cma.CMAEvolutionStrategy(np.ones(10), 1, options={'verb_disp_overwrite':1, 'maxfevals': 5e6})  #doctest: +ELLIPSIS
    nh = cma.NoiseHandler(es.N, maxevals=[1, 1, 200])

    with cma.optimization_tools.EvalParallel2(fitness_function=fun, number_of_processes=nprocesses) as p_objective:
          X, fit_vals = es.ask_and_eval(fun, evaluations=nh.evaluations, args=args, parallel_mode=True)
          es.tell(X, fit_vals)  # prepare for next iteration
          es.sigma *= nh(X, fit_vals, fun, es.ask, args=args)  # see method __call__
          es.countevals += nh.evaluations_just_done  # this is a hack, not important though
          es.logger.add(more_data = [nh.evaluations, nh.noiseS])  # add a data point
          es.disp()
(5_w,10)-aCMA-ES (mu_w=3.2,w_1=45%) in dimension 10 (seed=1037176, Mon Nov 18 17:29:57 2024)
Traceback (most recent call last):

  File E:\ProgramData\Lib\site-packages\spyder_kernels\py3compat.py:356 in compat_exec
    exec(code, globals, locals)

  File f:\git\test_cma_noisehandler_parallel.py:50
    X, fit_vals = es.ask_and_eval(fun, evaluations=nh.evaluations, args=args, parallel_mode=True)

  File E:\ProgramData\Lib\site-packages\cma\evolution_strategy.py:2526 in ask_and_eval
    x, f = X_first.pop(0), fit_first.pop(0)

AttributeError: 'numpy.ndarray' object has no attribute 'pop'
@nikohansen
Copy link
Contributor

I am not 100% sure this is the reason for the bail, but p_objective is defined but never used, hence nothing is parallelized and, I think, fit_vals is computed as the scalar sum over all sample variables.

AFAICS, the fun argument to es.ask_and_eval must be p_objective.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants