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

Occupations interface #160

Merged
merged 12 commits into from
Jun 10, 2024
Merged

Conversation

aryavorskiy
Copy link
Contributor

@aryavorskiy aryavorskiy commented Apr 14, 2024

This PR extends #157 by providing a more thought-out occupations interface. It also fixes the #102 issue, because the statistics is now stored in the occupations object.

To implement the occupations interface, one must implement these methods for the object:

  • Ordering by defining == and isless
  • Conversion from the occupations represented as a Vector{Int}, aka convert(::Type{YourType}, v::AbstractVector) so that basisstate could work normally
  • QuantumOpticsBase.state_transition!(buffer, occ, at_inds, a_inds) for transition coefficients
  • similar (if mutable) or QuantumOpticsBase.allocate_buffer (if immutable) for allocating a buffer

Maybe this should be documented for someone who needs, for example, anyon statistics or extra performance?

@aryavorskiy
Copy link
Contributor Author

aryavorskiy commented Apr 14, 2024

Also this PR introduces (as an example of the interface and for performance reasons) fermion states as bitstrings. This introduces up to 5x speedup in operator creation (below - 36 modes, 4 fermions)

Vector occupations:
BenchmarkTools.Trial: 36 samples with 1 evaluation.
 Range (min … max):  136.681 ms … 153.661 ms  ┊ GC (min … max): 0.00% … 5.47%
 Time  (median):     140.449 ms               ┊ GC (median):    0.00%
 Time  (mean ± σ):   141.117 ms ±   3.466 ms  ┊ GC (mean ± σ):  1.03% ± 1.61%

   █   ▃   █▃ ▃    █▃  ▃ █    ▃
  ▇█▇▇▁█▇▇▇██▁█▁▇▁▇██▁▁█▁█▁▁▁▁█▁▁▇▇▁▁▁▁▁▇▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▇ ▁
  137 ms           Histogram: frequency by time          154 ms <

 Memory estimate: 23.86 MiB, allocs estimate: 58.

Bitstring occupations:
BenchmarkTools.Trial: 135 samples with 1 evaluation.
 Range (min … max):  33.617 ms … 44.738 ms  ┊ GC (min … max): 0.00% … 11.08%
 Time  (median):     35.879 ms              ┊ GC (median):    0.00%
 Time  (mean ± σ):   37.058 ms ±  2.687 ms  ┊ GC (mean ± σ):  3.78% ±  5.34%

      ▅█▅ ▃▃▅▃▅▅
  ▄▄▄███████████▅█▇▅▁▄▁▅▄▅▇▄▁▄▇▅▄▄▁▄██▅▄▄▇▁▄▅▄▁▁▅▄▅▁▅▁▁▁▅▄▄▁▄ ▄
  33.6 ms         Histogram: frequency by time        43.8 ms <

 Memory estimate: 23.86 MiB, allocs estimate: 57.

@Krastanov
Copy link
Collaborator

Thanks, Alexander, this is great! Sorry for the slow response, it is end of the semester and we are a bit short staffed. I will try to review this in the next couple of days.

@aryavorskiy
Copy link
Contributor Author

Thanks, Alexander, this is great! Sorry for the slow response, it is end of the semester and we are a bit short staffed. I will try to review this in the next couple of days.

It's OK, I understand, I also have end of semester now :)

This was the last-est commit before review, had to unify the interface for fermionstates/bosonstates

@Krastanov
Copy link
Collaborator

Sorry for the long wait on review! This is awesome, thank you for taking the time to implement it. Looking through it, I do not see anything that raises any flags for me. I added a commit to bump the version number. When the tests pass I will merge and make a release.

I will make a new issue to track:

  • defaulting to the faster FermionBitstring implementation
  • documenting the required interface
  • anyon statistics

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