LocalTerm Class

Single-site Hamiltonian contributions and local-observable measurements on a lattice.

class edlgt.modeling.local_term.LocalTerm(operator, op_name, **kwargs)[source]

Bases: QMBTerm

Single-site term on a lattice model.

Initialize a local term definition.

Parameters:
  • operator (scipy.sparse.spmatrix) – Single-site operator.

  • op_name (str) – Human-readable operator name.

  • **kwargs – Additional keyword arguments forwarded to QMBTerm.

Return type:

None

get_hamiltonian(strength, mask=None)[source]

Build the local Hamiltonian contribution.

Parameters:
  • strength (scalar) – Coupling constant multiplying the local term.

  • mask (numpy.ndarray, optional) – Boolean lattice mask selecting the sites where the term is applied.

Returns:

Return type depends on the current workflow:

  • if self.sector_configs is None: sparse matrix Hamiltonian term;

  • otherwise: (r_list, c_list, v_list) as three NumPy arrays in the symmetry-reduced basis.

Return type:

scipy.sparse.spmatrix or tuple

Raises:

TypeError – If strength is not scalar.

get_Hamiltonian(strength, mask=None)

Build the local Hamiltonian contribution.

Parameters:
  • strength (scalar) – Coupling constant multiplying the local term.

  • mask (numpy.ndarray, optional) – Boolean lattice mask selecting the sites where the term is applied.

Returns:

Return type depends on the current workflow:

  • if self.sector_configs is None: sparse matrix Hamiltonian term;

  • otherwise: (r_list, c_list, v_list) as three NumPy arrays in the symmetry-reduced basis.

Return type:

scipy.sparse.spmatrix or tuple

Raises:

TypeError – If strength is not scalar.

get_expval(psi, stag_label=None, print_values=True, get_variance=False)[source]

Compute local expectation values (and optionally variances) on all sites.

Parameters:
  • psi (QMB_state) – Quantum many-body state used for the measurement.

  • stag_label (str, optional) – Optional staggered-site selector ("even" or "odd").

  • print_values (bool, optional) – If True, log per-site values and final averages.

  • get_variance (bool, optional) – If True, also compute local variances when supported.

Returns:

Results are stored on the instance attributes obs, var (if requested), avg, and std.

Return type:

None

Raises:

TypeError – If psi is not a QMB_state instance.

Notes

For local operators without momentum basis, squaring the non-zero matrix entries is sufficient to compute the variance contribution. In momentum basis, the variance requires constructing a dedicated operator.