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

GreenFunction indexing refactor #315

Merged
merged 8 commits into from
Oct 25, 2024
Merged

GreenFunction indexing refactor #315

merged 8 commits into from
Oct 25, 2024

Conversation

pablosanjose
Copy link
Owner

@pablosanjose pablosanjose commented Oct 20, 2024

This is a major cleanup and refactor of the indexing machinery of GreenFunctions. It is relatively risky, with subtle behavioral changes.

User-facing changes

  • We now consistently return an OrbitalSliceArray whenever the indexing a GreenSolution contains enough information to do so. That means "always" except when indexing with sites, as in g(0.2)[diagonal(sites(1))] or g(0.3)[sites(SA[1],2:3)]
  • diagonal indexing now returns a Diagonal matrix or a OrbitalSparseMatrix
  • the override keyword in densitymatrix and josephson is now called override_path
  • Function siteindexdict is now exported (to be paired with orbaxes, which is exported and now also documented).

New features

  • We can now index sparsely by using a hopselector using the sitepairs function. g(0.2)[sitepairs(range = 2)] will return a sparse OrbitalSliceMatrix with gᵢⱼ for any site j in cell zero and any site i within a distance of 2 to any i. We can also use sitepairs(::HopSelector). This functionality will allow efficient non-local mean field calculations in an upcoming PR. In the future, sparse observables such as current should move to using this mechanism too.

Internal changes

  • SparseIndices: The sparse indexing machinery (both diagonal and sitepairs) relies on a common SparseIndices type, and a set of new codepaths for them. These are designed to be also used to index other objects o that just need to define getindex(o, ::CellOrbitals, ::CellOrbitals) methods. One example is EigenProduct, used by GS.Spectrum, which represents the product Ψf(ϵ)Ψ'*e^{iϕdn}' in terms of eigenpairs ϵ, Ψ without computing the product explicitly.
  • Internalized GreenSlice output: A gs::GreenSlice is a lazy wrapper of a g::GreenFunction and some GreenIndices. Here we add a new field output, which is a preallocated AbstractArray that is the output of call!(gs, ω; params...). This is not really done for performance reason (the gain is small, as the main runtime is spent finding the GreenSolution g(ω; params...), but rather for organization purposes: the complicated issue of what kind of AbstractArray should be produced and of what size is now gathered cleanly in the GreenSlice constructor. Also it allows to introduce the getindex!(output, g::GreenSolution, inds...) method, which will be useful when we need to extend it in the general mean-field machinery (where g will be swapped for a DensityMatrix)

fix dispatch

indexing fix

fix dispatch

fix GreenSlice constructor
@pablosanjose pablosanjose changed the title Internalize call output in GreenSlice GreenFunction indexing refactor Oct 23, 2024
@codecov-commenter
Copy link

codecov-commenter commented Oct 23, 2024

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

Attention: Patch coverage is 86.76845% with 52 lines in your changes missing coverage. Please review.

Project coverage is 92.59%. Comparing base (5a6b446) to head (f3e5213).

Files with missing lines Patch % Lines
src/specialmatrices.jl 59.57% 19 Missing ⚠️
src/tools.jl 76.92% 9 Missing ⚠️
src/types.jl 86.44% 8 Missing ⚠️
src/show.jl 30.00% 7 Missing ⚠️
src/observables.jl 86.11% 5 Missing ⚠️
src/slices.jl 93.10% 2 Missing ⚠️
src/greenfunction.jl 99.06% 1 Missing ⚠️
src/hamiltonian.jl 75.00% 1 Missing ⚠️

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

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #315      +/-   ##
==========================================
- Coverage   92.90%   92.59%   -0.31%     
==========================================
  Files          38       38              
  Lines        6678     6819     +141     
==========================================
+ Hits         6204     6314     +110     
- Misses        474      505      +31     

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

@pablosanjose pablosanjose force-pushed the gsliceoutput branch 3 times, most recently from cd15e11 to f9a47b2 Compare October 24, 2024 06:58
going through tests

working through tests

fixing and adding tests

several fixes

sitepairs test

removed docstring test

fixed doctest

fix test
@pablosanjose pablosanjose merged commit d284b67 into master Oct 25, 2024
9 checks passed
@pablosanjose pablosanjose deleted the gsliceoutput branch October 25, 2024 15:37
@pablosanjose pablosanjose mentioned this pull request Feb 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants