API Reference¤
attractors.Solver
dataclass
¤
Data class representing a numerical ODE solver with JIT compilation support.
Attributes:
Name | Type | Description |
---|---|---|
func |
SolverCallable
|
Original solver function |
jitted_func |
SolverCallable
|
JIT-compiled solver function |
name |
str
|
Solver identifier |
Source code in src/attractors/solvers/registry.py
attractors.Solver.get_func(jitted=True)
¤
Get solver function.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
jitted
|
bool
|
Whether to return JIT-compiled version. Defaults to True. |
True
|
Returns:
Name | Type | Description |
---|---|---|
SolverCallable |
SolverCallable
|
Solver function (JIT-compiled or original) |
Source code in src/attractors/solvers/registry.py
attractors.SolverRegistry
¤
Registry for numerical ODE solvers with JIT compilation support.
Each solver must be registered with a unique name and follow the interface
- Input: (system_func, state, params, dt)
- Output: next state vector
Solvers are automatically JIT-compiled during registration.
Attributes:
Name | Type | Description |
---|---|---|
_solvers |
dict[str, Solver]
|
Internal dict mapping solver names to Solver instances |
Examples:
>>> @SolverRegistry.register("rk4")
>>> def rk4(system_func, state, params, dt):
... # RK4 implementation
... return next_state
Source code in src/attractors/solvers/registry.py
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
|
attractors.SolverRegistry.register(name)
classmethod
¤
Register a solver function in the SolverRegistry.
Decorator that registers a solver function and creates a JIT-compiled version. The registered solver must take (system_func, state, params, dt) arguments and return the next state vector.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
Unique identifier for the solver |
required |
Returns:
Type | Description |
---|---|
Callable[[F], F]
|
Callable[[F], F]: Decorator function that registers and JIT-compiles the solver |
Raises:
Type | Description |
---|---|
TypeError
|
If name is not a string or decorated object is not callable |
ValueError
|
If solver name is already registered |
Examples:
>>> @SolverRegistry.register("solver_name")
>>> def custom_solver(system_func, state, params, dt):
... # Solver implementation
... return next_state
Source code in src/attractors/solvers/registry.py
attractors.SolverRegistry.get(name)
classmethod
¤
Retrieve a registered solver by name
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
Name of solver to retrieve |
required |
Raises:
Type | Description |
---|---|
KeyError
|
If solver name not found |
Returns:
Name | Type | Description |
---|---|---|
Solver |
Solver
|
Registered Solver instance |
Source code in src/attractors/solvers/registry.py
attractors.SolverRegistry.list_solvers()
classmethod
¤
Get list of all registered solver names.
Returns:
Type | Description |
---|---|
list[str]
|
list[str]: List of solver names |
attractors.SolverRegistry.is_jitted(func)
staticmethod
¤
Check if a function is JIT-compiled.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
func
|
Callable[..., Any]
|
Function to check |
required |
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if function is JIT-compiled |
Source code in src/attractors/solvers/registry.py
attractors.System
dataclass
¤
Data class representing a dynamical system with JIT compilation support.
Attributes:
Name | Type | Description |
---|---|---|
func |
SystemCallable
|
Original system function |
jitted_func |
SystemCallable
|
JIT-compiled system function |
name |
str
|
System identifier |
params |
Vector
|
System parameters vector |
param_names |
list[str]
|
List of parameter names |
reference |
str
|
Academic reference |
init_coord |
Vector
|
Initial state vector |
plot_lims |
PlotLimits | None
|
Optional plotting limits |
Source code in src/attractors/systems/registry.py
attractors.System.set_params(params)
¤
Set system parameters.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
params
|
Vector
|
New parameter vector |
required |
Raises:
Type | Description |
---|---|
ValueError
|
If parameter count doesn't match expected number of parameters |
Source code in src/attractors/systems/registry.py
attractors.System.set_init_coord(coord)
¤
Set initial state coordinates.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
coord
|
Vector
|
Initial state vector (must have length 3) |
required |
Raises:
Type | Description |
---|---|
ValueError
|
If coordinate vector length is not 3 |
Source code in src/attractors/systems/registry.py
attractors.System.get_func(jitted=True)
¤
Get system function.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
jitted
|
bool
|
Whether to return JIT-compiled version. Defaults to True. |
True
|
Returns:
Name | Type | Description |
---|---|---|
SystemCallable |
SystemCallable
|
System function (JIT-compiled or original) |
Source code in src/attractors/systems/registry.py
attractors.SystemRegistry
¤
Registry for dynamical systems with JIT compilation support.
Each system must be registered with
- Unique name
- Default parameters and their names
- Initial coordinates
- Optional plotting limits and academic reference
Systems are automatically JIT-compiled during registration.
Attributes:
Name | Type | Description |
---|---|---|
_systems |
dict[str, System]
|
Internal dict mapping system names to System instances |
Examples:
>>> @SystemRegistry.register(
... "lorenz",
... default_params=np.array([10.0, 28.0, 8 / 3]),
... param_names=["sigma", "rho", "beta"],
... init_coord=np.array([0.0, 1.0, 0.0]),
... )
... def lorenz(state: Vector, params: Vector) -> Vector:
... x, y, z = state
... sigma, rho, beta = params
... return np.array([sigma * (y - x), x * (rho - z) - y, x * y - beta * z])
Source code in src/attractors/systems/registry.py
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 |
|
attractors.SystemRegistry.register(name, *, default_params, param_names, reference='', init_coord, plot_lims=None)
classmethod
¤
Register a system function in the SystemRegistry.
Decorator that registers a system function and creates a JIT-compiled version. The registered system must take (state, params) Vector type arguments and return the next state vector.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
Unique identifier for the system |
required |
default_params
|
Vector
|
Default parameter values |
required |
param_names
|
list[str]
|
Names of parameters |
required |
reference
|
str
|
Academic reference. Defaults to "". |
''
|
init_coord
|
Vector
|
Initial state vector |
required |
plot_lims
|
PlotLimits | None
|
Plotting limits. Defaults to None. |
None
|
Returns:
Type | Description |
---|---|
Callable[[F], F]
|
Callable[[F], F]: Decorator function that registers and JIT-compiles the system |
Raises:
Type | Description |
---|---|
TypeError
|
If name is not a string or decorated object is not callable |
ValueError
|
If system name is already registered |
Examples:
>>> @SystemRegistry.register("lorenz")
... def lorenz(state: Vector, params: Vector) -> Vector:
... x, y, z = state
... sigma, rho, beta = params
... return np.array([sigma * (y - x), x * (rho - z) - y, x * y - beta * z])
Source code in src/attractors/systems/registry.py
attractors.SystemRegistry.get(name)
classmethod
¤
Get registered system by name.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
Name of system to retrieve |
required |
Returns:
Name | Type | Description |
---|---|---|
System |
System
|
Registered System instance |
Raises:
Type | Description |
---|---|
KeyError
|
If system name is not found |
Source code in src/attractors/systems/registry.py
attractors.SystemRegistry.list_systems()
classmethod
¤
Get list of all registered system names.
Returns:
Type | Description |
---|---|
list[str]
|
list[str]: List of registered system names |
attractors.SystemRegistry.is_jitted(func)
staticmethod
¤
Check if a function is JIT-compiled.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
func
|
Callable[..., Any]
|
Function to check |
required |
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if function is JIT-compiled |
Source code in src/attractors/systems/registry.py
attractors.ThemeManager
¤
Manager for loading and accessing visualization themes.
Themes can be loaded from JSON files, added/removed programmatically, and accessed by name or randomly. A default theme is always available.
Examples:
>>> ThemeManager.load("themes.json")
>>> theme = ThemeManager.get("dark")
>>> ThemeManager.set_default("light")
>>> random_theme = ThemeManager.random()
Source code in src/attractors/themes/manager.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
|
attractors.ThemeManager.load(path)
classmethod
¤
Load themes from JSON file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path
|
str | Path
|
Path to JSON theme file |
required |
Source code in src/attractors/themes/manager.py
attractors.ThemeManager.get(name=None)
classmethod
¤
Get theme by name or default.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str | None
|
Theme name. Uses default if None. Defaults to None. |
None
|
Returns:
Name | Type | Description |
---|---|---|
Theme |
Theme
|
Requested theme instance |
Raises:
Type | Description |
---|---|
KeyError
|
If theme name not found |
Source code in src/attractors/themes/manager.py
attractors.ThemeManager.list_themes()
classmethod
¤
List available themes.
Returns:
Type | Description |
---|---|
list[str]
|
list[str]: List of theme names |
attractors.ThemeManager.set_default(name)
classmethod
¤
Set default theme.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
Name of theme to set as default |
required |
Raises:
Type | Description |
---|---|
KeyError
|
If theme name not found |
Source code in src/attractors/themes/manager.py
attractors.ThemeManager.add(theme)
classmethod
¤
attractors.ThemeManager.remove(name)
classmethod
¤
Remove theme.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
Name of theme to remove |
required |
Raises:
Type | Description |
---|---|
ValueError
|
If attempting to remove default theme |
Source code in src/attractors/themes/manager.py
attractors.Theme
dataclass
¤
Immutable theme data class for visualization styling.
Attributes:
Name | Type | Description |
---|---|---|
name |
str
|
Theme identifier |
background |
str
|
Background color in hex format |
foreground |
str
|
Foreground color in hex format |
colors |
str | list[str]
|
Either matplotlib colormap name or list of hex colors |
Source code in src/attractors/themes/theme.py
attractors.Theme.colormap
property
¤
Get matplotlib colormap for theme colors.
Returns:
Type | Description |
---|---|
Colormap
|
matplotlib.colors.Colormap: Generated colormap from theme colors |
attractors.AnimatedPlotter
¤
Bases: BasePlotter
Source code in src/attractors/visualizers/animate.py
attractors.AnimatedPlotter.visualize_impl(trajectory, **kwargs)
¤
Create an animation showing trajectory evolution over time with colored segments.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
trajectory
|
Vector
|
Trajectory points to visualize |
required |
**kwargs
|
AnimatedVisualizeKwargs
|
Animation parameters. Refer to attributes of AnimatedVisualizeKwargs. |
{}
|
Returns: AnimatedPlotter: Self reference for method chaining
Source code in src/attractors/visualizers/animate.py
attractors.AnimatedVisualizeKwargs
¤
Bases: TypedDict
Type definition for animation visualization parameters.
Attributes:
Name | Type | Description |
---|---|---|
speed |
int
|
Speed multiplier for animation |
interval |
int
|
Animation interval in milliseconds |
rotate_view |
Callable[[Axes3D], None]
|
Function to rotate view in each frame |
line_kwargs |
dict[str, Any]
|
Additional arguments for matplotlib line plots |
anim_kwargs |
dict[str, Any]
|
Additional arguments for matplotlib animation |
Source code in src/attractors/visualizers/animate.py
attractors.BasePlotter
¤
Bases: ABC
Abstract base class for visualization of dynamical systems.
An abstract base class that handles the common functionality for plotting and visualizing dynamical systems trajectories, including color mapping and plot setup.
Attributes:
Name | Type | Description |
---|---|---|
VALID_COLOR_OPTIONS |
tuple[str, ...]
|
Valid color mapping options ("time", "x", "y", "z", "velocity") |
Source code in src/attractors/visualizers/base.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
|
attractors.BasePlotter.__init__(system, theme, num_segments=50, color_by='time', color_cycles=1.0, fig_kwargs=None)
¤
Initialize the plotter.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
system
|
System
|
Dynamical system to visualize |
required |
theme
|
Theme
|
Visual theme for plots |
required |
num_segments
|
int
|
Number of segments for visualization |
50
|
color_by
|
str | ColorMapper
|
Color mapping strategy ("time", "x", "y", "z", "velocity") or ColorMapper instance |
'time'
|
color_cycles
|
float
|
Number of color cycles through the palette |
1.0
|
fig_kwargs
|
dict[str, Any] | None
|
Additional arguments for matplotlib figure |
None
|
Raises:
Type | Description |
---|---|
ValueError
|
If color_by is not a valid option or ColorMapper instance |
Source code in src/attractors/visualizers/base.py
attractors.BasePlotter.visualize(trajectory, compression=0.0, compression_method=CompressionMethod.VELOCITY, **kwargs)
¤
Process and visualize trajectory data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
trajectory
|
Vector
|
Trajectory points to visualize |
required |
compression
|
float
|
Compression ratio (0.0 to 1.0) |
0.0
|
compression_method
|
CompressionMethod
|
Method for trajectory compression |
VELOCITY
|
**kwargs
|
Any
|
Additional visualization parameters |
{}
|
Returns:
Name | Type | Description |
---|---|---|
BasePlotter |
BasePlotter
|
Self reference for method chaining |
Source code in src/attractors/visualizers/base.py
attractors.BasePlotter.visualize_impl(trajectory, **kwargs)
abstractmethod
¤
attractors.StaticPlotter
¤
Bases: BasePlotter
Plotter for static visualization of dynamical system trajectories.
Source code in src/attractors/visualizers/static.py
attractors.StaticPlotter.visualize_impl(trajectory, line_kwargs=None, segment_overlap=1, **kwargs)
¤
Create a static plot of trajectory segments with color mapping.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
trajectory
|
Vector
|
Trajectory points to visualize |
required |
line_kwargs
|
dict[str, Any] | None
|
Additional arguments for matplotlib line plots. Defaults to None. |
None
|
segment_overlap
|
int
|
Number of points to overlap between segments. Defaults to 1. |
1
|
**kwargs
|
Any
|
Additional visualization parameters |
{}
|
Returns:
Name | Type | Description |
---|---|---|
StaticPlotter |
StaticPlotter
|
Self reference for method chaining |
Source code in src/attractors/visualizers/static.py
attractors.integrate_system(system, solver, steps, dt, use_jit=None)
¤
Integrates a dynamical system using the specified numerical solver.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
system
|
System
|
System to integrate |
required |
solver
|
Solver
|
Numerical solver to use for integration |
required |
steps
|
int
|
Number of integration steps |
required |
dt
|
float
|
Time step size |
required |
use_jit
|
bool | None
|
Whether to use Numba JIT compilation. Defaults to True. |
None
|
Raises:
Type | Description |
---|---|
ValueError
|
If steps <= 0 or dt <= 0 |
Returns:
Type | Description |
---|---|
tuple[Vector, Vector]
|
tuple[Vector, Vector]: A tuple containing: - Vector: System state trajectory at each time step - Vector: Time points corresponding to trajectory |