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

Generalized pair couplings #176

Merged
merged 12 commits into from
Oct 8, 2023
Merged

Generalized pair couplings #176

merged 12 commits into from
Oct 8, 2023

Conversation

kbarros
Copy link
Member

@kbarros kbarros commented Oct 4, 2023

This PR provides initial support for #63, with some differences:

  1. It uses the built-in LinearAlgebra.kron as the tensor product operation.
  2. Given a general interaction of the form $\sum_i A_i \otimes B_i$, this PR will "extract" the bilinear spin-spin exchange, and the scalar biquadratic parts, if present. This is done to reduce the number of terms present in the sum of tensor products, which is empirically the slowest part of a simulation.
  3. The generalized pair couplings work in the classical SU(N) dynamics but not yet spin wave theory. This will be addressed in a future PR.
  4. Currently :dipole mode simulations cannot handle anything but scalar biquadratic. That will be addressed in another PR.

@Lazersmoke
Copy link
Contributor

How many terms in the SVD sum do you need in the best/worst/typical case?

@kbarros
Copy link
Member Author

kbarros commented Oct 6, 2023

This illustrates the behavior on the this branch. The user interface is subject to change, and that's the current blocker for this PR.

using Sunny

S1 = spin_matrices(; N=3)
S2 = spin_matrices(; N=4)
Si, Sj = Sunny.to_product_space(S1, S2)

D = Si'*randn(3,3)*Sj
@assert length(Sunny.svd_tensor_expansion(D, 3, 4)) == 3

D = (Si'*randn(3,3)*Sj)^2
@assert length(Sunny.svd_tensor_expansion(D, 3, 4)) == 9

# In practice, though, parameters to `set_pair_coupling!` will pass through this
# decomposition function:
bilin, tensordec = Sunny.decompose_general_coupling(D, S1, S2; fast=true)
@assert length(tensordec.data) == 6  # Just 6 terms left after extracting 3x3 dipole-dipole part

# As an optimization, `decompose_general_coupling`, could also extract the 5x5
# quadrupole-quadrupole part. For this particular example, there would be no terms
# left in the "genereal" expansion. (Not yet implemented.)

# bilin, biquad, tensordec = Sunny.decompose_general_coupling(D, S1, S2; fast=true)

Basic things work, but seems to be missing 20% performance on
"test_conservation", even in dipole mode.
The `foreachbond` abstraction was actually slowing various tests down.
This can be useful because general pair coupling can be very slow
-- scales like O(N^2), whereas custom generated functions for spin
operators scales like O(N).

In the future, could also imagine special handling of all quadrupoles.
Export instead `to_product_space`
@kbarros kbarros merged commit af1cf19 into main Oct 8, 2023
4 checks passed
@kbarros kbarros deleted the gen_exchange branch October 8, 2023 13:37
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