Skip to content

Commit

Permalink
add docs about numpy example
Browse files Browse the repository at this point in the history
  • Loading branch information
scarlehoff committed Sep 2, 2020
1 parent db9e936 commit d1139fb
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
29 changes: 29 additions & 0 deletions doc/source/examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,35 @@ integrand.
You can find a `runnable example of such a basic example in the repository <https://github.com/N3PDF/vegasflow/blob/master/examples/simgauss_tf.py>`_.


Integrating a numpy function
============================

``VegasFlow`` admits also the integration of non-tensorflow python-based integrands.
In this case, however, it is necessary to activate ``eager-mode``, see :ref:`eager-label`.

.. code-block:: python
import numpy as np
import tensorflow as tf
tf.config.run_functions_eagerly(True)
def my_integrand(xarr, **kwargs):
return np.sum(xarr)
from VegasFlow.vflow import vegas_wrapper
n_dim = 10
n_events = int(1e6)
n_iter = 5
result = vegas_wrapper(my_integrand, n_dim, n_iter, n_events)
Note, however, that in this case the integrand will always be run on CPU, while the internal steps of the integration will be run on GPU by ``VegasFlow``.
In order to run the integration exclusively on GPU the environment variable ``CUDA_VISIBLE_DEVICES`` should be set to ``''``:

.. code-block:: bash
export CUDA_VISIBLE_DEVICES=""
Interfacing C code: CFFI
========================

Expand Down
1 change: 1 addition & 0 deletions doc/source/how_to.rst
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ If you have a set-up with more than one GPU you can select which one you will
want to use for the integration by setting the environment variable to the
right device, e.g., ``export CUDA_VISIBLE_DEVICES=0``.

.. _eager-label:

Eager Vs Graph-mode
-------------------
Expand Down

0 comments on commit d1139fb

Please sign in to comment.