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

Make diffeqzoo.vector_fields module public #129

Merged
merged 2 commits into from
Dec 27, 2023
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
12 changes: 6 additions & 6 deletions diffeqzoo/bvps.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
import math # for the constant "PI"
from typing import Callable, Iterable, NamedTuple

from diffeqzoo import _vector_fields
from diffeqzoo import vector_fields


class _BoundaryValueProblem(NamedTuple):
Expand Down Expand Up @@ -84,7 +84,7 @@ def g1(u):
return u

return _BoundaryValueProblem(
vector_field=_vector_fields.bratu,
vector_field=vector_fields.bratu,
boundary_conditions=(g0, g1),
vector_field_args=parameters,
time_span=time_span,
Expand All @@ -105,7 +105,7 @@ def g1(u, _):
return u

return _BoundaryValueProblem(
vector_field=_vector_fields.bratu_with_unused_derivative_argument,
vector_field=vector_fields.bratu_with_unused_derivative_argument,
boundary_conditions=(g0, g1),
vector_field_args=parameters,
time_span=time_span,
Expand All @@ -128,7 +128,7 @@ def g1(u, _):
return u

return _BoundaryValueProblem(
vector_field=_vector_fields.pendulum_with_unused_derivative_argument,
vector_field=vector_fields.pendulum_with_unused_derivative_argument,
boundary_conditions=(g0, g1),
vector_field_args=parameters,
time_span=time_span,
Expand Down Expand Up @@ -157,7 +157,7 @@ def g1(u):
return u

return _BoundaryValueProblem(
vector_field=_vector_fields.pendulum,
vector_field=vector_fields.pendulum,
boundary_conditions=(g0, g1),
vector_field_args=parameters,
time_span=time_span,
Expand Down Expand Up @@ -208,7 +208,7 @@ def bcond(u_left, u_right):
return u_left - u_right

return _BoundaryValueProblem(
vector_field=_vector_fields.measles,
vector_field=vector_fields.measles,
boundary_conditions=bcond,
vector_field_args=parameters,
time_span=time_span,
Expand Down
8 changes: 4 additions & 4 deletions diffeqzoo/ivps/_chaos.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Chaotic systems."""

from diffeqzoo import _vector_fields, backend
from diffeqzoo import backend, vector_fields
from diffeqzoo.ivps import _ivp


Expand Down Expand Up @@ -37,7 +37,7 @@ def lorenz96(
)

return _ivp.InitialValueProblem(
vector_field=_vector_fields.lorenz96,
vector_field=vector_fields.lorenz96,
vector_field_args=(forcing,),
initial_values=initial_values,
time_span=time_span,
Expand Down Expand Up @@ -82,7 +82,7 @@ def lorenz63(
initial_values = backend.numpy.asarray(initial_values)

return _ivp.InitialValueProblem(
vector_field=_vector_fields.lorenz63,
vector_field=vector_fields.lorenz63,
vector_field_args=parameters,
initial_values=initial_values,
time_span=time_span,
Expand Down Expand Up @@ -118,7 +118,7 @@ def roessler(
initial_values = backend.numpy.asarray(initial_values)

return _ivp.InitialValueProblem(
vector_field=_vector_fields.roessler,
vector_field=vector_fields.roessler,
vector_field_args=parameters,
initial_values=initial_values,
time_span=time_span,
Expand Down
8 changes: 4 additions & 4 deletions diffeqzoo/ivps/_epidem.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Epidemiological models."""


from diffeqzoo import _vector_fields, backend
from diffeqzoo import backend, vector_fields
from diffeqzoo.ivps import _ivp


Expand Down Expand Up @@ -43,7 +43,7 @@ def sir(
parameters = (beta, gamma, backend.numpy.sum(initial_values[0]))

return _ivp.InitialValueProblem(
vector_field=_vector_fields.sir,
vector_field=vector_fields.sir,
vector_field_args=parameters,
initial_values=initial_values,
time_span=time_span,
Expand Down Expand Up @@ -95,7 +95,7 @@ def seir(
parameters = (alpha, beta, gamma, backend.numpy.sum(initial_values[0]))

return _ivp.InitialValueProblem(
vector_field=_vector_fields.seir,
vector_field=vector_fields.seir,
vector_field_args=parameters,
initial_values=initial_values,
time_span=time_span,
Expand Down Expand Up @@ -146,7 +146,7 @@ def sird(
parameters = (beta, gamma, eta, backend.numpy.sum(initial_values[0]))

return _ivp.InitialValueProblem(
vector_field=_vector_fields.sird,
vector_field=vector_fields.sird,
vector_field_args=parameters,
initial_values=initial_values,
time_span=time_span,
Expand Down
10 changes: 5 additions & 5 deletions diffeqzoo/ivps/_misc.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Miscellaneous problems."""


from diffeqzoo import _vector_fields, backend
from diffeqzoo import backend, vector_fields
from diffeqzoo.ivps import _ivp


Expand All @@ -25,7 +25,7 @@ def logistic(*, initial_value=0.1, time_span=(0.0, 2.5), parameters=(1.0, 1.0)):
initial_value = backend.numpy.asarray(initial_value)

return _ivp.InitialValueProblem(
vector_field=_vector_fields.logistic,
vector_field=vector_fields.logistic,
vector_field_args=parameters,
initial_values=initial_value,
time_span=time_span,
Expand All @@ -44,7 +44,7 @@ def affine_independent(*, initial_values=1.0, time_span=(0.0, 1.0), a=1.0, b=0.0
initial_values = backend.numpy.asarray(initial_values)

return _ivp.InitialValueProblem(
vector_field=_vector_fields.affine_independent,
vector_field=vector_fields.affine_independent,
vector_field_args=(a, b),
initial_values=initial_values,
time_span=time_span,
Expand All @@ -67,7 +67,7 @@ def affine_dependent(
b = backend.numpy.asarray(b)

return _ivp.InitialValueProblem(
vector_field=_vector_fields.affine_dependent,
vector_field=vector_fields.affine_dependent,
vector_field_args=(A, b),
initial_values=initial_values,
time_span=time_span,
Expand Down Expand Up @@ -98,7 +98,7 @@ def neural_ode_mlp(
initial_values = backend.numpy.asarray(initial_values)
params = _init_random_params(scale, layer_sizes, seed)
return _ivp.InitialValueProblem(
vector_field=_vector_fields.neural_ode_mlp,
vector_field=vector_fields.neural_ode_mlp,
vector_field_args=(params,),
initial_values=initial_values,
time_span=time_span,
Expand Down
14 changes: 7 additions & 7 deletions diffeqzoo/ivps/_nbody.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""N-Body problems and celestial mechanics."""

from diffeqzoo import _vector_fields, backend, transform
from diffeqzoo import backend, transform, vector_fields
from diffeqzoo.ivps import _ivp


Expand Down Expand Up @@ -41,7 +41,7 @@ def rigid_body(
initial_values = backend.numpy.asarray(initial_values)

return _ivp.InitialValueProblem(
vector_field=_vector_fields.rigid_body,
vector_field=vector_fields.rigid_body,
vector_field_args=parameters,
initial_values=initial_values,
time_span=time_span,
Expand Down Expand Up @@ -111,7 +111,7 @@ def pleiades(*, initial_values=(_U0, _DU0), time_span=(0.0, 3.0)):
initial_values = (u0, du0)

return _ivp.InitialValueProblem(
vector_field=_vector_fields.pleiades,
vector_field=vector_fields.pleiades,
initial_values=initial_values,
time_span=time_span,
)
Expand All @@ -134,7 +134,7 @@ def pleiades_with_unused_derivative_argument(**kwargs):
_, initial_values, time_span, args = pleiades(**kwargs)

return _ivp.InitialValueProblem(
vector_field=_vector_fields.pleiades_with_unused_derivative_argument,
vector_field=vector_fields.pleiades_with_unused_derivative_argument,
initial_values=initial_values,
time_span=time_span,
vector_field_args=args,
Expand Down Expand Up @@ -195,7 +195,7 @@ def henon_heiles(*, initial_values=_HENON_HEILES_INITS, time_span=(0.0, 100.0),
initial_values = (backend.numpy.asarray(u0), backend.numpy.asarray(du0))

return _ivp.InitialValueProblem(
vector_field=_vector_fields.henon_heiles,
vector_field=vector_fields.henon_heiles,
initial_values=initial_values,
time_span=time_span,
vector_field_args=(p,),
Expand All @@ -219,7 +219,7 @@ def henon_heiles_with_unused_derivative_argument(**kwargs):
_, initial_values, time_span, args = henon_heiles(**kwargs)

return _ivp.InitialValueProblem(
vector_field=_vector_fields.henon_heiles_with_unused_derivative_argument,
vector_field=vector_fields.henon_heiles_with_unused_derivative_argument,
initial_values=initial_values,
time_span=time_span,
vector_field_args=args,
Expand Down Expand Up @@ -271,7 +271,7 @@ def three_body_restricted(
initial_values = (u0, du0)

return _ivp.InitialValueProblem(
vector_field=_vector_fields.three_body_restricted,
vector_field=vector_fields.three_body_restricted,
vector_field_args=(standardised_moon_mass,),
initial_values=initial_values,
time_span=time_span,
Expand Down
10 changes: 5 additions & 5 deletions diffeqzoo/ivps/_oscillators.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Oscillating systems."""

from diffeqzoo import _vector_fields, backend, transform
from diffeqzoo import backend, transform, vector_fields
from diffeqzoo.ivps import _ivp


Expand Down Expand Up @@ -60,7 +60,7 @@ def lotka_volterra(
initial_values = backend.numpy.asarray(initial_values)

return _ivp.InitialValueProblem(
vector_field=_vector_fields.lotka_volterra,
vector_field=vector_fields.lotka_volterra,
vector_field_args=parameters,
initial_values=initial_values,
time_span=time_span,
Expand Down Expand Up @@ -116,7 +116,7 @@ def fitzhugh_nagumo(
initial_values = backend.numpy.asarray(initial_values)

return _ivp.InitialValueProblem(
vector_field=_vector_fields.fitzhugh_nagumo,
vector_field=vector_fields.fitzhugh_nagumo,
vector_field_args=parameters,
initial_values=initial_values,
time_span=time_span,
Expand Down Expand Up @@ -156,7 +156,7 @@ def van_der_pol(
initial_values = (u0, du0)

return _ivp.InitialValueProblem(
vector_field=_vector_fields.van_der_pol,
vector_field=vector_fields.van_der_pol,
vector_field_args=(stiffness_constant,),
initial_values=initial_values,
time_span=time_span,
Expand Down Expand Up @@ -210,7 +210,7 @@ def goodwin(

k = backend.numpy.asarray(k)
return _ivp.InitialValueProblem(
vector_field=_vector_fields.goodwin,
vector_field=vector_fields.goodwin,
vector_field_args=(r, a1, a2, alpha, k),
initial_values=initial_values,
time_span=time_span,
Expand Down
4 changes: 2 additions & 2 deletions diffeqzoo/ivps/_pde.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""Discretised partial differential equations."""
from diffeqzoo import _vector_fields, backend
from diffeqzoo import backend, vector_fields
from diffeqzoo.ivps import _ivp

# todo: Should the "info" be part of the IVP data structure, i.e., always returned?
Expand Down Expand Up @@ -41,7 +41,7 @@ def heat_1d_dirichlet(

# Load the vector field and return the IVP
ivp = _ivp.InitialValueProblem(
vector_field=_vector_fields.heat_1d_dirichlet,
vector_field=vector_fields.heat_1d_dirichlet,
vector_field_args=(stencil_weights, coefficient),
initial_values=initial_values,
time_span=time_span,
Expand Down
10 changes: 5 additions & 5 deletions diffeqzoo/ivps/_reactions.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Chemical reactions."""

from diffeqzoo import _vector_fields, backend
from diffeqzoo import backend, vector_fields
from diffeqzoo.ivps import _ivp


Expand Down Expand Up @@ -56,7 +56,7 @@ def hires(
initial_values = backend.numpy.asarray(initial_values)

return _ivp.InitialValueProblem(
vector_field=_vector_fields.hires,
vector_field=vector_fields.hires,
vector_field_args=(), # todo: move vf-params here
initial_values=initial_values,
time_span=time_span,
Expand Down Expand Up @@ -111,7 +111,7 @@ def rober(
initial_values = backend.numpy.asarray(initial_values)

return _ivp.InitialValueProblem(
vector_field=_vector_fields.rober,
vector_field=vector_fields.rober,
vector_field_args=(k1, k2, k3),
initial_values=initial_values,
time_span=time_span,
Expand Down Expand Up @@ -159,7 +159,7 @@ def oregonator(
initial_values = backend.numpy.asarray(initial_values)

return _ivp.InitialValueProblem(
vector_field=_vector_fields.rober,
vector_field=vector_fields.rober,
vector_field_args=(s, w, q),
initial_values=initial_values,
time_span=time_span,
Expand Down Expand Up @@ -201,7 +201,7 @@ def nonlinear_chemical_reaction(
initial_values = backend.numpy.asarray(initial_values)

return _ivp.InitialValueProblem(
vector_field=_vector_fields.nonlinear_chemical_reaction,
vector_field=vector_fields.nonlinear_chemical_reaction,
vector_field_args=(k1, k2),
initial_values=initial_values,
time_span=time_span,
Expand Down
2 changes: 1 addition & 1 deletion diffeqzoo/_vector_fields.py → diffeqzoo/vector_fields.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""ODE vector fields."""
"""Vector fields for differential equations."""

from diffeqzoo import backend, transform

Expand Down
3 changes: 2 additions & 1 deletion docs/source/api_documentation/diffeqzoo.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
.. toctree::
:maxdepth: 1

diffeqzoo.ivps
diffeqzoo.bvps
diffeqzoo.ivps
diffeqzoo.transform
diffeqzoo.vector_fields
2 changes: 2 additions & 0 deletions docs/source/api_documentation/diffeqzoo.vector_fields.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.. automodapi:: diffeqzoo.vector_fields
:no-inheritance-diagram:
Loading