Skip to content

Commit

Permalink
chore(ruff): #80 comment by @emptymalei #86 (comment)
Browse files Browse the repository at this point in the history
  • Loading branch information
cmp0xff committed Aug 22, 2024
1 parent 8526655 commit 21d5c96
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 8 deletions.
4 changes: 3 additions & 1 deletion docs/tutorials/harmonic_oscillator.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,9 @@
DampedHarmonicOscillator(system=s)(
n_periods=n_periods,
n_samples_per_period=n_samples_per_period,
).assign(system=rf"{s_name} (omega = {s.get('omega')}, zeta = {s.get('zeta')})"),
).assign(
system=rf"{s_name} (omega = {s.get('omega')}, zeta = {s.get('zeta')})",
),
)

fig = px.line(
Expand Down
4 changes: 3 additions & 1 deletion hamilflow/models/brownian_motion.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,9 @@ class BrownianMotion:
def __init__(
self,
system: Mapping[str, float],
initial_condition: Mapping[str, "Sequence[float] | npt.ArrayLike"] | None = None,
initial_condition: (
Mapping[str, "Sequence[float] | npt.ArrayLike"] | None
) = None,
):
initial_condition = initial_condition or {}
self.system = BrownianMotionSystem.model_validate(system)
Expand Down
10 changes: 8 additions & 2 deletions hamilflow/models/harmonic_oscillator.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,10 @@ def _x_under_damped(self, t: "Sequence[float] | npt.ArrayLike") -> npt.ArrayLike
omega_damp = self.system.omega * np.sqrt(1 - self.system.zeta)
return (
self.initial_condition.x0 * np.cos(omega_damp * t)
+ (self.system.zeta * self.system.omega * self.initial_condition.x0 + self.initial_condition.v0)
+ (
self.system.zeta * self.system.omega * self.initial_condition.x0
+ self.initial_condition.v0
)
/ omega_damp
* np.sin(omega_damp * t)
) * np.exp(-self.system.zeta * self.system.omega * t)
Expand Down Expand Up @@ -296,7 +299,10 @@ def _x_over_damped(self, t: "Sequence[float] | npt.ArrayLike") -> npt.ArrayLike:

return (
self.initial_condition.x0 * np.cosh(gamma_damp * t)
+ (self.system.zeta * self.system.omega * self.initial_condition.x0 + self.initial_condition.v0)
+ (
self.system.zeta * self.system.omega * self.initial_condition.x0
+ self.initial_condition.v0
)
/ gamma_damp
* np.sinh(gamma_damp * t)
) * np.exp(-self.system.zeta * self.system.omega * t)
Expand Down
8 changes: 6 additions & 2 deletions hamilflow/models/harmonic_oscillator_chain.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,18 @@ def definition(
self,
) -> dict[
str,
float | dict[str, dict[str, float | list[float]]] | list[dict[str, dict[str, float | tuple[float, float]]]],
float
| dict[str, dict[str, float | list[float]]]
| list[dict[str, dict[str, float | tuple[float, float]]]],
]:
"""model params and initial conditions defined as a dictionary."""
return dict(
omega=self.omega,
n_dof=self.n_dof,
free_mode=self.free_mode.definition,
independent_csho_modes=[rwm.definition for rwm in self.independent_csho_modes],
independent_csho_modes=[
rwm.definition for rwm in self.independent_csho_modes
],
)

def _z(
Expand Down
4 changes: 3 additions & 1 deletion hamilflow/models/kepler_problem/numerics.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ def nsolve_u_from_tau_bisect(ecc: float, tau: "npt.ArrayLike") -> list[OptimizeR
raise ValueError(f"Expect ecc > 0, ecc != 1, got {ecc}")

def f(u: float, tau: float) -> np.float64:
return np.finfo(np.float64).max if u == -1 else np.float64(tau_of_u(ecc, u) - tau)
return (
np.finfo(np.float64).max if u == -1 else np.float64(tau_of_u(ecc, u) - tau)
)

return [toms748(f, max(-1, -ecc), ecc, (ta,), 2, full_output=True) for ta in tau_s]

Expand Down
4 changes: 3 additions & 1 deletion tests/models/test_harmonic_oscillator_chain.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ def free_mode(self, request: pytest.FixtureRequest) -> dict[str, int]:
return dict(zip(("x0", "v0"), request.param))

@pytest.fixture(
params=chain.from_iterable(product(_possible_wave_modes, repeat=r) for r in range(3)),
params=chain.from_iterable(
product(_possible_wave_modes, repeat=r) for r in range(3)
),
)
def wave_modes(
self,
Expand Down

0 comments on commit 21d5c96

Please sign in to comment.