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 SubDitStr function to enable DitStr slicing #54

Merged
merged 7 commits into from
Jun 28, 2024

Conversation

hz-xiaxz
Copy link
Contributor

I studied the official implementation of SubStrings in Julia's Base library SubString.jl

I think same implementation can be added into BitBasis.jl for high performance slicing, so I imitated the implementation in the Base Library in this PR

@hz-xiaxz
Copy link
Contributor Author

This is related to (#53)

@hz-xiaxz
Copy link
Contributor Author

Sorry that I may have accidentally modified some other lines with my auto formatting tool :(

@GiggleLiu
Copy link
Member

GiggleLiu commented Jun 25, 2024

Thank you for the contribution! The code quality is pretty good. I am wondering if there is a practical using case for this feature?

@hz-xiaxz
Copy link
Contributor Author

hz-xiaxz commented Jun 26, 2024

I am using LongBitStr to represent the basis vector in Fock space. In spinful Fermion systems, as hopping is usually not allowed between spin up and spin down fermions, we can divide the whole Hilbert space into tensor products of spin up and spin down Hilbert spaces, i.e. $ V = V_{up}\otimes V_{down} $ . Thus, the basis vector can be stored as $ |0101>\otimes |1010> $ or simply $ |01011010> $. In Variational Monte Carlo simulation, some updates (like the change of Slater Determinant) only relate to the subspace vector, and some other updates like Gutzwiller ansatz relate to the whole vector.

Hence, a SubDitStr is useful when we need to do calculation in the subspace of the whole Hilbert Space and this slicing reduces computational complexity.

The former implementation of slicing relys on the getindex method of DitStr and returns a array, it will cost redundant time to convert a array back to DitStr. This is a bottleneck in my current code.

@hz-xiaxz
Copy link
Contributor Author

This PR is still WIP, just push here to see if it is a suitable solution.

Copy link
Member

@GiggleLiu GiggleLiu left a comment

Choose a reason for hiding this comment

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

This feature seems to be useful, and is throughly tested. I am wondering if it is beneficial to add some eye candies like bit_string[start:stop]?

src/DitStr.jl Outdated Show resolved Hide resolved
test/DitStr.jl Show resolved Hide resolved
* new `DitStr` function to raise `SubDitStr` struct to `DitStr`
* tests added
src/DitStr.jl Show resolved Hide resolved
* add benchmark
@hz-xiaxz
Copy link
Contributor Author

hz-xiaxz commented Jun 27, 2024

This is the last commit for this PR. If the code is approved, I hope it can be merged with a version bump. Thanks a lot for your review and kind help!

test/DitStr.jl Outdated Show resolved Hide resolved
@hz-xiaxz
Copy link
Contributor Author

Will this commit be approved now?

@GiggleLiu GiggleLiu merged commit 4c1e25a into QuantumBFS:master Jun 28, 2024
6 checks passed
@GiggleLiu
Copy link
Member

I just merged this PR and will tag a new patch version later.

@hz-xiaxz
Copy link
Contributor Author

Thanks!

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