The production spintronics backend of the COOLJAPAN scientific stack just got faster in the hot loop and safer at the API edge.
On June 10 we released Spintronics 0.3.1 — an incremental patch on top of the production-grade 0.3.0 release, sharpening the micromagnetic demagnetizing-field path, tightening a topological-Hamiltonian API, and refreshing the scirs2 dependency line.
No Python loops. No C++ memory bugs. No Fortran.
No external binaries or unsafe code in hot paths.
Just clean, memory-safe, physically accurate simulations that compile to a single static binary (or WASM) and run everywhere.
This is not a debut and not a rewrite. 0.3.0 already shipped the full physics stack — LLG/LLB solvers, skyrmions and hopfions, ISHE/SSE, magnon BEC, altermagnets, the SimulationBuilder fluent API, PyO3 bindings, and WASM — validated against landmark Saitoh Group experiments. 0.3.1 polishes the parts that mattered most for large-scale micromagnetic runs.
Why 0.3.1
The demagnetizing field is the single most expensive term in any finite-size micromagnetic simulation. Its O(N²) Newell-tensor convolution dominates wall-clock time on large cubes, and in 0.3.0 that inner loop dispatched through Option-returning tensor-component helpers (get_n_xx/yy/zz) on every cell pair. 0.3.1 removes that overhead and unlocks the multi-core path:
- Flat kernel indexing.
DemagField::computenow indexes a direct flat kernel array (kidx = row_base + u_base − jx) instead of dispatching through Option-returning helpers. Results are bit-for-bit identical to 0.3.0 — guaranteed by a new regression test, not just inspection. - Optional rayon parallelism. With the
parallelfeature enabled, every target cell of the demag convolution is now computed concurrently viarayon::into_par_iter, giving the heaviest kernel in the library straightforward multi-core speedup. - Safer topological API.
BbhModel::hamiltonian_at(kx, ky)(the Benalcazar–Bernevig–Hughes higher-order topological insulator model) now returnsResult<CMatrix>, propagating matrix-dimension errors through?instead of panicking on a shape mismatch.
These build on the 0.3.0 baseline — 52–100× faster than Python+NumPy across LLG, skyrmion-number and spin-chain kernels, with a memory pool allocator delivering 99% allocation reduction in hot paths. 0.3.1 keeps every one of those results and makes the demag path cheaper still.
Technical note: the changed areas
The work in 0.3.1 is concentrated in three files, and the changes are surgical:
-
src/micromagnetics/demag.rs— the inner convolution loop was rewritten around direct flat kernel-array indexing. The oldget_n_xx/yy/zzhelper dispatch is gone; the kernel is read by precomputed offset. Underparallel, the per-cell loop becomes arayon::into_par_iter, so the demag field for all target cells is assembled concurrently. A new regression test pins the output bit-for-bit against the previous implementation. -
src/topomagnon/hoti.rs—BbhModel::hamiltonian_atgraduates from returning a bareCMatrixtoResult<CMatrix>. Shape errors now flow through?rather than panicking. Breaking change: callers that consumed the return value directly must now handle theResult(propagate with?, or.unwrap()at a call site you control). -
src/validation/standard_problems/sp3.rs—test_large_cube_vortex_stable(µMAG Standard Problem 3) was reduced from 100 to 25 relaxation steps to stay inside the CI time budget on the O(N²) Newell-tensor demag path, with clarified comments. The physics being validated is unchanged; only the iteration count in the test fixture moved.
On the dependency side, scirs2-core and scirs2-spatial both move to 0.5.0, now pulled with default-features = false and an explicit feature list (["std", "array", "random", "parallel"] for the core), so the build no longer drags in unused optional sub-crates. The workspace also unifies version tracking: the top-level and demo/ manifests now use version.workspace = true.
Getting Started
cargo add spintronics
spintronics defaults to ["fem", "scirs2", "serde"], so the FEM helpers, the scirs2-core scientific backend, and serde I/O are on out of the box. A minimal YIG/Pt spin-pumping run through the 0.3.0 SimulationBuilder fluent API:
use spintronics::prelude::*;
fn main() -> Result<()> {
// YIG film magnetization, with an external field along z.
let m0 = Vector3::new(1.0, 0.0, 0.0);
let h_ext = Vector3::new(0.0, 0.0, 1.0);
// Build an LLG simulation with the adaptive Dormand–Prince 4(5) solver.
let result = SimulationBuilder::new()
.material(Ferromagnet::yig())
.initial_magnetization(m0)
.external_field(h_ext)
.solver_dp45()
.steps(1_000)
.run()?;
println!("final magnetization: {:?}", result.final_magnetization());
Ok(())
}
To turn on the parallel demag path for large micromagnetic problems, add the parallel feature:
cargo add spintronics --features parallel
What’s New in 0.3.1
- DemagField hot loop rewritten to use direct flat kernel-array indexing, removing the Option-returning
get_n_xx/yy/zzhelper dispatch — bit-for-bit identical output, verified by a new regression test. - Parallel demag convolution under the
parallelfeature: all target cells computed concurrently viarayon::into_par_iter. BbhModel::hamiltonian_atnow returnsResult<CMatrix>for proper error propagation (breaking change for direct callers).- µMAG Standard Problem 3 test (
test_large_cube_vortex_stable) trimmed from 100 to 25 relaxation steps to fit the CI time budget. scirs2-coreandscirs2-spatialupgraded to 0.5.0, both withdefault-features = falseand an explicit feature list to avoid unused optional sub-crate dependencies.- Workspace version tracking unified via
version.workspace = truein the top-level anddemo/manifests. - 1829 tests passing, zero warnings across unit, doc, and integration suites.
Tips
- Flip on
parallelfor big demag jobs. The flat-kernel rewrite already helps single-threaded, but the win compounds on large cubes oncerayon::into_par_iterfans the convolution across cores:cargo add spintronics --features parallel. - Migrating from 0.3.0? The only source-breaking change is
BbhModel::hamiltonian_at. Add a?(or.unwrap()where appropriate) at each call site; everything else —SimulationBuilder, the LLG/LLB solvers, thetexture/magnon/afmmodules — is wire-compatible. - Keep your demag results reproducible. The new flat indexing is bit-for-bit identical to 0.3.0, so trajectories and exported VTK/HDF5 fields don’t shift across the upgrade — the regression test guarantees it.
- Lean default features stay lean. Because
scirs2-coreis now pulled withdefault-features = false, you get exactlystd,array,random, andparallel. If you need more from the scientific backend, enable it explicitly rather than relying on transitive defaults. - Building for WASM? Keep
scirs2/femoff and reach for thewasmfeature — thescirs2-coreandscirs2-spatialdependencies are optional precisely so browser builds stay slim.
This is the foundation
Spintronics remains the spintronics and magnonics backend for the COOLJAPAN scientific stack:
- SciRS2 / NumRS2 — core spin dynamics and magnon calculations, now on
scirs2-core0.5.0 - OxiMedia — visualization of magnetic textures and domain walls
- ToRSh — high-throughput spin-transport workloads
- Future integration with OxiLean for formally verified LLG solvers
0.3.1 keeps that surface stable while making the heaviest micromagnetic kernel cheaper and one more topological API panic-free.
Repository: https://github.com/cool-japan/spintronics
Star the repo if you want production-grade spintronics that gets faster and safer one patch at a time — without ever touching C++ or Fortran.
Pure Rust spintronics simulation is here — fast, safe, and sovereign.
— KitaSan at COOLJAPAN OÜ June 10, 2026