Common API for `Integrate`. IntegrationBase

I’ve observed a conflict of different packages exporting integrate (e.g.).

It would be nice to have IntegrationBase with API.
Currently, the ecosystem is diverse.

Overview of methods

  • integrate is exported by Polynomial
  • in Distributions.jl, it’s called cdf :slight_smile:
  • quadgk
  • Integrals.jl does different stuff
  • hcubature of HCubature.jl
  • nintegrate of NIntegration.jl

Need

I’d be happy to make dependency on IntegrationBase, and define

integrate(o::MyObject, domain::Domain)

Thoughts are welcome. Please point any relevant discussions.

These types of “Base packages” with a single function in them don’t really work because of how different their APIs are and what they expect their inputs to be.

If you want it to be useful, you can take inspiration from GitHub - SciML/LinearSolve.jl: LinearSolve.jl: High-Performance Unified Interface for Linear Solvers in Julia. Easily switch between factorization and Krylov methods, add preconditioners, and all in one interface., which provides a common API to different linear solvers (but then actually does the work to adapt to the different solvers API).

1 Like

There’s also not necessarily any problem with export conflicts.

Another alternative comes from the IO and plotting ecosystems. Lots of packages define Package.read and Package.write or Package.plot with similar APIs. This allows you to swap out the method used in, e.g., HCubature.integrate(sin, 0.0, 1pi) to Trapz.integrate(sin, 0.0, 1pi) or whatever.

Isn’t this what Integrals.jl does? It wraps a bunch of different quadrature packages already.

5 Likes

Ok, I see the benefits of same name, even without a common base interface.
My original concern comes from example of not-integration packages that still export integral method, like

  • histogram can be integrated, therefore FHist defines integrate,
  • Polynomials can be integrated, therefore Polynomials.jl export integrate.

My question is not on genuite integration libraries, rather on defining integrate on user objects.

1 Like

Yup and it adds AD support on top of the interface too! So :sweat_smile: open an issue if it’s missing anything.

2 Likes