报错求教
jingxinma opened this issue · 6 comments
请问执行run.py后,报错 AttributeError: Can't pickle local object 'problem_maker..problem'该如何处理
Can you provide more details about this AttributeError to reproduce it? E.g. the version of the dependencies (especially ZOOpt) and more detailed error message. If you installed ZOOpt following the instructions in readme.md, can you provide the commit id of the ZOOpt package?
我是通过pip安装的zoopt-0.4.2,是因为这个库的原因吗,麻烦您了
Traceback (most recent call last):
File "E:/新冠疫情/MLSim-master2/run.py", line 159, in
repeat_time=1, training_date_end=training_end_date, seed=i, json_name='data_run{}.json'.format(int(i)))
File "E:/新冠疫情/MLSim-master2/run.py", line 74, in run_opt
repeat=repeat_time, seed=seed, intermediate_freq=10000, init_samples=init_samples, loss_ord=loss_ord)
File "E:\新冠疫情\MLSim-master2\components\simulator.py", line 535, in fit
solution_list = ExpOpt.min(objective, parameter, repeat=repeat, plot=plot, plot_file=plot_file)
File "D:\Software\Anaconda\envs\MLSim-master2\lib\site-packages\zoopt\exp_opt.py", line 48, in min
solution = Opt.min(objective, parameter)
File "D:\Software\Anaconda\envs\MLSim-master2\lib\site-packages\zoopt\opt.py", line 50, in min
result = optimizer.opt(objective, parameter)
File "D:\Software\Anaconda\envs\MLSim-master2\lib\site-packages\zoopt\algos\opt_algorithms\racos\racos_optimization.py", line 50, in opt
self.__best_solution = ASRacos().opt(objective, parameter, strategy, ub)
File "D:\Software\Anaconda\envs\MLSim-master2\lib\site-packages\zoopt\algos\opt_algorithms\racos\asracos.py", line 40, in opt
evaluator.start()
File "D:\Software\Anaconda\envs\MLSim-master2\lib\multiprocessing\process.py", line 105, in start
self._popen = self._Popen(self)
File "D:\Software\Anaconda\envs\MLSim-master2\lib\multiprocessing\context.py", line 223, in _Popen
return _default_context.get_context().Process._Popen(process_obj)
File "D:\Software\Anaconda\envs\MLSim-master2\lib\multiprocessing\context.py", line 322, in _Popen
return Popen(process_obj)
File "D:\Software\Anaconda\envs\MLSim-master2\lib\multiprocessing\popen_spawn_win32.py", line 65, in init
reduction.dump(process_obj, to_child)
File "D:\Software\Anaconda\envs\MLSim-master2\lib\multiprocessing\reduction.py", line 60, in dump
ForkingPickler(file, protocol).dump(obj)
AttributeError: Can't pickle local object 'problem_maker..problem'
我感觉问题应该出在这段代码上,好像是因为闭包没法进行序列号
def problem_maker(simulator, real_result, date_end=None, ord=0):
def problem(solution):
x = solution.get_x()
simulator.set_param(x)
start_date = datetime.strptime(real_result["date"].min(), "%Y-%m-%d").date()
duration = len(real_result["date"].unique()) - 1
# print('start_data ', start_date, 'duration: ', duration)
sim_res, _ = simulator.simulate(str(start_date), duration)
if date_end is None:
return get_loss(sim_res, real_result, ord)
else:
return get_loss(sim_res[sim_res['date'] <= str(date_end)],
real_result[real_result['date'] <= str(date_end)], 2)
return problem
I find the code work well with zoopt-0.4.2. Have you ever changed the code? If so, I suggest that you can check the changed part. Is there any thing that could not be pickled?
It seems that the problem is due to the multiprocessing, Try to do such modification in MLSim/components/simulator.py line 508:
Parallel = True —> Parallel=False
It seems that the problem is due to the multiprocessing, Try to do such modification in MLSim/components/simulator.py line 508: Parallel = True —> Parallel=False
解决了,谢谢!!!