Skip to content

added Krylov tolerance as high-level parameter#439

Merged
aaronleesander merged 13 commits into
mainfrom
krylov-threshold
May 26, 2026
Merged

added Krylov tolerance as high-level parameter#439
aaronleesander merged 13 commits into
mainfrom
krylov-threshold

Conversation

@aaronleesander
Copy link
Copy Markdown
Member

@aaronleesander aaronleesander commented May 26, 2026

Description

This PR adds the Krylov tolerance used within the matrix exponential of TDVP as a high-level parameter.
This is based off work by @martinamonctum and its behavior is currently active research.

Additionally, it renames the threshold to svd_threshold to differentiate this setting more clearly.
Finally, an extra "exact" preset was added with the new tolerance.

The purpose of overriding tolerance values etc. is made more clear in the relevant docs example.

Checklist

  • The pull request only contains commits that are focused and relevant to this change.
  • I have added appropriate tests that cover the new/changed functionality.
  • I have updated the documentation to reflect these changes.
  • I have added entries to the changelog for any noteworthy additions, changes, fixes, or removals.
  • I have added migration instructions to the upgrade guide (if needed).
  • The changes follow the project's style guidelines and introduce no new warnings.
  • The changes are fully tested and pass the CI checks.
  • I have reviewed my own code changes.

If PR contains AI-assisted content:

  • I have disclosed the use of AI tools in the PR description as per our AI Usage Guidelines.
  • AI-assisted commits include an Assisted-by: [Model Name] via [Tool Name] footer.
  • I confirm that I have personally reviewed and understood all AI-generated content, and accept full responsibility for it.

@aaronleesander aaronleesander self-assigned this May 26, 2026
@aaronleesander aaronleesander added the feature New feature or request label May 26, 2026
@aaronleesander
Copy link
Copy Markdown
Member Author

@CodeRabbit review

@aaronleesander aaronleesander changed the title added Krylov threshold as high-level parameter added Krylov tolerance as high-level parameter May 26, 2026
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 26, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 26, 2026

Review Change Stack

Warning

Review limit reached

@aaronleesander, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 16 minutes and 31 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 40b2e19a-e965-4e25-a5ef-b9946f87b766

📥 Commits

Reviewing files that changed from the base of the PR and between a291282 and 52c3783.

📒 Files selected for processing (7)
  • CHANGELOG.md
  • UPGRADING.md
  • docs/examples/simulation_parameters.md
  • src/mqt/yaqs/core/data_structures/simulation_parameters.py
  • src/mqt/yaqs/core/methods/tdvp.py
  • tests/core/data_structures/test_simulation_parameters.py
  • tests/core/methods/test_bug.py
📝 Walkthrough

Walkthrough

The PR refactors the simulation parameter API by replacing the AccuracyPreset/ACCURACY_PRESETS system with a unified SimulationPreset/SIMULATION_PRESETS system. All three parameter classes adopt explicit svd_threshold and krylov_tol fields that can be derived from presets or overridden individually. TDVP methods thread krylov_tol through Krylov evolution, and all truncation/tolerance references across methods are updated accordingly. Tests and documentation are fully migrated to the new interface.

Changes

Simulation Parameter API Refactoring

Layer / File(s) Summary
Preset system types and validators
src/mqt/yaqs/core/data_structures/simulation_parameters.py
SimulationPreset literal and PresetTypes TypedDict introduced; SIMULATION_PRESETS dictionary provides preset configurations; new validators enforce finite/positive svd_threshold and krylov_tol values.
Parameter class constructors
src/mqt/yaqs/core/data_structures/simulation_parameters.py
AnalogSimParams, StrongSimParams, and WeakSimParams constructors now accept preset (keyword-only) with optional svd_threshold/krylov_tol overrides; initialization derives num_traj/max_bond_dim from SIMULATION_PRESETS and validates all parameters.
Method-level truncation integration
src/mqt/yaqs/analog/lindblad.py, src/mqt/yaqs/core/methods/bug.py, src/mqt/yaqs/core/methods/dissipation.py, src/mqt/yaqs/core/methods/scheduled_jumps.py, src/mqt/yaqs/core/methods/stochastic_process.py
All method calls to split_two_site() and truncation operations updated to use sim_params.svd_threshold instead of sim_params.threshold; ODE solver tolerances in lindblad.py adjusted accordingly.
TDVP Krylov tolerance integration
src/mqt/yaqs/core/methods/tdvp.py
_evolve_local_tensor_krylov accepts krylov_tol and forwards to expm_krylov; update_site/update_bond expose krylov_tol as keyword-only parameter; all TDVP integration routines (single_site_tdvp, two_site_tdvp, local_dynamic_tdvp) thread sim_params.krylov_tol; _bond_dim_at_or_above_cap refactors bond-dimension cap checking.
Test suite updates
tests/core/data_structures/test_simulation_parameters.py, tests/core/methods/test_bug.py, tests/core/methods/test_tdvp.py, tests/analog/test_ensemble.py, tests/test_simulator.py
Tests migrated to use SIMULATION_PRESETS; new parametrized tests verify preset resolution and explicit overrides; krylov_tol parameter added to relevant test cases; parameter construction updated throughout.
Documentation and guides
CHANGELOG.md, UPGRADING.md, docs/examples/*.md, docs/index.md
Changelog documents Krylov threshold addition and PR link; upgrade guide explains thresholdsvd_threshold rename; all example notebooks updated to use svd_threshold and preset-based configuration; simulation_parameters.md rewritten with preset table and construction patterns; new page added to docs index.

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

Suggested labels

enhancement

Poem

🐰 A preset system hops into view,
Where thresholds now sparkle in Krylov's true blue,
From threshold to svd_threshold they bound,
With krylov_tol threading through TDVP round,
The parameters dance, both accurate and fleet! 🎯

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically identifies the main change: adding Krylov tolerance as a high-level parameter, which aligns with the primary feature introduced in this pull request.
Docstring Coverage ✅ Passed Docstring coverage is 95.24% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description check ✅ Passed The PR description covers the main changes, includes all required checklist items marked as complete, and discloses AI-assisted content per project guidelines.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch krylov-threshold

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

coderabbitai[bot]
coderabbitai Bot previously requested changes May 26, 2026
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 4

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
src/mqt/yaqs/core/methods/tdvp.py (2)

72-77: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Update the touched docstrings to the renamed parameter names.

These docstrings still describe the legacy threshold field even though the implementation now consumes sim_params.svd_threshold and sim_params.krylov_tol. Keeping the old names here will make the migration path harder to follow.

Also applies to: 572-574, 687-692, 831-835

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/mqt/yaqs/core/methods/tdvp.py` around lines 72 - 77, Update the
docstrings in tdvp-related functions (e.g., the TDVP method in
src/mqt/yaqs/core/methods/tdvp.py) to replace legacy names like "threshold" with
the current sim_params fields: reference sim_params.svd_threshold for SVD
truncation tolerance and sim_params.krylov_tol for Krylov solver tolerance (and
mention sim_params.trunc_mode/svd_distribution/max_bond_dim as applicable); make
the same replacements in the other docstring blocks referenced around the file
(the blocks near the top-level TDVP function and the other two docstring
occurrences) so examples and parameter descriptions match the actual parameter
names used by the implementation.

455-467: 🛠️ Refactor suggestion | 🟠 Major | ⚡ Quick win

Convert the updated docstrings to Google style while touching them.

The newly added krylov_tol entries keep the old name (type): format, so this file still diverges from the repository’s Python docstring convention.

As per coding guidelines, **/*.py: Use Google-style docstrings in Python code.

Also applies to: 504-513, 538-546

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/mqt/yaqs/core/methods/tdvp.py` around lines 455 - 467, The docstring for
the TDVP evolution function still uses the old "name (type):" param style for
the newly added krylov_tol and similar entries; update these to Google-style
parameter entries (under Args:) e.g. "krylov_tol: float, optional. Tolerance for
the adaptive Krylov/Lanczos matrix exponential." and similarly convert any other
parameter entries in the docstrings around the tdvp-related functions
(references: the docstring block containing projector, tensor, dt, proj_args,
dense_threshold, krylov_tol and the other docstrings at the ranges noted) so all
parameter lines follow "name: type, optional. Description." Keep descriptions
unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/mqt/yaqs/core/data_structures/simulation_parameters.py`:
- Around line 51-59: Add a Google-style "Args:" section to the _validate_preset
docstring documenting the preset parameter (name, type SimulationPreset, and
what values/semantics are expected) so the docstring includes Args, Returns, and
Raises; update the docstring for the _validate_preset function to follow the
repo's Google-style format and describe the preset argument concisely.
- Around line 210-217: The constructor currently uses max_bond_dim: int | None =
None which conflates “omit to use preset” and “None means no cap”; change the
API to use a unique sentinel default so None can mean no cap: introduce a
module-level sentinel (e.g. _USE_PRESET = object()) and change the signature to
max_bond_dim: int | None | object = _USE_PRESET, then update all internal checks
(places that currently treat None as “use preset” — e.g. in
SimulationParameters.__init__ and the logic at the sites corresponding to the
prior lines 279-280, 334-340, 390-391, 437-443, 472) to treat _USE_PRESET as
“take preset value” and preserve None as “no cap”; finally update the
constructor and class docstrings to state “omit max_bond_dim to use the preset;
pass None for no cap.”

In `@tests/core/data_structures/test_simulation_parameters.py`:
- Around line 111-113: Change the test parameter typing so valid preset values
are typed as SimulationPreset instead of a bare str and remove the unnecessary
"# ty: ignore[invalid-argument-type]" comments; specifically update the test
function test_analog_simparams_presets(preset: str, ...) to preset:
SimulationPreset and drop the ty ignores on the AnalogSimParams(...) calls (and
make the analogous edits in the other test functions mentioned around the same
blocks for lines 130-132 and 170-172) so the tests keep correct static typing
without suppression.

In `@UPGRADING.md`:
- Around line 40-42: Update the migration note that currently reads "Accuracy
presets use the key `svd_threshold` in `ACCURACY_PRESETS`" so it references the
new preset API: replace `ACCURACY_PRESETS` with `SIMULATION_PRESETS` (keep
`svd_threshold` and surrounding wording unchanged) to reflect the refactor and
avoid confusing users; search for the exact phrase containing `svd_threshold`
and `ACCURACY_PRESETS` and update it to mention `SIMULATION_PRESETS`.

---

Outside diff comments:
In `@src/mqt/yaqs/core/methods/tdvp.py`:
- Around line 72-77: Update the docstrings in tdvp-related functions (e.g., the
TDVP method in src/mqt/yaqs/core/methods/tdvp.py) to replace legacy names like
"threshold" with the current sim_params fields: reference
sim_params.svd_threshold for SVD truncation tolerance and sim_params.krylov_tol
for Krylov solver tolerance (and mention
sim_params.trunc_mode/svd_distribution/max_bond_dim as applicable); make the
same replacements in the other docstring blocks referenced around the file (the
blocks near the top-level TDVP function and the other two docstring occurrences)
so examples and parameter descriptions match the actual parameter names used by
the implementation.
- Around line 455-467: The docstring for the TDVP evolution function still uses
the old "name (type):" param style for the newly added krylov_tol and similar
entries; update these to Google-style parameter entries (under Args:) e.g.
"krylov_tol: float, optional. Tolerance for the adaptive Krylov/Lanczos matrix
exponential." and similarly convert any other parameter entries in the
docstrings around the tdvp-related functions (references: the docstring block
containing projector, tensor, dt, proj_args, dense_threshold, krylov_tol and the
other docstrings at the ranges noted) so all parameter lines follow "name: type,
optional. Description." Keep descriptions unchanged.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 4c6aac27-dfac-4234-9c73-b06684310ddb

📥 Commits

Reviewing files that changed from the base of the PR and between 5bd7071 and a291282.

📒 Files selected for processing (21)
  • CHANGELOG.md
  • UPGRADING.md
  • docs/examples/analog_simulation.md
  • docs/examples/ensemble_evolution.md
  • docs/examples/simulation_parameters.md
  • docs/examples/simulator_initialization.md
  • docs/examples/strong_circuit_simulation.md
  • docs/examples/weak_circuit_simulation.md
  • docs/index.md
  • src/mqt/yaqs/analog/lindblad.py
  • src/mqt/yaqs/core/data_structures/simulation_parameters.py
  • src/mqt/yaqs/core/methods/bug.py
  • src/mqt/yaqs/core/methods/dissipation.py
  • src/mqt/yaqs/core/methods/scheduled_jumps.py
  • src/mqt/yaqs/core/methods/stochastic_process.py
  • src/mqt/yaqs/core/methods/tdvp.py
  • tests/analog/test_ensemble.py
  • tests/core/data_structures/test_simulation_parameters.py
  • tests/core/methods/test_bug.py
  • tests/core/methods/test_tdvp.py
  • tests/test_simulator.py

Comment thread src/mqt/yaqs/core/data_structures/simulation_parameters.py
Comment thread src/mqt/yaqs/core/data_structures/simulation_parameters.py Outdated
Comment thread tests/core/data_structures/test_simulation_parameters.py Outdated
Comment thread UPGRADING.md Outdated
@aaronleesander
Copy link
Copy Markdown
Member Author

@CodeRabbit review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 26, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@aaronleesander
Copy link
Copy Markdown
Member Author

@CodeRabbit review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 26, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 26, 2026

Codecov Report

❌ Patch coverage is 95.52239% with 3 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...yaqs/core/data_structures/simulation_parameters.py 96.0% 2 Missing ⚠️
src/mqt/yaqs/core/methods/tdvp.py 92.3% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@aaronleesander
Copy link
Copy Markdown
Member Author

@CodeRabbit review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 26, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@aaronleesander aaronleesander merged commit 8271755 into main May 26, 2026
14 checks passed
@aaronleesander aaronleesander deleted the krylov-threshold branch May 26, 2026 19:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant