Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev #254

Merged
merged 29 commits into from
Sep 30, 2024
Merged

Dev #254

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
6ed06fa
try to make window inline
ConnorStoneAstro Jul 16, 2024
f57caa6
fix embed
ConnorStoneAstro Jul 16, 2024
3d425e8
adjust sizing
ConnorStoneAstro Jul 16, 2024
4556385
change to md
ConnorStoneAstro Jul 17, 2024
c4c50c3
remove div class
ConnorStoneAstro Jul 17, 2024
6e33aa9
fix aspect ratio
ConnorStoneAstro Jul 17, 2024
71bce55
fix aspect ratio v2
ConnorStoneAstro Jul 17, 2024
54a2734
add note if it doesn't work
ConnorStoneAstro Jul 18, 2024
f72d8ad
refactor: move quad_level to init (#245)
ConnorStoneAstro Jul 27, 2024
6c4585b
Merge branch 'main' into dev
ConnorStoneAstro Aug 8, 2024
62a036b
docs: Add example with local modelling (#239)
ConnorStoneAstro Aug 31, 2024
faeb1a6
Merge branch 'dev' into inwindowdemo
ConnorStoneAstro Aug 31, 2024
9246593
Merge branch 'main' into dev
ConnorStoneAstro Aug 31, 2024
902d1ef
Add MH and MALA MCMC examples (#251)
ConnorStoneAstro Aug 31, 2024
87d2efa
Merge branch 'dev' into inwindowdemo
ConnorStoneAstro Sep 1, 2024
ca32f64
Merge pull request #241 from Ciela-Institute/inwindowdemo
mjyb16 Sep 2, 2024
af9ad1d
chore(deps): bump pypa/gh-action-pypi-publish from 1.9.0 to 1.10.0 (#…
dependabot[bot] Sep 2, 2024
48ea3ae
docs: Put logo gif in main docs page (#243)
ConnorStoneAstro Sep 3, 2024
e00635f
Merge branch 'main' into dev
ConnorStoneAstro Sep 4, 2024
64da2b5
ci: fix codecov token
ConnorStoneAstro Sep 11, 2024
0508962
Merge branch 'main' into dev
ConnorStoneAstro Sep 11, 2024
6f8bdfd
chore(deps): bump pypa/gh-action-pypi-publish from 1.10.0 to 1.10.1 (…
dependabot[bot] Sep 11, 2024
e154ff8
use pytest mark parametrize to massively increase the number of tests…
ConnorStoneAstro Sep 12, 2024
e8e45bf
chore(deps): bump pypa/gh-action-pypi-publish from 1.10.1 to 1.10.2 (…
dependabot[bot] Sep 23, 2024
ecbda4e
Improve forward raytrace to better find all images (#264)
ConnorStoneAstro Sep 26, 2024
13575c3
Merge branch 'main' into dev
ConnorStoneAstro Sep 26, 2024
9c398dc
Merge branch 'main' into dev
ConnorStoneAstro Sep 26, 2024
f1c3ff5
small fix forward_raytrace convergence
ConnorStoneAstro Sep 26, 2024
04d0c71
update sim example in readme (#265)
ConnorStoneAstro Sep 26, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.9.0
uses: pypa/gh-action-pypi-publish@v1.10.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.9.0
- uses: pypa/gh-action-pypi-publish@v1.10.2
if: startsWith(github.ref, 'refs/tags')
3 changes: 2 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,9 @@ jobs:
if:
${{ matrix.python-version == '3.10' && matrix.os == 'ubuntu-latest'}}
uses: codecov/codecov-action@v4
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./coverage.xml
flags: unittests
name: codecov-umbrella
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ x = torch.tensor([
5.0, -0.2, 0.0, 0.8, 0.0, 1., 1.0, 10.0
]) # fmt: skip

minisim = caustics.LensSource(
sim = caustics.LensSource(
lens=sie, source=src, lens_light=lnslt, pixelscale=0.05, pixels_x=100
)
plt.imshow(minisim(x, quad_level=3), origin="lower")
plt.imshow(sim(x), origin="lower")
plt.axis("off")
plt.show()
```
Expand All @@ -63,7 +63,7 @@ plt.show()
newx = x.repeat(20, 1)
newx += torch.normal(mean=0, std=0.1 * torch.ones_like(newx))

images = torch.vmap(minisim)(newx)
images = torch.vmap(sim)(newx)

fig, axarr = plt.subplots(4, 5, figsize=(20, 16))
for ax, im in zip(axarr.flatten(), images):
Expand All @@ -76,7 +76,7 @@ plt.show()
### Automatic Differentiation

```python
J = torch.func.jacfwd(minisim)(x)
J = torch.func.jacfwd(sim)(x)

# Plot the new images
fig, axarr = plt.subplots(3, 7, figsize=(20, 9))
Expand Down
1 change: 1 addition & 0 deletions docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
emcee
ipywidgets
jupyter-book
matplotlib
Expand Down
3 changes: 1 addition & 2 deletions docs/source/_toc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,10 @@ chapters:
- file: tutorials/InvertLensEquation
- file: tutorials/Parameters
- file: tutorials/Simulators
- file: tutorials/Playground
- file: examples/index
sections:
- file: examples/Example_ImageFit_LM
- file: examples/Example_ImageFit_NUTS
- file: examples/Example_ImageFit_MCMC
- file: examples/Example_QSOLensFit
- file: contributing
- file: frequently_asked_questions
Expand Down
30 changes: 21 additions & 9 deletions docs/source/examples/Example_ImageFit_LM.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
"cosmology.to(dtype=torch.float32)\n",
"\n",
"upsample_factor = 1\n",
"quad_level = 3\n",
"thx, thy = caustics.utils.meshgrid(\n",
" pixelscale / upsample_factor,\n",
" upsample_factor * numPix,\n",
Expand Down Expand Up @@ -117,6 +118,7 @@
" pixels_x=numPix,\n",
" pixelscale=pixelscale,\n",
" upsample_factor=upsample_factor,\n",
" quad_level=quad_level,\n",
" z_s=2.0,\n",
")"
]
Expand All @@ -128,16 +130,18 @@
"source": [
"## Sample some mock data\n",
"\n",
"Here we write out the true values for all the parameters in the model. In total there are 21 parameters, so this is quite a complex model already! We then plot the data so we can see what it is we re trying to fit.\n",
"\n",
"Note that when we sample the simulator we call it with `quad_level=7`. This means the simulator will use gaussian quadrature sub-pixel integration to ensure the brightness of each pixel is very accurately computed."
"Here we write out the true values for all the parameters in the model. In total there are 21 parameters, so this is quite a complex model already! We then plot the data so we can see what it is we re trying to fit."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "7",
"metadata": {},
"metadata": {
"tags": [
"hide-input"
]
},
"outputs": [],
"source": [
"# Generate the mock data\n",
Expand Down Expand Up @@ -178,7 +182,7 @@
"print(true_params)\n",
"\n",
"# simulate lens, crop extra evaluation for PSF\n",
"true_system = sim(allparams, quad_level=7) # simulate at high resolution\n",
"true_system = sim(allparams)\n",
"\n",
"fig, axarr = plt.subplots(1, 2, figsize=(15, 8))\n",
"axarr[0].imshow(\n",
Expand Down Expand Up @@ -231,7 +235,7 @@
"res = caustics.utils.batch_lm(\n",
" batch_inits,\n",
" obs_system.reshape(-1).repeat(10, 1),\n",
" lambda x: sim(x, quad_level=3).reshape(-1),\n",
" lambda x: sim(x).reshape(-1),\n",
" C=variance.reshape(-1).repeat(10, 1),\n",
")\n",
"best_fit = res[0][np.argmin(res[2].numpy())]\n",
Expand All @@ -242,7 +246,11 @@
"cell_type": "code",
"execution_count": null,
"id": "10",
"metadata": {},
"metadata": {
"tags": [
"hide-input"
]
},
"outputs": [],
"source": [
"print(best_fit, allparams)\n",
Expand Down Expand Up @@ -288,7 +296,7 @@
"outputs": [],
"source": [
"# Compute jacobian\n",
"J = torch.func.jacfwd(lambda x: sim(x, quad_level=3))(best_fit)\n",
"J = torch.func.jacfwd(lambda x: sim(x))(best_fit)\n",
"fig, axarr = plt.subplots(3, 7, figsize=(21, 9))\n",
"for i, ax in enumerate(axarr.flatten()):\n",
" ax.imshow(J[..., i], origin=\"lower\")\n",
Expand All @@ -310,7 +318,11 @@
"cell_type": "code",
"execution_count": null,
"id": "14",
"metadata": {},
"metadata": {
"tags": [
"hide-cell"
]
},
"outputs": [],
"source": [
"def corner_plot_covariance(\n",
Expand Down
Loading