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

Subtle aliasing issue in Schur slicer #268

Open
pablosanjose opened this issue Apr 20, 2024 · 0 comments
Open

Subtle aliasing issue in Schur slicer #268

pablosanjose opened this issue Apr 20, 2024 · 0 comments

Comments

@pablosanjose
Copy link
Owner

pablosanjose commented Apr 20, 2024

The Schur slicer has uninitialized fields that get only computed at call time. Thus, their eventual value depends on the parent hamiltonian at call time, not creation time. This can produce bugs if the unexported gs = Quantica.call!(g, ω; params...) is used and then parent(g) is called before slicing gs for the first time. This makes call! unsafe, strictly speaking. The reason for the design is performance: we don't initialize any slicer fields that may not be used at all. The exported g(ω; params...) syntax decouples the slicer's parent Hamiltonian, so it is safe.

MWE

  g = LP.linear() |> hamiltonian(@onsite((; q = 1) -> q) + @hopping((; q = 1) -> q)) |> greenfunction
  m = g(0.4, q = 0.1)[cells = 0]
  gs = Quantica.call!(g, 0.4, q = 0.1)
  @test gs[cells = 0] == m     # passes
  gs = Quantica.call!(g, 0.4, q = 0.1)
  parent(g)(q = 2)
  @test gs[cells = 0] == m       # fails

It is not clear if this issue should be fixed. As long as Quantica.call! is used with care (it is equivalent to unsafe methods in Base, and it is not exported for that reason). However, the issue is not unavoidable, as it relies on the uninitialized behavior of SchurGreenSlicer, which is a risky pattern to use. Better alternatives could be sought without sacrificing performance.

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

No branches or pull requests

1 participant