Integrator
Three time-integration strategies, selected at construction and shared by
every model: IVPIntegrator for continuous systems (SciPy's solve_ivp,
with a lazily created multiprocessing pool for m > 1 ensembles),
DiscreteIntegrator for fixed-step maps such as the ETDRK4 scheme, and
ConstantIntegrator for a frozen state.
dynamodels.integrator.Integrator
Abstract base class for the time-integration strategies.
Defines the interface for advancing the model state; child classes implement
advance_single and advance_ensemble. Three strategies are provided:
IVPIntegrator— continuous, variable-step integration with SciPy'ssolve_ivpof \(\dot{\boldsymbol{\psi}} = f(t, \boldsymbol{\psi}, \boldsymbol{\alpha})\); the model must definetime_derivative.DiscreteIntegrator— fixed, discrete-step maps \(\boldsymbol{\psi}_{t+\Delta t} = F(\boldsymbol{\psi}_t, \boldsymbol{\alpha})\) (e.g., ETDRK4, ESN); the model must definetime_step.ConstantIntegrator— holds the state constant, \(\boldsymbol{\psi}(t) = \boldsymbol{\psi}(0)\).
Source code in dynamodels/integrator.py
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 | |
is_ensemble
property
bool: True if model.current_state carries more than one member
(its last axis has size \(>1\)), i.e. advance should dispatch to
advance_ensemble rather than advance_single.
__init__(model_instance)
Initialize the integrator with a model instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_instance
|
object
|
The (not necessarily |
required |
Source code in dynamodels/integrator.py
49 50 51 52 53 54 55 56 57 58 59 60 61 | |
close()
Close resources held by the integrator (e.g., multiprocessing pools).
Source code in dynamodels/integrator.py
75 76 77 | |
advance(averaged=False, **kwargs)
Common entry point for all integrators; dispatches to
advance_single or advance_ensemble based on is_ensemble.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
averaged
|
bool
|
Forwarded to |
False
|
**kwargs
|
Forwarded to |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
psi |
ndarray
|
Forecasted state, excluding the initial condition. |
t |
ndarray
|
Corresponding time stamps. |
Source code in dynamodels/integrator.py
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 | |
advance_single(**kwargs)
Advance a single (non-ensemble) member. Must be implemented by child classes.
Returns:
| Name | Type | Description |
|---|---|---|
psi |
ndarray
|
Forecasted state, excluding the initial condition. |
t |
ndarray
|
Corresponding time stamps. |
Source code in dynamodels/integrator.py
105 106 107 108 109 110 111 112 113 114 115 116 | |
advance_ensemble(Nt=100, averaged=False, alpha=None)
Advance every ensemble member. Must be implemented by child classes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Nt
|
int
|
Number of forecast steps. |
100
|
averaged
|
bool
|
Strategy-dependent flag controlling whether members are propagated individually or only the ensemble mean is integrated. |
False
|
alpha
|
dict
|
Parameter values forwarded to the governing equations. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
psi |
ndarray
|
Forecasted ensemble state, excluding the initial condition. |
t |
ndarray
|
Corresponding time stamps. |
Source code in dynamodels/integrator.py
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 | |
dynamodels.integrator.IVPIntegrator
Bases: Integrator
Integrator using SciPy's solve_ivp for continuous, variable-step
integration of \(\dot{\psi}=f(t,\psi,\alpha)\).
The model must define time_derivative(t, psi, **params). A single
member is solved directly with ivp_forecast_helper; an ensemble is
either solved member-by-member in parallel (a multiprocessing pool sized
to model.m, created lazily) or, if averaged=True, solved once for
the ensemble mean with each member's deviation from the mean left
unchanged (see advance_ensemble).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_instance
|
object
|
See |
required |
method
|
str
|
Integration method forwarded to |
'RK45'
|
Source code in dynamodels/integrator.py
286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 | |
close()
Terminate and join the multiprocessing pool, if one was created.
Source code in dynamodels/integrator.py
323 324 325 326 327 328 | |
advance_single(Nt=100, averaged=False, alpha=None)
Solve the IVP for the single (non-ensemble) member.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Nt
|
int
|
Number of forecast steps. |
100
|
averaged
|
bool
|
Accepted for interface compatibility with |
False
|
alpha
|
dict
|
Accepted for interface compatibility but not used: the governing
equations are called with |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
psi |
ndarray, shape ``(Nt, N, 1)``
|
Forecasted state, excluding the initial condition. |
t |
ndarray, shape ``(Nt,)``
|
Time stamps spaced by |
Source code in dynamodels/integrator.py
349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 | |
advance_ensemble(Nt=100, averaged=False, alpha=None)
Solve the IVP for every ensemble member.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Nt
|
int
|
Number of forecast steps. |
100
|
averaged
|
bool
|
If False (default), each member is solved independently and in
parallel (via a multiprocessing pool), each with its own
parameters from |
False
|
alpha
|
dict
|
Accepted for interface compatibility but not used: parameters are
always taken from |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
psi |
ndarray, shape ``(Nt, N, m)``
|
Forecasted ensemble state, excluding the initial condition. |
t |
ndarray, shape ``(Nt,)``
|
Time stamps spaced by |
Source code in dynamodels/integrator.py
394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 | |
dynamodels.integrator.DiscreteIntegrator
Bases: Integrator
Integrator for models advanced by a fixed, discrete map or scheme
(single member), \(\psi_{t+\mathrm{d}t}=F(\psi_t,\alpha)\) (e.g. ETDRK4 in
KS, or an ESN).
The model must define time_step(Nt), stepping at its own internal
time step dt_step (dt_integrator); if this differs from the model's
output step dt (dt_output), the integrator's output is linearly
interpolated back onto the requested output times.
Attributes:
| Name | Type | Description |
|---|---|---|
dt_output |
float
|
Output time step, |
dt_integrator |
float
|
Time step used internally by |
relation_integrator_output |
float
|
|
Source code in dynamodels/integrator.py
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 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 | |
__init__(model_instance)
See Integrator.__init__; also derives dt_output,
dt_integrator, and relation_integrator_output from the model.
Source code in dynamodels/integrator.py
212 213 214 215 216 217 218 219 220 221 222 223 224 225 | |
advance_single(Nt=100, **kwargs)
Advance the model via model.time_step, resampled onto the
requested output times.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Nt
|
int
|
Number of output forecast steps (at spacing |
100
|
**kwargs
|
Accepted for interface compatibility with |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
psi |
ndarray, shape ``(Nt, N, m)``
|
Forecasted state at the output times, excluding the initial
condition. Taken directly from |
t |
ndarray, shape ``(Nt,)``
|
Output time stamps, spaced by |
Source code in dynamodels/integrator.py
228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 | |
advance_ensemble(Nt=100, averaged=False, alpha=None)
Identical to advance_single; averaged and alpha are
forwarded but unused (the discrete map is applied uniformly to
however many members model.time_step handles internally).
Source code in dynamodels/integrator.py
274 275 276 277 278 279 | |
dynamodels.integrator.ConstantIntegrator
Bases: Integrator
Integrator that holds the state constant over time, \(\psi(t)=\psi(0)\).
Useful for testing or as a placeholder while other model components (e.g. a bias model) are advanced.
Source code in dynamodels/integrator.py
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 | |
__init__(model_instance)
See Integrator.__init__.
Source code in dynamodels/integrator.py
150 151 152 | |
advance_single(Nt=100, **kwargs)
Repeat model.current_state at every output time.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Nt
|
int
|
Number of forecast steps. |
100
|
**kwargs
|
Accepted for interface compatibility with |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
psi |
ndarray, shape ``(Nt, N, m)``
|
|
t |
ndarray, shape ``(Nt,)``
|
Time stamps spaced by |
Source code in dynamodels/integrator.py
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 | |
advance_ensemble(Nt=100, averaged=False, alpha=None)
Identical to advance_single (the state is constant regardless of
ensemble size); averaged and alpha are forwarded but unused.
Source code in dynamodels/integrator.py
182 183 184 185 186 | |