Skip to content

feat: forward integrand args via integrate(..., args=...) - #246

Merged
gomezzz merged 2 commits into
developfrom
feat/args-passthrough
Jul 24, 2026
Merged

feat: forward integrand args via integrate(..., args=...)#246
gomezzz merged 2 commits into
developfrom
feat/args-passthrough

Conversation

@gomezzz

@gomezzz gomezzz commented Jul 24, 2026

Copy link
Copy Markdown
Collaborator

What

Lets a parametric integrand be integrated directly, without a lambda wrapper:

def fn(x, alpha, beta):
    return alpha * x[:, 0] + beta

Trapezoid().integrate(fn, dim=1, N=101, integration_domain=[[0, 1]], args=(alpha, beta))

BaseIntegrator.evaluate_integrand already accepted args and called
fn(points, *args), but no public integrate() exposed it. This threads an
args parameter through every integrator — Trapezoid, Simpson, Boole,
GaussLegendre, MonteCarlo and VEGAS.

  • args defaults to None (fn(points)), so all existing calls are unchanged.
  • Scope is the eager integrate() path; the JIT-compiled path is untouched.

This re-implements the stale PR #188 by Dan Barzilay (credited as co-author) and
closes #187.

Test plan

  • args_test.py: every integrator forwards args and integrates the
    parametric integrand correctly across backends (grid rules exact; MC/VEGAS
    within tolerance); args=None matches a pre-bound lambda — 12 passed
  • full integrator sweep (trapezoid/simpson/boole/gauss/monte_carlo/vegas/
    integrator_types) still green — 46 passed
  • ruff / pydoclint / vulture clean

Closes #187. Roadmap F3.

gomezzz and others added 2 commits July 24, 2026 18:43
evaluate_integrand already accepted args and called fn(points, *args), but the
public integrate() methods never exposed it. Threads an args parameter through
every integrator (Trapezoid, Simpson, Boole, GaussLegendre, MonteCarlo, VEGAS)
so parametric integrands can be integrated without a lambda wrapper.

- args defaults to None (fn(points)), so existing calls are unchanged.
- Applies to the eager integrate() path; the JIT-compiled path is unchanged.

Re-implements the stale PR #188 and closes #187.

Co-Authored-By: Dan Barzilay <barzilaydn@gmail.com>
@gomezzz

gomezzz commented Jul 24, 2026

Copy link
Copy Markdown
Collaborator Author

Claude: Thanks!

  • Finding 2: added a comment in vegas.py explaining that VEGAS bakes the integrand into a closure (and evaluates via _eval) rather than routing args through evaluate_integrand, so the None -> () normalization is intentionally local — with a note to keep the two in sync (1d97cac).
  • Finding 1 (tutorial): deferring to the F4 docs bundle, whose 'passing parameters' section (issue Example/documentation for parametric domain of integration? #186) is exactly the discoverability fix Integrate function with parameters #187 asked for. I'll add the args=(alpha, beta) parametric example there alongside the QMC and VEGAS-error snippets so all the new-feature docs land together.

@github-actions

github-actions Bot commented Jul 24, 2026

Copy link
Copy Markdown

Overall Coverage

Coverage Report
FileStmtsMissCoverMissing
torchquad
   __init__.py25292%63–64
torchquad/integration
   base_integrator.py49786%28, 71–74, 78, 113, 117, 122
   boole.py30390%54, 73–76
   gaussian.py51394%84, 108, 128
   grid_integrator.py97397%50, 164, 268
   integration_grid.py49492%64–65, 132, 135
   monte_carlo.py93397%79, 101, 230
   rng.py60788%71–74, 93–94, 102
   simpson.py29390%52, 71–74
   utils.py1311192%35–36, 102, 173, 177, 184, 196, 198, 204, 299, 306
   vegas.py162498%102–103, 193, 340
   vegas_map.py103892%247–257
torchquad/utils
   deployment_test.py1926367%53–55, 65–66, 69–70, 78–79, 91–93, 164, 175–176, 180–181, 183–184, 196–199, 211–213, 221, 232–234, 237, 247, 250, 253, 256–259, 267–275, 280–288, 297–306, 316–323
   enable_cuda.py15660%17–22
   set_log_level.py14286%45–46
   set_precision.py34974%35–38, 50–51, 70–72
TOTAL123013889% 

Tests Skipped Failures Errors Time
104 0 💤 0 ❌ 0 🔥 2m 34s ⏱️

@gomezzz
gomezzz merged commit ff4b7f2 into develop Jul 24, 2026
9 checks passed
@gomezzz
gomezzz deleted the feat/args-passthrough branch July 24, 2026 17:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant