-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG] Parallel usage of Wavelets results in errors #101
Comments
Can you format the code in this issue to make it more readable? |
Updated codes |
Cool, can you also provide a minimal failing example so that we can directly copy-paste and investigate easily (it will also potentially be the base for a future unit test)? Finally, remember to also format the code when in text. |
Well, it is not quite direct, but here is the smallest I could get. import pysap
from pysap.base.utils import flatten
from pysap.base.utils import unflatten
from joblib import Parallel, delayed
import numpy as np
num_channels = 32
n_cpu = 8
N = 64
def op(data, transform):
if isinstance(data, np.ndarray):
data = pysap.Image(data=data)
transform.data = data
transform.analysis()
coeffs, coeffs_shape = flatten(transform.analysis_data)
return coeffs, coeffs_shape
def adj_op(coeffs, coeffs_shape, transform):
transform.analysis_data = unflatten(coeffs, coeffs_shape)
image = transform.synthesis()
return image.data
transform_klass = pysap.load_transform("db4")
transform = np.asarray([transform_klass(nb_scale=4) for i in np.arange(num_channels)])
data = (np.random.randn(num_channels, N, N) +
1j * np.random.randn(num_channels, N, N))
coeffs, coeffs_shape =\
zip(*Parallel(n_jobs=n_cpu)
(delayed(op)
(data[i], transform[i])
for i in np.arange(num_channels)))
coeffs_shape = np.asarray(coeffs_shape)
image = Parallel(n_jobs=n_cpu)(
delayed(adj_op)
(coeffs[i], coeffs_shape[i], transform[i])
for i in np.arange(num_channels)) Note that the test fails if n_cpu>1 with following traceback : (I did not add this earlier as to me it doesn't make a lot of sense)
For some reason, when we try to run in parallel the nb_band_per_scale is not initialized. However the above code works great with n_cpu=1, in which case, we are running sequentially |
It looks like this is related with multiple imports of pysap as the backend is loky. Moving backend to threading solves this issue. I dont think there's much left to address here. |
I don't think we can close this. Indeed if at some point we want to do multi-processing (and not simply multi-threading) we will need to potentially use other backends. Can you explain what you mean by the multiple imports of pysap? |
For each process, a new pysap is loaded. Firstly, this adds to a lot of overhead. I am fine with keeping it open, I just felt that this could at this point mean, just merely more debug. |
Well yes there should only be an overhead but not the error you were mentioning. Let's keep it open for further investigation. |
System setup
OS: [e.g] macOS v10.14.1
Python version: [e.g.] v3.6.7
Python environment (if any): [e.g.] conda v4.5.11
Describe the bug
While using Pysap with Parallel in joblib to carry out Wavelet Transforms for various cases, We face issues. The nb_band_per_scale variable is not being populated.
To Reproduce
with _op function defined as :
Expected behavior
We expect the adjoint operation to work. But we get random errors, especially that nb_band_per_scale is None.
Module and lines involved
I see that when n_cpu=1, things work smoothly, the issue is when we extend it to have more cores.
Are you planning to submit a Pull Request?
The text was updated successfully, but these errors were encountered: