Herculens: differentiable gravitational lensing
Analysis of strong lensing imaging data
The primary purpose of Herculens is to provide flexible modeling methods to model current and future observations of strong gravitational lenses. Currently, it supports various degrees of model complexity, ranging from standard smooth analytical profiles to pixelated models combined with machine learning approaches.
Currently, Herculens supports several of the most widely-used analytical profiles, as well as multi-scale pixelated models regularized with wavelets. Future updates will include the support of point source modeling, new regularization techniques, and more expressive models based on neural networks.
JAX-based automatic differentiation and code compilation
Herculens is based on the powerful framework of differentiable programming. The code is entirely based on the automatic differentiation and compilation features of JAX. This simply means that you have access, analytically, to all partial derivatives of your model with respect to any of its parameters. This enables faster convergence to the solution, more efficient exploration of the parameter space including the sampling of posterior distributions, and new ways to mitigate degeneracies that affect gravitational lensing.
This highly modular framework offers a way to merge all modeling paradigms explored in the literature, into a single tool:
- analytical: model components are described by analytical functions with few parameters and clear physical meaning, but that may be insufficient to fit all observations;
- pixelated: regular or irregular grid of pixels are used as individual parameters, which offer higher flexibility, but requires well-motivated regularization strategies;
- deep learning: neural networks (among others) are by construction fully differentiable, regardless of being pre-trained or not. It is therefore effortless to plug-in any deep learning-based model component to
Herculens.
Being based on JAX means that Herculens runs effortlessly on CPUs, GPUs and TPUs with no changes to the code.
Works using Herculens
You can find a list of analyses that used Herculens, as well as their ADS bibtex entries, on this page.
Example notebooks
Several examples to run Herculens in many different situations are available in the herculens_workspace repository.
Installation
Manual installation
The package will be soon available through PyPi directly, but it is as easy to install it manually. It has been texted against Python 3.7, but should work with Python 3.8 or more recent versions.
Good practice is to create a new python environment:
conda create -n herculens-env python=3.12
conda activate herculens-env
Download the package cd into the directory. Then install the local Herculens package (or use -e for a development install) as follows:
pip install (-e) .
The mandatory dependencies will be installed automatically.
Package requirements
The requirements.txt file lists all required and optional package dependencies, along with their specific versions.
Note on
jaxinterp2d: This optional dependency (used for fast bilinear interpolation in pixelated profiles) is not available on PyPI and must be installed manually:pip install git+https://github.com/adam-coogan/jaxinterp2d@master
Slack channel
We have a Slack workspace dedicated to users of Herculens, for getting help and sharing ideas. Please feel free to send an email to be added to the workspace.
Attribution
Citation
If you make use of Herculens, please cite Galan et al. 2022. If you use the CorrelatedField model, please also cite Galan et al. 2024. The corresponding bibtex entries are available in this file.
Special mention regarding Lenstronomy
Part of the Herculens code originates from the open-source lens modeling software package lenstronomy, described in Birrer et al. 2021 (and references therein). In every source file, proper credits are given to the specific developers and contributors to both the original lenstronomy (up to version 1.9.3) and Herculens.
Contributors
The list of people that contributed to Herculens and credits to original lenstronomy contributors, is in this document.
Metadata
Release files for herculens 0.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| herculens-0.3.0.tar.gz | 179.6 kB | With provenance | Details for herculens-0.3.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| herculens-0.3.0-py3-none-any.whl | Python 3 | none | any | Details for herculens-0.3.0-py3-none-any.whl |
Total release size: 401.5 kB
Release files / herculens-0.3.0.tar.gz
| Download URL | herculens-0.3.0.tar.gz |
|---|---|
| Size | 179.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a29350096d5ae16462308812c57b2ee487736b892819ce4a3e3b548b09335c07
|
|
BLAKE2b-256 checksum How to use checksums |
22c7f3444738b9a7923fde2b9e275c790c332597b8d7f0e6d7e54ce3d89b0452
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Apr 9, 2026.
Transparency logRelease files / herculens-0.3.0-py3-none-any.whl
| Download URL | herculens-0.3.0-py3-none-any.whl |
|---|---|
| Size | 221.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
27cbc3c858887d15f099f1b3b57ef4fcf8c658ab4f646d08162ad3f300b2a169
|
|
BLAKE2b-256 checksum How to use checksums |
babd3bc2bff1dd70c91ab964c848c978e28b577733bad15871b59f0fd1d940c0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Apr 9, 2026.
Transparency logSecurity for herculens 0.3.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for herculens-0.3.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Apr 9, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.