Skip to main content

Make your Python code fly at transonic speeds!

Project description

Make your Python code fly at transonic speeds!

Latest version Code coverage Documentation status Supported Python versions Heptapod CI Github Actions Linux Github Actions Windows mybinder sonarcloud

Documentation: https://transonic.readthedocs.io

Transonic is a pure Python package (requiring Python >= 3.11) to easily accelerate modern Python-Numpy code with different accelerators (currently Cython, Pythran, Numba and JAX, but potentially later Cupy, PyTorch, Weld, Pyccel, etc...).

The accelerators are not hard dependencies of Transonic: Python codes using Transonic run fine without any accelerators installed (of course without speedup)!

[!WARNING] Transonic is still in an active development stage (see our roadmap). Remarks and suggestions are very welcome.

However, Transonic is now really usable, useful and used "in production" in FluidSim and FluidFFT (see examples for blocks and @boost).

The long-term project

[!NOTE] The context of the creation of Transonic is presented in these documents:

Transonic targets Python end-users and library developers.

It is based on the following principles:

  • We'd like to write scientific / computing applications / libraries with pythonic, readable, modern code (Python >= 3.6).

  • In some cases, Python-Numpy is too slow. However, there are tools to accelerate such Python-Numpy code which lead to very good performances!

  • Let's try to write universal code which express what we want to compute and not the special hacks we want to use to make it fast. We just need nice ways to express that a function, a method or a block of code has to be accelerated (and how it has to be accelerated). We'd like to be able to do this in a pythonic way, with decorators and context managers.

  • There are many tools to accelerate Python-Numpy code! Let's avoid writting code specialized for only one of these tools.

  • Let's try to keep the code as it would be written without acceleration. For example, with Transonic, we are able to accelerate (simple) methods of classes even though some accelerators don't support classes.

  • Let's accelerate/compile only what needs to be accelerated, i.e. only the bottlenecks. Python and its interpreters are good for the rest. In most cases, the benefice of writting big compiled extensions (with Cython or in other languages) is negligible.

  • Adding types is sometimes necessary. In modern Python, we have nice syntaxes for type annotations! Let's use them.

  • Ahead-of-time (AOT) and just-in-time (JIT) compilation modes are both useful. We'd like to have a nice, simple and unified API for these two modes.

    • AOT is useful to be able to distribute compiled packages and in some cases, more optimizations can be applied.
    • JIT is simpler to use (no need for type annotations) and optimizations can be more hardware specific.

    Note that with Transonic, AOT compilers (Pythran and Cython) can be used as JIT compilers (with a cache mechanism).

To summarize, a strategy to quickly develop a very efficient scientific application/library with Python could be:

  1. Use modern Python coding, standard Numpy/Scipy for the computations and all the cool libraries you want.
  2. Profile your applications on real cases, detect the bottlenecks and apply standard optimizations with Numpy.
  3. Add few lines of Transonic to compile the hot spots.

What we have now

We start to have a good API to accelerate Python-Numpy code (functions, methods and blocks of code). The default Transonic backend uses Pythran and works well. Here, we explain why Pythran is so great for Python users and why Transonic is great for Pythran users. There are also (more experimental) backends for Cython and Numba.

[!NOTE] Transonic can be used in libraries and applications using MPI (as FluidSim).

Installation and configuration

pip install transonic

Transonic is sensible to environment variables:

  • TRANSONIC_DIR can be set to control where the cached files are saved.
  • TRANSONIC_DEBUG triggers a verbose mode.
  • TRANSONIC_COMPILE_AT_IMPORT can be set to enable a mode for which Transonic compiles at import time the Pythran file associated with the imported module. This behavior can also be triggered programmatically by using the function set_compile_at_import.
  • TRANSONIC_NO_REPLACE can be set to disable all code replacements. This is useful to compare execution times and when measuring code coverage.
  • TRANSONIC_COMPILE_JIT can be set to false to disable the compilation of jited functions. This can be useful for unittests.
  • TRANSONIC_BACKEND to choose between the supported backends. The default backend "pythran" is quite robust. There are now 3 other backends: "cython", "numba" and "python" (prototypes).
  • TRANSONIC_MPI_TIMEOUT sets the MPI timeout (default to 5 s).

License

Transonic is distributed under the BSD License.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

transonic-0.8.0.tar.gz (72.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

transonic-0.8.0-py3-none-any.whl (77.0 kB view details)

Uploaded Python 3

File details

Details for the file transonic-0.8.0.tar.gz.

File metadata

  • Download URL: transonic-0.8.0.tar.gz
  • Upload date:
  • Size: 72.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: pdm/2.25.9 CPython/3.11.13 Linux/6.16.9-clevercloud-vm-dirty

File hashes

Hashes for transonic-0.8.0.tar.gz
Algorithm Hash digest
SHA256 1204c297da5a6e1700efc04d007143477ef29eb7b6ec8049fb90dfd59490f64e
MD5 db48ef1d65966beb9381460883450f66
BLAKE2b-256 40619b6e9ef6ec0e55b7e996553c529cddb78e5c8d5b94c9edb5130f60b0dbf9

See more details on using hashes here.

File details

Details for the file transonic-0.8.0-py3-none-any.whl.

File metadata

  • Download URL: transonic-0.8.0-py3-none-any.whl
  • Upload date:
  • Size: 77.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: pdm/2.25.9 CPython/3.11.13 Linux/6.16.9-clevercloud-vm-dirty

File hashes

Hashes for transonic-0.8.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0c40b8c4c34497875638fa80b944e48752a909502d6678dcff580e8446a1e1a8
MD5 1e9e7f7096cd495794854c810644a187
BLAKE2b-256 8da9741b5cb0d008877c2c52c2b057dbd190bd0cc281bf5440724e2d6ea6bf88

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page