Skip to content

Add in-place Hamiltonian-coefficient setter to LindbladSpec - #266

Open
kseetharam wants to merge 1 commit into
QuEraComputing:kossakowski-dissipatorfrom
kseetharam:h-coeffs-setter
Open

kseetharam wants to merge 1 commit into
QuEraComputing:kossakowski-dissipatorfrom
kseetharam:h-coeffs-setter

Conversation

@kseetharam

Copy link
Copy Markdown

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

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>

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👋 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-files locally; 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

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant