Checks
Utilities for input validation and sparse-matrix consistency checks used across the library.
Validation, diagnostics, and matrix consistency checks.
This module collects small utility functions used across the library for:
validating common input parameters,
pausing or logging debug messages during script execution,
checking commutation relations, matrix equality, and Hermiticity,
timing function calls with a lightweight decorator.
Most matrix checks operate on SciPy sparse matrices.
- edlgt.tools.checks.validate_parameters(lvals=None, loc_dims=None, lattice_dim=None, has_obc=None, axes=None, site_label=None, coords=None, ops_dict=None, op_list=None, op_names_list=None, op_sites_list=None, add_dagger=None, get_real=None, get_imag=None, staggered_basis=None, stag_label=None, all_sites_equal=None, gauge_basis=None, dictionary=None, filename=None, phrase=None, debug=None, psi=None, spmatrix=None, index=None, threshold=None, print_plaq=None, spin_list=None, int_list=None, sz_list=None, pure_theory=None, matter=None, psi_vacuum=None, get_singlet=None, array=None)[source]
Validate commonly used library arguments by type and basic value rules.
Only parameters passed with a value different from
Noneare checked. The function is intentionally broad and centralizes validation logic shared by multiple modules.- Parameters:
... (
object, optional) – Any named argument in the function signature. Each argument provided with a value different fromNoneis validated against the expected type (and, where implemented, basic value constraints).- Return type:
- Raises:
TypeError – If an argument has an invalid type.
ValueError – If an argument has an invalid value (for example
stag_label).
- edlgt.tools.checks.pause(phrase, debug)[source]
Pause execution and wait for user input when debugging is enabled.
- edlgt.tools.checks.commutator(matrix_a, matrix_b)[source]
Compute the commutator
[A, B] = AB - BA.- Parameters:
matrix_a (
scipy.sparse.spmatrix) – Sparse matrices with compatible shapes.matrix_b (
scipy.sparse.spmatrix) – Sparse matrices with compatible shapes.
- Returns:
Sparse matrix representing
AB - BA.- Return type:
- Raises:
TypeError – If
matrix_aormatrix_bis not a SciPy sparse matrix.
- edlgt.tools.checks.anti_commutator(matrix_a, matrix_b)[source]
Compute the anti-commutator
{A, B} = AB + BA.- Parameters:
matrix_a (
scipy.sparse.spmatrix) – Sparse matrices with compatible shapes.matrix_b (
scipy.sparse.spmatrix) – Sparse matrices with compatible shapes.
- Returns:
Sparse matrix representing
AB + BA.- Return type:
- Raises:
TypeError – If
matrix_aormatrix_bis not a SciPy sparse matrix.
- edlgt.tools.checks.check_commutator(matrix_a, matrix_b)[source]
Check whether two sparse operators commute within a fixed tolerance.
The function computes a normalized commutator norm and raises if the ratio exceeds
1e-15.- Parameters:
matrix_a (
scipy.sparse.spmatrix) – Sparse matrices with compatible shapes.matrix_b (
scipy.sparse.spmatrix) – Sparse matrices with compatible shapes.
- Return type:
- Raises:
TypeError – If
matrix_aormatrix_bis not a SciPy sparse matrix.ValueError – If the normalized commutator norm is larger than the tolerance.
- edlgt.tools.checks.check_matrix(matrix_a, matrix_b)[source]
Compare two sparse matrices using a normalized Frobenius-norm criterion.
- Parameters:
matrix_a (
scipy.sparse.csr_matrix) – Sparse matrices to compare.matrix_b (
scipy.sparse.csr_matrix) – Sparse matrices to compare.
- Return type:
- Raises:
TypeError – If
matrix_aormatrix_bis not a SciPy sparse matrix.ValueError – If shapes differ or the normalized difference is larger than
1e-14.
- edlgt.tools.checks.check_hermitian(matrix_a)[source]
Validate that a sparse matrix is Hermitian.
- Parameters:
matrix_a (
scipy.sparse.spmatrix) – Sparse matrix to test.- Return type:
- Raises:
TypeError – If
matrix_ais not a SciPy sparse matrix.ValueError – If
matrix_adiffers from its Hermitian conjugate beyond the tolerance used bycheck_matrix().
- edlgt.tools.checks.get_time(func)[source]
Decorate a function to log its execution time at debug level.
- Parameters:
func (
collections.abc.Callable) – Function to wrap.- Returns:
Wrapped function with the same signature and return value.
- Return type: