Repository navigation
Add in-place Hamiltonian-coefficient setter to LindbladSpec - #266
Open
kseetharam wants to merge 1 commit into
Open
kseetharam wants to merge 1 commit into
kseetharam wants to merge 1 commit into
Conversation
LindbladSpec::set_h_coeffs / h_coeffs in ppvm-lindblad overwrite and read the HTerm coefficients in place (O(num_h_terms)). The coefficients are read directly by the commutator loop in compute_action_terms and are not folded into any precomputed table; the support index is coefficient-independent, so nothing else is rebuilt and jump/Kossakowski data are untouched. Exposed through pyo3 as _LindbladSpec.set_h_coeffs (ValueError on wrong shape or dtype) and the h_coeffs getter (copy), and on the Python Lindbladian as set_h_coeffs(coeffs) and the h_coeffs property. Tests check action/leakage/generator/pc_step bit-identity against a freshly built Lindbladian. Version 0.1.0+hcoeffs; ppvm.__version__ added. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
👋 Thanks for opening your first pull request against PPVM!
A quick note on contribution terms: by submitting this PR you
agree that your contribution is licensed under the
Apache License 2.0
and that you accept the
PPVM Contributor License Agreement.
Please skim those before a maintainer reviews — opening this PR
counts as your acceptance.
A few things that will speed up review:
- Read
CONTRIBUTING.md
for the workflow, build commands, and style notes. - Run
prek run --all-fileslocally; CI runs the same checks. - Use Conventional Commits
for commit messages.
We'll get to your PR as soon as we can. Thanks for contributing!
This branch has not been deployed
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Adds an in-place setter for the Hamiltonian coefficients of a compiled Lindbladian, so a time-dependent Hamiltonian can be stepped as a sequence of constant-generator steps without recompiling the spec per step:
• LindbladSpec::set_h_coeffs(&[f64]) / h_coeffs() in ppvm-lindblad (the coefficients are only read by compute_action_terms, so the setter is a plain O(num_h_terms) overwrite; jump and Kossakowski data, including the PSD check, are untouched).
• pyo3 binding _LindbladSpec.set_h_coeffs(coeffs) / h_coeffs (ValueError on wrong length, non-1-D, non-float64), and Lindbladian.set_h_coeffs(coeffs) / Lindbladian.h_coeffs in the Python wrapper (accepts any array-like, converts to contiguous float64).
• ppvm.version from package metadata (there was no version attribute).
• The pyproject version carries a local label 0.1.0+hcoeffs; drop it if you prefer.
Use case: Pauli propagation of NMR pulse sequences with shaped pulses and field ramps (piecewise-constant envelopes), where the Hamiltonian strings are fixed and only their coefficients change per sample. For a 54-term Hamiltonian a setter call is 0.25 µs; a recompile of a large Kossakowski-form Lindbladian is minutes.
Test plan
• ppvm-python/test/lindblad/test_h_coeffs.py (9 tests): for random 3- and 5-qubit Lindbladians with Hermitian, σ± and multi-term complex jumps plus a Kossakowski block, after set_h_coeffs(c) the outputs of action_arr, leakage_arr (with and without protected words), generator_arr and six pc_step_arr steps in two truncation modes are np.array_equal to a freshly built Lindbladian with coefficients c; restoring the original coefficients restores the outputs; the getter round-trips and returns a copy; wrong shapes raise and leave the coefficients unchanged.
• The existing test/lindblad folder: 32 passed, 1 skipped.
• cargo check clean (clippy/rustfmt were not available in the toolchain used).
Based on kossakowski-dissipator at 2f4e7f5.
🤖 Generated with Claude Code