Skip to main content

The lensing pipeline of the future: GPU-accelerated, automatically-differentiable, highly modular. Currently under heavy development: expect interface changes and some imprecise/untested calculations.

Project description

caustics logo

ssec CI pre-commit.ci status Documentation Status PyPI version coverage status Zenodo arXiv

Caustics

The lensing pipeline of the future: GPU-accelerated, automatically-differentiable, highly modular. Currently under heavy development: expect interface changes and some imprecise/untested calculations.

Installation

Simply install caustics from PyPI:

pip install caustics

Note: Python 3.9 through 3.12 are recommended; compatibility with versions >=3.13 is currently untested.

Minimal Example

# fmt: off
import matplotlib.pyplot as plt
import caustics
import torch

cosmology = caustics.FlatLambdaCDM()
sie = caustics.SIE(cosmology=cosmology, name="lens", z_l=0.5, z_s=1.0, x0=-0.2, y0=0.0, q=0.4, phi=1.5708, Rein=1.7)
src = caustics.Sersic(name="source", x0=0.0, y0=0.0, q=0.5, phi=-0.985, n=1.3, Re=1.0, Ie=5.0)
lnslt = caustics.Sersic(name="lenslight", x0=-0.2, y0=0.0, q=0.8, phi=0.0, n=1.0, Re=1.0, Ie=10.0)

sim = caustics.LensSource(lens=sie, source=src, lens_light=lnslt, pixelscale=0.05, pixels_x=100)

plt.imshow(sim(), origin="lower")
plt.axis("off")
plt.show()

Caustics lensed image

Batched simulator

sim.to_dynamic(False)
cosmology.to_static()
x = sim.build_params_tensor()
newx = x.repeat(20, 1)
newx += torch.normal(mean=0, std=0.1 * torch.ones_like(newx))

images = torch.vmap(sim)(newx)

fig, axarr = plt.subplots(4, 5, figsize=(20, 16))
for ax, im in zip(axarr.flatten(), images):
    ax.imshow(im, origin="lower")
plt.show()

Batched Caustics lensed images

Automatic Differentiation

J = torch.func.jacfwd(sim)(x)

# Plot the new images
fig, axarr = plt.subplots(3, 7, figsize=(20, 9))
for i, ax in enumerate(axarr.flatten()):
    ax.imshow(J[..., i], origin="lower")
plt.show()

Jacobian Caustics lensed image

Documentation

Please see our documentation page for more detailed information.

Contribution

We welcome contributions from collaborators and researchers interested in our work. If you have improvements, suggestions, or new findings to share, please submit an issue or pull request. Your contributions help advance our research and analysis efforts.

To get started with your development (or fork), click the "Open with GitHub Codespaces" button below to launch a fully configured development environment with all the necessary tools and extensions.

Open in GitHub Codespaces

Instruction on how to contribute to this project can be found in the CONTRIBUTION.md

Some guidelines:

  • Please use isort and black to format your code.
  • Use CamelCase for class names and snake_case for variable and method names.
  • Open up issues for bugs/missing features.
  • Use pull requests for additions to the code.
  • Write tests that can be run by pytest.

Thanks to our contributors so far!

Contributors

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

caustics-1.6.0.tar.gz (7.5 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

caustics-1.6.0-py3-none-any.whl (107.3 kB view details)

Uploaded Python 3

File details

Details for the file caustics-1.6.0.tar.gz.

File metadata

  • Download URL: caustics-1.6.0.tar.gz
  • Upload date:
  • Size: 7.5 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for caustics-1.6.0.tar.gz
Algorithm Hash digest
SHA256 184a54cf972780be51730e7c80d0044d8d14b920410b56d3904117db4ed5946b
MD5 d48a6330e26fc411f6cf55bfcd351253
BLAKE2b-256 7fadd6f4e0f9a89b3078be0afa3b010a50290e146fceea52b9b17b9dfc895dd7

See more details on using hashes here.

Provenance

The following attestation bundles were made for caustics-1.6.0.tar.gz:

Publisher: cd.yml on Ciela-Institute/caustics

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file caustics-1.6.0-py3-none-any.whl.

File metadata

  • Download URL: caustics-1.6.0-py3-none-any.whl
  • Upload date:
  • Size: 107.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for caustics-1.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b8e8a287ede488bbbb9ffde9c1412beb7820a93ddc60f6e88c8e33b7b6c36928
MD5 2cc94ee7869151f52a83a85b2723edbf
BLAKE2b-256 b66cb7f6bc66c6f10245797f91fc24957f2eb2b3568e186efaff513f66e0dc15

See more details on using hashes here.

Provenance

The following attestation bundles were made for caustics-1.6.0-py3-none-any.whl:

Publisher: cd.yml on Ciela-Institute/caustics

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page