From d1139fb81435de5d74c05b7fea62d032a58f3d93 Mon Sep 17 00:00:00 2001 From: juacrumar Date: Wed, 2 Sep 2020 11:12:18 +0200 Subject: [PATCH] add docs about numpy example --- doc/source/examples.rst | 29 +++++++++++++++++++++++++++++ doc/source/how_to.rst | 1 + 2 files changed, 30 insertions(+) diff --git a/doc/source/examples.rst b/doc/source/examples.rst index 7a829a3..caeef45 100644 --- a/doc/source/examples.rst +++ b/doc/source/examples.rst @@ -41,6 +41,35 @@ integrand. You can find a `runnable example of such a basic example in the repository `_. +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 ======================== diff --git a/doc/source/how_to.rst b/doc/source/how_to.rst index b70c66f..2b8851f 100644 --- a/doc/source/how_to.rst +++ b/doc/source/how_to.rst @@ -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 -------------------