GithubHelp home page GithubHelp logo

letianwu / zmcintegral Goto Github PK

View Code? Open in Web Editor NEW
19.0 19.0 8.0 974 KB

An easy way to use multi-GPUs to calculate multi-dimensional integration

Home Page: https://arxiv.org/pdf/1902.07916v2.pdf

License: Apache License 2.0

Python 100.00%
monte-carlo-integration multi-gpu-device numba ray

zmcintegral's People

Contributors

juenjie avatar letianwu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

zmcintegral's Issues

TensorFlow version

Hi, I've read your paper with great interest, but I could not find the TensorFlow version of ZMCintegral. Could you may point me to the right repository?

change of the function definition in example fails

Hi. I using the example with the integration
math.sin(x[0]+x[1]+x[2]+x[3])
I inserted an intermediate function: ( I checked that it can be evaluated outside of my_func(x))

def my_func(x):
yu = math.sin(x[0]+x[1]+x[2]+x[3])
integrand = P3_integrand_Eq2_c(x[0], x[1], x[2], x[3], wo, omegas, phase_type)
return yu

I get the following errors:

Process Process-2:
Traceback (most recent call last):
File "/home/ubuntu/anaconda3/lib/python3.6/multiprocessing/process.py", line 258, in _bootstrap
self.run()
File "/home/ubuntu/anaconda3/lib/python3.6/multiprocessing/process.py", line 93, in run
self._target(*self._args, **self._kwargs)
File "/home/ubuntu/anaconda3/lib/python3.6/site-packages/ZMCintegral/ZMCintegral.py", line 111, in multi_processing
result.append(self.MCkernel(domain, i_batch))
File "/home/ubuntu/anaconda3/lib/python3.6/site-packages/ZMCintegral/ZMCintegral.py", line 373, in MCkernel
integration_kernel[blockspergrid, threadsperblock](num_loops, MCresult, chunk_size, n_chunk_x, domain, domain_range, batch_size, i_batch, rng_states, n_chunk)
File "/home/ubuntu/anaconda3/lib/python3.6/site-packages/numba/cuda/compiler.py", line 765, in call
kernel = self.specialize(*args)
File "/home/ubuntu/anaconda3/lib/python3.6/site-packages/numba/cuda/compiler.py", line 776, in specialize
kernel = self.compile(argtypes)
File "/home/ubuntu/anaconda3/lib/python3.6/site-packages/numba/cuda/compiler.py", line 792, in compile
**self.targetoptions)
File "/home/ubuntu/anaconda3/lib/python3.6/site-packages/numba/compiler_lock.py", line 32, in _acquire_compile_lock
return func(*args, **kwargs)
File "/home/ubuntu/anaconda3/lib/python3.6/site-packages/numba/cuda/compiler.py", line 62, in compile_kernel
cres = compile_cuda(pyfunc, types.void, args, debug=debug, inline=inline)
File "/home/ubuntu/anaconda3/lib/python3.6/site-packages/numba/compiler_lock.py", line 32, in _acquire_compile_lock
return func(*args, **kwargs)
File "/home/ubuntu/anaconda3/lib/python3.6/site-packages/numba/cuda/compiler.py", line 51, in compile_cuda
locals={})
File "/home/ubuntu/anaconda3/lib/python3.6/site-packages/numba/compiler.py", line 941, in compile_extra
return pipeline.compile_extra(func)
File "/home/ubuntu/anaconda3/lib/python3.6/site-packages/numba/compiler.py", line 372, in compile_extra
return self._compile_bytecode()
File "/home/ubuntu/anaconda3/lib/python3.6/site-packages/numba/compiler.py", line 872, in _compile_bytecode
return self._compile_core()
File "/home/ubuntu/anaconda3/lib/python3.6/site-packages/numba/compiler.py", line 859, in _compile_core
res = pm.run(self.status)
File "/home/ubuntu/anaconda3/lib/python3.6/site-packages/numba/compiler_lock.py", line 32, in _acquire_compile_lock
return func(*args, **kwargs)
File "/home/ubuntu/anaconda3/lib/python3.6/site-packages/numba/compiler.py", line 253, in run
raise patched_exception
File "/home/ubuntu/anaconda3/lib/python3.6/site-packages/numba/compiler.py", line 244, in run
stage()
File "/home/ubuntu/anaconda3/lib/python3.6/site-packages/numba/compiler.py", line 500, in stage_nopython_frontend
self.locals)
File "/home/ubuntu/anaconda3/lib/python3.6/site-packages/numba/compiler.py", line 1044, in type_inference_stage
infer.propagate()
File "/home/ubuntu/anaconda3/lib/python3.6/site-packages/numba/typeinfer.py", line 861, in propagate
raise errors[0]
numba.errors.TypingError: Failed in nopython mode pipeline (step: nopython frontend)
Invalid use of Function(<numba.cuda.compiler.DeviceFunctionTemplate object at 0x7fd0ffc81a90>) with argument(s) of type(s): (array(float64, 1d, C))

  • parameterized
    In definition 0:
    TypingError: Failed in nopython mode pipeline (step: nopython frontend)
    Untyped global name 'P3_integrand_Eq2_c': cannot determine Numba type of <class 'builtin_function_or_method'>

File "script.py", line 130:
def my_func(x):

yu = math.sin(x[0]+x[1]+x[2]+x[3])
integrand = P3_integrand_Eq2_c(x[0], x[1], x[2], x[3], wo, omegas, phase_type)
^

raised from /home/ubuntu/anaconda3/lib/python3.6/site-packages/numba/typeinfer.py:1180

In definition 1:
TypingError: Failed in nopython mode pipeline (step: nopython frontend)
Untyped global name 'P3_integrand_Eq2_c': cannot determine Numba type of <class 'builtin_function_or_method'>

File "script.py", line 130:
def my_func(x):

yu = math.sin(x[0]+x[1]+x[2]+x[3])
integrand = P3_integrand_Eq2_c(x[0], x[1], x[2], x[3], wo, omegas, phase_type)
^

raised from /home/ubuntu/anaconda3/lib/python3.6/site-packages/numba/typeinfer.py:1180

This error is usually caused by passing an argument of a type that is unsupported by the named function.
[1] During: resolving callee type: Function(<numba.cuda.compiler.DeviceFunctionTemplate object at 0x7fd0ffc81a90>)
[2] During: typing of call at /home/ubuntu/anaconda3/lib/python3.6/site-packages/ZMCintegral/ZMCintegral.py (365)

File "../../anaconda3/lib/python3.6/site-packages/ZMCintegral/ZMCintegral.py", line 365:
def integration_kernel(num_loops, MCresult, chunk_size, n_chunk_x, domain, domain_range, batch_size, i_batch, rng_states, n_chunk):

# feed in values to user defined function
cuda.atomic.add(MCresult, thread_id, fun(x_tuple))
^

Traceback (most recent call last):
File "script.py", line 139, in
result = MC.evaluate()
File "/home/ubuntu/anaconda3/lib/python3.6/site-packages/ZMCintegral/ZMCintegral.py", line 74, in evaluate
MCresult = self.importance_sampling_iteration(self.initial_domain, 0)
File "/home/ubuntu/anaconda3/lib/python3.6/site-packages/ZMCintegral/ZMCintegral.py", line 80, in importance_sampling_iteration
MCresult_chunks, large_std_chunk_id, MCresult_std_chunks = self.MCevaluate(domain)
File "/home/ubuntu/anaconda3/lib/python3.6/site-packages/ZMCintegral/ZMCintegral.py", line 130, in MCevaluate
MCresult.append(np.load(os.getcwd()+'/multi_temp/result'+str(i_batch)+'.npy'))
File "/home/ubuntu/anaconda3/lib/python3.6/site-packages/numpy/lib/npyio.py", line 372, in load
fid = open(file, "rb")
FileNotFoundError: [Errno 2] No such file or directory: '/home/ubuntu/workspace/phase_step/multi_temp/result0.npy'

Linear Algebra in ZMCintegral

Is there a way to perform linear algebra routines with ZMCintegral?

It seems that it is not supported to use kernels in the device function, and CuPy/PyCulib does not seem to be usable in a device function either.

Any suggestions on performing matrix algebra within a device function?

Error When the function is too long

I have a very long expression that I want to integrate and i am getting the following error :

LLVM ERROR: out of memory
Traceback (most recent call last):
File "./Program.py", line 4382, in
result = MC.evaluate()
File "/home/.../ZMCintegral.py", line 82, in evaluate
MCresult = self.importance_sampling_iteration(self.initial_domain, 0)
File "/home/.../ZMCintegral.py", line 88, in importance_sampling_iteration
MCresult_chunks, large_std_chunk_id, MCresult_std_chunks = self.MCevaluate(domain)
File "/home/.../ZMCIntegral.py", line 140, in MCevaluate
MCresult.append(np.load(os.getcwd()+'/multi_temp/result'+str(i_batch)+'.npy'))
File "/home/.../miniconda3/envs/myenv/lib/python3.7/site-packages/numpy/lib/npyio.py", line 422, in load
fid = open(os_fspath(file), "rb")
FileNotFoundError: [Errno 2] No such file or directory: '/home/.../multi_temp/result0.npy'

Any suggestion on how to circumvent this problem ?

Setting constant parameters for a function

The code throws an error if the function takes more arguments than given in the domain, but setting the end and beginning of an interval in the domain causes the calculations to loop infinitely.

I suggest adding the ability to pass function arguments that are not integrated over.

In the meantime (or permanently), an error should be thrown if the two ends of a domain are equal.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.