Skip to content

Commit

Permalink
Merge branch 'topic/default/maintain' into 'branch/default'
Browse files Browse the repository at this point in the history
PDM lock + update doc

See merge request fluiddyn/transonic!138
  • Loading branch information
paugier committed Jun 4, 2024
2 parents e4b32f2 + 897705d commit f5dc91a
Show file tree
Hide file tree
Showing 6 changed files with 3,297 additions and 4,780 deletions.
2 changes: 1 addition & 1 deletion .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ image: registry.heptapod.net:443/fluiddyn/transonic/ci/default:stable

pixi:test:
stage: pixi
image: registry.heptapod.net:443/fluiddyn/fluidsim/ci/default:pixi
image: registry.heptapod.net:443/fluiddyn/fluiddyn/ci/default:pixi
script:
- pixi info
- pixi run install-editable
Expand Down
3 changes: 3 additions & 0 deletions .mdformat.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
wrap = 89
number = true
end_of_line = "lf"
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ COV=pytest --cov --cov-config=pyproject.toml
develop:
pdm sync --clean

lock:
pdm lock -G :all

black:
black -l 82 src _transonic_testing data_tests tests

Expand Down
136 changes: 69 additions & 67 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,27 @@

**Documentation**: <https://transonic.readthedocs.io>

Transonic is a pure Python package (requiring Python >= 3.9) to easily
accelerate modern Python-Numpy code with different accelerators (currently
[Cython](https://cython.org/), [Pythran](https://github.com/serge-sans-paille/pythran) and [Numba](https://numba.pydata.org/), but potentially later [Cupy](https://cupy.chainer.org/), [PyTorch](https://pytorch.org/), [JAX](https://github.com/google/jax), [Weld](https://www.weld.rs/), [Pyccel](https://github.com/pyccel/pyccel), [Uarray](https://github.com/Quansight-Labs/uarray), 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](https://transonic.readthedocs.io/en/latest/roadmap.html)).
> Remarks and suggestions are very welcome.
Transonic is a pure Python package (requiring Python >= 3.9) 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](https://transonic.readthedocs.io/en/latest/roadmap.html)). Remarks and
> suggestions are very welcome.
>
> However, Transonic is now really usable, useful and used "in production" in
> [FluidSim](https://foss.heptapod.net/fluiddyn/fluidsim) and
> [FluidFFT](https://foss.heptapod.net/fluiddyn/fluidfft) (see examples for
> [blocks](https://foss.heptapod.net/fluiddyn/fluidsim/src/default/fluidsim/base/time_stepping/pseudo_spect.py) and
> [blocks](https://foss.heptapod.net/fluiddyn/fluidsim/src/default/fluidsim/base/time_stepping/pseudo_spect.py)
> and
> [@boost](https://foss.heptapod.net/fluiddyn/fluidfft/src/default/fluidfft/fft3d/operators.py)).
## The long-term project

> [!NOTE]
> The context of the creation of Transonic is presented in these documents:
> [!NOTE] The context of the creation of Transonic is presented in these documents:
>
> - [Transonic Vision](https://fluiddyn.netlify.app/transonic-vision.html)
> - [Make your numerical Python code fly at transonic speed (EuroScipy 2019)](http://www.legi.grenoble-inp.fr/people/Pierre.Augier/docs/ipynbslides/20190904-euroscipy-transonic/pres.slides.html#/),
Expand All @@ -45,63 +43,60 @@ 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).
- 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!
- 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.
- 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.
- 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 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.
- 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.
- 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.
- 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.
- 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).
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.
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](https://transonic.readthedocs.io/en/latest/backends/pythran.html). There are
also (more experimental) backends for Cython and Numba.
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](https://transonic.readthedocs.io/en/latest/backends/pythran.html).
There are also (more experimental) backends for Cython and Numba.

> [!NOTE]
> Transonic can be used in libraries and applications using MPI (as
> [!NOTE] Transonic can be used in libraries and applications using MPI (as
> [FluidSim](https://foss.heptapod.net/fluiddyn/fluidsim)).
## Installation and configuration
Expand All @@ -112,22 +107,29 @@ pip install transonic

Transonic is sensible to environment variables:

- `TRANSONIC_DIR` can be set to control where the cached files are
saved.
- `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_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.

[cupy]: https://cupy.chainer.org/
[cython]: https://cython.org/
[jax]: https://github.com/google/jax
[numba]: https://numba.pydata.org/
[pyccel]: https://github.com/pyccel/pyccel
[pythran]: https://github.com/serge-sans-paille/pythran
[pytorch]: https://pytorch.org/
[weld]: https://github.com/weld-project/weld
Loading

0 comments on commit f5dc91a

Please sign in to comment.