Skip to content

Refactor expectation_value implementations - #423

Open
leburgel wants to merge 13 commits into
mainfrom
lb/expval
Open

Refactor expectation_value implementations#423
leburgel wants to merge 13 commits into
mainfrom
lb/expval

Conversation

@leburgel

@leburgel leburgel commented Aug 31, 2026

Copy link
Copy Markdown
Member

Some refactoring and reorganization related to the evaluation of expectation values. The main motivation for this refactor is making it easier to add support for computing expectation values of different kinds of operators, and evaluate these using different kinds of environments. Some examples of this are given in #425 and #426, which are built on top of this refactor.

Short summary:

  • Moved around some existing code to different/new files, hopefully improving the organization a bit.
  • Remove as many type annotations as possible from the methods used along the evaluation of expectation values, allowing to reuse the main entry points for different types of operators and environments.
  • Insert a dedicated local_expectation_value method to catch local expectation values for different kinds of operators. This goes through the reduced_densitymatrix approach for AbstractTensorMap local terms, but can follow a different path for different kinds of local terms (see for example [WIP] Add support for local expectation values of tensor product and MPO terms #425).
  • Implement BPEnv expectation values via reduced density matrix contraction along the generic AbstractTensorMap path, by specializing the appropriate methods.
  • Write the main local patch contraction as generic methods in terms of a fixed set of contraction expression generators . These generators then dispatch on the appropriate type to generate an appropriate expression. The idea would be that to add support support for a different type of state, operator or environment, we now only need to overload one of the main expression generators boundary_contraction_expr, bulk_contraction_expr or operator_contraction_expr.

@codecov

codecov Bot commented Aug 31, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 94.89796% with 5 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/utility/util.jl 75.00% 4 Missing ⚠️
src/algorithms/contractions/bp_contractions.jl 93.75% 1 Missing ⚠️
Files with missing lines Coverage Δ
...hms/contractions/ctmrg/characteristic_equations.jl 87.59% <ø> (+0.46%) ⬆️
src/algorithms/contractions/ctmrg/network_value.jl 100.00% <100.00%> (ø)
src/algorithms/contractions/localoperator.jl 99.19% <100.00%> (+2.73%) ⬆️
src/algorithms/ctmrg/gaugefix.jl 93.57% <ø> (ø)
src/algorithms/toolbox.jl 95.19% <100.00%> (-1.74%) ⬇️
src/algorithms/contractions/bp_contractions.jl 90.32% <93.75%> (-2.06%) ⬇️
src/utility/util.jl 76.14% <75.00%> (-0.20%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@leburgel
leburgel marked this pull request as draft August 31, 2026 14:18
@leburgel leburgel changed the title Slight reorganization of expectation_value implementation Refactor expectation_value implementations Sep 2, 2026
@leburgel
leburgel marked this pull request as ready for review September 3, 2026 06:55
@Yue-Zhengyuan

Copy link
Copy Markdown
Member

I'll try coming up with a source tree of expectation-value-related functions to better discuss where each function should be placed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants