Skip to content

Commit

Permalink
Keyword only arguments. Update simphony/libraries/sipann.py. Clarify …
Browse files Browse the repository at this point in the history
…description in docs/tutorials/intro.ipynb and add link to PEP 3102.
  • Loading branch information
mm13000 committed Sep 30, 2024
1 parent 624e351 commit 50187ac
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
5 changes: 3 additions & 2 deletions docs/tutorials/intro.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@
"import sax\n",
"from jax.typing import ArrayLike\n",
"\n",
"def custom_model(param: float = 0.5) -> sax.SDict:\n",
"def custom_model(*, param: float = 0.5) -> sax.SDict:\n",
" \"\"\"This model will have one parameter, param, which defaults to 0.5.\n",
" \n",
" Args:\n",
Expand Down Expand Up @@ -164,10 +164,11 @@
"\n",
"* [Python 3 guide for scientists](https://python-3-for-scientists.readthedocs.io/en/latest/python3_advanced.html)\n",
"* [Luke Plant's Blog](https://lukeplant.me.uk/blog/posts/keyword-only-arguments-in-python/)\n",
"* [PEP 3102: Keyword-Only Arguments](https://peps.python.org/pep-3102/)\n",
"```\n",
"\n",
"```{important}\n",
"Model function parameters **are required to be keyword-only**.\n",
"Model function parameters **are required to be keyword-only**. Syntactically, this means the first argument in the function definition must be `*`.\n",
"```\n",
"\n",
"* In the backend, SAX inspects the model signature and passes in only the requested variables to the model function. \n",
Expand Down
10 changes: 10 additions & 0 deletions simphony/libraries/sipann.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ def _create_sdict_from_model(model, wl: Union[float, ArrayLike]) -> sax.SDict:


def gap_func_symmetric(
*,
wl: Union[float, ArrayLike] = 1.55,
width: float = 500.0,
thickness: float = 220.0,
Expand Down Expand Up @@ -110,6 +111,7 @@ def gap_func_symmetric(


def gap_func_antisymmetric(
*,
wl: Union[float, ArrayLike] = 1.55,
width: float = 500.0,
thickness: float = 220.0,
Expand Down Expand Up @@ -178,6 +180,7 @@ def gap_func_antisymmetric(


def half_ring(
*,
wl: Union[float, ArrayLike] = 1.55,
width: float = 500.0,
thickness: float = 220.0,
Expand Down Expand Up @@ -230,6 +233,7 @@ def half_ring(


def straight_coupler(
*,
wl: Union[float, ArrayLike] = 1.55,
width: float = 500.0,
thickness: float = 220.0,
Expand Down Expand Up @@ -280,6 +284,7 @@ def straight_coupler(


def standard_coupler(
*,
wl: Union[float, ArrayLike] = 1.55,
width: float = 500.0,
thickness: float = 220.0,
Expand Down Expand Up @@ -339,6 +344,7 @@ def standard_coupler(


def double_half_ring(
*,
wl: Union[float, ArrayLike] = 1.55,
width: float = 500.0,
thickness: float = 220.0,
Expand Down Expand Up @@ -393,6 +399,7 @@ def double_half_ring(


def angled_half_ring(
*,
wl: Union[float, ArrayLike] = 1.55,
width: float = 500.0,
thickness: float = 220.0,
Expand Down Expand Up @@ -457,6 +464,7 @@ def angled_half_ring(


def waveguide(
*,
wl: Union[float, ArrayLike] = 1.55,
width: float = 500.0,
thickness: float = 220.0,
Expand Down Expand Up @@ -496,6 +504,7 @@ def waveguide(


def racetrack(
*,
wl: Union[float, ArrayLike] = 1.55,
width: float = 500.0,
thickness: float = 220.0,
Expand Down Expand Up @@ -554,6 +563,7 @@ def racetrack(


def premade_coupler(
*,
wl: Union[float, ArrayLike] = 1.55,
split: int = 50,
) -> sax.SDict:
Expand Down

0 comments on commit 50187ac

Please sign in to comment.