-
-
Notifications
You must be signed in to change notification settings - Fork 18
improved Lanczos iteration and introduced numba usage leading to significant speedup #310
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
78 commits
Select commit
Hold shift + click to select a range
53815fa
updated to adaptive Lanczos and changed dense path
aaronleesander 91fd995
added eigendecomposition caching to matrix exponential
aaronleesander 356d3a0
added numba path for large tensors
aaronleesander d171e68
updated comments and docstrings
aaronleesander b637e66
lanczos method removed where unneeded
aaronleesander e3c8926
ruff and ty fixes
aaronleesander bd4acdf
Added numba path for dense Hamiltonian path
aaronleesander 33a4e78
updated docs
aaronleesander 2efee31
fixed ruff and ty errors
aaronleesander 4b2f7d4
Merge branch 'main' into lanczos-speedup
aaronleesander ae347ff
🎨 pre-commit fixes
pre-commit-ci[bot] 6a7ae24
updated changelog
aaronleesander 658f044
removed unneeded ruff flags
aaronleesander baf10ce
set ordering for numba
aaronleesander 2568f7b
fixed versioning and ty errors
aaronleesander 6c698b2
updated changelog
aaronleesander 21cff91
updated numba dependencies
aaronleesander 2c381a2
Merge branch 'main' into lanczos-speedup
aaronleesander d4183e9
pre-commit update
aaronleesander 9e7beca
🎨 pre-commit fixes
pre-commit-ci[bot] e25e9e1
fix pre-commit
aaronleesander 60c0677
🎨 pre-commit fixes
pre-commit-ci[bot] cd4cb69
update pre-commit
aaronleesander 2618846
new dependency requires tests to be skipped on macos with Python 3.14
aaronleesander 9ba549f
skip mac intel tests due to missing wheels
aaronleesander d2d3980
Update .pre-commit-config.yaml
aaronleesander 29c48b7
Update .pre-commit-config.yaml
aaronleesander 2b9ace1
Update CHANGELOG.md
aaronleesander 600bf77
Update CHANGELOG.md
aaronleesander a0de445
Update noxfile.py
aaronleesander f9524be
🎨 pre-commit fixes
pre-commit-ci[bot] 652ae2d
dropped suport for x86 macOS
aaronleesander 75e6b67
🎨 pre-commit fixes
pre-commit-ci[bot] 6efdbe6
fixed typo
aaronleesander 838e0ab
update uv.lock to fix pre-commit error
aaronleesander 6207427
Merge branch 'lanczos-speedup' of https://github.com/munich-quantum-t…
aaronleesander d9aec4e
Update ci.yml
burgholzer 6721aea
Update CHANGELOG.md
burgholzer e34e49d
removed 0.3.3 reference
aaronleesander fb0864f
Merge branch 'lanczos-speedup' of https://github.com/munich-quantum-t…
aaronleesander 1e9ba8e
Merge branch 'main' into lanczos-speedup
aaronleesander 880f6a7
uv lock regenerated
aaronleesander 54bac29
reduced test sizes for test speedup
aaronleesander 00a7ad4
capped parallel workers during testing
aaronleesander 61fffab
lowered number of trajectories to speed up slow tests
aaronleesander 2df689a
minimum tests reduced to one OS to speed up test suite
aaronleesander 38084f5
🎨 pre-commit fixes
pre-commit-ci[bot] 5eccd52
updated docstrings
aaronleesander c044877
Merge branch 'lanczos-speedup' of https://github.com/munich-quantum-t…
aaronleesander 384ba16
updated thresholds
aaronleesander e68da4c
disabled numba for testing
aaronleesander 86e0b6f
updated thresholds
aaronleesander f0a445f
removed unneeded error check
aaronleesander 59b2ea9
removed comment
aaronleesander 9af45b0
🎨 pre-commit fixes
pre-commit-ci[bot] d51d419
updated minimums check
aaronleesander e769fe2
added ruff exception to numba import
aaronleesander 0174612
merge
aaronleesander 3b3bf97
🎨 pre-commit fixes
pre-commit-ci[bot] 34ea3bc
increased trajectories in tests
aaronleesander 77c61cc
Merge branch 'lanczos-speedup' of https://github.com/munich-quantum-t…
aaronleesander 1000b30
added catch for OSError
aaronleesander 966cae3
added ruff exception
aaronleesander 4f199b2
🎨 pre-commit fixes
pre-commit-ci[bot] b97bc3d
simplified long range noise test for stability
aaronleesander 09f89d2
updated comment
aaronleesander 62c8d10
added tests for numba implementation
aaronleesander c03f3a3
🎨 pre-commit fixes
pre-commit-ci[bot] d4fff73
ruff and ty fixes
aaronleesander 11904b2
import fixes
aaronleesander 4bf3c65
removed unneeded variable
aaronleesander e3bcba3
change test value to fortran array
aaronleesander a740107
fixed unneeded lines in test
aaronleesander 2d3676c
added ruff exception
aaronleesander 1823246
🎨 pre-commit fixes
pre-commit-ci[bot] 004897a
added explicit check for numba path
aaronleesander b05ab9b
ruff fixes
aaronleesander 23e5f35
fixed CodeCov result by disabling JIT for coverage
aaronleesander File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| # Copyright (c) 2025 - 2026 Chair for Design Automation, TUM | ||
| # All rights reserved. | ||
| # | ||
| # SPDX-License-Identifier: MIT | ||
| # | ||
| # Licensed under the MIT License | ||
|
|
||
| """Numba-accelerated Lanczos methods.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import numpy as np | ||
| from numba import jit | ||
|
|
||
|
|
||
| @jit(nopython=True, cache=True, fastmath=True) | ||
| def orthogonalize_step( | ||
| v: np.ndarray, | ||
| w: np.ndarray, | ||
| j: int, | ||
| alpha: np.ndarray, | ||
| beta: np.ndarray, | ||
| ) -> float: | ||
| """Perform the orthogonalization step of the Lanczos iteration. | ||
|
|
||
| Computes alpha[j] = <v_j, w>, orthogonalizes w against v_j and v_{j-1}, | ||
| and computes the norm beta[j] = ||w||. | ||
|
|
||
| Args: | ||
| v: (N, m) matrix of Lanczos vectors. Columns should be contiguous (F-order) for best performance. | ||
| w: (N,) candidate vector. Modified in-place. | ||
| j: Current iteration index. | ||
| alpha: (m,) diagonal elements. | ||
| beta: (m-1,) off-diagonal elements. | ||
|
|
||
| Returns: | ||
| float: The norm of the orthogonalized vector (beta[j]), or 0.0 if not computed. | ||
| """ | ||
| # Note: v[:, j] creates a view. If v is F-ordered, this view is contiguous. | ||
| vj = v[:, j] | ||
|
|
||
| # 1. alpha_j = <v_j, w> | ||
| aj = np.vdot(vj, w).real | ||
| alpha[j] = aj | ||
|
|
||
| # 2. w <- w - aj * vj | ||
| w_len = w.size | ||
| for i in range(w_len): | ||
| w[i] -= aj * vj[i] | ||
|
|
||
| # 3. Orthogonalize against v_{j-1} if applicable | ||
| if j > 0: | ||
| v_prev = v[:, j - 1] | ||
| b_prev = beta[j - 1] | ||
| for i in range(w_len): | ||
| w[i] -= b_prev * v_prev[i] | ||
|
|
||
| # 4. Compute norm | ||
| norm_sq = 0.0 | ||
| for i in range(w_len): | ||
| val = w[i] | ||
| norm_sq += val.real * val.real + val.imag * val.imag | ||
|
|
||
| bj = np.sqrt(norm_sq) | ||
|
|
||
| if j < len(beta): | ||
| beta[j] = bj | ||
|
|
||
| return bj | ||
|
|
||
|
|
||
| @jit(nopython=True, cache=True, fastmath=True) | ||
| def normalize_and_store(v: np.ndarray, w: np.ndarray, j: int, bj: float) -> None: | ||
| """Normalize a Lanczos vector and store it in the Lanczos basis matrix. | ||
|
|
||
| This helper function completes the Lanczos iteration by normalizing the | ||
| candidate vector `w` by the computed norm `bj` and storing the result | ||
| as the next Lanczos vector in column `j+1` of the basis matrix `v`. | ||
|
|
||
| If `bj` is zero (indicating loss of orthogonality or convergence), the | ||
| normalization is skipped and the column remains unchanged. | ||
|
|
||
| Args: | ||
| v: (N, m) matrix of Lanczos vectors. Column `j+1` will be overwritten. | ||
| Should be F-ordered for optimal memory access. | ||
| w: (N,) candidate vector to normalize. Not modified. | ||
| j: Current iteration index. The normalized vector is stored in `v[:, j+1]`. | ||
| bj: Normalization factor (the computed norm of `w` after orthogonalization). | ||
| If `bj <= 0`, normalization is skipped. | ||
|
|
||
| Note: | ||
| Modifies `v` in-place. | ||
| """ | ||
| if bj > 0: | ||
| inv_bj = 1.0 / bj | ||
|
|
||
| # explicit loop | ||
| w_len = w.size | ||
| for i in range(w_len): | ||
| v[i, j + 1] = w[i] * inv_bj |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.