Skip to content
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
2 changes: 1 addition & 1 deletion emulsim/actors/autonomous/active_particles.py
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
2 changes: 1 addition & 1 deletion emulsim/actors/autonomous/box.py
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
2 changes: 1 addition & 1 deletion emulsim/actors/autonomous/brownian_motion.py
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
4 changes: 2 additions & 2 deletions emulsim/actors/autonomous/coalescence.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down Expand Up @@ -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`
Expand Down
2 changes: 1 addition & 1 deletion emulsim/actors/autonomous/emitters.py
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
12 changes: 6 additions & 6 deletions emulsim/actors/autonomous/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down Expand Up @@ -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`
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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`
Expand Down Expand Up @@ -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`
Expand Down
6 changes: 3 additions & 3 deletions emulsim/actors/coupling/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -279,7 +279,7 @@ def evolver(
field1 -= dt * flux
field2 += dt * flux

return evolver # type: ignore
return evolver

def evolve(
self,
Expand Down Expand Up @@ -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`
Expand Down
6 changes: 3 additions & 3 deletions emulsim/actors/coupling/multicomponent_droplet.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def regularize(phi: np.ndarray) -> np.ndarray:

return correction

return regularize # type: ignore
return regularize


class MulticomponentDropletActor(ActorBase):
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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`
Expand Down
5 changes: 3 additions & 2 deletions emulsim/actors/coupling/nucleation.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from __future__ import annotations

from collections.abc import Callable
from typing import Any

import numpy as np

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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`
Expand Down
2 changes: 1 addition & 1 deletion emulsim/actors/coupling/point_droplet.py
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
8 changes: 4 additions & 4 deletions emulsim/actors/coupling/spherical_droplet.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion emulsim/actors/function.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions emulsim/elements/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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:
Expand Down Expand Up @@ -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

Expand Down
10 changes: 5 additions & 5 deletions emulsim/elements/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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):
Expand Down Expand Up @@ -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.
Expand All @@ -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):
Expand Down Expand Up @@ -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
4 changes: 2 additions & 2 deletions emulsim/elements/multicomponent_droplets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
16 changes: 8 additions & 8 deletions emulsim/simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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`
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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"]
Loading
Loading