Ask Your Question
1

Pickling error with multiprocessing

asked 2024-07-23 16:17:57 +0200

mn124700 gravatar image

Good morning all. I'm trying to run a test example of multiprocessing in SageMath 10.3 on Jupyter. I get an error saying that the lookup for the function "task" failed. I'm a bit new to this, and am wondering where I'm going wrong. Is there a package I forgot to install or something? Thanks. Eric

reset()
from random import random
from time import sleep
from multiprocessing.pool import Pool


def task(identifier):
    # generate a value
    value = random()
    # report a message
    print(f'Task {identifier} executing with {value}', flush=True)
    # block for a moment
    sleep(value)
    # return the generated value
    return value

def eric():
    # create and configure the process pool
    with Pool() as pool:
        # execute tasks in order, process results out of order
        for result in pool.imap_unordered(task, range(50)):
            print(f'Got result: {result}', flush=True)

eric()

PicklingError: Can't pickle <function task="" at="" 0x15676bc40="">: attribute lookup task on sage.all_cmdline failed

edit retag flag offensive close merge delete

Comments

Your code works fine in Sagecell

Max Alekseyev gravatar imageMax Alekseyev ( 2024-07-23 17:20:42 +0200 )edit

How do you run your code?

vdelecroix gravatar imagevdelecroix ( 2024-07-23 21:52:38 +0200 )edit
1

In doing a bit more research, I found that the pickling problem is with the "multiprocessing" package in Sage. This does not work on MacOS. An improved package, called "multiprocess", is available. I've installed this in my python environment, but can't seem to access it from Sage. As I understand things, Sage uses it's own python, and does not recognize the newly installed multiprocess.

Question: how do I import multiprocess into SageMath? I tried the command (from Jupyter running Sage 10.3):

pip install multiprocess

but this gives a syntax error at the word "install"

Thanks for any guidance Eric

mn124700 gravatar imagemn124700 ( 2024-07-24 21:18:33 +0200 )edit

I run it on OSX from Anaconda Navigator. From there I launch JupyterLab and select the SageMath 10.3 kernel for my notebook.

mn124700 gravatar imagemn124700 ( 2024-07-24 21:21:12 +0200 )edit

Have you tried to use built-in Sage's parallel computing functionality? https://doc.sagemath.org/html/en/refe...

Max Alekseyev gravatar imageMax Alekseyev ( 2024-07-24 22:02:15 +0200 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2024-08-11 22:02:22 +0200

slelievre gravatar image

Addressing the question in your comment, rather than the original question.

Here is how to install the multiprocess package for SageMath's Python.

In a code cell of a Jupyter sheet running the SageMath kernel, type:

%pip install multiprocess

and run that cell.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2024-07-23 16:17:57 +0200

Seen: 237 times

Last updated: Aug 11