Skip to content

ValueError: attempt to get argmin of an empty sequence. How can I avoid this error? #53

@ZhiqiangD

Description

@ZhiqiangD

On an 80-core, 160-thread CPU, an error occurs when running asynchronous parallel:

asynchronous=True cann't run.
File "/data2/dzq/help/hhc/changjiang/cali/cali-up/calibration.py", line 215, in vic_calibration
station_cali(basin_dir, n_cpu, n_max, n_para)
File "/data2/dzq/help/hhc/changjiang/cali/cali-up/calibration.py", line 189, in station_cali
controller.run()
File "/home/dzq/software/anaconda3/envs/py312/lib/python3.9/site-packages/poap/controller.py", line 344, in r
return self._run(merit=merit, filter=filter)
File "/home/dzq/software/anaconda3/envs/py312/lib/python3.9/site-packages/poap/controller.py", line 314, in _
proposal = self.strategy.propose_action()
File "/home/dzq/software/anaconda3/envs/py312/lib/python3.9/site-packages/pySOT/strategy/surrogate_strategy.pne 285, in propose_action
self.generate_evals(num_pts=1)
File "/home/dzq/software/anaconda3/envs/py312/lib/python3.9/site-packages/pySOT/strategy/srbf_strategy.py", l3, in generate_evals
new_points = candidate_srbf(
File "/home/dzq/software/anaconda3/envs/py312/lib/python3.9/site-packages/pySOT/auxiliary_problems/candidate_y", line 92, in candidate_srbf
xbest = np.copy(X[np.argmin(fX), :]).ravel()
File "<array_function internals>", line 5, in argmin
File "/home/dzq/software/anaconda3/envs/py312/lib/python3.9/site-packages/numpy/core/fromnumeric.py", line 12 argmin
return _wrapfunc(a, 'argmin', axis=axis, out=out)
File "/home/dzq/software/anaconda3/envs/py312/lib/python3.9/site-packages/numpy/core/fromnumeric.py", line 57wrapfunc
return bound(*args, **kwds)
ValueError: attempt to get argmin of an empty sequence

asynchronous=False can run.

code:
def station_cali(basin_dir, n_cpu=80, n_max=400, n_para=13):
"""
优化率定主程序,控制多线程
"""
cali = Calibration(n_para, basin_dir)
rbf = RBFInterpolant(
dim=cali.dim,
lb=cali.lb,
ub=cali.ub,
kernel=CubicKernel(),
tail=LinearTail(cali.dim),
)
num_pts = int(2 * (cali.dim + 1))
slhd = SymmetricLatinHypercube(dim=cali.dim, num_pts=num_pts)
controller = ThreadController()
strategy = SRBFStrategy(
max_evals=n_max,
opt_prob=cali,
exp_design=slhd,
surrogate=rbf,
asynchronous=False,
batch_size=n_cpu,
)
controller.strategy = strategy
for i in range(n_cpu):

    worker = solve(controller)
    threaddir = f"{basin_dir}/model" + str(i).rjust(3, "0")
    worker.dir = threaddir
    if os.path.exists(threaddir):
        shutil.rmtree(threaddir)

    shutil.copytree(f"{basin_dir}/model", threaddir)
    controller.launch_worker(worker)
controller.run()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions