pyccel package#

Subpackages#

Submodules#

Module contents#

Pyccel : write Python code, get Fortran speed

Find documentation at pyccel.github.io/pyccel/

pyccel.epyccel(function_class_or_module, *, language='fortran', compiler_family=None, compiler_config=None, flags=None, wrapper_flags=None, debug=None, include=(), libdir=(), libs=(), folder=None, mpi=False, openmp=False, verbose=0, time_execution=False, developer_mode=False, conda_warnings='basic', context_dict=None, comm=None, root=0, bcast=True)[source]View on GitHub#

Accelerate Python function or module using Pyccel in “embedded” mode.

This function accelerates a Python function or module using Pyccel in “embedded” mode. It generates optimized code in the specified language (default is ‘fortran’) and compiles it for improved performance. Please be aware that only one of the parameters compiler_family and compiler_config may be provided.

Parameters:
  • function_class_or_module (function | class | module | str) – Python function, class, or module to be accelerated. If a string is passed then it is assumed to be the code from a module which should be accelerated. The module must be capable of running as a standalone file so it must include any necessary import statements.

  • language ({'fortran', 'c', 'python'}) – Language of generated code (default: ‘fortran’).

  • compiler_family ({'GNU', 'intel', 'PGI', 'nvidia', 'LLVM'}, optional) – Compiler family for which Pyccel uses a default configuration (default: ‘GNU’).

  • compiler_config (pathlib.Path | str, optional) – Path to a JSON file containing a compiler configuration (overrides compiler_family).

  • flags (iterable of str, optional) – Compiler flags.

  • wrapper_flags (iterable of str, optional) – Compiler flags for the wrapper.

  • debug (bool, optional) – Indicates whether the file should be compiled in debug mode. The default value is taken from the environment variable PYCCEL_DEBUG_MODE. If no such environment variable exists then the default is False.

  • include (tuple, optional) – Additional include directories for the compiler.

  • libdir (tuple, optional) – Additional library directories for the compiler.

  • libs (tuple, optional) – Additional libraries to link with.

  • folder (str, optional) – Output folder for the compiled code.

  • mpi (bool, default=False) – If True, use MPI for parallel execution.

  • openmp (bool, default=False) – If True, use OpenMP for parallel execution.

  • verbose (int, default=0) – Set the level of verbosity to see additional information about the Pyccel process.

  • time_execution (bool) – Time the execution of Pyccel’s internal stages.

  • developer_mode (bool, default=False) – If True, set error mode to developer.

  • conda_warnings ({'off', 'basic', 'verbose'}) – Specify the level of Conda warnings to display (default: ‘basic’).

  • context_dict (dict[str, Any], optional) – A dictionary containing any Python objects from the calling scope which should be made available to the translated code. By default any objects that are used in the body of the function are made available, as well as any global objects. If the argument is provided then these objects will be treated as additional to the default arguments.

  • comm (mpi4py.MPI.Comm, optional) – MPI communicator for calling Pyccel in parallel mode (default: None) (for parallel mode).

  • root (int, optional) – MPI rank of process in charge of accelerating code (default: 0) (for parallel mode).

  • bcast ({True, False}) – If False, only root process loads accelerated function/module (default: True) (for parallel mode).

Returns:

Accelerated function, class or module.

Return type:

function | class | module

See also

epyccel_seq

The version of this function called in a sequential context.

Examples

>>> def one(): return 1
>>> from pyccel import epyccel
>>> one_f = epyccel(one, language='fortran')
>>> one_c = epyccel(one, language='c')
pyccel.lambdify(expr: Expr, args: dict[Symbol, str], *, result_type: str | None = None, use_out=False, **kwargs)[source]View on GitHub#

Convert a SymPy expression into a Pyccel-accelerated function.

Convert a SymPy expression into a function that allows for fast numeric evaluation. This is done using SymPy’s NumPyPrinter to generate code that can be accelerated by Pyccel.

Parameters:
  • expr (sp.Expr) – The SymPy expression that should be returned from the function.

  • args (dict[sp.Symbol, str]) – A dictionary of the arguments of the function being created. The keys are variables representing the arguments that will be passed to the function. The values are the the type annotations for those functions. To use more complex objects (e.g. TypeVars) please use the epyccel keyword argument context_dicts.

  • result_type (str, optional) – The type annotation for the result of the function. This argument is optional but it is recommended to provide it as SymPy expressions do not always evaluate to the expected type. For example if the SymPy expression simplifies to 0 then the default type will be int even if the arguments are floats.

  • use_out (bool, default=False) – If true the function will modify an argument called ‘out’ instead of returning a newly allocated array. If this argument is set then result_type must be provided. This only works if the result is an array type.

  • **kwargs (dict) – Additional arguments that are passed to epyccel.

Returns:

A Pyccel-accelerated function which allows the evaluation of the SymPy expression.

Return type:

func

See also

sympy.lambdify

<https://docs.sympy.org/latest/modules/utilities/lambdify.html>.

epyccel

The function that accelerates the generated code.