Skip to content

ENH: Allow registering a different pickling backend #669

Description

@hmgaudecker

Is your feature request related to a problem?

Running pytask in a project with optimagic & LCM left a colleague baffled by the error reproduced below. For debugging it, some developer (well, reviewer) knowledge of the three libraries was certainly helpful.

Reason is that these libraries require pickling functions that the built-in pickle cannot handle, so optimagic uses cloudpickle internally. So it is possible to work around this by doing the pickling / unpickling manually, but it would be nice to just continue using the pytask data catalogue abstraction directly.

Traceback (most recent call last):
  File "/Users/abc/project/.pixi/envs/default/lib/python3.12/site-packages/loky/process_executor.py", line 490, in _process_worker
    r = call_item()
        ^^^^^^^^^^^
  File "/Users/abc/project/.pixi/envs/default/lib/python3.12/site-packages/loky/process_executor.py", line 291, in __call__
    return self.fn(*self.args, **self.kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/abc/project/.pixi/envs/default/lib/python3.12/site-packages/pytask_parallel/wrappers.py", line 137, in wrap_task_in_process
    products = _handle_function_products(task, out, remote=remote)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/abc/project/.pixi/envs/default/lib/python3.12/site-packages/pytask_parallel/wrappers.py", line 272, in _handle_function_products
    return tree_map_with_path(_save_and_carry_over_product, task.produces)  # type: ignore[arg-type]
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/abc/project/.pixi/envs/default/lib/python3.12/site-packages/optree/ops.py", line 859, in tree_map_with_path
    return treespec.unflatten(map(func, paths, *flat_args))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/abc/project/.pixi/envs/default/lib/python3.12/site-packages/pytask_parallel/wrappers.py", line 269, in _save_and_carry_over_product
    node.save(value)
  File "/Users/abc/project/.pixi/envs/default/lib/python3.12/site-packages/_pytask/nodes.py", line 336, in save
    pickle.dump(value, f)
AttributeError: Can't get local object 'get_converter.<locals>._params_to_internal'

Describe the solution you'd like

Some stable mechanism to specify the backend to in pytask.PNode.load / .save.

I guess subclassing would do the trick, but maybe it is common enough to support it project-wide?

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions