-
Notifications
You must be signed in to change notification settings - Fork 1
Adaptive Pauli-Lindbladian shim + adaptive-evolution demo #98
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
Draft
AlexSchuckert
wants to merge
26
commits into
main
Choose a base branch
from
lindblad-shim
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
177fbee
feat(python-native): Rust shim for adaptive Pauli-Lindbladian time ev…
AlexSchuckert 962ba18
feat(python): adaptive Lindbladian demo, shim tests, lazy SciPy
AlexSchuckert 1a7d054
feat(lindblad): extract ppvm-lindblad crate, non-Hermitian jumps, pur…
AlexSchuckert ea294e3
feat(python): Lindbladian pc_step, sigma_plus/minus jumps, convergenc…
AlexSchuckert 5e70242
Fix SPDX header formatting in lindblad.py
Copilot e54b88c
review: address PR #98 review comments
AlexSchuckert 9fd6ef5
review(ppvm-lindblad): swap custom CsrMatrix for sprs::CsMatI<f64, u3…
AlexSchuckert e043ae1
feat(ppvm-lindblad): add `drop_tol` to pc_step for in-Rust basis pruning
AlexSchuckert 5ad4e83
Remove action_cache from LindbladSpec
AlexSchuckert 53f7ff2
perf(ppvm-lindblad): mimalloc allocator + chunked leakage → ~50% peak…
AlexSchuckert d763aa8
feat(lindblad): K parameter for pc_step; default K=5
AlexSchuckert dfc3204
Merge remote-tracking branch 'origin/main' into lindblad-pr-fixes
AlexSchuckert a591310
feat(ppvm-lindblad): matrix-free pc_step, rk4_step, and memory opts
AlexSchuckert a8e4dcc
Update Julia version and make sure benchmarks are consistent
david-pl 6dca8a5
Merge branch 'main' into david/update-julia-benches
david-pl 13aaad4
More efficient weight calculation
david-pl 1a67b31
Inline cutoff
david-pl 1a2b8f8
Hard-code weight to avoid slicing overhead
david-pl 8ea602f
Add an early return for max_weight == usize::MAX
david-pl 0072256
Remove svg
david-pl 3fa4a0f
Merge david/fix-weight-calc (#126, faster weight calc) into lindblad-…
AlexSchuckert b2e06c9
fix(ppvm-lindblad): set max_krylov_m in ExpmOpts test constructors
AlexSchuckert fe486ff
feat(ppvm-lindblad): drive real expm action via quspin-expm (matrix-f…
AlexSchuckert 84ab1a1
refactor(ppvm-lindblad): remove retired expm engine and CSR-for-real …
AlexSchuckert b07f75d
refactor(ppvm-lindblad): address PR #98 review comments
AlexSchuckert f14edaf
refactor(ppvm-python-native): drop the mimalloc global allocator
AlexSchuckert 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
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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,24 @@ | ||
| [package] | ||
| name = "ppvm-lindblad" | ||
| version = "0.1.0" | ||
| edition = "2024" | ||
| description = "Direct Heisenberg-picture Lindbladian evolution on an adaptive Pauli-string basis." | ||
|
|
||
| [dependencies] | ||
| fxhash = "0.2.1" | ||
| ndarray = "0.17" | ||
| num = "0.4.3" | ||
| ppvm-runtime = { version = "0.1.0", path = "../ppvm-runtime" } | ||
| rayon = "1.11" | ||
| sprs = { version = "0.11", default-features = false, features = ["multi_thread"] } | ||
| # Matrix-exponential action (Al-Mohy & Higham). NOTE: QuSpin-rust currently has | ||
| # no LICENSE file; this pin is a placeholder pending a permissive license being | ||
| # added upstream (the authors are co-authors of the ppvm paper). | ||
| quspin-expm = { git = "https://github.com/QuSpin/QuSpin-rust", rev = "6f4a1581e14d5258c9aeb684b4aec964bdff4e34" } | ||
| # `QuSpinError` (the error type returned by the `LinearOperator` trait methods | ||
| # we implement in `mf_expm.rs`) is not re-exported from `quspin-expm`'s root, | ||
| # so we depend on `quspin-types` directly. Same git rev as `quspin-expm`. | ||
| quspin-types = { git = "https://github.com/QuSpin/QuSpin-rust", rev = "6f4a1581e14d5258c9aeb684b4aec964bdff4e34" } | ||
|
|
||
| [dev-dependencies] | ||
| approx = "0.5.1" |
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,27 @@ | ||
| // SPDX-FileCopyrightText: 2026 The PPVM Authors | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| //! Configuration objects for the predictor-corrector stepper. | ||
|
|
||
| /// Policy options for a single predictor-corrector step | ||
| /// ([`crate::LindbladSpec::pc_step`] / [`crate::LindbladSpec::pc_step_timed`]). | ||
| /// | ||
| /// These are the per-run *tuning knobs*, kept separate from the per-call data | ||
| /// (`basis`, `coeffs`, `dt`, `protected`) so the step functions don't grow an | ||
| /// unwieldy positional-argument list. | ||
| #[derive(Debug, Clone, Copy)] | ||
| pub struct PcStepConfig { | ||
| /// Leakage-rate threshold for basis growth: a leakage Pauli is appended to | ||
| /// the basis only if its `|coeff|` exceeds `tau_add`. Larger values keep the | ||
| /// basis smaller (faster, less accurate); it also drives the streaming | ||
| /// Cauchy-Schwarz prune in [`crate::LindbladSpec::leakage_with_prune`]. | ||
| pub tau_add: f64, | ||
| /// Magnitude prune applied after the corrector: basis entries whose | ||
| /// `|coeff|` is below `drop_tol` are discarded (protected words are always | ||
| /// kept). `drop_tol <= 0.0` disables pruning. | ||
| pub drop_tol: f64, | ||
| /// When `Some(n)`, run the entire step inside a freshly built rayon thread | ||
| /// pool of `n` threads (useful for benchmarking parallel scaling). When | ||
| /// `None`, the global rayon pool is used. | ||
| pub num_threads: Option<usize>, | ||
| } |
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,76 @@ | ||
| // SPDX-FileCopyrightText: 2026 The PPVM Authors | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| //! Error type for [`crate::LindbladSpec`] construction and stepping. | ||
|
|
||
| use crate::MAX_QUBITS; | ||
| use std::fmt; | ||
|
|
||
| /// Errors raised when constructing a [`crate::LindbladSpec`]. | ||
| #[derive(Debug, Clone)] | ||
| pub enum Error { | ||
| TooManyQubits { | ||
| got: usize, | ||
| }, | ||
| LengthMismatch { | ||
| what: &'static str, | ||
| a: usize, | ||
| b: usize, | ||
| }, | ||
| InvalidPauliCode { | ||
| code: u8, | ||
| }, | ||
| InvalidPauliChar { | ||
| c: char, | ||
| }, | ||
| WrongLength { | ||
| expected: usize, | ||
| got: usize, | ||
| }, | ||
| NegativeRate { | ||
| index: usize, | ||
| rate: f64, | ||
| }, | ||
| EmptyLincomb { | ||
| index: usize, | ||
| }, | ||
| Internal(String), | ||
| } | ||
|
|
||
| impl fmt::Display for Error { | ||
| fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
| match self { | ||
| Error::TooManyQubits { got } => { | ||
| write!( | ||
| f, | ||
| "LindbladSpec supports n_qubits ≤ {MAX_QUBITS}; got {got}" | ||
| ) | ||
| } | ||
| Error::LengthMismatch { what, a, b } => { | ||
| write!(f, "{what}: expected matching lengths, got {a} and {b}") | ||
| } | ||
| Error::InvalidPauliCode { code } => write!( | ||
| f, | ||
| "Pauli code must be 0 (I), 1 (X), 2 (Z), or 3 (Y); got {code}" | ||
| ), | ||
| Error::InvalidPauliChar { c } => { | ||
| write!(f, "invalid Pauli character '{c}'; expected I, X, Y, or Z") | ||
| } | ||
| Error::WrongLength { expected, got } => { | ||
| write!(f, "Pauli string has length {got} but n_qubits = {expected}") | ||
| } | ||
| Error::NegativeRate { index, rate } => { | ||
| write!(f, "jump rate must be non-negative; got γ_{index} = {rate}") | ||
| } | ||
| Error::EmptyLincomb { index } => { | ||
| write!( | ||
| f, | ||
| "jump {index}: lincomb must contain at least one Pauli term" | ||
| ) | ||
| } | ||
| Error::Internal(msg) => write!(f, "internal error: {msg}"), | ||
| } | ||
| } | ||
| } | ||
|
|
||
| impl std::error::Error for Error {} |
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,99 @@ | ||
| // SPDX-FileCopyrightText: 2026 The PPVM Authors | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| //! Support pieces for the `quspin-expm`-backed `exp(t·A)·b` engine. | ||
| //! | ||
| //! The hand-rolled scaling-and-squaring engine that once lived here has been | ||
| //! retired in favour of the external `quspin-expm` crate (driven from | ||
| //! [`crate::mf_expm`]). What remains is the shared scaffolding the new path | ||
| //! still relies on: the `(m, s)` selection table [`THETA`] / [`select_ms`] | ||
| //! from Al-Mohy & Higham (2011), used to pick the Taylor partition handed to | ||
| //! `quspin-expm`'s `from_parts`. | ||
|
|
||
| /// `θ_m` table from Al-Mohy & Higham (2011), Table A.3, for double | ||
| /// precision (unit roundoff `u = 2^{-53}`). | ||
| /// | ||
| /// `θ_m` bounds `‖A‖₁` such that the degree-`m` Taylor polynomial | ||
| /// approximates `exp(A)` to within `u`. We pick `(m, s)` with | ||
| /// `s ≥ ⌈‖tA‖₁ / θ_m⌉` and minimise `m·s` (total SpMV count). | ||
| pub(crate) const THETA: &[(u32, f64)] = &[ | ||
| (1, 2.29e-16), | ||
| (2, 2.58e-8), | ||
| (3, 1.39e-5), | ||
| (4, 3.40e-4), | ||
| (5, 2.40e-3), | ||
| (6, 9.07e-3), | ||
| (7, 2.38e-2), | ||
| (8, 5.00e-2), | ||
| (9, 8.96e-2), | ||
| (10, 1.44e-1), | ||
| (11, 2.14e-1), | ||
| (12, 3.00e-1), | ||
| (13, 4.00e-1), | ||
| (14, 5.14e-1), | ||
| (15, 6.41e-1), | ||
| (16, 7.81e-1), | ||
| (17, 9.31e-1), | ||
| (18, 1.09), | ||
| (19, 1.26), | ||
| (20, 1.44), | ||
| (21, 1.62), | ||
| (22, 1.82), | ||
| (23, 2.01), | ||
| (24, 2.22), | ||
| (25, 2.43), | ||
| (26, 2.64), | ||
| (27, 2.86), | ||
| (28, 3.08), | ||
| (29, 3.31), | ||
| (30, 3.54), | ||
| ]; | ||
|
|
||
| /// Pick `(m, s)` minimising `s·m` subject to `s ≥ ⌈t_norm / θ_m⌉, s ≥ 1`. | ||
| /// Restricted to `m ≤ 30`; for larger norms `s` simply grows linearly. | ||
| /// When `max_m` is set, only entries with `m ≤ max_m` are considered. | ||
| pub(crate) fn select_ms(t_norm: f64, max_m: Option<u32>) -> (u32, u32) { | ||
| if t_norm <= 0.0 { | ||
| return (1, 1); | ||
| } | ||
| let mut best_m = 1u32; | ||
| let mut best_s = 1u32; | ||
| let mut best_cost = u64::MAX; | ||
| for &(m, theta) in THETA { | ||
| if let Some(cap) = max_m { | ||
| if m > cap { | ||
| continue; | ||
| } | ||
| } | ||
| let s_f = (t_norm / theta).ceil(); | ||
| let s = if s_f >= 1.0 { s_f as u32 } else { 1 }; | ||
| let cost = (m as u64) * (s as u64); | ||
| if cost < best_cost { | ||
| best_cost = cost; | ||
| best_m = m; | ||
| best_s = s; | ||
| } | ||
| } | ||
| (best_m, best_s) | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::*; | ||
|
|
||
| #[test] | ||
| fn ms_selection_sane() { | ||
| // tiny norm → small m, s = 1 | ||
| let (m, s) = select_ms(1e-9, None); | ||
| assert!(m <= 5, "expected small m for tiny norm, got m={m}"); | ||
| assert_eq!(s, 1); | ||
|
|
||
| // moderate norm → m·s should be ~10-50 | ||
| let (m, s) = select_ms(1.0, None); | ||
| assert!((m * s) <= 50, "moderate norm cost too high: m={m} s={s}"); | ||
|
|
||
| // large norm → s grows | ||
| let (_m, s) = select_ms(100.0, None); | ||
| assert!(s >= 20, "large norm should require many steps, got s={s}"); | ||
| } | ||
| } | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you're adding this as an internal implementation, it would be nice to add this as a separate crate instead of within ppvm-liblblod. I imagine this will be useful for other Rust developers as well, and it will also help clean up the dependency a little bit.
It would be nice to first submit a separate PR that creates a single crate that implements sparse matrix and exponential.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed: rather than a first-party crate, the matrix-exponential is now provided by the external
quspin-expmcrate (QuSpin-rust).expm.rsis reduced to just the(m, s)selection table, so the dependency surface is much smaller.