Open vprusso opened 4 years ago
Hi @vprusso , this looks interesting. However, it will require some more work than just following what they have done in QETLAB, as there they have used a parfor
loop, which is a parallel for loop which we is not available in Python. So we need to look for alternatives, like joblibs or concurrent.futures. But we might also need to add some dependencies to this project as joblib needs an installation too. Please let me know how we should approach this, if this enhancement is still needed.
Thank You
Hey @Shivansh20128 ,
True, there are multiple approaches one could take for this issue. As you mentioned joblib
is one. Another might be to use something like multiprocessing
:
import multiprocessing
def my_function(x):
# Just a dummy function, this would be where we would invoke the NLG function.
return x * x
if __name__ == "__main__":
data = [1, 2, 3, 4, 5]
pool = multiprocessing.Pool() # Create a pool of processes
result = pool.map(my_function, data) # This is similar to MATLAB's parfor
pool.close() # Close the pool to new tasks
pool.join() # Wait for all worker processes to complete
print(result)
I've had varying experiences with being able to write effective multiprocessing
code, but it might be one of the possible approaches to try here. Happy to hear if you have any specific ways of handling this that you think might be particularly useful or elegant! Thanks again for your interest and help, @Shivansh20128 !
I have added a PR. Can you also assign this to me? Thank you
Done! :)
The following loop inside of the
nonlocal_game.py
file under theclassical_value
function should be parallelized for large nonlocal games.This parallelization is also performed in QETLAB where indeed the approach to calculating the classical value of a nonlocal game has been inspired from.