Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .jules/bolt.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@
## 2025-11-01 - [Avoid Temporary Array Allocations in Reductions]
**Learning:** In loops over parameters like temperature (`thermal_scan`), doing `np.sum(arr1 * arr2)` where array sizes match the system Hilbert space creates huge temporary arrays per loop iteration. Memory allocation dominates execution time.
**Action:** Use `np.dot(arr1, arr2)` instead of `np.sum(arr1 * arr2)` for 1D arrays to evaluate reductions in C-level BLAS/NumPy functions, bypassing Python/NumPy array allocations and boosting performance significantly with less peak memory.
## 2025-11-01 - [Avoid O(N^3) Full Matrix Multiplication when Only the Diagonal is Needed]
**Learning:** In computing expectation values of squared operators (like $A^2$ in finite temperature static susceptibility calculations), using `A @ A` computes the entire full matrix which has an $O(N^3)$ computational cost and $O(N^2)$ memory allocation cost, only for `np.diag(A @ A)` to discard everything but the diagonal elements.
**Action:** Replace `np.diag(A @ A)` with `np.einsum('ij,ji->i', A, A, optimize=True)`. This computes only the diagonal elements mathematically taking $O(N^2)$ operations and zero intermediate $O(N^2)$ allocations, dramatically speeding up calculations for large dimensions (e.g. from 20s to <1s for large N).
Loading