Config
pynapple.core.config
This module controls the pynapple configurations.
Backend configuration
By default, pynapple core functions are compiled with Numba. It is possible to change the backend to Jax through the pynajax package.
While numba core functions runs on CPU, the jax
backend allows pynapple to use GPU accelerated core functions.
For some core functions, the jax
backend offers speed gains (provided that Jax runs on the GPU).
See the example below to update the backend. Don't forget to install pynajax.
import pynapple as nap
import numpy as np
nap.nap_config.set_backend("jax") # Default option is 'numba'.
You can view the current backend with
Warnings configuration
pynapple gives warnings that can be helpful to debug. For example when passing time indexes that are not sorted:
>>> import pynapple as nap
>>> t = [0, 2, 1]
>>> nap.Ts(t)
UserWarning: timestamps are not sorted
warn("timestamps are not sorted", UserWarning)
Time (s)
0.0
1.0
2.0
shape: 3
pynapple's warnings can be suppressed :
>>> nap.nap_config.suppress_time_index_sorting_warnings = True
>>> nap.Ts(t=t)
Time (s)
0.0
1.0
2.0
shape: 3
PynappleConfig
A class to hold configuration settings for pynapple.
This class includes all configuration settings that control the behavior of pynapple. It offers a structured way to access and modify settings.
Attributes:
Name | Type | Description |
---|---|---|
backend |
str
|
Current pynapple backend. Options are ('numba' [default], 'jax') |
suppress_conversion_warnings |
boolean
|
Determines whether to suppress warnings when automatically converting non-NumPy array-like objects to NumPy arrays. This is useful for users who frequently work with array-like objects from other libraries (e.g., JAX, TensorFlow) and prefer not to receive warnings for automatic conversions. Defaults to False, which means warnings will be shown. |
suppress_time_index_sorting_warnings |
boolean
|
Control the warning raised when passing a non-sorted array for time index. It can be useful to catch data where timestamps are not properly sorted before using pynapple. |
time_index_precision |
int
|
Number of decimal places to round time index. Pynapple's precision is set by default to 9. |
Source code in pynapple/core/config.py
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 157 158 159 160 161 162 163 164 165 166 167 |
|
time_index_precision
property
Precision for the time index
Returns:
Type | Description |
---|---|
Int
|
Parameter for the |
suppress_conversion_warnings
property
writable
Gets or sets the suppression state for conversion warnings. When set to True, warnings for automatic conversions of non-NumPy array-like objects or pynapple objects to NumPy arrays are suppressed. Ensures that only boolean values are assigned.
suppress_time_index_sorting_warnings
property
writable
Gets or sets the suppression state for sorting time index. When set to True, warnings for sorting are suppressed. Ensures that only boolean values are assigned.
restore_defaults
Set all configuration settings to their default values.
This method can be used to easily set/reset the configuration state of pynapple to its initial, default configuration.