def _cost_function(self, samples, cem_timestep):
    print(f'cem_timestep: {cem_timestep}')
    env_name = self.env_params['env_name']
    backend = self.env_params['backend']
    pop_size = self.train_params['pop_size']
    argss = [(env_name, backend, self.train_params, self.env_params, samples[rank][:(len(samples[rank]) // 2)], samples[rank][(len(samples[rank]) // 2):]) for rank in range(len(samples))]
    for rank in range(1, COMM.size):
        COMM.send(argss[rank], dest=rank)
    r = self.train(*argss[0])
    reses = [(0, r)]
    for rank in range(1, COMM.size):
        r = COMM.recv(source=rank)
        reses.append((rank, r))
    reses = sorted(reses, key=(lambda k: k[0]))
    print(reses)
    max_idx = 0
    max_perf = max(reses[0][1])
    for (i, item) in enumerate(reses):
        perf = max(item[1])
        if (perf > max_perf):
            max_perf = perf
            max_idx = i
    costs = [(- max(i[1])) for i in reses]
    print(costs)
    print(min(costs))
    print()
    return costs
def _cost_function(self, samples, cem_timestep):
    print(f'cem_timestep: {cem_timestep}')
    env_name = self.env_params['env_name']
    backend = self.env_params['backend']
    pop_size = self.train_params['pop_size']
    argss = [(env_name, backend, self.train_params, self.env_params, samples[rank][:(len(samples[rank]) // 2)], samples[rank][(len(samples[rank]) // 2):]) for rank in range(len(samples))]
    for rank in range(1, COMM.size):
        COMM.send(argss[rank], dest=rank)
    r = self.train(*argss[0])
    reses = [(0, r)]
    for rank in range(1, COMM.size):
        r = COMM.recv(source=rank)
        reses.append((rank, r))
    reses = sorted(reses, key=(lambda k: k[0]))
    print(reses)
    max_idx = 0
    max_perf = max(reses[0][1])
    for (i, item) in enumerate(reses):
        perf = max(item[1])
        if (perf > max_perf):
            max_perf = perf
            max_idx = i
    costs = [(- max(i[1])) for i in reses]
    print(costs)
    print(min(costs))
    print()
    return costs