Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add check for zero norm to expect #1249

Merged
merged 4 commits into from
Nov 16, 2023
Merged

Add check for zero norm to expect #1249

merged 4 commits into from
Nov 16, 2023

Conversation

emstoudenmire
Copy link
Collaborator

Description

Currently if you pass an MPS to expect whose norm is zero, the code will compute the norm and later divide by it, siletly producing NaN's in the output. A user recently ran into this issue. This PR adds a simple error check of the norm.

Minimal demonstration of previous behavior

using ITensors

function ITensors.op!(Op::ITensor,
                      ::OpName"Pdn",
                      ::SiteType"S=1/2",
                      s::Index)
  Op[s'=>2,s=>2] = 1.0
end

let
  N = 10
  s = siteinds("S=1/2",N)

  psi0 = MPS(s,"Up")
  psi1 = apply(op("Pdn",s[5]),psi0)

  @show expect(psi1,"Sz")

  return
end

@codecov-commenter
Copy link

codecov-commenter commented Nov 15, 2023

Codecov Report

Attention: 1 lines in your changes are missing coverage. Please review.

Comparison is base (d9265a2) 85.44% compared to head (b8d3e35) 54.80%.
Report is 2 commits behind head on main.

❗ Current head b8d3e35 differs from pull request most recent head 2767746. Consider uploading reports for the commit 2767746 to get more accurate results

Files Patch % Lines
src/mps/mps.jl 0.00% 1 Missing ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@             Coverage Diff             @@
##             main    #1249       +/-   ##
===========================================
- Coverage   85.44%   54.80%   -30.64%     
===========================================
  Files          89       88        -1     
  Lines        8401     8349       -52     
===========================================
- Hits         7178     4576     -2602     
- Misses       1223     3773     +2550     

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

@mtfishman
Copy link
Member

Makes sense, thanks! Could you add a test?

@mtfishman mtfishman merged commit 9060282 into main Nov 16, 2023
7 checks passed
@mtfishman mtfishman deleted the expect_zero_norm branch November 16, 2023 17:01
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