Hello community members,
I have written a code (attached below) to compute interface heights for my melt-solid-melt simulation setup. I wish to parallelize it for an improved efficiency. I want to divide the loop in chunks of frames and analyze them in parallel. When I do that, i get an error - “cannot pickle object ovito.pipeline”. Can you help me fix this by suggesting how i can parallelize the for loop below.
Original Code:
function to compute interface heights
error_list = []
def compute_interface_heights(pipeline):
frame = 0
top_height = np.zeros((snapshot_count,bins))
bottom_height = np.zeros((snapshot_count,bins))
for frame in range(pipeline.source.num_frames-1):
try:
clear_output(wait=True)
print(frame)
data = pipeline.compute(frame)
#compute the bottom interface height for each frame
data_TopCopy = data.clone()
data_BottomCopy = data.clone()
#top interface
data_TopCopy.apply(modifier0)
data_TopCopy.apply(modifier1)
data_TopCopy.apply(modifier3)
top_height[frame,:] = data_TopCopy.tables['binning'].xy()[:,1]
#bottom interface
data_BottomCopy.apply(modifier0)
data_BottomCopy.apply(modifier2)
data_BottomCopy.apply(modifier3)
bottom_height[frame,:] = data_BottomCopy.tables['binning'].xy()[:,1]
#delete objects for reuse in next loop
del data_TopCopy
del data_BottomCopy
except Exception as e:
error_message = f"An error occurred at frame {frame}. Error: {e}"
error_list.append(error_message)
continue
return top_height, bottom_height