Developer Start Guide¶
This document is outdated.
You want to contribute to Aesara? That is great! This page explain our workflow and some resource for doing so.
Looking for an idea for a first contribution? Check the GitHub issues.
We recommend creating an issue to discuss proposed changes before making them. This is a good way to make sure that proposed changes will be accepted.
See Community for a list of Aesara resources.
The Theano Google group is also relevant to (early) Aesara versions: theano-dev.
To get up to speed, you’ll need to
Requirements for Quality Contributions¶
- All code should be accompanied by quality unit tests.
- The code should be compatible with Python 3.6 and above.
- All the code should respect the PEP8 Code Style Guide.
- The docstrings of all the classes and functions should respect the PEP257 rules and follow the Numpy docstring standard.
Each point will be referred to more in detail in the following.
When you submit a pull request, your changes will automatically be tested via our continuous integration (CI).
Just because the tests run automatically does not mean you shouldn’t run them yourself to make sure everything is all right. You can run only the portion you are modifying to go faster and have CI make sure there are no broader problems.
To run the test suite with the default options, see How to test that Aesara works properly.
Setting up your Editor for PEP8¶
Detection of warnings and errors is done by the pep8 script (or flake8, that also checks for other things, like syntax errors). Syntax highlighting and general integration into Vim is done by the Syntastic plugin for Vim.
To setup VIM:
Install flake8 (if not already installed) with:
pip install flake8
Starting version 3.0.0, flake8 changed its dependencies and moved its Python API to a legacy module, breaking Aesara’s flake8 tests. We recommend using a version prior to 3.
You can use
flake8if you prefer. The important thing is that the
pep8executable ends up in your
Install vundle with:
git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim
~/.vimrcand add the lines:
set nocompatible " be iMproved, required filetype off " required " set the runtime path to include Vundle and initialize set rtp+=~/.vim/bundle/Vundle.vim call vundle#begin() Plugin 'gmarik/Vundle.vim' " let Vundle manage Vundle (required!) Plugin 'scrooloose/syntastic' Plugin 'jimf/vim-pep8-text-width' call vundle#end() " Syntastic settings " You can run checkers explicitly by calling :SyntasticCheck <checker let g:syntastic_python_checkers = ['flake8'] "use one of the following checkers: " flake8, pyflakes, pylint, python (native checker) let g:syntastic_enable_highlighting = 1 "highlight errors and warnings let g:syntastic_style_error_symbol = ">>" "error symbol let g:syntastic_warning_symbol = ">>" "warning symbol let g:syntastic_check_on_open = 1 let g:syntastic_auto_jump = 0 "do not jump to errors when detected
Open a new vim and run
:PluginInstallto automatically install the plugins. When the installation is done, close the installation “window” with
:q. From now on Vim will check for PEP8 errors and highlight them whenever a file is saved.
A few useful commands¶
- Open the list of errors:
:lopen, that can be abbreviated in
- Close that list:
- Next error:
- Previous error:
Once you fix errors, messages and highlighting will still appear in the fixed file until you save it again.
We can also configure the
~/.vimrc to make it easier to work with Syntastic.
For instance, to add a summary in the status bar, you can add:
To bind F2 and F3 to navigate to previous and next error, you can add:
map <F2> :lprevious<CR> map <F3> :lnext<CR>
You can prefix those by
autocmd FileType python if you want these
bindings to work only on Python files.
There is an excellent system to configure emacs for Python: emacs-for-python. It gathers many emacs config into one, and modifies them to behave together nicely. You can use it to check for pep8 compliance and for Python syntax errors.
To install it on Linux, you can do like this:
cd git clone https://github.com/gabrielelanaro/emacs-for-python.git ~/.emacs.d/emacs-for-python
Then in your
~/.emacs file, add this:
;; Mandatory (load-file "~/.emacs.d/emacs-for-python/epy-init.el") (add-to-list 'load-path "~/.emacs.d/emacs-for-python/") ;; tell where to load the various files ;; Each of them enables different parts of the system. ;; Only the first two are needed for pep8, syntax check. (require 'epy-setup) ;; It will setup other loads, it is required! (require 'epy-python) ;; If you want the python facilities [optional] (require 'epy-completion) ;; If you want the autocompletion settings [optional] (require 'epy-editing) ;; For configurations related to editing [optional] ;; [newer version of emacs-for-python] ;; Define f10 to previous error ;; Define f11 to next error (require 'epy-bindings) ;; For my suggested keybindings [optional] ;; Some shortcut that do not collide with gnome-terminal, ;; otherwise, "epy-bindings" define f10 and f11 for them. (global-set-key [f2] 'flymake-goto-prev-error) (global-set-key [f3] 'flymake-goto-next-error) ;; Next two lines are the checks to do. You can add more if you wish. (epy-setup-checker "pyflakes %f") ;; For python syntax check (epy-setup-checker "pep8 -r %f") ;; For pep8 check
The script highlights problematic lines. This can make part of the line not readable depending on the background. To replace the line highlight by an underline, add this to your emacs configuration file:
;; Make lines readable when there is an warning [optional] (custom-set-faces ‘(flymake-errline ((((class color)) (:underline “red”)))) ‘(flymake-warnline ((((class color)) (:underline “yellow”)))))
Documentation and docstrings¶
- The documentation and the API documentation are generated using Sphinx.
- The documentation should be written in reStructuredText and the docstrings of all the classes and functions should respect the PEP257 rules and follow the Numpy docstring standard.
- To cross-reference other objects (e.g. reference other classes or methods) in
the docstrings, use the
:pycan be omitted, see e.g. this stackoverflow answer.
- See Documentation Documentation AKA Meta-Documentation, for some information on how to generate the documentation.
A Docstring Example¶
Here is an example on how to add a docstring to a class.
import aesara from aesara.graph.op import Op class DoubleOp(Op): """ Double each element of a tensor. Parameters ---------- x : tensor Input tensor Returns ------- tensor a tensor of the same shape and dtype as the input with all values doubled. Notes ----- this is a test note See Also -------- :class:`~aesara.tensor.elemwise.Elemwise` : You can use this to replace this example. Just execute `x * 2` with x being an Aesara variable. .. versionadded:: 0.6 """
This is how it will show up for files that we auto-list in the library documentation:
Double each element of a tensor.
Parameters: x (tensor) – Input tensor Returns: a tensor of the same shape and dtype as the input with all values doubled. Return type: tensor
this is a test note
- You can use this to replace
New in version 0.6.
Construct a graph for the R-operator.
This method is primarily used by
[ f_1(inputs), ..., f_n(inputs) ].
- inputs – The
- eval_points – A
Variableor list of
Variables with the same length as inputs. Each element of
eval_pointsspecifies the value of the corresponding input at the point where the R-operator is to be evaluated.
Returns: Return type:
Rop(f=f_i(inputs), wrt=inputs, eval_points=eval_points).
- inputs – The
Construct a graph for the gradient with respect to each input variable.
Variablerepresents the gradient with respect to that input computed based on the symbolic gradients with respect to each output. If the output is not differentiable with respect to an input, then this method should return an instance of type
NullTypefor that input.
- inputs (list of Variable) – The input variables.
- output_grads (list of Variable) – The gradients of the output variables.
grads – The gradients with respect to each
list of Variable
Applynode that represent the application of this operation to the given inputs.
This must be implemented by sub-classes.
Returns: node – The constructed
Return type: Apply
perform(node, inputs, output_storage)¶
Calculate the function on the inputs and put the variables in the output storage.
- node (Apply) – The symbolic
Applynode that represents this computation.
- inputs (Sequence) – Immutable sequence of non-symbolic/numeric inputs. These
are the values of each
- output_storage (list of list) – List of mutable single-element lists (do not change the length of
these lists). Each sub-list corresponds to value of each
node.outputs. The primary purpose of this method is to set the values of these sub-lists.
- params (tuple) – A tuple containing the values of each entry in
output_storagelist might contain data. If an element of output_storage is not
None, it has to be of the right type, for instance, for a
TensorVariable, it has to be a NumPy
ndarraywith the right number of dimensions and the correct dtype. Its shape and stride pattern can be arbitrary. It is not guaranteed that such pre-set values were produced by a previous call to this
Op.perform(); they could’ve been allocated by another
Opis free to reuse
output_storageas it sees fit, or to discard it and allocate new memory.
- node (Apply) – The symbolic
Installation and configuration¶
This will create your own Aesara project on GitHub, referred later as “YourProfile/Aesara”, or “origin”, from which you will be able to contribute to the original Aesara/Aesara, also called “central”.
Create a local copy¶
Clone your fork locally with
git clone email@example.com:YOUR_GITHUB_LOGIN/Aesara.git
For this URL to work, you must set your public ssh keys inside your github account setting.
From your local repository, your own fork on GitHub will be called “origin”.
Then, add a reference to the original (“central”) Aesara repository with
git remote add central git://github.com/aesara-devs/aesara.git
You can choose another name than “central” to reference Aesara/Aesara (for instance, NumPy uses “upstream”), but this documentation will stick to “central.”
You can then test your installation of Aesara by following the steps of How to test that Aesara works properly.
Using your local copy¶
To update your library to the latest revision, you should have a local branch
origin/main. You can add one (named “trunk” here) with:
git fetch origin git branch trunk origin/main
Once you have such a branch, in order to update it, do:
git checkout trunk git pull
Keep in mind that this branch should be “read-only”: if you want to patch Aesara, you should work in another branch, like described in the Development Workflow section below.
On your local machine, you need to configure git with basic information:
git config --global user.email firstname.lastname@example.org git config --global user.name "Your Name Comes Here"
You can also instruct git to use color in diff. For this, you need to add those lines in the file ~/.gitconfig
[color] branch = auto diff = auto interactive = auto status = auto
Start a new local branch¶
When working on a new feature in your own fork, start from an up-to-date copy
main branch (the principal one) of the central repository
(Aesara/Aesara on GitHub):
git fetch origin git checkout -b my_shiny_feature origin/main
This last line is a shortcut for:
git branch my_shiny_feature origin/main git checkout my_shiny_feature
Submit your changes to the central repository¶
Once your code is ready for others to review, you need to commit all the changes and then push your branch to your GitHub fork first:
git commit -a -m "Your message here"
git push -u origin my_shiny_feature
Then, go to your fork’s GitHub page on the GitHub website, select your
feature branch and hit the “Pull Request” button in the top right
corner. This will signal the maintainers that you wish to submit your
changes for inclusion in
Address reviewer comments¶
Your pull request will be reviewed by members of the core development team. If your branch is not directly accepted, the reviewers will use GitHub’s system to add “notes”, either general (on the entire commit), or “line notes”, relative to a particular line of code. In order to have the pull request accepted, you may have to answer the reviewer’s questions, you can do that on GitHub.
You may also have to edit your code to address their concerns. Some of the usual requests include fixing typos in comments, adding or correcting comments, adding unit tests in the test suite. In order to do that, you should continue your edits in the same branch you used (in this example, “my_shiny_feature”). For instance, if you changed your working branch, you should first:
git checkout my_shiny_feature
Then, edit your code, and test it appropriately (see
Requirements for Quality Contributions below), and push it again to your GitHub
fork, like the first time (except the
-u option is only needed the
git push origin my_shiny_feature
The pull request to the central repository will then be automatically updated by GitHub. However, the reviewers will not be automatically notified of your revision, so it is advised to reply to the comments on GitHub, to let them know that you have submitted a fix.
More Advanced Git Usage¶
You can find information and tips in the numpy development page. Here are a few.
Cleaning up branches¶
When your pull request has been merged, you can delete the branch from your GitHub fork’s list of branches. This is useful to avoid having too many branches staying there. Deleting this remote branch is achieved with:
git push origin :my_shiny_feature
This lines pushes to the “origin” repository (your fork of Aesara on GitHub), into the branch “my_shiny_feature”, an empty content (that’s why there is nothing before the colon), effectively removing it.
The branch will still be present in your local clone of the repository. If you want to delete it from there, too, you can run:
git branch -d my_shiny_feature
Amending a submitted pull request¶
If you want to fix a commit already submitted within a pull request (e.g. to fix a small typo), before the pull request is accepted, you can do it like this to keep history clean:
git checkout my_shiny_feature git commit --amend git push origin my_shiny_feature:my_shiny_feature
Do not abuse that command, and please use it only when there are only small issues to be taken care of. Otherwise, it becomes difficult to match the comments made by reviewers with the new modifications. In the general case, you should stick with the approach described above.
Cleaning up history¶
Sometimes you may have commits in your feature branch that are not needed in the final pull request. There is a page that talks about this. In summary:
- Commits to the trunk should be a lot cleaner than commits to your feature branch; not just for ease of reviewing but also because intermediate commits can break blame (the bisecting tool).
git merge --squashwill put all of the commits from your feature branch into one commit.
- There are other tools that are useful if your branch is too big for one squash.
Add another distant repository¶
To collaborate with another user on some feature he is developing, and that is not ready for inclusion in central, the easiest way is to use a branch of their Aesara fork (usually on GitHub).
Just like we added Aesara/Aesara as a remote repository, named “central”, you can add (on your local machine) a reference to their fork as a new remote repository. REPO_NAME is the name you choose to name this fork, and GIT_REPO_PATH is the URL of the fork in question.
git remote add REPO_NAME GIT_REPO_PATH
Then, you can create a new local branch (LOCAL_BRANCH_NAME) based on a specific branch (REMOTE_BRANCH_NAME) from the remote repository (REPO_NAME):
git checkout -b LOCAL_BRANCH_NAME REPO_NAME/REMOTE_BRANCH_NAME
Other tools that can help you¶
- cProfile: time profiler that work at function level.
- Yep: A module for profiling compiled extensions.
- autopep8: A tool that automatically formats Python code to conform to the PEP 8 style guide.
- line_profiler: Line-by-line profiler.
- memory_profiler: memory profiler
- runsnake: Gui for cProfile(time profiler) and Meliae(memory profiler)
- Guppy: Supports object and heap memory sizing, profiling and debugging.
- hub: A tool that adds github commands to the git command line.
- git pull-requests: Another tool for git/github command line.