qlroms.atlas
Atlas: the shared global coordinate system over a collection of local charts.
Implements sections 1/4 of docs/streamlined_vision_building_blocks.md: - build_global_assimilation_basis: the atlas basis Phi_g -- the Gram-Schmidt (eigendecomposition) of the union of all local chart bases and centroid offsets, so every local affine space is contained in it and the local<->atlas maps (Tgk/dgk/Tkg/dkg) are exact inverses (docs/shared_global.txt). - Atlas: the dynamics-free collection of charts, with pairwise transition operators and (optionally) the exact global atlas. Mw-aware: pass the chart inner-product weight (None = identity, (N,) diagonal, or a dense/sparse (N, N) mass matrix) and every projection/transition/atlas build uses it. - fit_charts: raw snapshots -> Atlas, the one-call offline geometry build.
Atlas
Dynamics-free chart provider exposing the surface qlESN/qlOpinf consumes: r, K, dt, device, rdtype, tree, tmap, tshift, _get_cluster_rom, recover_state. Tgk/dgk/Tkg/dkg (exact atlas switching, see build_global_atlas) are built by default from the chart geometry unless method='pairwise' is requested; g_mean_all/mu_bar_all (a separate, dynamics-related zero-mean refinement) are always None here -- qlESN treats all of these as optional.
Source code in qlroms/atlas.py
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 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 280 281 282 283 284 285 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 | |
N
property
Physical state dimension (rows of Phi_all), as on the case qlROMs.
__init__(centroids, Phi_all, dt=1.0, Mw=None, tmap=None, tshift=None, tree=None, qbar_g=None, method='auto')
Args: centroids: (K, N) cluster centroids. Phi_all: (N, r, K) local POD bases, Mw-orthonormal. dt: snapshot spacing (metadata; used by fit timing only). Mw: chart inner-product weight (see qlroms.charts.Chart): None for M = I, a (N,) diagonal, or a dense/sparse (N, N) mass matrix. Used by the per-chart projections, the pairwise transition operators, and build_global_atlas. tmap/tshift/tree: prebuilt pairwise operators (from_rom); built here if None. qbar_g: optional atlas reference state. When omitted, the atlas is built about the mean of the stored chart centroids, which is sufficient for the exact affine-space inclusion/mapping identities. fit_charts later overwrites this with the training-snapshot mean when available. method: transition strategy. Default 'auto' builds the exact shared atlas immediately and uses it when available. Use 'pairwise' to keep only tmap/tshift switching.
Source code in qlroms/atlas.py
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 | |
build_global_atlas(X, tol=1e-11, assume_tgk_transpose=True)
Attach the exact global assimilation basis (Phi_g/Tgk/dgk), so qlroms/esn_base.rom_distance switches charts on EXACT physical distances instead of falling back to the distorted in-chart tshift rule (on a real run: 100% vs 83% correct distance ordering). Uses the atlas' inner-product weight Mw.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
either a (N, Nt) snapshot matrix whose mean defines qbar_g -- typically the same matrix fit_charts was called on -- or an explicit (N,) atlas reference state. |
required | |
tol
|
float
|
relative eigenvalue cutoff dropping redundant directions (see build_global_assimilation_basis). |
1e-11
|
assume_tgk_transpose
|
bool
|
pass through to build_global_assimilation_basis; defaults to True so Tgk is enforced as Tkg^T at build time. |
True
|
Returns: self, for chaining (fit_charts(...).build_global_atlas(X) reads naturally, though fit_charts already calls this by default).
Source code in qlroms/atlas.py
278 279 280 281 282 283 284 285 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 | |
project_state(state, cluster_id=None)
(N,) or (N, m) physical -> (r+1, m) augmented coords, nearest-chart per column with the chart id in the last row -- the inverse of recover_state and the same convention as the case qlROMs, so ensemble/workflow code can run on a bare Atlas.
Source code in qlroms/atlas.py
320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 | |
recover_state(apod)
Augmented (r+1, m) coords (cluster id in the last row) -> (N, m) physical, matching qlROM.recover_state's per-column id dispatch (what qlESN.recover_state delegates to).
Source code in qlroms/atlas.py
343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 | |
from_rom(rom)
classmethod
Adapt an existing qlROM's charts (exact copy of its centroids/Phi/tmap/tshift, preserving whatever inner-product weight it was built with).
Source code in qlroms/atlas.py
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 | |
from_charts(charts, dt=1.0, *, qbar_g=None, method='auto')
classmethod
Assemble an Atlas from K already-built Chart objects (e.g. Chart.from_fenics conversions of a dolfinx POD stack): stacks their Phi/centroids, takes the inner-product weight from the first chart (all charts of one atlas share it), and by default also builds the exact shared atlas from those chart objects. Pass method='pairwise' to keep only pairwise switching.
Source code in qlroms/atlas.py
388 389 390 391 392 393 394 395 396 397 398 399 400 401 | |
save(path, **extra)
One compressed npz holding the atlas core (centroids, Phi_all, dt, qbar_g)
plus any caller metadata arrays. POD bases are nested (the leading r columns
of a rank-R basis are the rank-r basis for the same partition), so one save
at large R serves every smaller r through Atlas.load(path, r=r).
Source code in qlroms/atlas.py
403 404 405 406 407 408 409 410 411 412 413 | |
load(source, r=None, **kwargs)
classmethod
Rebuild an Atlas from save()'s npz -- a path, or an already-open
mapping of its arrays (e.g. a dict of memory-mapped .npy files). r
truncates every chart basis to its leading r modes (nested POD); transition
operators and the shared atlas are rebuilt by the constructor.
Source code in qlroms/atlas.py
415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 | |
build_global_assimilation_basis(Phi_all, centroids, qbar_g, Mw=None, tol=1e-11, assume_tgk_transpose=True)
Global M-orthonormal assimilation basis and exact local<->global maps.
Implements docs/shared_global.txt: Phi_g = build_atlas(U) U = [Phi_1..Phi_K, d_1..d_K], where d_k=(c_k-qbar_g) so every local affine space is contained in the global one and the maps below are exact inverses (up to the numerical rank of U).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Phi_all
|
(Nh, r, K) local POD bases. |
required | |
centroids
|
(K, Nh) state-space centroids. |
required | |
qbar_g
|
(Nh,) global reference (snapshot mean). |
required | |
Mw
|
chart inner-product weight: None for M = I, a (Nh,) mass-matrix diagonal, or a dense/sparse (Nh, Nh) matrix (e.g. an assembled FEM mass matrix) -- applied through qlroms.charts.apply_weight. |
None
|
|
tol
|
relative eigenvalue cutoff dropping redundant directions of U. Default: 1e-11 NB: At large K*r (e.g. K=40, r=50 -> U has 2040 columns), dividing by their near-zero eigenvalues below (Vr/sqrt(Lr)) pushes the exact-atlas residual (assert below) over 1e-6. Lowering tol keeps more of the real structure the offsets need to reconstruct exactly; verified across seeds that 1e-11 stays well short of where Phi_g's own M-orthonormality (Phi_g.T @ M @ Phi_g == I) starts degrading (1e-12 and below). |
1e-11
|
|
assume_tgk_transpose
|
bool
|
if True (default), enforce Tgk[k] = Tkg[k].T at build time. dgk/dkg are still computed independently and are NOT tied by this flag. |
True
|
Returns: Phi_g (Nh, rg), Tgk (K, rg, r), dgk (K, rg), Tkg (K, r, rg), dkg(K, r), where z = Tgk[k] @ a_k + dgk[k]; #local->atlas a_k = Tkg[k] @ z + dkg[k]; #atlas->local
Source code in qlroms/atlas.py
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 | |
fit_charts(X, K, r, dt=1.0, *, random_state=1, pod_method='exact', pod_kwargs=None, clustering_kwargs=None, cluster_space='physical', Mw=None, build_atlas=True, assume_tgk_transpose=True, time_index=None, include_transition_snapshots=False, device=None, rdtype=torch.float64)
Build an Atlas from raw snapshots: KMeans clusters + per-cluster POD. No dynamics fitted -- this is all a qlESN needs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
(N, Ntrain) snapshot matrix, any source (chronological order not required for charts, but qlESN.fit later needs it for dwell segments). |
required | |
K, r
|
number of clusters and POD modes per cluster. |
required | |
dt
|
float
|
snapshot spacing (metadata). |
1.0
|
clustering_kwargs
|
dict | None
|
forwarded to fit_clusters (random_state, kmeans_method, assign_overlapping, overlap_tolerance, ...). |
None
|
pod_kwargs
|
dict | None
|
extra compute_pod_basis knobs for the randomized methods (oversampling, n_iter, block_size, random_state). |
None
|
cluster_space
|
CLUSTER_SPACES
|
which representation of the snapshots k-means clusters on -- "physical" (default), "pod_lossless", "pod_r", or a callable; see clustering_features. For non-physical spaces the centroids are recomputed as physical-space means of the assigned columns afterwards. |
'physical'
|
Mw
|
chart inner-product weight (None = identity). When given, the per-cluster POD is Mw-weighted (method of snapshots, Mw-orthonormal modes) and the Atlas carries Mw through projections/transitions/global atlas. Clustering stays Euclidean (labels only). |
None
|
|
build_atlas
|
bool
|
also fit the global assimilation basis (Tgk/dgk) so qlESN's chart switching uses exact physical distances (Atlas.build_global_atlas). Default True; set False to skip the extra eigendecomposition (O((Kr+K)^2) or so) when K*r is large and only approximate switching is needed. |
True
|
assume_tgk_transpose
|
bool
|
when building the atlas, enforce Tgk = Tkg^T (default True). dgk/dkg remain independently computed. |
True
|
time_index
|
optional (Ntrain,) monotone integer index, one entry per X column, marking genuine time adjacency (gap > 1 = not consecutive -- e.g. multi-run seams from split.data.concat_wake_runs). Only used by include_transition_snapshots; None assumes one contiguous run. |
None
|
|
include_transition_snapshots
|
bool
|
if True (needs X in chronological order), each cluster k's POD basis is additionally fit on the immediate POST-SWITCH snapshots (the genuinely-next-in-time snapshot of each member that leaves cluster k, which itself belongs to a different cluster). Default False (previous behaviour). |
False
|
Source code in qlroms/atlas.py
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 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 | |