|
| 1 | +# Contributing to `nada-numpy` |
| 2 | + |
| 3 | +Thank you for considering contributing to `nada-numpy`! There are two ways to contribute to `nada-numpy`: |
| 4 | + |
| 5 | +1. [Open issues](#open-issues) to report bugs and typos, or to suggest new ideas. |
| 6 | +2. [Submit a PR](#submit-a-pull-request) with a new feature or improvement. |
| 7 | + |
| 8 | +To ensure a consistent development process, please follow the guidelines outlined below. |
| 9 | + |
| 10 | +## Code quality and type checking |
| 11 | + |
| 12 | +- All contributions must adhere to the project's coding standards. We enforce these standards using `pylint` for code quality and `mypy` for type checking. |
| 13 | +- Before submitting your contributions, ensure that your code passes both `pylint` and `mypy` checks. |
| 14 | +- These tools are also integrated into our CI/CD pipeline, and any PR will be automatically validated against these checks. |
| 15 | + |
| 16 | +## Development |
| 17 | + |
| 18 | +We recommend continuously running your code through `pylint` and `mypy` during the development process. These tools help identify potential issues early, enforce coding standards, and maintain type safety. |
| 19 | + |
| 20 | +### Installation |
| 21 | + |
| 22 | +1. Install [black](https://pypi.org/project/black/) and [isort](https://pycqa.github.io/isort/) for code formating |
| 23 | +```bash |
| 24 | +pip3 install black && isort |
| 25 | +``` |
| 26 | +2. Fork the [repo](https://github.com/NillionNetwork/nada-numpy.git) |
| 27 | +3. Install from source the `nada-numpy` library: |
| 28 | +```bash |
| 29 | +cd nada-numpy |
| 30 | +pip3 install -e . |
| 31 | +``` |
| 32 | + |
| 33 | +### Adding tests |
| 34 | + |
| 35 | +The [`tests/nada-tests`](https://github.com/NillionNetwork/nada-numpy/tree/main/tests/nada-tests) folder contains the testing infrastructure for `nada_numpy`. You will need to create one or more scripts to test your functionality. You can read the [docs](https://docs.nillion.com/nada#generate-a-test-file) for more info about testing. Follow these steps for testing: |
| 36 | + |
| 37 | +1. Add a script to [`tests/nada-tests/nada-project.toml`](https://github.com/NillionNetwork/nada-numpy/blob/main/tests/nada-tests/nada-project.toml). |
| 38 | + |
| 39 | +2. Place your test script in [`tests/nada-tests/src/`](https://github.com/NillionNetwork/nada-numpy/blob/main/tests/nada-tests/src), where it will verify the expected behavior. |
| 40 | + |
| 41 | +3. Generate the test file by running |
| 42 | +```bash |
| 43 | +nada generate-test --test-name <TEST_NAME> <PROGRAM> |
| 44 | +``` |
| 45 | +and placing it in [`tests/nada-tests/tests/`](https://github.com/NillionNetwork/nada-numpy/blob/main/tests/nada-tests/tests). |
| 46 | + |
| 47 | +4. Finally, add the script to the `TESTS` array in [`tests/test_all.py`](https://github.com/NillionNetwork/nada-numpy/blob/dd112a09835c2354cbf7ecc89ad2714ca7171b20/tests/test_all.py#L6) to integrate it with the CI/CD pipeline. |
| 48 | + |
| 49 | +### Hints to add new features |
| 50 | + |
| 51 | +Below we provide some hints on how to add new features. We give two examples: adding a `NadaArray` method and adding a `Rational` method. |
| 52 | + |
| 53 | +#### New `NadaArray` method |
| 54 | + |
| 55 | +As an example, we use the `variance` operation to describe the development flow: |
| 56 | + |
| 57 | +1. **Integrate the variance function:** |
| 58 | + - In [`nada_numpy/array.py`](https://github.com/NillionNetwork/nada-numpy/blob/main/nada_numpy/array.py), integrate the `variance` method inside the `NadaArray` class as a new member function. This will allow the `variance` to be called as `array.var()`. |
| 59 | + |
| 60 | +2. **Add a Wrapper in `nada_numpy/funcs.py`:** |
| 61 | + - In `nada-numpy`, functions can also be called in the form `na.var(array)`. To support this, add a wrapper in [`nada_numpy/funcs.py`](https://github.com/NillionNetwork/nada-numpy/blob/main/nada_numpy/funcs.py). You can refer to the existing functions in this file to see how they simply wrap around `array.var()` in this context. |
| 62 | + |
| 63 | +#### New `Rational` method |
| 64 | + |
| 65 | +As an example, we use the exponential `exp` function to describe the development flow: |
| 66 | + |
| 67 | +1. **Integrate the exp function with Rational:** |
| 68 | + - In [`nada_numpy/types.py`](https://github.com/NillionNetwork/nada-numpy/blob/main/nada_numpy/types.py), integrate the `exp` method inside both the `Rational` and `SecretRational` classes as a new member function. This will allow the `exp` to be called as `value.exp()`. |
| 69 | + |
| 70 | +2. **Integrate the exp function with NadaArray:** |
| 71 | + - In [`nada_numpy/array.py`](https://github.com/NillionNetwork/nada-numpy/blob/main/nada_numpy/array.py), integrate the `exp` method inside the `NadaArray` class as a new member function. This will allow the `exp` to be called as `array.exp()`. |
| 72 | + |
| 73 | +3. **Add a Wrapper in `nada_numpy/funcs.py`:** |
| 74 | + - In `nada-numpy`, functions can also be called in the form `na.exp(array)`. To support this, add a wrapper in [`nada_numpy/funcs.py`](https://github.com/NillionNetwork/nada-numpy/blob/main/nada_numpy/funcs.py). You can refer to the existing functions in this file to see how they simply wrap around `array.exp()` in this context. |
| 75 | + |
| 76 | +## Submit a Pull Request |
| 77 | + |
| 78 | +We actively welcome your pull requests. Please follow these steps to successfully submit a PR: |
| 79 | + |
| 80 | +1. Fork the [repo](https://github.com/NillionNetwork/nada-numpy.git) and create your branch from `main`. |
| 81 | +2. If you've added code that should be tested, add tests as explained [above](#adding-tests). |
| 82 | +3. Ensure that the test suite passes. Under [`tests/nada-tests/tests/`](https://github.com/NillionNetwork/nada-numpy/blob/main/tests/nada-tests/tests) run |
| 83 | +```bash |
| 84 | +nada test <TEST_NAME> |
| 85 | +``` |
| 86 | +4. Run from the root directory both |
| 87 | +```bash |
| 88 | +black . && isort . |
| 89 | +``` |
| 90 | +5. Ensure that your code passes both `pylint` and `mypy` checks: |
| 91 | +```bash |
| 92 | +poetry run pylint |
| 93 | +poetry run mypy |
| 94 | +``` |
| 95 | + |
| 96 | +## Open Issues |
| 97 | + |
| 98 | +We use [GitHub issues](https://github.com/NillionNetwork/nada-numpy/issues/new/choose) to report bugs and typos, or to suggest new ideas. Please ensure your description is clear and has sufficient instructions to be able to reproduce the issue. |
| 99 | + |
| 100 | +## License |
| 101 | +By contributing to `nada-numpy`, you agree that your contributions will be licensed under the [LICENSE](./LICENSE) file in the root directory of this source tree. |
0 commit comments