|
| 1 | +<div align="center"> |
| 2 | + |
| 3 | +<img src="./doc/images/aesara_logo_2400.png" alt="logo"></img> |
| 4 | + |
| 5 | +[![Pypi][pypi-badge]][pypi] |
| 6 | +[![Downloads][downloads-badge]][releases] |
| 7 | +[![Contributors][contributors-badge]][contributors] |
| 8 | + </br> |
| 9 | +[![Gitter][gitter-badge]][gitter] |
| 10 | +[![Discord][discord-badge]][discord] |
| 11 | +[![Twitter][twitter-badge]][twitter] |
| 12 | + |
| 13 | +Aesara is a Python library that allows one to define, optimize, and |
| 14 | +efficiently evaluate mathematical expressions involving multi-dimensional |
| 15 | +arrays. |
| 16 | + |
| 17 | +[Features](#features) • |
| 18 | +[Get Started](#get-started) • |
| 19 | +[Installation](#installation) • |
| 20 | +[Get help](#get-help) • |
| 21 | +[Contribute](#contribute) |
| 22 | + |
| 23 | +</div> |
| 24 | + |
| 25 | +## Features |
| 26 | + |
| 27 | +- A hackable, pure-Python codebase |
| 28 | +- Extensible graph framework suitable for rapid development of custom operators and symbolic optimizations |
| 29 | +- Implements an extensible graph transpilation framework that currently provides |
| 30 | + compilation via C, [JAX](https://github.com/google/jax), and [Numba](https://github.com/numba/numba). |
| 31 | +- Based on one of the most widely-used Python tensor libraries: [Theano](https://github.com/Theano/Theano). |
| 32 | + |
| 33 | +## Get started |
| 34 | + |
| 35 | +``` python |
| 36 | +import aesara |
| 37 | +from aesara import tensor as at |
| 38 | + |
| 39 | +# Declare two symbolic floating-point scalars |
| 40 | +a = at.dscalar("a") |
| 41 | +b = at.dscalar("b") |
| 42 | + |
| 43 | +# Create a simple example expression |
| 44 | +c = a + b |
| 45 | + |
| 46 | +# Convert the expression into a callable object that takes `(a, b)` |
| 47 | +# values as input and computes the value of `c`. |
| 48 | +f_c = aesara.function([a, b], c) |
| 49 | + |
| 50 | +assert f_c(1.5, 2.5) == 4.0 |
| 51 | + |
| 52 | +# Compute the gradient of the example expression with respect to `a` |
| 53 | +dc = aesara.grad(c, a) |
| 54 | + |
| 55 | +f_dc = aesara.function([a, b], dc) |
| 56 | + |
| 57 | +assert f_dc(1.5, 2.5) == 1.0 |
| 58 | + |
| 59 | +# Compiling functions with `aesara.function` also optimizes |
| 60 | +# expression graphs by removing unnecessary operations and |
| 61 | +# replacing computations with more efficient ones. |
| 62 | + |
| 63 | +v = at.vector("v") |
| 64 | +M = at.matrix("M") |
| 65 | + |
| 66 | +d = a/a + (M + a).dot(v) |
| 67 | + |
| 68 | +aesara.dprint(d) |
| 69 | +# Elemwise{add,no_inplace} [id A] '' |
| 70 | +# |InplaceDimShuffle{x} [id B] '' |
| 71 | +# | |Elemwise{true_div,no_inplace} [id C] '' |
| 72 | +# | |a [id D] |
| 73 | +# | |a [id D] |
| 74 | +# |dot [id E] '' |
| 75 | +# |Elemwise{add,no_inplace} [id F] '' |
| 76 | +# | |M [id G] |
| 77 | +# | |InplaceDimShuffle{x,x} [id H] '' |
| 78 | +# | |a [id D] |
| 79 | +# |v [id I] |
| 80 | + |
| 81 | +f_d = aesara.function([a, v, M], d) |
| 82 | + |
| 83 | +# `a/a` -> `1` and the dot product is replaced with a BLAS function |
| 84 | +# (i.e. CGemv) |
| 85 | +aesara.dprint(f_d) |
| 86 | +# Elemwise{Add}[(0, 1)] [id A] '' 5 |
| 87 | +# |TensorConstant{(1,) of 1.0} [id B] |
| 88 | +# |CGemv{inplace} [id C] '' 4 |
| 89 | +# |AllocEmpty{dtype='float64'} [id D] '' 3 |
| 90 | +# | |Shape_i{0} [id E] '' 2 |
| 91 | +# | |M [id F] |
| 92 | +# |TensorConstant{1.0} [id G] |
| 93 | +# |Elemwise{add,no_inplace} [id H] '' 1 |
| 94 | +# | |M [id F] |
| 95 | +# | |InplaceDimShuffle{x,x} [id I] '' 0 |
| 96 | +# | |a [id J] |
| 97 | +# |v [id K] |
| 98 | +# |TensorConstant{0.0} [id L] |
| 99 | + |
| 100 | +``` |
| 101 | + |
| 102 | +See [the Aesara documentation][documentation] for in-depth tutorials. |
| 103 | + |
| 104 | +## Installation |
| 105 | + |
| 106 | +The latest release of Aesara can be installed from PyPI using ``pip``: |
| 107 | + |
| 108 | +``` python |
| 109 | +pip install aesara |
| 110 | +``` |
| 111 | + |
| 112 | +Or via conda-forge: |
| 113 | + |
| 114 | +``` python |
| 115 | +conda install -c conda-forge aesara |
| 116 | +``` |
| 117 | + |
| 118 | + |
| 119 | +The current development branch of Aesara can be installed from GitHub, also using ``pip``: |
| 120 | + |
| 121 | +``` python |
| 122 | +pip install git+https://github.com/aesara-devs/aesara |
| 123 | +``` |
| 124 | + |
| 125 | + |
| 126 | +## Get help |
| 127 | + |
| 128 | +Report bugs by opening an [issue][issues]. If you have a question regarding the usage of Aesara, start a [discussion][discussions]. For real-time feedback or more general chat about Aesara use our [Discord server][discord], or [Gitter][gitter]. |
| 129 | + |
| 130 | +## Contribute |
| 131 | + |
| 132 | +We welcome bug reports and fixes and improvements to the documentation. |
| 133 | + |
| 134 | +For more information on contributing, please see the |
| 135 | +[contributing guide](https://github.com/aesara-devs/aesara/blob/main/CONTRIBUTING.md) |
| 136 | +and the Aesara [Mission Statement](https://github.com/aesara-devs/aesara/mission.rst). |
| 137 | + |
| 138 | +A good place to start contributing is by looking through [the issues][issues]. |
| 139 | + |
| 140 | +## Support |
| 141 | + |
| 142 | +Special thanks to [Bram Timmer](http://beside.ca) for the logo. |
| 143 | + |
| 144 | +[contributors]: https://github.com/aesara-devs/aesara/graphs/contributors |
| 145 | +[contributors-badge]: https://img.shields.io/github/contributors/aesara-devs/aesara?style=flat-square&logo=github&logoColor=white&color=ECEFF4 |
| 146 | +[discussions]: https://github.com/aesara-devs/aesara/discussions |
| 147 | +[documentation]: https://aesara.readthedocs.io/en/latest |
| 148 | +[downloads-badge]: https://img.shields.io/pypi/dm/aesara?style=flat-square&logo=pypi&logoColor=white&color=8FBCBB |
| 149 | +[discord]: https://discord.gg/h3sjmPYuGJ |
| 150 | +[discord-badge]: https://img.shields.io/discord/1072170173785723041?color=81A1C1&logo=discord&logoColor=white&style=flat-square |
| 151 | +[gitter]: https://gitter.im/aesara-devs/aesara |
| 152 | +[gitter-badge]: https://img.shields.io/gitter/room/aesara-devs/aesara?color=81A1C1&logo=matrix&logoColor=white&style=flat-square |
| 153 | +[issues]: https://github.com/aesara-devs/aesara/issues |
| 154 | +[releases]: https://github.com/aesara-devs/aesara/releases |
| 155 | +[twitter]: https://twitter.com/AesaraDevs |
| 156 | +[twitter-badge]: https://img.shields.io/twitter/follow/AesaraDevs?style=social |
| 157 | +[pypi]: https://pypi.org/project/aesara/ |
| 158 | +[pypi-badge]: https://img.shields.io/pypi/v/aesara?color=ECEFF4&logo=python&logoColor=white&style=flat-square |
0 commit comments