Skip to content

Commit

Permalink
Merge pull request #159 from Ciela-Institute/dev
Browse files Browse the repository at this point in the history
Dev updates v0.8.0
  • Loading branch information
ConnorStoneAstro authored Feb 14, 2024
2 parents 52a9fb7 + 61c4c51 commit a6e40f2
Show file tree
Hide file tree
Showing 48 changed files with 1,643 additions and 628 deletions.
12 changes: 6 additions & 6 deletions .devcontainer/cpu/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
"context": "../..",
"dockerfile": "../Dockerfile",
"args": {
"CLANG_VERSION": ""
}
"CLANG_VERSION": "",
},
},

// Use 'forwardPorts' to make a list of ports inside the container available locally.
Expand All @@ -26,10 +26,10 @@
"ms-python.python",
"ms-vsliveshare.vsliveshare",
"DavidAnson.vscode-markdownlint",
"GitHub.copilot"
]
}
}
"GitHub.copilot",
],
},
},

// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
// "remoteUser": "root"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,4 @@ jobs:
pytest -vvv --cov=${{ env.PROJECT_NAME }} --cov-report=xml --cov-report=term tests/
- name: Upload coverage reports to Codecov with GitHub Action
uses: codecov/codecov-action@v3
uses: codecov/codecov-action@v4
25 changes: 12 additions & 13 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
exclude: |
(?x)^(
tests/utils.py
tests/utils/
)
ci:
Expand All @@ -9,7 +9,7 @@ ci:

repos:
- repo: https://github.com/psf/black
rev: "23.12.1"
rev: "24.1.1"
hooks:
- id: black-jupyter

Expand Down Expand Up @@ -50,20 +50,19 @@ repos:
args: [--prose-wrap=always]

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: "v0.1.9"
rev: "v0.2.1"
hooks:
- id: ruff
args: ["--fix", "--show-fixes"]

# 2023-12-11: Not use mypy for now.
# - repo: https://github.com/pre-commit/mirrors-mypy
# rev: "v1.8.0"
# hooks:
# - id: mypy
# files: src|tests
# args: []
# additional_dependencies:
# - pytest
- repo: https://github.com/pre-commit/mirrors-mypy
rev: "v1.8.0"
hooks:
- id: mypy
files: src
args: ["--ignore-missing-imports"]
additional_dependencies:
- pytest

- repo: https://github.com/codespell-project/codespell
rev: "v2.2.6"
Expand All @@ -72,7 +71,7 @@ repos:
args: ["--write-changes", "--ignore-words", ".codespell-whitelist"]

- repo: https://github.com/kynan/nbstripout
rev: 0.6.1
rev: 0.7.1
hooks:
- id: nbstripout
args: [--extra-keys=metadata.kernelspec metadata.language_info.version]
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ import matplotlib.pyplot as plt
import caustics
import torch

cosmology = caustics.cosmology.FlatLambdaCDM()
sie = caustics.lenses.SIE(cosmology=cosmology, name="lens")
src = caustics.light.Sersic(name="source")
lnslt = caustics.light.Sersic(name="lenslight")
cosmology = caustics.FlatLambdaCDM()
sie = caustics.SIE(cosmology=cosmology, name="lens")
src = caustics.Sersic(name="source")
lnslt = caustics.Sersic(name="lenslight")

x = torch.tensor([
# z_s z_l x0 y0 q phi b x0 y0 q phi n Re
Expand All @@ -44,7 +44,7 @@ x = torch.tensor([
5.0, -0.2, 0.0, 0.8, 0.0, 1., 1.0, 10.0
]) # fmt: skip

minisim = caustics.sims.Lens_Source(
minisim = caustics.Lens_Source(
lens=sie, source=src, lens_light=lnslt, pixelscale=0.05, pixels_x=100
)
plt.imshow(minisim(x, quad_level=3), origin="lower")
Expand Down
27 changes: 27 additions & 0 deletions docs/source/contributing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,31 @@ Finalizing a Pull Request

Once the PR is submitted, we will look through it and request any changes necessary before merging it into the main branch. You can make those changes just like any other edits on your fork. Then when you push them, they will be joined in to the PR automatically and any unit tests will run again.

Black Formatting Exceptions for Equations
-----------------------------------------

In the **caustics** project, we utilize the Black code formatter to ensure consistent and readable code. However, there are instances where the automatic formatting performed by Black may not align with the desired formatting for equations within the code.

To address this, we have introduced the use of ``#fmt: skip`` tags to exempt specific code blocks or lines from Black formatting. This is particularly useful when dealing with equations that have a specific format or layout that should not be altered by the code formatter.

How to Use ``#fmt: skip`` for Equations
---------------------------------------

To exempt a specific section of code, such as an equation, from Black formatting, simply add a comment with the ``#fmt: skip`` tag at the end of the line containing the code block. For example:

.. code-block:: python
psi = (q**2 * (x**2 + self.s**2) + y**2).sqrt() # fmt: skip
In the above example, the line with the ``#fmt: skip`` comment informs Black to skip formatting for the following line containing the equation. This allows developers to maintain control over the formatting of equations while still benefiting from the automatic formatting provided by Black for the rest of the codebase.

Best Practices for Black Formatting Exceptions
----------------------------------------------

- Use ``#fmt: skip`` sparingly and only for sections where manual formatting is essential.
- Clearly document the reason for using ``#fmt: skip`` to provide context for future developers.

By incorporating ``#fmt: skip`` tags for equations, we strike a balance between automated code formatting and the need for manual control over certain code elements.


Once the PR has been merged, you may delete your fork if you aren't using it any more, or take on a new issue, it's up to you!
10 changes: 5 additions & 5 deletions docs/source/intro.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ import matplotlib.pyplot as plt
import caustics
import torch

cosmology = caustics.cosmology.FlatLambdaCDM()
sie = caustics.lenses.SIE(cosmology=cosmology, name="lens")
src = caustics.light.Sersic(name="source")
lnslt = caustics.light.Sersic(name="lenslight")
cosmology = caustics.FlatLambdaCDM()
sie = caustics.SIE(cosmology=cosmology, name="lens")
src = caustics.Sersic(name="source")
lnslt = caustics.Sersic(name="lenslight")

x = torch.tensor([
# z_s z_l x0 y0 q phi b x0 y0 q phi n Re
Expand All @@ -39,7 +39,7 @@ x = torch.tensor([
5.0, -0.2, 0.0, 0.8, 0.0, 1., 1.0, 10.0
]) # fmt: skip

minisim = caustics.sims.Lens_Source(
minisim = caustics.Lens_Source(
lens=sie, source=src, lens_light=lnslt, pixelscale=0.05, pixels_x=100
)
plt.imshow(minisim(x, quad_level=3), origin="lower")
Expand Down
10 changes: 5 additions & 5 deletions docs/source/tutorials/BasicIntroduction.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"metadata": {},
"outputs": [],
"source": [
"cosmology = caustics.cosmology.FlatLambdaCDM()"
"cosmology = caustics.FlatLambdaCDM()"
]
},
{
Expand All @@ -62,7 +62,7 @@
"metadata": {},
"outputs": [],
"source": [
"sie = caustics.lenses.SIE(cosmology=cosmology, name=\"lens\")"
"sie = caustics.SIE(cosmology=cosmology, name=\"lens\")"
]
},
{
Expand All @@ -80,7 +80,7 @@
"metadata": {},
"outputs": [],
"source": [
"src = caustics.light.Sersic(name=\"source\")"
"src = caustics.Sersic(name=\"source\")"
]
},
{
Expand All @@ -98,7 +98,7 @@
"metadata": {},
"outputs": [],
"source": [
"lnslt = caustics.light.Sersic(name=\"lenslight\")"
"lnslt = caustics.Sersic(name=\"lenslight\")"
]
},
{
Expand All @@ -116,7 +116,7 @@
"metadata": {},
"outputs": [],
"source": [
"minisim = caustics.sims.Lens_Source(\n",
"minisim = caustics.Lens_Source(\n",
" lens=sie, source=src, lens_light=lnslt, pixelscale=0.05, pixels_x=100\n",
")"
]
Expand Down
16 changes: 8 additions & 8 deletions docs/source/tutorials/InvertLensEquation.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "markdown",
"id": "b7d08f1d",
"id": "0",
"metadata": {},
"source": [
"# Inverting the Lens Equation\n",
Expand All @@ -13,7 +13,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "4027aaf9",
"id": "1",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -36,13 +36,13 @@
{
"cell_type": "code",
"execution_count": null,
"id": "2118e1c1",
"id": "2",
"metadata": {},
"outputs": [],
"source": [
"# initialization stuff for an SIE lens\n",
"\n",
"cosmology = caustics.cosmology.FlatLambdaCDM(name=\"cosmo\")\n",
"cosmology = caustics.FlatLambdaCDM(name=\"cosmo\")\n",
"cosmology.to(dtype=torch.float32)\n",
"n_pix = 100\n",
"res = 0.05\n",
Expand All @@ -56,7 +56,7 @@
")\n",
"z_l = torch.tensor(0.5, dtype=torch.float32)\n",
"z_s = torch.tensor(1.5, dtype=torch.float32)\n",
"lens = caustics.lenses.SIE(\n",
"lens = caustics.SIE(\n",
" cosmology=cosmology,\n",
" name=\"sie\",\n",
" z_l=z_l,\n",
Expand All @@ -72,7 +72,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "98e46aa1",
"id": "3",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -90,7 +90,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "eb73147c",
"id": "4",
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -122,7 +122,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "e9f2d09f-6327-4d01-8d62-baa749ffc621",
"id": "5",
"metadata": {},
"outputs": [],
"source": []
Expand Down
Loading

0 comments on commit a6e40f2

Please sign in to comment.