1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[Python] How can I solve "cannot pickle local object" when trying to use parallelization?

Discussão em 'Python' iniciado por Stack, Outubro 25, 2024 às 10:22.

  1. Stack

    Stack Membro Participativo

    The method below belongs to a class and it is imported by a script that indirectly calls it. It is used to solve N constraints independent LSQ problems. The parallelization part is not function, and I am finding the following error message:


    Can't pickle local object 'aapy.U_matrix.<locals>.lsqSOLUTION'.

    How can I solve it?

    def U_matrix(self, V):
    U = np.zeros((0, self.c))
    iters, eabs, min_val = 500, 0.01, 1e-10


    def lsqSOLUTION(i):
    ui = cp.Variable((self.c))
    objective = cp.Minimize(cp.sum_squares(V @ ui - self.Data[:, i]))
    constraints = [0 <= ui, ui <= 1, cp.sum(ui)==1]
    prob = cp.Problem(objective, constraints)
    prob.solve(solver=cp.ECOS, max_iters=iters, abstol=eabs)
    u = np.transpose(ui.value)
    return u

    args = range(0, self.N)
    with multiprocessing.Pool() as pool:
    u = pool.map(lsqSOLUTION, args)
    vector = np.array(u)
    U = np.vstack(U, vector)
    return U


    I have the same code using basic for loop and it functions.

    Continue reading...

Compartilhe esta Página