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 None are 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 from None is validated against the expected type (and, where implemented, basic value constraints).

Return type:

None

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.

Parameters:
  • phrase (str) – Prompt displayed to the user.

  • debug (bool) – If True, call input(); otherwise do nothing.

Return type:

None

Raises:

TypeError – If phrase or debug has an invalid type.

edlgt.tools.checks.alert(phrase, debug)[source]

Log a debug message when debugging is enabled.

Parameters:
  • phrase (str) – Message to log.

  • debug (bool) – If True, emit the message at debug level; otherwise do nothing.

Return type:

None

Raises:

TypeError – If phrase or debug has an invalid type.

edlgt.tools.checks.commutator(matrix_a, matrix_b)[source]

Compute the commutator [A, B] = AB - BA.

Parameters:
Returns:

Sparse matrix representing AB - BA.

Return type:

scipy.sparse.spmatrix

Raises:

TypeError – If matrix_a or matrix_b is not a SciPy sparse matrix.

edlgt.tools.checks.anti_commutator(matrix_a, matrix_b)[source]

Compute the anti-commutator {A, B} = AB + BA.

Parameters:
Returns:

Sparse matrix representing AB + BA.

Return type:

scipy.sparse.spmatrix

Raises:

TypeError – If matrix_a or matrix_b is 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:
Return type:

None

Raises:
  • TypeError – If matrix_a or matrix_b is 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:
Return type:

None

Raises:
  • TypeError – If matrix_a or matrix_b is 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:

None

Raises:
  • TypeError – If matrix_a is not a SciPy sparse matrix.

  • ValueError – If matrix_a differs from its Hermitian conjugate beyond the tolerance used by check_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:

collections.abc.Callable