Skip to content

Repository files navigation

Field-map compression & fitting with HOSVD

CI License: MIT Python DOI

Multivariant spatial and geometric interpolation of field maps through model order reduction.

Complex three-dimensional field maps can be efficiently de-noised and compressed by High-Order Singular Value Decomposition (HOSVD). Building on the original application of the method to the electric field map of a drift-tube linac (X. Du & L. Groening, Phys. Rev. Accel. Beams 21, 084601, 2018), this repository accompanies the follow-up paper (X. Du & L. Groening, Phys. Rev. Accel. Beams 25, 124601, 2022), which extends it to inter-/extrapolation and to the determination of a basis-function representation. Inter-/extrapolation is applied both to spatial coordinates and to the parameters defining the geometry of the devices that create the maps. This yields compact, noise-free maps at high resolution. The method is illustrated on the RF cells of a radio-frequency quadrupole (RFQ).

HOSVD pipeline

Highlights

  • 🗜️ Compression — store a multi-dimensional field map in a tiny core tensor plus a few factor matrices (hundreds- to thousands-fold smaller).
  • 🧹 De-noising — discarding the small singular values removes simulation/measurement noise.
  • 🔍 Inter-/extrapolation — resample the compressed model onto an arbitrary grid and onto arbitrary device-geometry parameters.
  • 📐 Closed-form fitting — fit the singular vectors with Legendre polynomials for a continuous, analytic model.

Quickstart

No external data required — the example builds its own synthetic field map.

git clone https://github.com/duxngsi/Field_maps_HOSVD-compress-fitting.git
cd Field_maps_HOSVD-compress-fitting
pip install -r requirements.txt
python quickstart.py

Expected output (abridged):

synthetic field map: shape=(6, 6, 6, 40, 21, 21), 3,810,240 elements
injected noise (rel. L2): 4.998%
...
compressed to ranks (4, 4, 4, 4, 4, 4)
  stored elements : 4,496  (core (4, 4, 4, 4, 4, 4))
  compression     : 847x
  error vs clean  : 0.168%   <- de-noised reconstruction
  error vs noisy  : 4.989%
  -> reconstruction is closer to ground truth than the noisy input (de-noising works).
resampled mode 3 (z) from 40 to 80 nodes -> recovered shape (6, 6, 6, 80, 21, 21)

A 6-D field map of 3.8 M values is compressed 847× while the reconstruction sits within 0.2 % of the ground truth — well below the 5 % injected noise:

Clean vs noisy vs HOSVD reconstruction

Usage

import numpy as np
from HOSVD import hosvd

data = np.load("my_field_map.npy")   # an N-dimensional array

model = hosvd(data)                  # decompose every mode
model.trim((2, 2, 2, 3, 3, 3))       # keep the dominant modes -> compress & de-noise
model.save("./saved_HOSVD/")         # persist core tensor + factors

approx = model.recover()             # reconstruct the compressed map

# Inter-/extrapolate: resample chosen modes onto new (normalized 0..1) coordinates.
model.resample([[], [], [], np.linspace(0, 1, 400), [], []])
fine = model.recover()               # higher z-resolution than the original

hosvd API

Method / attribute Purpose
hosvd(data) Decompose an N-D array (covariance-based HOSVD).
hosvd(load_from=path) Reload a previously saved decomposition.
.trim(new_shape) Keep the leading singular vectors per mode (compression / de-noising).
.recover() Reconstruct the (compressed) tensor.
.resample(new_v) Resample factor matrices onto new coordinates (inter-/extrapolation).
.save(path) / .load(path) Persist / reload CoreT, v, s.
.v, .s, .CoreT Factor matrices, singular values, core tensor.

basis.py provides Legendre and Polynomial sampled bases used to fit the factor matrices.

Repository layout

Path Description
HOSVD.py Core library: the hosvd class and CST field-map readers.
basis.py Legendre / polynomial basis functions for fitting the factors.
make_synthetic_data.py Generate a self-contained synthetic field-map tensor.
quickstart.py End-to-end demo on synthetic data (no external files needed).
demo.py Reproduce the paper figures from the original RFQ data set.
RFQ_cell_map_producer.py Tkinter GUI to generate RFQ cell maps from a compressed model.
tests/ pytest unit tests.

Reproducing the paper figures

demo.py operates on the original RFQ data set (a 6-D tensor of CST-simulated RF-cell maps). The raw exports are large and are shared separately:

Data: https://drive.google.com/drive/folders/1cYFu_IA5WmKiDpTkB89WaOOAJSO79YnZ

Download the saved_HOSVD/ folder into the repository root, then call the relevant figure function (comp_para_expo, show_v, base_fitting_show, V_trim_demo, …) from demo.py.

Benchmark: HOSVD vs. the eight-term RFQ potential

benchmarks/compare_eightterm.py compares the polynomial-fit HOSVD model against the classic RFQ eight-term potential on the original check cell — for field evaluations used in particle tracking. Inside the aperture:

metric (vs. CST reference) HOSVD polynomial fit eight-term potential (best least-squares)
relative L2 error 1.9 % 5.4 %
evaluation throughput 2.7 Mpoint/s 1.0 Mpoint/s

The HOSVD representation is both more accurate (a data-adaptive basis captures the real, non-ideal field) and faster to evaluate (pure polynomial arithmetic instead of modified-Bessel and trigonometric functions). The eight-term coefficients and its longitudinal/transverse wavenumbers are fitted to give it its best case; the throughput is NumPy-vectorized, so a compiled tracking code would widen the gap further. (Requires the data set above; numbers are from one run.)

Tests

pip install -r requirements.txt pytest
pytest

Citation

If you use this code, please cite the paper it accompanies:

@article{Du2022Multivariant,
  title   = {Multivariant spatial and geometric interpolation of field maps through model order reduction},
  author  = {Du, Xiaonan and Groening, Lars},
  journal = {Physical Review Accelerators and Beams},
  volume  = {25},
  issue   = {12},
  pages   = {124601},
  year    = {2022},
  doi     = {10.1103/PhysRevAccelBeams.25.124601}
}

This work builds on the foundational method introduced in:

@article{Du2018FieldMaps,
  title   = {Compression and noise reduction of field maps},
  author  = {Du, Xiaonan and Groening, Lars},
  journal = {Physical Review Accelerators and Beams},
  volume  = {21},
  issue   = {8},
  pages   = {084601},
  year    = {2018},
  doi     = {10.1103/PhysRevAccelBeams.21.084601}
}

(See CITATION.cff.)

License

Released under the MIT License.

About

HOSVD-based de-noising, compression and multivariate inter/extrapolation of 3-D field maps. Companion code to Phys. Rev. Accel. Beams 25, 124601 (2022).

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages