Skip to content

Commit 520e93a

Browse files
authored
Merge pull request #229 from esa/Release
Release -> main
2 parents bbbfffc + 59ed9d3 commit 520e93a

62 files changed

Lines changed: 4407 additions & 672 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.flake8

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
[flake8]
2+
exclude =
3+
.git,
4+
__pycache__,
5+
build,
6+
dist,
7+
my_notebooks
28
extend-ignore =
39
# Allow whitespace before ':' because in some cases this whitespace
410
# avoids confusing the operator precedence,

.github/ISSUE_TEMPLATE/release.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,11 @@ _to be written during release process_
2020
- [ ] Create PR to merge from current develop into release branch
2121
- [ ] Write Changelog in PR and request review
2222
- [ ] Review the PR (if OK - merge, but DO NOT delete the branch)
23-
- [ ] Minimize packages in requirements.txt and conda-forge submission. Update packages in setup.py
23+
- [ ] On `Release` ,Minimize packages in requirements.txt and conda-forge submission. Update packages in pyproject.toml
2424
- [ ] Check unit tests -> Check all tests pass on CPU and [GPU (e.g. on colab)](https://colab.research.google.com/drive/1lFpdtY5zV7VpW88aazedA3n4khedHDQP?usp=sharing#scrollTo=IbU2vypPQ-Ej) and that there are tests for all important features
2525
- [ ] Check documentation -> Check presence of documentation for all features by locally building the docs on the release
26-
- [ ] Change version number in setup.py and docs (under conf.py)
26+
- [ ] Change version number in pyproject.toml and docs (under conf.py) and in `__init__.py`
27+
- [ ] In `__init__.py`, set `TORCHQUAD_DISABLE_LOGGING` to `True`
2728
- [ ] Trigger the Upload Python Package to testpypi GitHub Action (https://github.com/esa/torchquad/actions/workflows/deploy_to_test_pypi.yml) on the release branch (need to be logged in)
2829
- [ ] Test the build on testpypi (with `pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple torchquad`)
2930
- [ ] Finalize release on the release branch

.github/workflows/autoblack.yml

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
# GitHub Action that uses Black to reformat the Python code in an incoming pull request.
2-
# If all Python code in the pull request is compliant with Black then this Action does nothing.
3-
# Othewrwise, Black is run and its changes are committed back to the incoming pull request.
4-
# https://github.com/cclauss/autoblack
5-
6-
name: autoblack
1+
name: check_formatting
72
on: [pull_request]
83
jobs:
94
build:
@@ -15,6 +10,6 @@ jobs:
1510
with:
1611
python-version: 3.11
1712
- name: Install Black
18-
run: pip install black==24.4.2
19-
- name: Run black --check .
20-
run: black --check .
13+
run: pip install black==25.1.0
14+
- name: Run black --check --line-length 100 .
15+
run: black --check --line-length 100 .

.github/workflows/deploy_to_pypi.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@ jobs:
1414
python-version: "3.10"
1515
- name: Install dependencies
1616
run: |
17-
pip install setuptools wheel twine
17+
pip install build twine
1818
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
1919
- name: Build and publish to PyPI
2020
env:
2121
TWINE_USERNAME: "__token__"
2222
TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }}
23+
TORCHQUAD_RELEASE_BUILD: "True"
2324
run: |
24-
python setup.py sdist bdist_wheel
25+
python -m build
2526
twine upload dist/*

.github/workflows/deploy_to_test_pypi.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,13 @@ jobs:
1717
python-version: "3.10"
1818
- name: Install dependencies
1919
run: |
20-
pip install setuptools wheel twine
20+
pip install build twine
2121
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
2222
- name: Build and publish to Test PyPI
2323
env:
2424
TWINE_USERNAME: "__token__"
2525
TWINE_PASSWORD: ${{ secrets.TEST_PYPI_TOKEN }}
26+
TORCHQUAD_RELEASE_BUILD: "True"
2627
run: |
27-
python setup.py sdist bdist_wheel
28+
python -m build
2829
twine upload -r testpypi dist/*

.github/workflows/run_tests.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,22 +54,23 @@ jobs:
5454
shell: bash -l {0}
5555
run: |
5656
micromamba activate torchquad
57-
cd torchquad/tests/
57+
pip install -e .
58+
cd tests/
5859
pip install pytest
5960
pip install pytest-error-for-skips
6061
pip install pytest-cov
61-
pytest -ra --error-for-skips --junitxml=pytest.xml --cov-report=term-missing:skip-covered --cov=../../torchquad . | tee pytest-coverage.txt
62+
pytest -ra --error-for-skips --junitxml=pytest.xml --cov-report=term-missing:skip-covered --cov=../torchquad . | tee pytest-coverage.txt
6263
- name: pytest coverage comment
6364
uses: MishaKav/pytest-coverage-comment@main
6465
if: github.event_name == 'pull_request'
6566
continue-on-error: true
6667
with:
67-
pytest-coverage-path: ./torchquad/tests/pytest-coverage.txt
68+
pytest-coverage-path: ./tests/pytest-coverage.txt
6869
title: Coverage Report
6970
badge-title: Overall Coverage
7071
hide-badge: false
7172
hide-report: false
7273
create-new-comment: false
7374
hide-comment: false
7475
report-only-changed-files: false
75-
junitxml-path: ./torchquad/tests/pytest.xml
76+
junitxml-path: ./tests/pytest.xml

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,3 +132,5 @@ my_notebooks
132132
.vscode
133133
pytest-coverage.txt
134134
pytest.xml
135+
CLAUDE.md
136+
.claude/

README.md

Lines changed: 99 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,10 @@ import torchquad
148148
torchquad._deployment_test()
149149
```
150150

151-
After cloning the repository, developers can check the functionality of `torchquad` by running the following command in the `torchquad/tests` directory:
151+
After cloning the repository, developers can check the functionality of `torchquad` by running
152152

153153
```sh
154+
pip install -e .
154155
pytest
155156
```
156157

@@ -192,8 +193,48 @@ integral_value = mc.integrate(
192193
backend="torch",
193194
)
194195
```
195-
To change the logger verbosity, set the `TORCHQUAD_LOG_LEVEL` environment
196-
variable; for example `export TORCHQUAD_LOG_LEVEL=DEBUG`.
196+
## Logging Configuration
197+
198+
By default, torchquad disables its internal logging when installed from PyPI to avoid interfering with other loggers in your application. To enable logging change `TORCHQUAD_DISABLE_LOGGING` in `__init__.py`:
199+
200+
1. **Set the log level**: Use the `TORCHQUAD_LOG_LEVEL` environment variable:
201+
```bash
202+
export TORCHQUAD_LOG_LEVEL=DEBUG # For detailed debugging
203+
export TORCHQUAD_LOG_LEVEL=INFO # For general information
204+
export TORCHQUAD_LOG_LEVEL=WARNING # For warnings only (default when enabled)
205+
```
206+
207+
2. **Enable logging programmatically**:
208+
```python
209+
import torchquad
210+
torchquad.set_log_level("DEBUG") # This will enable and configure logging
211+
```
212+
213+
## Multi-GPU Usage
214+
215+
torchquad supports multi-GPU systems through standard PyTorch practices. The recommended approach is to use the `CUDA_VISIBLE_DEVICES` environment variable to control GPU selection:
216+
217+
```bash
218+
# Use specific GPU
219+
export CUDA_VISIBLE_DEVICES=0 # Use GPU 0
220+
python your_script.py
221+
222+
export CUDA_VISIBLE_DEVICES=1 # Use GPU 1
223+
python your_script.py
224+
225+
# Use multiple GPUs with separate processes
226+
export CUDA_VISIBLE_DEVICES=0 && python integration_script.py &
227+
export CUDA_VISIBLE_DEVICES=1 && python integration_script.py &
228+
```
229+
230+
For parallel processing across multiple GPUs, we recommend spawning separate processes rather than trying to coordinate multiple GPUs within a single process. This approach:
231+
232+
- Provides clean separation between GPU processes
233+
- Avoids complex device management
234+
- Follows PyTorch best practices
235+
- Enables easy load balancing and error handling
236+
237+
For detailed examples and advanced multi-GPU patterns, see the [Multi-GPU Usage section](https://torchquad.readthedocs.io/en/main/tutorial.html#multi-gpu-usage) in our documentation.
197238

198239
You can find all available integrators [here](https://torchquad.readthedocs.io/en/main/integration_methods.html).
199240

@@ -206,13 +247,60 @@ See the [open issues](https://github.com/esa/torchquad/issues) for a list of pro
206247
<!-- PERFORMANCE -->
207248
## Performance
208249

209-
Using GPUs torchquad scales particularly well with integration methods that offer easy parallelization. For example, below you see error and runtime results for integrating the function `f(x,y,z) = sin(x * (y+1)²) * (z+1)` on a consumer-grade desktop PC.
250+
Using GPUs, torchquad scales particularly well with integration methods that offer easy parallelization. The benchmarks below demonstrate performance across challenging functions from 1D to 15D, comparing torchquad's GPU-accelerated methods against scipy's CPU implementations.
251+
252+
<!-- TODO Update plot links -->
253+
### Convergence Analysis
254+
![](https://github.com/esa/torchquad/blob/benchmark-0.4.1/resources/torchquad_convergence.png?raw=true)
255+
*Convergence comparison across challenging test functions from 1D to 15D. GPU-accelerated torchquad methods demonstrate great performance, particularly for high-dimensional integration where scipy's nquad becomes computationally infeasible. Beyond 1D, torchquad significantly outperforms scipy in efficiency.*
256+
257+
### Runtime vs Error Efficiency
258+
![](https://github.com/esa/torchquad/blob/benchmark-0.4.1/resources/torchquad_runtime_vs_error.png?raw=true)
259+
*Runtime-error trade-offs across dimensions. Lower-left positions indicate better performance. While scipy's traditional methods are competitive for simple 1D problems, torchquad's GPU acceleration provides orders of magnitude better performance for multi-dimensional integration, achieving both faster computation and lower errors.*
260+
261+
### Scaling Performance
262+
![](https://github.com/esa/torchquad/blob/benchmark-0.4.1/resources/torchquad_scaling_analysis.png?raw=true)
263+
*Scaling investigation across problem sizes and dimensions of the different methods in torchquad.*
264+
265+
### Vectorized Integration Speedup
266+
![](https://github.com/esa/torchquad/blob/benchmark-0.4.1/resources/torchquad_vectorized_speedup.png?raw=true)
267+
*Strong performance gains when evaluating multiple integrands simultaneously. The vectorized approach shows exponential speedup (up to 200x) compared to sequential evaluation, making torchquad ideal for parameter sweeps, uncertainty quantification, and machine learning applications requiring batch integration.*
268+
269+
### Framework Comparison
270+
![](https://github.com/esa/torchquad/blob/benchmark-0.4.1/resources/torchquad_framework_comparison.png?raw=true)
271+
*Cross-framework performance comparison for 1D integration using Monte Carlo and Simpson methods. Demonstrates torchquad's consistent API across PyTorch, TensorFlow, JAX, and NumPy backends, with GPU acceleration providing significant performance advantages for large number of function evaluations. All frameworks achieve similar accuracy while showcasing the computational benefits of GPU acceleration for parallel integration methods.*
272+
273+
### Running Benchmarks
274+
275+
To reproduce these benchmarks or test performance on your hardware:
276+
277+
```bash
278+
# Run all benchmarks (convergence, framework comparison, scaling, vectorized)
279+
python benchmarking/modular_benchmark.py --dimensions 1,3,7,15
280+
281+
# Run specific benchmark types
282+
python benchmarking/modular_benchmark.py --convergence-only --dimensions 1,3,7,15
283+
python benchmarking/modular_benchmark.py --scaling-only
284+
python benchmarking/modular_benchmark.py --framework-only
285+
286+
# Generate all plots from results
287+
python benchmarking/plot_results.py
288+
289+
# Configure benchmark parameters
290+
# Edit benchmarking/benchmarking_cfg.toml to adjust:
291+
# - Evaluation point ranges
292+
# - Framework backends to test
293+
# - Timeout limits
294+
# - Method selection
295+
# - scipy integration tolerances
296+
```
210297

211-
![](https://github.com/esa/torchquad/blob/main/resources/torchquad_runtime.png?raw=true)
212-
*Runtime results of the integration. Note the far superior scaling on the GPU (solid line) in comparison to the CPU (dashed and dotted) for both methods.*
298+
**New Features:**
299+
- **Analytic Reference Values**: Uses SymPy for exact analytic solutions where possible, providing highly accurate reference values for error calculations
300+
- **Enhanced Test Functions**: Analytically tractable but numerically challenging functions that better demonstrate convergence behavior
301+
- **Framework Comparison**: Cross-backend performance benchmarking across PyTorch, TensorFlow, JAX, and NumPy with GPU/CPU device comparisons
213302

214-
![](https://github.com/esa/torchquad/blob/main/resources/torchquad_convergence.png?raw=true)
215-
*Convergence results of the integration. Note that Simpson quickly reaches floating point precision. Monte Carlo is not competitive here given the low dimensionality of the problem.*
303+
**Hardware:** RTX 4060 Ti 16GB, i5-13400F, Precision: float32
216304

217305
<!-- CONTRIBUTING -->
218306
## Contributing
@@ -245,12 +333,12 @@ Please note that PRs should be created from and into the `develop` branch. For e
245333
3. Create your Feature Branch (`git checkout -b feature/AmazingFeature`)
246334
4. Commit your Changes (`git commit -m 'Add some AmazingFeature'`)
247335
5. Push to the Branch (`git push origin feature/AmazingFeature`)
248-
6. Open a Pull Request on the `develop` branch, *not* `main` (NB: We autoformat every PR with black. Our GitHub actions may create additional commits on your PR for that reason.)
336+
6. Open a Pull Request on the `develop` branch, *not* `main`
249337

250338
and we will have a look at your contribution as soon as we can.
251339

252-
Furthermore, please make sure that your PR passes all automated tests. Review will only happen after that.
253-
Only PRs created on the `develop` branch with all tests passing will be considered. The only exception to this rule is if you want to update the documentation in relation to the current release on conda / pip. In that case you may ask to merge directly into `main`.
340+
Furthermore, please make sure that your PR passes all automated tests, you can ping `@gomezzz` to run the CI. Review will only happen after that.
341+
Only PRs created on the `develop` branch with all tests passing will be considered. The only exception to this rule is if you want to update the documentation in relation to the current release on conda / pip. In that case you open a PR directly into `main`.
254342

255343
<!-- LICENSE -->
256344
## License

0 commit comments

Comments
 (0)