My PhD research at Princeton University focused on optimizing the geometry of high-temperature superconducting magnets to achieve higher magnetic fields and improved quench protection by leveraging the anisotropic properties of superconducting materials using computational, simulation-based methods.
Our work involved computing elliptic integrals. However, we were using JAX so that the objective functions could be automatically differentiated and optimized efficiently on GPUs.
JAX did not provide built-in implementations of these elliptic integrals, so I created a package implementing them.
The package provides JAX implementations of ellipk , ellipkm1 , and ellipe , matching the API of SciPy:
ellipk and ellipkm1 are the same function with different parameterizations: ellipk takes and returns , while ellipkm1 takes , the distance from the singular point , and returns . The split exists because diverges logarithmically as , and near this point the result hinges on the exact value of . Taking as the argument make ellipkm1 remain accurate arbitrarily close to the singularity, at the cost of a small amount of additional computation.
Under the hood, ellipk and ellipe use the same Cephes minimax polynomial approximations as SciPy: polynomials in the complementary parameter plus logarithmic terms, with a Landen transformation for negative . ellipkm1 evaluates directly from , using a small- logarithmic expansion below .
Automatic differentiation is implemented with custom JVP rules. The derivative formulas reduce to Carlson’s symmetric integral , which is evaluated using a fixed-length duplication iteration with the zero argument handled analytically. The tests compare values against high-precision mpmath references and scipy.special, and check forward-, reverse-, and second-order JAX derivatives.
Check out the source code on GitHub: github.com/sinaatalay/jaxellip
Check out the package on PyPI: pypi.org/project/jaxellip