Compute error metrics#29
Draft
BrendanKKrueger wants to merge 8 commits into
Draft
Conversation
This was referenced May 28, 2026
- Add eigendecomposition_analysis() function in analysis.py - Support full and partial eigendecomposition modes - Add configuration fields: num_eigenvalues, eigendecomposition_matrices, which_eigenvalues - Support 'smallest', 'largest', and 'both' eigenvalue selection - Add save_eigendecomposition() and load_eigendecomposition() to file_io.py - Add 19 comprehensive tests in test_eigendecomposition.py - Update README.md with eigendecomposition documentation - Update config_full_analysis.py with eigendecomposition examples - All 200 tests passing (128 original + 53 Branch 1 + 19 Branch 2)
- Add error_analysis() function in analysis.py (~350 lines) - Three independent error types: 1. Eigenvalue errors: Compare k smallest eigenvalues 2. Matrix norm errors: Frobenius and spectral norms 3. State-dependent errors: Apply operators to specific states - Add configuration fields: error_num_eigenvalues, error_matrix_norms, error_state_inputs - Support matrix-free computation for large systems - Matrix norm computation with progress tracking - Add 18 comprehensive tests in test_error_analysis.py - Update README.md with error analysis documentation - Update config_full_analysis.py with error analysis examples - All 218 tests passing (128 original + 53 Branch 1 + 19 Branch 2 + 18 Branch 3)
0348180 to
0f15c52
Compare
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.
Depends on #28
Step 3 of #25
Summary from Claude below
Branch 3: Error Analysis
Title
Branch 3: Add comprehensive error analysis (eigenvalue, matrix norm, state-dependent errors)
Description
Overview
This PR implements comprehensive error analysis comparing exact Hamiltonian matrices with approximate algorithm unitaries. This is Branch 3 of a 5-branch implementation plan to add exact matrix analysis and error quantification capabilities to QHAT.
Purpose
Changes Made
Modified Files:
analysis/config_types.pyerror_num_eigenvaluesfield (default: 0, disabled)error_matrix_normsfield (default: None, disabled)error_state_inputsfield (default: None, disabled)analysis/analysis.pyerror_analysis()function (~350 lines)error_analysis.npzimport osfor file existence checksanalyze_algorithm()to:analysis/README.mdanalysis/examples/config_full_analysis.pyNew Files:
analysis/tests/test_error_analysis.py(775 lines)Technical Details
Three Independent Error Types:
Eigenvalue Errors (
error_num_eigenvalues > 0):Matrix Norm Errors (
error_matrix_normsnot None):Frobenius norm: ||H_exact - H_approx||_F = sqrt(sum of squares)
Spectral norm: ||H_exact - H_approx||_2 = largest singular value
Implementation paths:
State-Dependent Errors (
error_state_inputsnot None):Matrix-Free Computation:
For large systems (>15 qubits), matrix norm computation uses matrix-free methods:
Frobenius norm: Computes ||diff e_i|| for each basis vector e_i
Spectral norm: Power iteration on (H_exact - H_approx)† (H_exact - H_approx)
Automatic Strategy Selection:
The
error_analysis()function automatically:Output Format (
error_analysis.npz):eigenvalue_absolute_errors: Array of absolute errors (if eigenvalue errors enabled)eigenvalue_relative_errors: Array of relative errors (if eigenvalue errors enabled)eigenvalue_num: Number of eigenvalues comparedmatrix_frobenius_error: Scalar (if Frobenius norm requested)matrix_spectral_error: Scalar (if spectral norm requested)state_absolute_errors: Array of absolute errors (if state errors enabled)state_relative_errors: Array of relative errors (if state errors enabled)Type of Change
Testing
Test Coverage:
Test Highlights:
Running Tests:
Usage Example
Output:
error_analysis.npzresults = np.load('error_analysis.npz')results['eigenvalue_absolute_errors'],results['matrix_frobenius_error'], etc.Context: Implementation Plan
This is Branch 3 of a 5-branch sequence:
Each branch builds on the previous, delivering independent, testable functionality.
Benefits
For Users:
For Developers:
Performance
Scaling by error type:
Production recommendations:
Memory:
Checklist
Merge Dependencies
bkk_eigendecomposition(Branch 2)mainCommits
0348180: Branch 3: Add error analysis (eigenvalue, matrix norm, state-dependent)Related Issues
Part of the effort to add exact matrix analysis and error quantification capabilities to QHAT for validating algorithm accuracy.
Reviewers
@lanl/qhat-team
Notes for Reviewers
Key files to review:
analysis/analysis.py: Newerror_analysis()function (~350 lines)analysis/config_types.py: Three new configuration fieldsDesign decisions to consider:
Integration with Branches 1-2:
Testing:
Next steps (Branch 4):