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

style: Activated Mypy Checks and Code Update for Compliance #58

Merged
merged 2 commits into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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
16 changes: 8 additions & 8 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,14 @@ repos:
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 Down
23 changes: 12 additions & 11 deletions src/caustics/cosmology.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# mypy: disable-error-code="operator"
from abc import abstractmethod
from math import pi
from typing import Optional
Expand Down Expand Up @@ -56,7 +57,7 @@ class Cosmology(Parametrized):
Name of the cosmological model.
"""

def __init__(self, name: str = None):
def __init__(self, name: Optional[str] = None):
"""
Initialize the Cosmology.

Expand Down Expand Up @@ -296,7 +297,7 @@ def __init__(
h0: Optional[Tensor] = torch.tensor(h0_default),
critical_density_0: Optional[Tensor] = torch.tensor(critical_density_0_default),
Om0: Optional[Tensor] = torch.tensor(Om0_default),
name: str = None,
name: Optional[str] = None,
):
"""
Initialize a new instance of the FlatLambdaCDM class.
Expand Down Expand Up @@ -358,9 +359,9 @@ def critical_density(
z: Tensor,
*args,
params: Optional["Packed"] = None,
h0: Tensor = None,
critical_density_0: Tensor = None,
Om0: Tensor = None,
h0: Optional[Tensor] = None,
critical_density_0: Optional[Tensor] = None,
Om0: Optional[Tensor] = None,
**kwargs,
) -> torch.Tensor:
"""
Expand Down Expand Up @@ -410,9 +411,9 @@ def comoving_distance(
z: Tensor,
*args,
params: Optional["Packed"] = None,
h0: Tensor = None,
critical_density_0: Tensor = None,
Om0: Tensor = None,
h0: Optional[Tensor] = None,
critical_density_0: Optional[Tensor] = None,
Om0: Optional[Tensor] = None,
**kwargs,
) -> Tensor:
"""
Expand Down Expand Up @@ -443,9 +444,9 @@ def transverse_comoving_distance(
z: Tensor,
*args,
params: Optional["Packed"] = None,
h0: Tensor = None,
critical_density_0: Tensor = None,
Om0: Tensor = None,
h0: Optional[Tensor] = None,
critical_density_0: Optional[Tensor] = None,
Om0: Optional[Tensor] = None,
**kwargs,
) -> Tensor:
return self.comoving_distance(z, params, **kwargs)
13 changes: 7 additions & 6 deletions src/caustics/lenses/base.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# mypy: disable-error-code="call-overload"
from abc import abstractmethod
from typing import Optional, Union
from functools import partial
Expand All @@ -21,7 +22,7 @@ class Lens(Parametrized):
Base class for all lenses
"""

def __init__(self, cosmology: Cosmology, name: str = None):
def __init__(self, cosmology: Cosmology, name: Optional[str] = None):
"""
Initializes a new instance of the Lens class.

Expand Down Expand Up @@ -609,7 +610,7 @@ def __init__(
self,
cosmology: Cosmology,
z_l: Optional[Union[Tensor, float]] = None,
name: str = None,
name: Optional[str] = None,
):
super().__init__(cosmology=cosmology, name=name)
self.add_param("z_l", z_l)
Expand All @@ -622,7 +623,7 @@ def reduced_deflection_angle(
z_s: Tensor,
*args,
params: Optional["Packed"] = None,
z_l: Tensor = None,
z_l: Optional[Tensor] = None,
**kwargs,
) -> tuple[Tensor, Tensor]:
"""
Expand Down Expand Up @@ -662,7 +663,7 @@ def physical_deflection_angle(
z_s: Tensor,
*args,
params: Optional["Packed"] = None,
z_l: Tensor = None,
z_l: Optional[Tensor] = None,
**kwargs,
) -> tuple[Tensor, Tensor]:
"""
Expand Down Expand Up @@ -766,7 +767,7 @@ def surface_density(
z_s: Tensor,
*args,
params: Optional["Packed"] = None,
z_l: Tensor = None,
z_l: Optional[Tensor] = None,
**kwargs,
) -> Tensor:
"""
Expand Down Expand Up @@ -844,7 +845,7 @@ def time_delay(
z_s: Tensor,
*args,
params: Optional["Packed"] = None,
z_l: Tensor = None,
z_l: Optional[Tensor] = None,
shapiro_time_delay: bool = True,
geometric_time_delay: bool = True,
**kwargs,
Expand Down
49 changes: 25 additions & 24 deletions src/caustics/lenses/epl.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# mypy: disable-error-code="operator"
from typing import Optional, Union

import torch
Expand Down Expand Up @@ -80,7 +81,7 @@ def __init__(
t: Optional[Union[Tensor, float]] = None,
s: float = 0.0,
n_iter: int = 18,
name: str = None,
name: Optional[str] = None,
):
"""
Initialize an EPL lens model.
Expand Down Expand Up @@ -137,13 +138,13 @@ def reduced_deflection_angle(
z_s: Tensor,
*args,
params: Optional["Packed"] = None,
z_l: Tensor = None,
x0: Tensor = None,
y0: Tensor = None,
q: Tensor = None,
phi: Tensor = None,
b: Tensor = None,
t: Tensor = None,
z_l: Optional[Tensor] = None,
x0: Optional[Tensor] = None,
y0: Optional[Tensor] = None,
q: Optional[Tensor] = None,
phi: Optional[Tensor] = None,
b: Optional[Tensor] = None,
t: Optional[Tensor] = None,
**kwargs,
) -> tuple[Tensor, Tensor]:
"""
Expand Down Expand Up @@ -220,13 +221,13 @@ def potential(
z_s: Tensor,
*args,
params: Optional["Packed"] = None,
z_l: Tensor = None,
x0: Tensor = None,
y0: Tensor = None,
q: Tensor = None,
phi: Tensor = None,
b: Tensor = None,
t: Tensor = None,
z_l: Optional[Tensor] = None,
x0: Optional[Tensor] = None,
y0: Optional[Tensor] = None,
q: Optional[Tensor] = None,
phi: Optional[Tensor] = None,
b: Optional[Tensor] = None,
t: Optional[Tensor] = None,
**kwargs,
):
"""
Expand All @@ -251,7 +252,7 @@ def potential(
ax, ay = self.reduced_deflection_angle(x, y, z_s, params)
ax, ay = derotate(ax, ay, -phi)
x, y = translate_rotate(x, y, x0, y0, phi)
return (x * ax + y * ay) / (2 - t)
return (x * ax + y * ay) / (2 - t) # fmt: skip

@unpack
def convergence(
Expand All @@ -261,15 +262,15 @@ def convergence(
z_s: Tensor,
*args,
params: Optional["Packed"] = None,
z_l: Tensor = None,
x0: Tensor = None,
y0: Tensor = None,
q: Tensor = None,
phi: Tensor = None,
b: Tensor = None,
t: Tensor = None,
z_l: Optional[Tensor] = None,
x0: Optional[Tensor] = None,
y0: Optional[Tensor] = None,
q: Optional[Tensor] = None,
phi: Optional[Tensor] = None,
b: Optional[Tensor] = None,
t: Optional[Tensor] = None,
**kwargs,
):
) -> Tensor:
"""
Compute the convergence of the lens, which describes the local density of the lens.

Expand Down
32 changes: 16 additions & 16 deletions src/caustics/lenses/external_shear.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def __init__(
gamma_1: Optional[Union[Tensor, float]] = None,
gamma_2: Optional[Union[Tensor, float]] = None,
s: float = 0.0,
name: str = None,
name: Optional[str] = None,
):
super().__init__(cosmology, z_l, name=name)

Expand All @@ -68,11 +68,11 @@ def reduced_deflection_angle(
z_s: Tensor,
*args,
params: Optional["Packed"] = None,
z_l: Tensor = None,
x0: Tensor = None,
y0: Tensor = None,
gamma_1: Tensor = None,
gamma_2: Tensor = None,
z_l: Optional[Tensor] = None,
x0: Optional[Tensor] = None,
y0: Optional[Tensor] = None,
gamma_1: Optional[Tensor] = None,
gamma_2: Optional[Tensor] = None,
**kwargs,
) -> tuple[Tensor, Tensor]:
"""
Expand Down Expand Up @@ -113,11 +113,11 @@ def potential(
z_s: Tensor,
*args,
params: Optional["Packed"] = None,
z_l: Tensor = None,
x0: Tensor = None,
y0: Tensor = None,
gamma_1: Tensor = None,
gamma_2: Tensor = None,
z_l: Optional[Tensor] = None,
x0: Optional[Tensor] = None,
y0: Optional[Tensor] = None,
gamma_1: Optional[Tensor] = None,
gamma_2: Optional[Tensor] = None,
**kwargs,
) -> Tensor:
"""
Expand Down Expand Up @@ -151,11 +151,11 @@ def convergence(
z_s: Tensor,
*args,
params: Optional["Packed"] = None,
z_l: Tensor = None,
x0: Tensor = None,
y0: Tensor = None,
gamma_1: Tensor = None,
gamma_2: Tensor = None,
z_l: Optional[Tensor] = None,
x0: Optional[Tensor] = None,
y0: Optional[Tensor] = None,
gamma_1: Optional[Tensor] = None,
gamma_2: Optional[Tensor] = None,
**kwargs,
) -> Tensor:
"""
Expand Down
27 changes: 14 additions & 13 deletions src/caustics/lenses/mass_sheet.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# mypy: disable-error-code="operator"
from typing import Optional, Union

import torch
Expand Down Expand Up @@ -48,7 +49,7 @@ def __init__(
x0: Optional[Union[Tensor, float]] = None,
y0: Optional[Union[Tensor, float]] = None,
surface_density: Optional[Union[Tensor, float]] = None,
name: str = None,
name: Optional[str] = None,
):
super().__init__(cosmology, z_l, name=name)

Expand All @@ -64,10 +65,10 @@ def reduced_deflection_angle(
z_s: Tensor,
*args,
params: Optional["Packed"] = None,
z_l: Tensor = None,
x0: Tensor = None,
y0: Tensor = None,
surface_density: Tensor = None,
z_l: Optional[Tensor] = None,
x0: Optional[Tensor] = None,
y0: Optional[Tensor] = None,
surface_density: Optional[Tensor] = None,
**kwargs,
) -> tuple[Tensor, Tensor]:
"""
Expand Down Expand Up @@ -103,10 +104,10 @@ def potential(
z_s: Tensor,
*args,
params: Optional["Packed"] = None,
z_l: Tensor = None,
x0: Tensor = None,
y0: Tensor = None,
surface_density: Tensor = None,
z_l: Optional[Tensor] = None,
x0: Optional[Tensor] = None,
y0: Optional[Tensor] = None,
surface_density: Optional[Tensor] = None,
**kwargs,
) -> Tensor:
# Meneghetti eq 3.81
Expand All @@ -120,10 +121,10 @@ def convergence(
z_s: Tensor,
*args,
params: Optional["Packed"] = None,
z_l: Tensor = None,
x0: Tensor = None,
y0: Tensor = None,
surface_density: Tensor = None,
z_l: Optional[Tensor] = None,
x0: Optional[Tensor] = None,
y0: Optional[Tensor] = None,
surface_density: Optional[Tensor] = None,
**kwargs,
) -> Tensor:
# Essentially by definition
Expand Down
4 changes: 3 additions & 1 deletion src/caustics/lenses/multiplane.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ class Multiplane(ThickLens):
List of thin lenses.
"""

def __init__(self, cosmology: Cosmology, lenses: list[ThinLens], name: str = None):
def __init__(
self, cosmology: Cosmology, lenses: list[ThinLens], name: Optional[str] = None
):
super().__init__(cosmology, name=name)
self.lenses = lenses
for lens in lenses:
Expand Down
Loading
Loading