Skip to content

Commit

Permalink
Merge branch 'main' into JOSS
Browse files Browse the repository at this point in the history
  • Loading branch information
ConnorStoneAstro committed Nov 21, 2024
2 parents d669a33 + 7e5782a commit 77aaacb
Show file tree
Hide file tree
Showing 94 changed files with 1,686 additions and 5,285 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ jobs:
ls -ltrh
ls -ltrh dist
- name: Publish to Test PyPI
uses: pypa/gh-action-pypi-publish@v1.11.0
uses: pypa/gh-action-pypi-publish@v1.12.2
with:
repository-url: https://test.pypi.org/legacy/
verbose: true
Expand Down Expand Up @@ -95,5 +95,5 @@ jobs:
name: artifact
path: dist

- uses: pypa/gh-action-pypi-publish@v1.11.0
- uses: pypa/gh-action-pypi-publish@v1.12.2
if: startsWith(github.ref, 'refs/tags')
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ jobs:
- name: Upload coverage reports to Codecov with GitHub Action
if:
${{ matrix.python-version == '3.10' && matrix.os == 'ubuntu-latest'}}
uses: codecov/codecov-action@v4
uses: codecov/codecov-action@v5
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
with:
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ repos:
args: [--prose-wrap=always]

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: "v0.7.2"
rev: "v0.7.4"
hooks:
- id: ruff
args: ["--fix", "--show-fixes"]
Expand Down
2 changes: 1 addition & 1 deletion CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ authors:
- family-names: "Hezaveh"
given-names: "Yashar"
orcid: "https://orcid.org/0000-0002-8669-5733"
title: "caustics"
title: "Caustics: A Python Package for Accelerated Strong Gravitational Lensing Simulations"
doi: 10.5281/zenodo.10806382
abstract: "The lensing pipeline of the future: GPU-accelerated, automatically-differentiable, highly modular. Currently under heavy development."
repository-code: "https://github.com/Ciela-Institute/caustics"
12 changes: 9 additions & 3 deletions docs/source/examples/Example_ImageFit_LM.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@
"batch_inits = batch_inits.to(dtype=torch.float32)\n",
"res = caustics.utils.batch_lm(\n",
" batch_inits,\n",
" obs_system.reshape(-1).repeat(10, 1),\n",
" obs_system.reshape(-1).repeat(10, 1).to(dtype=torch.float32),\n",
" lambda x: sim(x).reshape(-1),\n",
" C=variance.reshape(-1).repeat(10, 1),\n",
")\n",
Expand Down Expand Up @@ -423,7 +423,7 @@
"source": [
"J = J.reshape(-1, len(best_fit))\n",
"# Compute Hessian\n",
"H = J.T @ (J / variance.reshape(-1, 1))\n",
"H = J.T @ (J / variance.reshape(-1, 1).to(dtype=torch.float32))\n",
"# Compute covariance matrix\n",
"C = torch.linalg.inv(H)\n",
"plt.imshow(np.log10(np.abs(C.detach().cpu().numpy())))\n",
Expand Down Expand Up @@ -461,6 +461,11 @@
}
],
"metadata": {
"kernelspec": {
"display_name": "PY39",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
Expand All @@ -470,7 +475,8 @@
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3"
"pygments_lexer": "ipython3",
"version": "3.9.5"
}
},
"nbformat": 4,
Expand Down
21 changes: 16 additions & 5 deletions docs/source/examples/Example_QSOLensFit.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,15 @@
"sp_x = torch.tensor(0.2)\n",
"sp_y = torch.tensor(0.2)\n",
"\n",
"# true parameters x0 y0 q phi b\n",
"# true parameters x0 y0 q phi b\n",
"params = torch.tensor([0.0, 0.0, 0.4, np.pi / 5, 1.0])\n",
"# Points in image plane\n",
"x, y = lens.forward_raytrace(sp_x, sp_y, z_s, params)"
"x, y = lens.forward_raytrace(sp_x, sp_y, z_s, params)\n",
"# get magnifications\n",
"mu = lens.magnification(x, y, z_s, params)\n",
"# remove heavily demagnified points\n",
"x = x[mu > 1e-2]\n",
"y = y[mu > 1e-2]"
]
},
{
Expand Down Expand Up @@ -233,7 +238,7 @@
"detA = torch.linalg.det(A)\n",
"\n",
"CS = ax.contour(\n",
" thx, thy, detA, levels=[0.0], colors=\"green\", linestyles=\"dashed\", zorder=1\n",
" thx, thy, detA, levels=[0.0], colors=\"orange\", linestyles=\"dashed\", zorder=1\n",
")\n",
"# Get the path from the matplotlib contour plot of the critical line\n",
"paths = CS.allsegs[0]\n",
Expand All @@ -246,7 +251,7 @@
" y1, y2 = lens.raytrace(x1, x2, z_s, params)\n",
"\n",
" # Plot the caustic\n",
" ax.plot(y1, y2, color=\"orange\", linestyle=\"--\", label=\"Fit\", zorder=1)\n",
" ax.plot(y1, y2, color=\"green\", linestyle=\"--\", label=\"Fit\", zorder=1)\n",
"plt.legend()\n",
"plt.show()"
]
Expand All @@ -261,6 +266,11 @@
}
],
"metadata": {
"kernelspec": {
"display_name": "PY39",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
Expand All @@ -270,7 +280,8 @@
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3"
"pygments_lexer": "ipython3",
"version": "3.9.5"
}
},
"nbformat": 4,
Expand Down
38 changes: 30 additions & 8 deletions docs/source/frequently_asked_questions.rst
Original file line number Diff line number Diff line change
@@ -1,10 +1,32 @@
FAQs - Frequently asked questions
=================================
| **Q:** How do I know what order to put the parameter values in the pytorch tensor which gets passed to the simulator?
| **A:** If you are using a simulator, then you can get the parameters using ``your_simulator.state_dict()``. The parameters whose values are set dynamically will say "None", while the static parameters will have their values shown. The order of the dynamical parameters corresponds to the order you should use in your parameter value tensor.
|
| **Q:** Why can I put the lens redshift at higher values than the source redshift or to negative values for some parametric models?
| **A:** We can calculate everything for those profiles with reduced deflection angles where the redshifts do not actually play into the calculation. If you use a profile defined by the lens mass, like a NFW lens, or a Multiplane lens then it does matter that the redshifts make sense and you will very likely get errors for those. Similarly, if you call the ``lens.physical_deflection_angle`` you will encounter errors.
|
| **Q:** I do (multiplane-)lensing with pixelated convergence using the pixelated kappa map of a parametric profile. The lensing effect differs from directly using the parametric lens. Why is the lensing effect different?
| **A:** Since you do pixelated convergence your mass is binned in pixels in a finite field of view (FOV) so you are missing some mass. At the limit of infinite resolution and infinite FOV the pixelated profile gives you the parametric profile. If the difference is above your error tolerance then you have to increase the resolution and/or FOV of your pixelated convergence map. Especially for SIE or EPL profiles (which go to infinity density in the center, and have infinite mass outside any FOV) you will miss infinite mass when pixelating.

**Q:** How do I know what order to put the parameter values in the pytorch tensor which gets passed to the simulator?
-----------

**A:** If you are using any ``Module``` object (so a simulator), then you can
get the parameters using ``print(simulator)``. The order of the dynamical
parameters (top to bottom) corresponds to the order you should use in your
parameter value tensor. Note that you can ignore the static parameters.

**Q:** Why can I put the lens redshift at higher values than the source redshift or to negative values for some parametric models?
-----------

**A:** We can calculate everything for those profiles with reduced deflection
angles where the redshifts do not actually play into the calculation. If you use
a profile defined by the lens mass, like a NFW lens, or a Multiplane lens then
it does matter that the redshifts make sense and you will very likely get errors
for those. Similarly, if you call the ``lens.physical_deflection_angle`` you
will encounter errors.

**Q:** I do (multiplane-)lensing with pixelated convergence using the pixelated kappa map of a parametric profile. The lensing effect differs from directly using the parametric lens. Why is the lensing effect different?
-----------

**A:** Since you do pixelated convergence your mass is binned in pixels in a
finite field of view (FOV) so you are missing some mass. At the limit of
infinite resolution and infinite FOV the pixelated profile gives you the
parametric profile. If the difference is above your error tolerance then you
have to increase the resolution and/or FOV of your pixelated convergence map.
Especially for SIE or EPL profiles (which go to infinity density in the
center, and have infinite mass outside any FOV) you will miss infinite mass
when pixelating.
14 changes: 10 additions & 4 deletions docs/source/tutorials/InterfaceIntroduction_oop.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@
"source": [
"# Print out the order of model parameters\n",
"# Note that parameters with values are \"static\" so they don't need to be provided by you\n",
"sim.state_dict()"
"print(sim)"
]
},
{
Expand Down Expand Up @@ -240,7 +240,7 @@
"outputs": [],
"source": [
"fig, axarr = plt.subplots(3, 7, figsize=(20, 9))\n",
"labels = tuple(sim.state_dict().keys())[3:]\n",
"labels = tuple(p.name for p in sim.dynamic_params)\n",
"for i, ax in enumerate(axarr.flatten()):\n",
" ax.imshow(J[..., i], origin=\"lower\")\n",
" ax.set_title(labels[i])\n",
Expand All @@ -265,7 +265,7 @@
"outputs": [],
"source": [
"# Substitute sim with sim for the yaml method\n",
"sim.graph(True, True)"
"sim.graphviz()"
]
},
{
Expand Down Expand Up @@ -301,6 +301,11 @@
}
],
"metadata": {
"kernelspec": {
"display_name": "PY39",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
Expand All @@ -310,7 +315,8 @@
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3"
"pygments_lexer": "ipython3",
"version": "3.9.5"
}
},
"nbformat": 4,
Expand Down
10 changes: 5 additions & 5 deletions docs/source/tutorials/InterfaceIntroduction_yaml.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
"source": [
"# Print out the order of model parameters\n",
"# Note that parameters with values are \"static\" so they don't need to be provided by you\n",
"sim.state_dict()"
"print(sim)"
]
},
{
Expand Down Expand Up @@ -177,7 +177,7 @@
"outputs": [],
"source": [
"fig, axarr = plt.subplots(3, 7, figsize=(20, 9))\n",
"labels = tuple(sim.state_dict().keys())[3:]\n",
"labels = tuple(p.name for p in sim.dynamic_params)\n",
"for i, ax in enumerate(axarr.flatten()):\n",
" ax.imshow(J[..., i], origin=\"lower\")\n",
" ax.set_title(labels[i])\n",
Expand All @@ -202,7 +202,7 @@
"outputs": [],
"source": [
"# The simulator is internally represented as a directed acyclic graph of operations\n",
"sim.graph(True, True)"
"sim.graphviz()"
]
},
{
Expand Down Expand Up @@ -384,7 +384,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "caustic",
"display_name": "PY39",
"language": "python",
"name": "python3"
},
Expand All @@ -398,7 +398,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.18"
"version": "3.9.5"
}
},
"nbformat": 4,
Expand Down
Loading

0 comments on commit 77aaacb

Please sign in to comment.