|
1 | | -# Contributing |
| 1 | +# Contributing to TensorFlow Quantum |
2 | 2 |
|
3 | | -## Contributor License Agreements |
| 3 | +Thank you for your interest in contributing to this project! We look forward to |
| 4 | +working with you. Here are some guidelines to get you started. |
4 | 5 |
|
5 | | -We'd love to accept your patches! Before we can take them, we have to jump a |
6 | | -couple of legal hurdles. |
| 6 | +## Before you begin |
7 | 7 |
|
8 | | -Please fill out either the individual or corporate Contributor License Agreement |
9 | | -(CLA). |
| 8 | +### Summary |
10 | 9 |
|
11 | | -* If you are an individual writing original source code and you're sure you |
12 | | - own the intellectual property, then you'll need to sign an |
13 | | - [individual CLA](http://code.google.com/legal/individual-cla-v1.0.html). |
14 | | -* If you work for a company that wants to allow you to contribute your work, |
15 | | - then you'll need to sign a |
16 | | - [corporate CLA](http://code.google.com/legal/corporate-cla-v1.0.html). |
| 10 | +* Read and sign the [Contributor License Agreement] |
| 11 | +* Read the [code of conduct]. |
| 12 | +* Follow the [development process]. |
17 | 13 |
|
18 | | -Follow either of the two links above to access the appropriate CLA and |
19 | | -instructions for how to sign and return it. Once we receive it, we'll be able to |
20 | | -accept your pull requests. |
| 14 | +[Contributor License Agreement]: https://cla.developers.google.com/ |
| 15 | +[code of conduct]: CODE_OF_CONDUCT.md |
| 16 | +[development process]: #development-process |
21 | 17 |
|
22 | | -NOTE: Only original source code from you and other people that have signed the |
23 | | -CLA can be accepted into the main repository. |
| 18 | +### Sign our Contributor License Agreement |
24 | 19 |
|
25 | | -## Code Reviews |
| 20 | +Contributions to this project must be accompanied by a [Contributor License |
| 21 | +Agreement] (CLA). You or your employer retain the copyright to your |
| 22 | +contribution; the CLA simply gives us permission to use and redistribute your |
| 23 | +contributions as part of the project. If you or your current employer have |
| 24 | +already signed the Google CLA (even if it was for a different project), you |
| 25 | +probably don't need to do it again. Visit <https://cla.developers.google.com/> |
| 26 | +to see your current agreements or to sign a new one. |
26 | 27 |
|
27 | | -All submissions, including submissions by project members, require review. We |
28 | | -use GitHub pull requests for this purpose. Consult |
29 | | -[GitHub Help](https://help.github.com/articles/about-pull-requests/) for more |
30 | | -information on using pull requests and the |
31 | | -[TensorFlow Community Guidelines](https://www.tensorflow.org/community/contribute) |
32 | | -for more information on contributor best practices. |
| 28 | +Only original work from you and other people who have signed the CLA can be |
| 29 | +incorporated into the project. By signing the Contributor License Agreement, you |
| 30 | +agree that your contributions are an original work of authorship. |
33 | 31 |
|
34 | | -Before making any changes, we recommend opening an issue (if it doesn't already |
35 | | -exist) and discussing your proposed changes. This will let us give you advice |
36 | | -on the proposed changes. If the changes are minor, then feel free to make |
37 | | -them without discussion. |
| 32 | +### Review our community guidelines |
38 | 33 |
|
39 | | -## Code Standards |
| 34 | +In the interest of fostering an open and welcoming environment, contributors and |
| 35 | +maintainers pledge to make participation in our project and our community a |
| 36 | +harassment-free experience for everyone. Our community aspires to treat everyone |
| 37 | +equally, and to value all contributions. Please review our [code of conduct] for |
| 38 | +more information. |
40 | 39 |
|
41 | | -We have some standards in place to ensure that incoming code is the highest |
42 | | -quality it can be. Before a code review can happen you should make sure that |
43 | | -the following tests are passing locally: |
| 40 | +## Code base conventions |
44 | 41 |
|
45 | | -1. `./scripts/test_all.sh` passes. We use TensorFlow's testing suite for our |
46 | | -testing and be sure that any code you add follows the structure they have |
47 | | -[outlined](https://www.tensorflow.org/api_docs/python/tf/test). |
| 42 | +TensorFlow Quantum (TFQ) is a Python framework for quantum machine learning |
| 43 | +(QML) implemented as an add-on to [TensorFlow]. Documentation for TFQ is |
| 44 | +available on the [TensorFlow Quantum documentation site]. The TFQ project |
| 45 | +generally follows TensorFlow development practices, and the [TensorFlow |
| 46 | +contribution guide] is essential reading if you want to get involved with TFQ. |
48 | 47 |
|
49 | | -2. `./scripts/lint_all.sh` passes. We use [pylint](https://www.pylint.org/) |
50 | | -to ensure that code has proper formatting and is lint free. |
| 48 | +[TensorFlow]: https://tensorflow.org |
| 49 | +[TensorFlow Quantum documentation site]: https://tensorflow.org/quantum |
| 50 | +[TensorFlow contribution guide]: https://www.tensorflow.org/community/contribute |
51 | 51 |
|
52 | | -3. `./scripts/format_check.sh` passes. We use |
53 | | -[yapf](https://github.com/google/yapf) along with |
54 | | -[clang format](https://clang.llvm.org/docs/ClangFormat.html) to ensure we have |
55 | | -consistent formatting everywhere. |
| 52 | +### Getting oriented |
56 | 53 |
|
57 | | -### Adding Modules |
| 54 | +Here is a summary of the main subdirectories in the TFQ source tree: |
58 | 55 |
|
59 | | -If you are adding new modules, be sure to properly expose them to the user |
60 | | -using `__init__.py` files and update the `/scripts/import_test.py` file |
61 | | -to ensure that you are exposing them properly. |
| 56 | +* `benchmarks/`: Code for performance benchmarking |
| 57 | +* `docs/`: Documentation source files |
| 58 | +* `release/`: Scripts and configurations for building TFQ releases |
| 59 | +* `scripts/`: Utilities for running tests and doing other tasks |
| 60 | +* `tensorflow_quantum/`: The core source code for TensorFlow Quantum |
| 61 | +* `third_party/`: External dependencies and third-party integrations |
| 62 | +* `.github/`: GitHub-specific configurations and workflows |
62 | 63 |
|
| 64 | +Some of the important files found at the top level include the following: |
| 65 | + |
| 66 | +* `README.md`: General introduction to the project |
| 67 | +* `configure.sh`: TFQ build configuration script |
| 68 | +* `requirements.txt`: Python dependencies |
| 69 | + |
| 70 | +### Coding style |
| 71 | + |
| 72 | +This project follows the [TensorFlow style], which in turn follows these Google |
| 73 | +style guides: |
| 74 | + |
| 75 | +* [C++ Style Guide](https://google.github.io/styleguide/cppguide.html) |
| 76 | +* [Python Style Guide](https://google.github.io/styleguide/pyguide.html) |
| 77 | +* [Markdown Style Guide](https://google.github.io/styleguide/docguide/style.html) |
| 78 | +* [Shell Style Guide](https://google.github.io/styleguide/shellguide.html) |
| 79 | + |
| 80 | +Software tool configurations can be found in the following files at the top |
| 81 | +level of the source tree: |
| 82 | + |
| 83 | +* `.clang-format`: formatting C++ files using [clang-format] |
| 84 | +* `.editorconfig`: basic code editor configuration |
| 85 | +* `.pylintrc`: linting Python files using [Pylint] |
| 86 | +* `.style.yapf`: formatting Python files using [YAPF] |
| 87 | +* `.yamllint.yaml`: linting YAML files using [yamllint] |
| 88 | + |
| 89 | +All source code files longer than a few lines must begin with a header comment |
| 90 | +with the copyright and license. We use the [Apache 2.0 license](./LICENSE). |
| 91 | + |
| 92 | +[clang-format]: https://releases.llvm.org/18.1.6/tools/clang/docs/ClangFormat.html |
| 93 | +[Pylint]: https://www.pylint.org |
| 94 | +[TensorFlow style]: https://www.tensorflow.org/community/contribute/code_style |
| 95 | +[yamllint]: https://github.com/adrienverge/yamllint |
| 96 | +[YAPF]: https://github.com/google/yapf |
| 97 | + |
| 98 | +### Git conventions |
| 99 | + |
| 100 | +Git commits should be small and focused. Granular commits make changes easier |
| 101 | +and faster to understand and evaluate, allow more effective use of tools like |
| 102 | +`git bisect` for debugging, and allow easier management of changes with tools |
| 103 | +like `git cherry-pick` and `git rebase`. |
| 104 | + |
| 105 | +Each commit should: |
| 106 | + |
| 107 | +* Represent a single, self-contained change, such as a specific bug fix or the |
| 108 | + addition of a specific feature. |
| 109 | + |
| 110 | +* Not combine unrelated changes. Reverting a commit should not affect |
| 111 | + unrelated parts of the overall code. |
| 112 | + |
| 113 | +* Have an easily understood, concise title written in the imperative: "Fix bug |
| 114 | + ABC" and not "Fixed bug ABC" or "Fixes bug ABC". |
| 115 | + |
| 116 | +* Include a description, unless the change is exceptionally small or obvious. |
| 117 | + |
| 118 | +## Development process |
| 119 | + |
| 120 | +TFQ development takes place on GitHub using a GitHub-centric workflow. |
| 121 | + |
| 122 | +### Past issues |
| 123 | + |
| 124 | +First, search the [issue tracker](https://github.com/tensorflow/quantum/issues) |
| 125 | +to check if your idea or bug has been discussed before. |
| 126 | + |
| 127 | +Before beginning on any substantial changes, we recommend opening a new issue on |
| 128 | +GitHub (if one doesn't already exist for the topic) to describe your proposed |
| 129 | +changes. This will allow the maintainers to provide feedback. |
| 130 | + |
| 131 | +### Repository forks and branches |
| 132 | + |
| 133 | +The preferred approach to working on TensorFlow Quantum is to first create a |
| 134 | +[fork](https://docs.github.com/articles/fork-a-repo) of the repository in your |
| 135 | +GitHub account, then clone that fork to your local computing environment. Keep |
| 136 | +your fork regularly synchronized with the upstream TFQ repository. Create a |
| 137 | +separate [git branch](https://docs.github.com/articles/about-branches) for your |
| 138 | +work on individual issues or topics. |
| 139 | + |
| 140 | +### Environment setup |
| 141 | + |
| 142 | +Follow the instructions in [docs/install.md](docs/install.md) for setting up a |
| 143 | +development environment. After doing that, you should end up with: |
| 144 | + |
| 145 | +* The correct version of Bazel (6.5.0) |
| 146 | +* A Python virtual environment with a Python version between 3.10 and 3.12 |
| 147 | +* The TFQ Python requirements installed in that Python virtual environment |
| 148 | +* The TFQ build configured by running `./configure.sh` |
| 149 | + |
| 150 | +### Adding modules |
| 151 | + |
| 152 | +If you are adding new modules, be sure to properly expose them to the user using |
| 153 | +`__init__.py` files and update the `scripts/import_test.py` file to ensure that |
| 154 | +you are exposing them properly. |
| 155 | + |
| 156 | +### Linting and formatting |
| 157 | + |
| 158 | +Code should meet common style standards for Python and be free of error-prone |
| 159 | +constructs. Use the following commands regularly to lint and reformat your code |
| 160 | +according to project conventions: |
| 161 | + |
| 162 | +```shell |
| 163 | +scripts/format_check.sh |
| 164 | +scripts/lint_all.sh |
| 165 | +``` |
| 166 | + |
| 167 | +If the format check reports problems, you can correct them automatically using |
| 168 | + |
| 169 | +```shell |
| 170 | +scripts/format_all.sh |
| 171 | +``` |
| 172 | + |
| 173 | +### Building TFQ |
| 174 | + |
| 175 | +For relatively "quick" builds of TFQ during development, you can use the |
| 176 | +following command, which builds everything needed for a release and thus acts as |
| 177 | +a good indicator that changes in one part of the code do not break other parts: |
| 178 | + |
| 179 | +```shell |
| 180 | +bazel build release:build_pip_package |
| 181 | +``` |
| 182 | + |
| 183 | +(The first time you run the command above, it will take a long time, but |
| 184 | +subsequent invocations will be much faster because Bazel is smart about what it |
| 185 | +rebuilds.) |
| 186 | + |
| 187 | +### Running tests |
| 188 | + |
| 189 | +When new functions, classes, and files are introduced, they should also have |
| 190 | +corresponding tests. Bug fixes also generally require new unit tests, because |
| 191 | +the presence of bugs usually indicates insufficient test coverage. Existing |
| 192 | +tests must continue to pass (or be updated) when changes are introduced. |
| 193 | + |
| 194 | +We use TensorFlow's testing suite for our testing. Tests must follow the |
| 195 | +[TensorFlow test guidelines](https://www.tensorflow.org/api_docs/python/tf/test) |
| 196 | +in order to work correctly. To run the full TFQ test suite, run this command: |
| 197 | + |
| 198 | +```shell |
| 199 | +scripts/test_all.sh |
| 200 | +``` |
| 201 | + |
| 202 | +During development, it is often useful to run tests on just one file, which you |
| 203 | +can do using a command of this form: |
| 204 | + |
| 205 | +```shell |
| 206 | +bazel test //tensorflow_quantum/SUBDIRECTORY:TARGET |
| 207 | +``` |
| 208 | + |
| 209 | +where _SUBDIRECTORY_ is a subdirectory under `tensorflow_quantum/` and `TARGET` |
| 210 | +is a test. Here is a full example: |
| 211 | + |
| 212 | +```shell |
| 213 | +bazel test //tensorflow_quantum/python/differentiators:adjoint_test |
| 214 | +``` |
| 215 | + |
| 216 | +### Contributing code |
| 217 | + |
| 218 | +All submissions require review. We use GitHub's tools for code reviews on |
| 219 | +[pull requests](https://docs.github.com/articles/about-pull-requests). |
| 220 | + |
| 221 | +#### Final checks |
| 222 | + |
| 223 | +Before opening a pull request (PR) and requesting a code review, you should make |
| 224 | +sure that the following tests are passing locally: |
| 225 | + |
| 226 | +```shell |
| 227 | +scripts/format_check.sh |
| 228 | +scripts/lint_all.sh |
| 229 | +scripts/test_all.sh |
| 230 | +``` |
| 231 | + |
| 232 | +#### Draft pull requests |
| 233 | + |
| 234 | +When getting ready to submit your work, first create a _draft_ pull request from |
| 235 | +your branch on GitHub to the main project repository. (Consult GitHub's |
| 236 | +[docs](https://docs.github.com/articles/creating-a-pull-request-from-a-fork) for |
| 237 | +help on creating draft pull requests.) |
| 238 | + |
| 239 | +When writing the PR title and description, please include the following: |
| 240 | + |
| 241 | +* A concise but descriptive title |
| 242 | +* A summary of what the PR is about |
| 243 | +* How you tested and validated the changes |
| 244 | +* Any important notes, such as assumptions, edge cases, etc. |
| 245 | + |
| 246 | +The pull request will trigger continuous integration (CI) checks and other |
| 247 | +automation on GitHub. Monitor the checks; if any tests fail, continue |
| 248 | +development and testing to resolve the problems. |
| 249 | + |
| 250 | +#### Continuous integration (CI) |
| 251 | + |
| 252 | +Every time a PR is opened or updated on GitHub, automated workflows run checks |
| 253 | +on the files in the PR. These workflows run the format, lint, and test scripts |
| 254 | +mentioned above; they also do additional verification, such as checking that all |
| 255 | +authors on the PR have signed the [Contributor License Agreement]. The outcomes |
| 256 | +of the checks (success, or failures and error messages) will be shown on the |
| 257 | +pull request page on GitHub. |
| 258 | + |
| 259 | +#### Code review |
| 260 | + |
| 261 | +Once all the CI checks pass and you are ready to submit the PR for |
| 262 | +consideration, [mark the PR as ready for review]. A reviewer from the TFQ team |
| 263 | +will comment on your code and may ask for changes. You can perform the necessary |
| 264 | +changes locally, commit them to your branch as usual, and then push changes to |
| 265 | +your fork on GitHub following the same process as above. When you do that, |
| 266 | +GitHub will update the code in the pull request automatically. |
| 267 | + |
| 268 | +[mark the PR as ready for review]: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/changing-the-stage-of-a-pull-request |
| 269 | + |
| 270 | +#### Closure |
| 271 | + |
| 272 | +After code review is finished, requested changes (if any) are made, and the PR |
| 273 | +is approved, the project maintainers will merge the PR into the code base. At |
| 274 | +that point, the work on the PR will be completed. |
0 commit comments