diff --git a/emulsim/actors/autonomous/active_particles.py b/emulsim/actors/autonomous/active_particles.py index 274f208..3ea0be0 100644 --- a/emulsim/actors/autonomous/active_particles.py +++ b/emulsim/actors/autonomous/active_particles.py @@ -94,7 +94,7 @@ def evolver(state_data: tuple[np.ndarray], t: float, dt: float) -> None: # higher dimensions are not currently supported raise NotImplementedError - return evolver # type: ignore + return evolver def evolve(self, elements: ElementsType, t: float, dt: float) -> None: """Evolve the field state from time `t` to `t + dt` diff --git a/emulsim/actors/autonomous/box.py b/emulsim/actors/autonomous/box.py index 636b7cd..17ba50e 100644 --- a/emulsim/actors/autonomous/box.py +++ b/emulsim/actors/autonomous/box.py @@ -142,7 +142,7 @@ def evolver(state_data: tuple[np.ndarray], t: float, dt: float) -> None: arg = (dist_left) % (2 * size_red) - size_red pos[ax] = xmin[ax] + radius + abs(arg) - return evolver # type: ignore + return evolver def evolve(self, elements: ElementsType, t: float, dt: float) -> None: """Evolve the field state from time `t` to `t + dt` diff --git a/emulsim/actors/autonomous/brownian_motion.py b/emulsim/actors/autonomous/brownian_motion.py index 96b21a6..ec66193 100644 --- a/emulsim/actors/autonomous/brownian_motion.py +++ b/emulsim/actors/autonomous/brownian_motion.py @@ -111,7 +111,7 @@ def evolver(state_data: tuple[np.ndarray], t: float, dt: float): for i in range(dim): droplet_data.position[i] += scale * np.random.randn() - return evolver # type: ignore + return evolver def evolve(self, elements: ElementsType, t: float, dt: float) -> None: """Evolve the state from time `t` to `t + dt` diff --git a/emulsim/actors/autonomous/coalescence.py b/emulsim/actors/autonomous/coalescence.py index 2dc3d53..df597c1 100644 --- a/emulsim/actors/autonomous/coalescence.py +++ b/emulsim/actors/autonomous/coalescence.py @@ -30,7 +30,7 @@ def fill_with_zeros(recarr: np.recarray) -> None: @overload(fill_with_zeros) def ol_fill_with_zeros(recarr: np.recarray) -> Callable[[np.recarray], None]: """Create numba implementation to fill a record array with zeros.""" - keys = tuple(recarr.dtype.fields.keys()) # type: ignore + keys = tuple(recarr.dtype.fields.keys()) def fill_with_zeros_impl(recarr: np.recarray) -> None: """Numba implementation to fill a record array with zeros.""" @@ -88,7 +88,7 @@ def evolver(state_data: tuple[np.ndarray], t: float, dt: float): fill_with_zeros(data[i1]) break # droplet with index i1 has been removed -> continue - return evolver # type: ignore + return evolver def evolve(self, elements: ElementsType, t: float, dt: float) -> None: """Evolve the field state from time `t` to `t + dt` diff --git a/emulsim/actors/autonomous/emitters.py b/emulsim/actors/autonomous/emitters.py index 77728d2..d926df6 100644 --- a/emulsim/actors/autonomous/emitters.py +++ b/emulsim/actors/autonomous/emitters.py @@ -89,7 +89,7 @@ def evolver(state_data: tuple[np.ndarray], t: float, dt: float): for i in range(num_emitters): add_amount(state_data[0], positions[i], dt * strengths[i]) - return evolver # type: ignore + return evolver def evolve(self, elements: ElementsType, t: float, dt: float) -> None: """Evolve the field state from time `t` to `t + dt` diff --git a/emulsim/actors/autonomous/fields.py b/emulsim/actors/autonomous/fields.py index 101929b..acca638 100644 --- a/emulsim/actors/autonomous/fields.py +++ b/emulsim/actors/autonomous/fields.py @@ -103,7 +103,7 @@ def evolver(fields_data: tuple[np.ndarray], t: float, dt: float) -> None: (field_data,) = fields_data field_data += dt * reation_flux(field_data, t) - return evolver # type: ignore + return evolver def evolve(self, elements: tuple[FieldElementBase], t: float, dt: float): # type: ignore """Evolve the field from time `t` to `t + dt` @@ -177,7 +177,7 @@ def evolver(fields_data: tuple[np.ndarray], t: float, dt: float) -> None: (field_data,) = fields_data field_data += dt * pde_rhs(field_data, t) - return evolver # type: ignore + return evolver def evolve(self, elements: tuple[ScalarFieldElement], t: float, dt: float): # type: ignore """Evolve the field from time `t` to `t + dt` @@ -322,9 +322,9 @@ def estimate_dt(self, elements: tuple[ScalarFieldElement]) -> float: # type: ig s_max = 0 for c in np.linspace(0, 1, 32): test_field.data = c - rates = self.pde.evolution_rate(test_field) # type: ignore + rates = self.pde.evolution_rate(test_field) s_max = max(s_max, np.max(np.abs(rates.data))) - diffusivity = self.parameters["diffusivity"] # type: ignore + diffusivity = self.parameters["diffusivity"] if s_max == 0: dt_reaction = float("inf") @@ -369,7 +369,7 @@ def evolver(fields_data: tuple[np.ndarray], t: float, dt: float) -> None: (field_data,) = fields_data field_data += dt * pde_rhs(field_data[np.newaxis, ...], t)[0] - return evolver # type: ignore + return evolver def evolve(self, elements: tuple[ScalarFieldElement], t: float, dt: float): # type: ignore """Evolve the field from time `t` to `t + dt` @@ -444,7 +444,7 @@ def evolver(fields_data: tuple[np.ndarray], t: float, dt: float) -> None: (field_data,) = fields_data field_data += dt * pde_rhs(field_data, t) - return evolver # type: ignore + return evolver def evolve(self, elements: tuple[FieldCollectionElement], t: float, dt: float): # type: ignore """Evolve the field from time `t` to `t + dt` diff --git a/emulsim/actors/coupling/fields.py b/emulsim/actors/coupling/fields.py index 76a9786..0a42c2e 100644 --- a/emulsim/actors/coupling/fields.py +++ b/emulsim/actors/coupling/fields.py @@ -137,7 +137,7 @@ def wrap(state_data: tuple[np.ndarray], t: float, dt: float) -> None: return chain(expression_id + 1, inner=wrap) else: # this is the outermost function - return wrap # type: ignore + return wrap # compile the recursive chain return chain(0, innermost) @@ -279,7 +279,7 @@ def evolver( field1 -= dt * flux field2 += dt * flux - return evolver # type: ignore + return evolver def evolve( self, @@ -520,7 +520,7 @@ def evolver( else: raise NotImplementedError - return evolver # type: ignore + return evolver def evolve(self, fields: ElementsType, t: float, dt: float) -> None: """Evolve the state from time `t` to `t + dt` diff --git a/emulsim/actors/coupling/multicomponent_droplet.py b/emulsim/actors/coupling/multicomponent_droplet.py index 54feee3..1c83c36 100644 --- a/emulsim/actors/coupling/multicomponent_droplet.py +++ b/emulsim/actors/coupling/multicomponent_droplet.py @@ -108,7 +108,7 @@ def regularize(phi: np.ndarray) -> np.ndarray: return correction - return regularize # type: ignore + return regularize class MulticomponentDropletActor(ActorBase): @@ -339,7 +339,7 @@ def calc_state_vars(phis: np.ndarray) -> tuple[float, np.ndarray, float]: return f, mu, p - return calc_state_vars # type: ignore + return calc_state_vars def _update_cache(self, elements: ActorElementType) -> None: """Prepare the simulation doing pre-calculations. @@ -639,7 +639,7 @@ def evolver( with nb.objmode: self.diagnostics["amount_corrections"] += amount_corrections - return evolver # type: ignore + return evolver def evolve(self, elements: ActorElementType, t: float, dt: float) -> None: # type: ignore """Evolve the state from time `t` to `t + dt` diff --git a/emulsim/actors/coupling/nucleation.py b/emulsim/actors/coupling/nucleation.py index d81ecab..a440b59 100644 --- a/emulsim/actors/coupling/nucleation.py +++ b/emulsim/actors/coupling/nucleation.py @@ -6,6 +6,7 @@ from __future__ import annotations from collections.abc import Callable +from typing import Any import numpy as np @@ -165,7 +166,7 @@ def estimate_dt(self, elements: ActorElementType) -> float: # type: ignore _, field = elements nucl_rate_cell = field.grid.cell_volumes * self.nucleation_rate(field).data bare_rate = self.parameters["prefactor"] - return 1 / max(bare_rate, nucl_rate_cell.max()) + return 1 / max(bare_rate, nucl_rate_cell.max()) # type: ignore def estimate_nucleation_count( self, field: FieldElementBase, t_range: float @@ -261,7 +262,7 @@ def evolver( amount_out = cEqIn * volume(droplet_data.radius) add_amount(field_data, droplet_data.position, -amount_out) - return evolver # type: ignore + return evolver def evolve(self, elements: ActorElementType, t: float, dt: float) -> None: # type: ignore """Evolve the state from time `t` to `t + dt` diff --git a/emulsim/actors/coupling/point_droplet.py b/emulsim/actors/coupling/point_droplet.py index 35bb7ab..f569121 100644 --- a/emulsim/actors/coupling/point_droplet.py +++ b/emulsim/actors/coupling/point_droplet.py @@ -404,7 +404,7 @@ def evolver( if droplet_data.radius > 0: droplet_update(droplet_data, droplet_id, field_data, t, dt) - return evolver # type: ignore + return evolver def evolve(self, elements: ActorElementType, t: float, dt: float) -> None: # type: ignore """Evolve the state from time `t` to `t + dt` diff --git a/emulsim/actors/coupling/spherical_droplet.py b/emulsim/actors/coupling/spherical_droplet.py index 2e226f8..34efa39 100644 --- a/emulsim/actors/coupling/spherical_droplet.py +++ b/emulsim/actors/coupling/spherical_droplet.py @@ -85,7 +85,7 @@ def haversine_distance(point1: np.ndarray, point2: np.ndarray) -> np.ndarray: # spherical coordinates - φ differs by π/4 factor = (1 - np.cos(λ2 - λ1)) / 2 arg = (1 - np.cos(φ2 - φ1)) / 2 + np.sin(φ1) * np.sin(φ2) * factor - return 2 * r1 * np.arcsin(np.sqrt(arg)) + return 2 * r1 * np.arcsin(np.sqrt(arg)) # type: ignore def get_spherical_polygon_area(vertices: np.ndarray, radius: float = 1) -> float: @@ -415,7 +415,7 @@ def get_shell(radius: float) -> tuple[np.ndarray, np.ndarray]: """Compiled helper function that extracts shell parameters.""" return vectors, weights - return get_shell # type: ignore + return get_shell class ShellCollection: @@ -629,7 +629,7 @@ def get_shell(radius: float) -> tuple[np.ndarray, np.ndarray]: i = int(min(np.searchsorted(max_radii, radius), num - 1)) # type: ignore return vectors[i], weights[i] - return get_shell # type: ignore + return get_shell ActorElementType = tuple[SphericalDropletsElement, FieldElementBase] @@ -677,7 +677,7 @@ def normalize_point(point: FloatingArray) -> None: point[i] = xmin[i] + abs(arg) # else: do nothing - return normalize_point # type: ignore + return normalize_point class SphericalDropletActor(ActorBase): diff --git a/emulsim/actors/function.py b/emulsim/actors/function.py index dc721a6..291fddc 100644 --- a/emulsim/actors/function.py +++ b/emulsim/actors/function.py @@ -131,7 +131,7 @@ def make_evolver_numba(self, elements: ElementsType) -> EvolverType: # actually compile the function since it seemed to have passed the test try: - return jit(self.func) # type: ignore + return jit(self.func) except (RuntimeError, TypingError) as err: self._logger.warning("Could not compile user-supplied function") raise NotImplementedError from err diff --git a/emulsim/elements/base.py b/emulsim/elements/base.py index ab41f52..55ea305 100644 --- a/emulsim/elements/base.py +++ b/emulsim/elements/base.py @@ -632,7 +632,7 @@ def error_estimator(data1: np.ndarray, data2: np.ndarray) -> float: field_names = tuple(arr.dtype.fields.keys()) @jit - def error_estimator(data1: np.ndarray, data2: np.ndarray) -> float: + def error_estimator(data1: np.ndarray, data2: np.ndarray) -> float: # type: ignore error = 0 for field in literal_unroll(field_names): error = max(np.abs(data1[field] - data2[field]).max(), error) @@ -641,7 +641,7 @@ def error_estimator(data1: np.ndarray, data2: np.ndarray) -> float: else: @jit - def error_estimator(data1: np.ndarray, data2: np.ndarray) -> float: + def error_estimator(data1: np.ndarray, data2: np.ndarray) -> float: # type: ignore return np.abs(data1 - data2).max() # type: ignore else: @@ -729,7 +729,7 @@ def error_estimator(data1: np.ndarray, data2: np.ndarray) -> float: return error if backend == "numba": - return jit(error_estimator) # type: ignore + return jit(error_estimator) else: return error_estimator diff --git a/emulsim/elements/fields.py b/emulsim/elements/fields.py index e43e69e..824f0d1 100644 --- a/emulsim/elements/fields.py +++ b/emulsim/elements/fields.py @@ -116,7 +116,7 @@ def make_get_concentration_compiled(self) -> Callable: def get_concentration(data: np.ndarray, point: np.ndarray): return data[0] - return get_concentration # type: ignore + return get_concentration def make_add_amount_compiled(self) -> Callable: """Get a compiled function for adding amount to the field. @@ -130,7 +130,7 @@ def make_add_amount_compiled(self) -> Callable: @jit def add_amount(data: np.ndarray, point: np.ndarray, amount: float): ... - return add_amount # type: ignore + return add_amount class FieldElementBase(ArrayElementBase, metaclass=ABCMeta): @@ -455,7 +455,7 @@ def make_get_concentration_compiled(self) -> Callable: def get_concentration(data: np.ndarray, point: np.ndarray): return data[0] - return get_concentration # type: ignore + return get_concentration def make_add_amount_compiled(self) -> Callable: """Get a compiled function for adding amount to the field. @@ -471,7 +471,7 @@ def make_add_amount_compiled(self) -> Callable: def add_amount(data: np.ndarray, point: np.ndarray, amount: float): data += amount / volume - return add_amount # type: ignore + return add_amount class ScalarFieldElement(FieldElementBase): @@ -1159,7 +1159,7 @@ def make_add_amount_compiled(self) -> Callable: def insert(data: np.ndarray, point: np.ndarray, amount: NumberOrArray) -> None: inserter(data, point, amount / thickness) - return insert # type: ignore + return insert def _get_napari_layer_data(self, **kwargs) -> dict[str, Any]: raise NotImplementedError diff --git a/emulsim/elements/multicomponent_droplets.py b/emulsim/elements/multicomponent_droplets.py index 01e604c..28a5515 100644 --- a/emulsim/elements/multicomponent_droplets.py +++ b/emulsim/elements/multicomponent_droplets.py @@ -102,7 +102,7 @@ def get_dtype(cls, **kwargs): @property def num_comps(self) -> int: """int: number of components inside the droplet""" - shape = self.data.dtype.fields["amounts"][0].shape # type: ignore + shape = self.data.dtype.fields["amounts"][0].shape return int(shape[0]) if shape else 1 @property @@ -205,7 +205,7 @@ class MulticomponentDropletsElement(SphericalDropletsElement): @property def num_comps(self) -> int: """int: the number of components inside each droplet""" - shape = self.data.dtype.fields["amounts"][0].shape # type: ignore + shape = self.data.dtype.fields["amounts"][0].shape return int(shape[0]) if shape else 1 @property diff --git a/emulsim/simulation.py b/emulsim/simulation.py index 59011f6..98efdba 100644 --- a/emulsim/simulation.py +++ b/emulsim/simulation.py @@ -467,7 +467,7 @@ def wrap( return chain(actor_id + 1, inner=wrap) else: # this is the outermost function - return wrap # type: ignore + return wrap if self.profile: # add code recording the profiling timings @@ -484,7 +484,7 @@ def evolver(state_data: tuple[np.ndarray, ...], t: float, dt: float): evolver_chain(state_data, t, dt, timings) # prevent garbage collection of array - evolver._timings = self.timings + evolver._timings = self.timings # type: ignore else: # construct the normal evolver using recursion @@ -495,7 +495,7 @@ def evolver(state_data: tuple[np.ndarray, ...], t: float, dt: float): sig = (nb.typeof(state._data_numba), nb.double, nb.double) evolver = jit(sig)(evolver) - return evolver # type: ignore + return evolver def evolve(self, state: State, t: float, dt: float) -> None: """Evolve the state from time `t` to `t + dt` @@ -677,8 +677,8 @@ def _make_single_step(self, state: State) -> Callable[[State, float, float], Non # use older style of selecting backends from pde import backends - def get_backend(name): - return backends[name] + def get_backend(name: str) -> backends.BackendBase: # type: ignore + return backends[name] # type: ignore # do automatic backend selection by trying numba and fall-back to numpy try: @@ -713,7 +713,7 @@ def single_step(state: State, t: float, dt: float) -> None: self.info["backend"] = self.backend.name return single_step - def _make_fixed_stepper( # type: ignore + def _make_fixed_stepper( self, state: State, dt: float ) -> Callable[[State, float, float], float]: """Return function evolving state using adaptive time steps. @@ -745,7 +745,7 @@ def fixed_stepper(state: State, t_start: float, t_end: float) -> float: return fixed_stepper - def _make_adaptive_stepper( # type: ignore + def _make_adaptive_stepper( self, state: State, dt: float ) -> Callable[[State, float, float], float]: """Return function evolving state using adaptive time steps. @@ -934,7 +934,7 @@ def get_element_states( else: raise NotImplementedError(f"{num_elements} elements in actor") - return get_element_states # type: ignore + return get_element_states __all__ = ["Simulation", "SimulationSolver"] diff --git a/emulsim/state.py b/emulsim/state.py index ff86ee8..737bfa8 100644 --- a/emulsim/state.py +++ b/emulsim/state.py @@ -401,9 +401,9 @@ def wrap(state1, state2) -> float: return chain(element_id + 1, inner=wrap) else: # this is the outermost function - return wrap # type: ignore + return wrap - return jit(chain(0)) # type: ignore + return jit(chain(0)) else: raise NotImplementedError(f"Unknown backend `{backend}`")