I’m calculating +100 plots in a loop (exploratory reasons …) and plotting them with holoviews.Layout(plot_list)
. It takes +3min. I tried to speed up the calculation using ray.io
(on a distributed cluster) and returning df.plot(datashader=True)
. However the process raises TypeError: cannot pickle 'weakref.ReferenceType' object
. Are there any other ways to speedup plot generation or do I have to copy some of the data to avoid weak references?
def plot(df1, df2, iloc_start: int, iloc_end):
@ray.remote
def get_plot(df1, df2, iloc, plot_opts):
pandas.options.plotting.backend = "holoviews"
row = df2.iloc[iloc]
col1 = row["list_members"][0]
col2 = row["list_members"][1]
df = df1[[col1, col2]]
return df.plot(**plot_opts, title=f"{col1}, {col2}").options(shared_axes=False)
plots = []
refs_task = []
ref_df1 = ray.put(df1)
ref_df2 = ray.put(df2
for iloc in range(iloc_start, iloc_end):
refs_task.append(get_plot.remote(ref_df1, ref_df2 iloc, plot_opts))
while refs_task:
refs_task_done, refs_task = ray.wait(refs_task)
plots += ray.get(refs_task)
return holoviews.Layout(plots).cols(5)
Traceback
File ~/workspace/venv/puma-lab/lib/python3.10/site-packages/ray/_private/client_mode_hook.py:105, in client_mode_hook.<locals>.wrapper(*args, **kwargs)
103 if func.__name__ != "init" or is_client_mode_enabled_by_default:
104 return getattr(ray, func.__name__)(*args, **kwargs)
--> 105 return func(*args, **kwargs)
File ~/workspace/venv/puma-lab/lib/python3.10/site-packages/ray/_private/worker.py:2309, in get(object_refs, timeout)
2307 worker.core_worker.dump_object_store_memory_usage()
2308 if isinstance(value, RayTaskError):
-> 2309 raise value.as_instanceof_cause()
2310 else:
2311 raise value
RayTaskError(TypeError): ray::get_plot() (pid=36727, ip=192.168.0.107)
File "/home/toaster/workspace/venv/puma-lab/lib/python3.10/site-packages/ray/cloudpickle/cloudpickle_fast.py", line 73, in dumps
cp.dump(obj)
File "/home/toaster/workspace/venv/puma-lab/lib/python3.10/site-packages/ray/cloudpickle/cloudpickle_fast.py", line 627, in dump
return Pickler.dump(self, obj)
TypeError: cannot pickle 'weakref.ReferenceType' object