I wrote this code as follows,
import dask.array as da
from distributed import Client
remote_server = 'localhost:8786'
client = Client(remote_server)
rows, cols = 4123, 4123
chunk_rows, chunk_cols = 1024, 1024
matrix1 = da.random.random(size=(rows, cols), chunks=(chunk_rows, chunk_cols))
matrix2 = da.random.random(size=(rows, cols), chunks=(chunk_rows, chunk_cols))
print(matrix1.compute_chunk_sizes())
print(matrix1.compute_chunk_sizes())
sz = matrix1.shape
dim0 = sz[0]
dim1 = sz[1]
chunk_remain = dim1 % chunk_rows
lack_rows = chunk_rows - chunk_remain
lack_cols = lack_rows
# Find the missing component where splitting into chunks does not make the chunks square
lack_mat0 = da.zeros(shape=[lack_cols, dim1], chunks=(chunk_rows, chunk_cols))
lack_mat1 = da.zeros(shape=[dim0 + lack_cols, lack_rows], chunks=(chunk_rows, chunk_cols))
# Combine generated components
new_arr0 = da.append(matrix1, lack_mat0, axis=0)
new_arr1 = da.append(new_arr0, lack_mat1, axis=1)
new_matrix1 = new_arr1
sz = matrix2.shape
dim0 = sz[0]
dim1 = sz[1]
chunk_remain = dim0 % chunk_rows
lack_rows = chunk_rows - chunk_remain
lack_cols = lack_rows
# Find the missing component where splitting into chunks does not make the chunks square
lack_mat0 = da.zeros(shape=[lack_cols, dim1], chunks=(chunk_rows, chunk_cols))
lack_mat1 = da.zeros(shape=[dim0 + lack_cols, lack_rows], chunks=(chunk_rows, chunk_cols))
# Combine generated components
new_arr0 = da.append(matrix2, lack_mat0, axis=0)
new_arr1 = da.append(new_arr0, lack_mat1, axis=1)
new_matrix2 = new_arr1
# Unit matrix the added component parts
for i in range(rows, new_matrix1.shape[1]):
new_matrix1[i, i] = 1.0
new_matrix2[i, i] = 1.0
# Reorganize chunks
new_new_matrix1 = new_matrix1.rechunk((chunk_rows, chunk_cols))
new_new_matrix2 = new_matrix1.rechunk((chunk_rows, chunk_cols))
result_graph = da.linalg.solve(new_new_matrix1, new_new_matrix2)
print(result_graph.compute_chunk_sizes())
result_future = client.compute(result_graph)
result_result = client.gather(result_future)
print(result_result)
run a script
python solve-test-104.py
I got error as follows,
2024-07-22 18:28:03,886 – distributed.protocol.pickle – ERROR – Failed to serialize <ToPickle: HighLevelGraph with 1 layers.
<dask.highlevelgraph.HighLevelGraph object at 0x7aa31b0cdd20>
0. 134840950195584
.
Traceback (most recent call last):
File “/home/gorn/Projects/Tohoku-U/solvetest/venv/lib/python3.10/site-packages/distributed/protocol/pickle.py”, line 63, in dumps
result = pickle.dumps(x, **dump_kwargs)
RecursionError: maximum recursion depth exceeded while pickling an object
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File “/home/gorn/Projects/Tohoku-U/solvetest/venv/lib/python3.10/site-packages/distributed/protocol/pickle.py”, line 68, in dumps
pickler.dump(x)
RecursionError: maximum recursion depth exceeded while pickling an object
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File “/home/gorn/Projects/Tohoku-U/solvetest/venv/lib/python3.10/site-packages/cloudpickle/cloudpickle.py”, line 1245, in dump
return super().dump(obj)
RecursionError: maximum recursion depth exceeded while pickling an object
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File “/home/gorn/Projects/Tohoku-U/solvetest/venv/lib/python3.10/site-packages/distributed/protocol/pickle.py”, line 81, in dumps
result = cloudpickle.dumps(x, **dump_kwargs)
File “/home/gorn/Projects/Tohoku-U/solvetest/venv/lib/python3.10/site-packages/cloudpickle/cloudpickle.py”, line 1479, in dumps
cp.dump(obj)
File “/home/gorn/Projects/Tohoku-U/solvetest/venv/lib/python3.10/site-packages/cloudpickle/cloudpickle.py”, line 1249, in dump
raise pickle.PicklingError(msg) from e
_pickle.PicklingError: Could not pickle object as excessively deep recursion required.
Traceback (most recent call last):
File “/home/gorn/Projects/Tohoku-U/solvetest/venv/lib/python3.10/site-packages/distributed/protocol/pickle.py”, line 63, in dumps
result = pickle.dumps(x, **dump_kwargs)
RecursionError: maximum recursion depth exceeded while pickling an object
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File “/home/gorn/Projects/Tohoku-U/solvetest/venv/lib/python3.10/site-packages/distributed/protocol/pickle.py”, line 68, in dumps
pickler.dump(x)
RecursionError: maximum recursion depth exceeded while pickling an object
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File “/home/gorn/Projects/Tohoku-U/solvetest/venv/lib/python3.10/site-packages/cloudpickle/cloudpickle.py”, line 1245, in dump
return super().dump(obj)
RecursionError: maximum recursion depth exceeded while pickling an object
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File “/home/gorn/Projects/Tohoku-U/solvetest/venv/lib/python3.10/site-packages/distributed/protocol/serialize.py”, line 366, in serialize
header, frames = dumps(x, context=context) if wants_context else dumps(x)
File “/home/gorn/Projects/Tohoku-U/solvetest/venv/lib/python3.10/site-packages/distributed/protocol/serialize.py”, line 78, in pickle_dumps
frames[0] = pickle.dumps(
File “/home/gorn/Projects/Tohoku-U/solvetest/venv/lib/python3.10/site-packages/distributed/protocol/pickle.py”, line 81, in dumps
result = cloudpickle.dumps(x, **dump_kwargs)
File “/home/gorn/Projects/Tohoku-U/solvetest/venv/lib/python3.10/site-packages/cloudpickle/cloudpickle.py”, line 1479, in dumps
cp.dump(obj)
File “/home/gorn/Projects/Tohoku-U/solvetest/venv/lib/python3.10/site-packages/cloudpickle/cloudpickle.py”, line 1249, in dump
raise pickle.PicklingError(msg) from e
_pickle.PicklingError: Could not pickle object as excessively deep recursion required.
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File “/home/gorn/Projects/Tohoku-U/solvetest/solve-test-104.py”, line 68, in
print(result_graph.compute_chunk_sizes())
File “/home/gorn/Projects/Tohoku-U/solvetest/venv/lib/python3.10/site-packages/dask/array/core.py”, line 1500, in compute_chunk_sizes
tuple(int(chunk) for chunk in chunks) for chunks in compute(tuple(c))[0]
File “/home/gorn/Projects/Tohoku-U/solvetest/venv/lib/python3.10/site-packages/dask/base.py”, line 662, in compute
results = schedule(dsk, keys, **kwargs)
File “/home/gorn/Projects/Tohoku-U/solvetest/venv/lib/python3.10/site-packages/distributed/protocol/serialize.py”, line 392, in serialize
raise TypeError(msg, str_x) from exc
TypeError: (‘Could not serialize object of type HighLevelGraph’, ‘<ToPickle: HighLevelGraph with 1 layers.n<dask.highlevelgraph.HighLevelGraph object at 0x7aa31b0cdd20>n 0. 134840950195584n>’)
Naoya Ikeda is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.