Read about our upcoming Code of Conduct on this issue

Commit fed08da4 authored by Pierre Augier's avatar Pierre Augier
Browse files

FLUIDPYTHRAN_NO_REPLACE

parent 18183b1652a7
......@@ -23,8 +23,8 @@ FluidPythran: easily speedup your Python code with Pythran
very welcome.
However, FluidPythran is now really usable and used "in production" in
`FluidSim <https://bitbucket.org/fluiddyn/fluidsim>`_ (see examples for
`blocks
`FluidSim <https://bitbucket.org/fluiddyn/fluidsim>`_ and `FluidFFT
<https://bitbucket.org/fluiddyn/fluidfft>`_ (see examples for `blocks
<https://bitbucket.org/fluiddyn/fluidsim/src/default/fluidsim/base/time_stepping/pseudo_spect.py>`_,
`@boost
<https://bitbucket.org/fluiddyn/fluidsim/src/default/fluidsim/operators/operators3d.py>`_
......@@ -134,15 +134,30 @@ that the developers can still read the Pythran files if needed.
`FluidSim <https://bitbucket.org/fluiddyn/fluidsim>`_).
Installation
------------
Installation and configuration
------------------------------
.. code ::
pip install fluidpythran
The environment variable :code:`FLUIDPYTHRAN_DIR` can be set to control where
the cached files are saved.
.. _pythranize-at-import :
FluidPythran is sensible to environment variables:
- :code:`FLUIDPYTHRAN_DIR` can be set to control where the cached files are
saved.
- :code:`PYTHRANIZE_AT_IMPORT` can be set to enable a mode for which
FluidPythran compiles at import time the Pythran file associated with the
imported module. This behavior can also be triggered programmatically by using
the function :code:`set_pythranize_at_import`.
- :code:`FLUIDPYTHRAN_NO_REPLACE` can be set to disable all code replacements.
This is useful only when measuring code coverage.
- :code:`FLUID_COMPILE_CACHEDJIT` can be set to false to disable the
compilation of cachedjited functions. This can be useful for unittests.
A short tour of FluidPythran syntaxes
......@@ -366,13 +381,6 @@ how it is done in the example package `example_package_fluidpythran
`fluidsim's setup.py
<https://bitbucket.org/fluiddyn/fluidsim/src/default/setup.py>`_).
.. _pythranize-at-import :
If the environment variable :code:`PYTHRANIZE_AT_IMPORT` is set, FluidPythran
compiles at import time (i.e. only when needed) the Pythran file associated
with the imported module. This behavior can also be triggered programmatically
by using the function :code:`set_pythranize_at_import`.
License
-------
......
......@@ -34,6 +34,7 @@ of the modules, classes and functions.
fluidpythran.run
fluidpythran.log
fluidpythran.util
fluidpythran.config
More
----
......
......@@ -59,6 +59,7 @@ from .transpiler import produce_code_class
from .log import logger
from . import mpi
from .mpi import Path
from .config import has_to_replace
if mpi.nb_proc == 1:
mpi.has_to_build = has_to_build
......@@ -197,7 +198,7 @@ class FluidPythran:
Parameters
----------
use_pythran : bool (optional, default True)
use_fluidpythranized : bool (optional, default True)
If False, don't use the pythranized versions at run time
......@@ -211,7 +212,7 @@ class FluidPythran:
"""
def __init__(self, use_pythran=True, frame=None, reuse=True):
def __init__(self, use_fluidpythranized=True, frame=None, reuse=True):
if frame is None:
frame = inspect.stack()[1]
......@@ -239,7 +240,7 @@ class FluidPythran:
self.is_transpiled = False
return
if not use_pythran:
if not use_fluidpythranized or not has_to_replace:
self.is_transpiled = False
return
......@@ -383,7 +384,7 @@ class FluidPythran:
self.functions[func.__name__] = func
return func
if not self.is_transpiled:
if not has_to_replace or not self.is_transpiled:
return func
if not hasattr(self.module_pythran, func.__name__):
......@@ -413,7 +414,7 @@ class FluidPythran:
func.__fluidpythran__ = "pythran_def_method"
return func
if not self.is_transpiled:
if not has_to_replace or not self.is_transpiled:
return func
return FluidPythranTemporaryMethod(func)
......@@ -450,7 +451,7 @@ class FluidPythran:
if jit_methods:
cls = cachedjit_class(cls, jit_methods)
if not self.is_transpiled:
if not has_to_replace or not self.is_transpiled:
return cls
cls_name = cls.__name__
......@@ -649,6 +650,9 @@ def cachedjit_class(cls, jit_methods):
3. replace the methods
"""
if not has_to_replace:
return cls
cls_name = cls.__name__
mod_name = cls.__module__
......
"""Configuration
================
FluidPythran is sensible to the environment variables:
- :code:`FLUIDPYTHRAN_DIR` can be set to control where the cached files are
saved.
- :code:`PYTHRANIZE_AT_IMPORT` can be set to enable a mode for which
FluidPythran compiles at import time the Pythran file associated with the
imported module. This behavior can also be triggered programmatically by using
the function :code:`set_pythranize_at_import`.
- :code:`FLUIDPYTHRAN_NO_REPLACE` can be set to disable all code replacements.
This is useful only when measuring code coverage.
- :code:`FLUID_COMPILE_CACHEDJIT` can be set to false to disable the
compilation of cachedjited functions. This can be useful for unittests.
Bye the way, for performance, it is important to configure Pythran with a file
`~/.pythranrc
<https://pythran.readthedocs.io/en/latest/MANUAL.html#customizing-your-pythranrc>`_:
For Linux, I use:
.. code::
[pythran]
complex_hook = True
[compiler]
CXX=clang++-6.0
CC=clang-6.0
blas=openblas
"""
import os
from pathlib import Path
from distutils.util import strtobool
path_root = Path(
os.environ.get("FLUIDPYTHRAN_DIR", Path.home() / ".fluidpythran")
)
has_to_replace = not strtobool(os.environ.get("FLUIDPYTHRAN_NO_REPLACE", "0"))
\ No newline at end of file
......@@ -88,6 +88,7 @@ from .aheadoftime import FluidPythranTemporaryJITMethod
from .compat import open
from . import mpi
from .log import logger
from .config import has_to_replace
modules = {}
......@@ -257,7 +258,7 @@ class CachedJIT:
func, self.native, self.xsimd, self.openmp
)
if not pythran:
if not pythran or not has_to_replace:
return func
func_name = func.__name__
......
......@@ -28,4 +28,4 @@ def test_not_fluidpythranized():
def test_use_pythran_false():
FluidPythran(use_pythran=False)
FluidPythran(use_fluidpythranized=False)
......@@ -502,7 +502,7 @@ imports: {imports}\n"""
if "# FLUIDPYTHRAN_NO_IMPORT" not in code:
logger.warning(
"module_name not in fluidpythran.aheadoftime.modules\n"
f"module_name = {module_name}"
f"module_name = {module_name}\n"
f"path_py = {path_py}"
)
......
......@@ -77,12 +77,10 @@ from .pythranizer import (
has_to_build,
)
__all__ = ["modification_date", "has_to_build"]
from .config import path_root
__all__ = ["modification_date", "has_to_build"]
path_root = Path(
os.environ.get("FLUIDPYTHRAN_DIR", Path.home() / ".fluidpythran")
)
path_cachedjit_classes = path_root / "__cachedjit_classes__"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment