-
Notifications
You must be signed in to change notification settings - Fork 755
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
Add typing and type annotations for icbc #1453
base: master
Are you sure you want to change the base?
Add typing and type annotations for icbc #1453
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some suggestions 🙂
Given that DeepXDE supports only Python 3.8+, we can use -
from __future__ import annotations
to stay up to date!
I have made a few suggestions regarding the comment above - the rest of the types can be revamped accordingly too!
Also, mypy
should be added in the CI to make sure that the types are correct and are being respected throughout the codebase. You can add mypy's configuration in pyproject.toml
. This can maybe go in another PR.
(PS: these are just suggestions, the final call would be of DeepXDE's maintainers.)
deepxde/icbc/boundary_conditions.py
Outdated
@@ -14,27 +14,37 @@ | |||
import numbers | |||
from abc import ABC, abstractmethod | |||
from functools import wraps | |||
from typing import Any, Callable, List, Optional, overload, Tuple, Union |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given that DeepXDE
supports Python 3.8+, you should use -
from __future__ import annotations
from typing import Any, Callable, Optional, overload
deepxde/icbc/boundary_conditions.py
Outdated
outputs: Tensor, | ||
beg: int, | ||
end: int, | ||
aux_var: Union[NDArray[np.float_], None] = None, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should work once the suggestion above is applied.
aux_var: Union[NDArray[np.float_], None] = None, | |
aux_var: NDArray[np.float_] | None = None, |
deepxde/icbc/boundary_conditions.py
Outdated
geom: Geometry, | ||
func: Callable[[NDArray[np.float_]], NDArray[np.float_]], | ||
on_boundary: Callable[[NDArray[Any], NDArray[Any]], NDArray[np.bool_]], | ||
component: Union[List[int], int] = 0, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
component: Union[List[int], int] = 0, | |
component: list[int] | int = 0, |
deepxde/types.py
Outdated
|
||
# Tensor from any backend | ||
Tensor = TypeVar("Tensor") | ||
TensorOrTensors = Union[Tensor, Sequence[Tensor]] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TensorOrTensors = Union[Tensor, Sequence[Tensor]] | |
TensorOrTensors = Tensor | Sequence[Tensor] | |
deepxde/types.py
Outdated
@@ -0,0 +1,7 @@ | |||
import numpy as np | |||
from typing import Callable, Dict, List, Optional, Sequence, Tuple, Union, TypeVar |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
from typing import Callable, Dict, List, Optional, Sequence, Tuple, Union, TypeVar | |
from __future__ import annotations | |
from typing import Sequence, TypeVar |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your suggestions, I will change them later 👍
Good suggestions @Saransh-cpp |
creating an extra file called
types.py
, referred from torch.