Skip to content

Conversation

starsfordummies
Copy link
Contributor

probably not too tenet-idiomatic but should work

Copy link

codecov bot commented Aug 6, 2025

Codecov Report

❌ Patch coverage is 0% with 64 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (master@4ae1574). Learn more about missing BASE report.

Files with missing lines Patch % Lines
src/Operations/expect.jl 0.00% 62 Missing ⚠️
src/Components/MPS.jl 0.00% 1 Missing ⚠️
src/Operations/evolve.jl 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff            @@
##             master     #384   +/-   ##
=========================================
  Coverage          ?   43.81%           
=========================================
  Files             ?       25           
  Lines             ?     1383           
  Branches          ?        0           
=========================================
  Hits              ?      606           
  Misses            ?      777           
  Partials          ?        0           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Member

@jofrevalles jofrevalles left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can work well, but maybe is better if we specialize this function for MixedCanonical form, and the default MPS expect function calls the one of MixedCanonical with canonize(MPS)?

@starsfordummies
Copy link
Contributor Author

yes, definitely! I just wanted to get the discussion started, since we definitely need a function to compute exp values after it disappeared in the latest refactorings

Copy link
Member

@mofeing mofeing left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for starting the work on this @starsfordummies

@jofrevalles yeah, the idea is to dispatch based on the CanonicalForm so that we can specialize behavior

the specialized implementations should do the following

  • on NonCanonical, i would just do a sweep contracting the tensors
  • on MixedCanonical,
    1. canonize! to the range of sites of the operator
    2. directly connect boundary virtual bonds between ket and bra (skipping the tensors outside of the range of the operator)
    3. call contract
  • on BondCanonical, canonize! to the range of sites of the operator (so move to MixedCanonical) and call expect again but on the MixedCanonical form
  • on VidalGauge, i would directly take the range of sites of the operator (so move to MixedCanonical), absorb the lambdas and contract

if you know a more efficient way, we can do it that way

Comment on lines 215 to 231
""" Expectation value for a one-site operator `op` on site `op_site` of mps `psi`, brings `psi` to canonical form. """
function expect_1site!(psi::MPS, op::AbstractArray, op_site::Int)
canonize!(psi, MixedCanonical(site"$(op_site)"))
plug_ind = ind_at(psi, plug"$(op_site)")
temp_ind = Index(:_temp_bra)
ev = binary_einsum(psi[op_site], Tensor(op, [temp_ind, plug_ind]))
ev = binary_einsum(ev, conj(replace(psi[op_site], plug_ind => temp_ind)))

return ev
end

""" Expectation value for a one-site operator `op` on site `op_site` of mps `psi`.
This makes a copy of the MPS """
function expect_1site(psi::MPS, op::AbstractArray, op_site::Int)
psi = copy(psi)
expect_1site!(psi, op, op_site)
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mind moving them to a Operations/expect.jl file please?

@starsfordummies
Copy link
Contributor Author

i added a few methods for exp values of local ops and mpo - it could well be that bringing the MPS to canonical form is always the best way (even if it involves making a copy+canonizing it), need to benchmark it

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.

3 participants