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

add type annotations to Simulation class #1919

Merged
merged 7 commits into from
Feb 4, 2022
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
68 changes: 34 additions & 34 deletions doc/docs/Python_User_Interface.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,40 +87,40 @@ control various parameters of the Meep computation.

```python
def __init__(self,
cell_size,
resolution,
geometry=None,
sources=None,
eps_averaging=True,
dimensions=3,
boundary_layers=None,
symmetries=None,
force_complex_fields=False,
default_material=Medium(),
m=0,
k_point=False,
kz_2d='complex',
extra_materials=None,
material_function=None,
epsilon_func=None,
epsilon_input_file='',
progress_interval=4,
subpixel_tol=0.0001,
subpixel_maxeval=100000,
loop_tile_base_db=0,
loop_tile_base_eh=0,
ensure_periodicity=True,
num_chunks=0,
Courant=0.5,
accurate_fields_near_cylorigin=False,
filename_prefix=None,
output_volume=None,
output_single_precision=False,
geometry_center=Vector3<0.0, 0.0, 0.0>,
force_all_components=False,
split_chunks_evenly=True,
cell_size: Union[meep.geom.Vector3, Tuple[float, ...], Tuple[int, ...], NoneType] = None,
resolution: float = None,
stevengj marked this conversation as resolved.
Show resolved Hide resolved
geometry: Optional[List[meep.geom.GeometricObject]] = None,
sources: Optional[List[meep.source.Source]] = None,
eps_averaging: bool = True,
dimensions: int = 3,
boundary_layers: Optional[List[meep.simulation.PML]] = None,
symmetries: Optional[List[meep.simulation.Symmetry]] = None,
force_complex_fields: bool = False,
default_material: meep.geom.Medium = Medium(),
m: float = 0,
k_point: Union[meep.geom.Vector3, Tuple[float, ...], Tuple[int, ...], bool] = False,
kz_2d: str = 'complex',
extra_materials: Optional[List[meep.geom.Medium]] = None,
material_function: Optional[Callable[[Union[meep.geom.Vector3, Tuple[float, ...], Tuple[int, ...]]], meep.geom.Medium]] = None,
epsilon_func: Optional[Callable[[Union[meep.geom.Vector3, Tuple[float, ...], Tuple[int, ...]]], float]] = None,
epsilon_input_file: str = '',
progress_interval: float = 4,
subpixel_tol: float = 0.0001,
subpixel_maxeval: int = 100000,
loop_tile_base_db: int = 0,
loop_tile_base_eh: int = 0,
ensure_periodicity: bool = True,
num_chunks: int = 0,
Courant: float = 0.5,
accurate_fields_near_cylorigin: bool = False,
filename_prefix: Optional[str] = None,
output_volume: Optional[meep.simulation.Volume] = None,
output_single_precision: bool = False,
geometry_center: Union[meep.geom.Vector3, Tuple[float, ...], Tuple[int, ...]] = Vector3<0.0, 0.0, 0.0>,
force_all_components: bool = False,
split_chunks_evenly: bool = True,
chunk_layout=None,
collect_stats=False):
collect_stats: bool = False):
```

<div class="method_docstring" markdown="1">
Expand Down Expand Up @@ -152,7 +152,7 @@ Python. `Vector3` is a `meep` class.

+ **`boundary_layers` [ list of `PML` class ]** — Specifies the
[PML](Perfectly_Matched_Layer.md) absorbing boundary layers to use. Defaults to
none.
none (empty list).

+ **`cell_size` [ `Vector3` ]** — Specifies the size of the cell which is centered
on the origin of the coordinate system. Any sizes of 0 imply a
Expand Down
77 changes: 40 additions & 37 deletions python/simulation.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# -*- coding: utf-8 -*-
from __future__ import division, print_function

from typing import Callable, List, Tuple, Union, Optional

import functools
import math
import numbers
Expand All @@ -21,8 +23,8 @@
import numpy as np

import meep as mp
from meep.geom import Vector3, init_do_averaging
from meep.source import EigenModeSource, GaussianBeamSource, IndexedSource, check_positive
from meep.geom import Vector3, init_do_averaging, GeometricObject, Medium
from meep.source import Source, EigenModeSource, GaussianBeamSource, IndexedSource, check_positive
import meep.visualization as vis
from meep.verbosity_mgr import Verbosity

Expand Down Expand Up @@ -168,6 +170,7 @@ def p(self):
return self._p

DefaultPMLProfile = lambda u: u * u
Vector3Type = Union[Vector3, Tuple[float, ...], Tuple[int, ...]]

class PML(object):
"""
Expand Down Expand Up @@ -933,40 +936,40 @@ class Simulation(object):
control various parameters of the Meep computation.
"""
def __init__(self,
cell_size,
resolution,
geometry=None,
sources=None,
eps_averaging=True,
dimensions=3,
boundary_layers=None,
symmetries=None,
force_complex_fields=False,
default_material=mp.Medium(),
m=0,
k_point=False,
kz_2d="complex",
extra_materials=None,
material_function=None,
epsilon_func=None,
epsilon_input_file='',
progress_interval=4,
subpixel_tol=1e-4,
subpixel_maxeval=100000,
loop_tile_base_db=0,
loop_tile_base_eh=0,
ensure_periodicity=True,
num_chunks=0,
Courant=0.5,
accurate_fields_near_cylorigin=False,
filename_prefix=None,
output_volume=None,
output_single_precision=False,
geometry_center=mp.Vector3(),
force_all_components=False,
split_chunks_evenly=True,
chunk_layout=None,
collect_stats=False):
cell_size: Optional[Vector3Type] = None,
resolution: float = None,
geometry: Optional[List[GeometricObject]] = None,
sources: Optional[List[Source]] = None,
eps_averaging: bool = True,
dimensions: int = 3,
boundary_layers: Optional[List[PML]] = None,
symmetries: Optional[List[Symmetry]] = None,
force_complex_fields: bool = False,
default_material: Medium = mp.Medium(),
m: float = 0,
k_point: Union[Vector3Type, bool] = False,
kz_2d: str = "complex",
extra_materials: Optional[List[Medium]] = None,
material_function: Optional[Callable[[Vector3Type], Medium]] = None,
epsilon_func: Optional[Callable[[Vector3Type], float]] = None,
epsilon_input_file: str = '',
progress_interval: float = 4,
subpixel_tol: float = 1e-4,
subpixel_maxeval: int = 100000,
loop_tile_base_db: int = 0,
loop_tile_base_eh: int = 0,
ensure_periodicity: bool = True,
num_chunks: int = 0,
Courant: float = 0.5,
accurate_fields_near_cylorigin: bool = False,
filename_prefix: Optional[str] = None,
output_volume: Optional[Volume] = None,
output_single_precision: bool = False,
geometry_center: Vector3Type = Vector3(),
force_all_components: bool = False,
split_chunks_evenly: bool = True,
chunk_layout = None,
collect_stats: bool = False):
"""
All `Simulation` attributes are described in further detail below. In brackets
after each variable is the type of value that it should hold. The classes, complex
Expand Down Expand Up @@ -995,7 +998,7 @@ def __init__(self,

+ **`boundary_layers` [ list of `PML` class ]** — Specifies the
[PML](Perfectly_Matched_Layer.md) absorbing boundary layers to use. Defaults to
none.
none (empty list).

+ **`cell_size` [ `Vector3` ]** — Specifies the size of the cell which is centered
on the origin of the coordinate system. Any sizes of 0 imply a
Expand Down