Skip to content

Commit

Permalink
Readme update for v0.3.3
Browse files Browse the repository at this point in the history
  • Loading branch information
abraemer committed Nov 23, 2021
1 parent 6f9cd81 commit b0cfe24
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 25 deletions.
38 changes: 20 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,28 +23,28 @@ julia> basis = symmetrized_basis(zbasis(9, 4), Flip(9), 0, Shift(9), 0);
julia> state = normalize!(ones(2^9)); # initial state - all up in x direction

julia> @btime symm_state = symmetrize_state(state, basis)
765.253 μs (7781 allocations: 727.29 KiB)
14-element Vector{ComplexF64}:
0.18750000000000006 + 0.0im
0.18750000000000006 + 0.0im
0.18750000000000006 + 0.0im
0.18750000000000006 + 0.0im
0.18750000000000006 + 0.0im
0.18750000000000006 + 0.0im
0.18750000000000006 + 0.0im
0.18750000000000006 + 0.0im
0.18750000000000006 + 0.0im
0.18750000000000006 + 0.0im
0.18750000000000006 + 0.0im
0.18750000000000006 + 0.0im
0.18750000000000006 + 0.0im
0.18750000000000006 + 0.0im
637.317 μs (4245 allocations: 646.05 KiB)
14-element Vector{Float64}:
0.18749999999999994
0.18749999999999994
0.18749999999999994
0.18749999999999994
0.18749999999999994
0.18749999999999994
0.18749999999999994
0.18749999999999994
0.18749999999999994
0.18749999999999994
0.18749999999999994
0.18749999999999994
0.18749999999999994
0.18749999999999994

julia> operator = kron([1 0; 0 -1], kron([1 0; 0 -1], I(2^7))); # operator Z ⊗ Z ⊗ 𝟙 ⊗ .. ⊗ 𝟙

julia> @btime symm_op = symmetrize_operator(operator, basis)
41.828 ms (922891 allocations: 29.66 MiB)
14×14 Matrix{ComplexF64}:
1.096 ms (4248 allocations: 703.76 KiB)
14×14 Matrix{Float64}:
[...]
```

Expand All @@ -62,6 +62,8 @@ The symmetry operations supported are:

where `N` denotes the number of spins in the system and their positions should be given as a Julian index, i.e. in the range `1:N`.

To get the tranformation matrix to the symmetrized subspace just use `transformationmatrix(symmetrized_basis)`.

**Note:** The projection on a specific magnetization block is applied first. Thus if you have spin flip symmetry and restrict to a magnetization block, your symmetrized basis states look like "|↑..↑⟩ ± |↓..↑⟩". So in this case you effectively specified S_z^2 and parity.

## User-defined symmetries
Expand Down
4 changes: 2 additions & 2 deletions src/SpinSymmetry.jl
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
module SpinSymmetry

import SparseArrays
using SparseArrays: sparse

export Flip, Shift, Swap, SpatialReflection, GenericSymmetry
export zbasis, FullZBasis, ZBlockBasis, basissize
export SymmetrizedBasis, symmetrized_basis, symmetrize_state, symmetrize_operator
export SymmetrizedBasis, symmetrized_basis, symmetrize_state, symmetrize_operator, transformationmatrix

include("abstract.jl")
include("basis.jl")
Expand Down
9 changes: 4 additions & 5 deletions src/basis.jl
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ function symmetrize_state(state, basis::SymmetrizedBasis)
throw(ArgumentError("""State has wrong size.
Expected $(2^basis.basis.N), got: $(length(state))"""))
end
return _transformationmatrix(basis) * state
return transformationmatrix(basis) * state
# inds = _indices(basis.basis)
# factors = _phase_factors(inds, basis.symmetries, basis.sectors)
# use_real = all(d -> all(denominator.(values(d)) .<= 2), factors)
Expand Down Expand Up @@ -200,7 +200,7 @@ function symmetrize_operator(operator, basis::SymmetrizedBasis)
Expected $(2^basis.basis.N)x$(2^basis.basis.N), got: $(size(operator))"""))
end

trafo = _transformationmatrix(basis)
trafo = transformationmatrix(basis)

return trafo * operator * trafo'

Expand Down Expand Up @@ -303,8 +303,7 @@ function _phase_factors(inds, symms, sectors)
output
end

SparseArrays.sparse(symmbasis::SymmetrizedBasis) = _transformationmatrix(symmbasis)
function _transformationmatrix(symmbasis)
function transformationmatrix(symmbasis)
inds = SpinSymmetry._indices(symmbasis.basis)
phases = SpinSymmetry._phase_factors(inds, symmbasis.symmetries, symmbasis.sectors)

Expand All @@ -326,5 +325,5 @@ function _transformationmatrix(symmbasis)
index += 1
end
end
SparseArrays.sparse(I,J,V,length(phases), 2^(symmbasis.basis.N))
sparse(I,J,V,length(phases), 2^(symmbasis.basis.N))
end

2 comments on commit b0cfe24

@abraemer
Copy link
Owner Author

Choose a reason for hiding this comment

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

@JuliaRegistrator register

Changelog:

  • huge speed increase for symmetrization
  • get transformation matrix to subspace with transformationmatrix

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

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

Registration pull request created: JuliaRegistries/General/49250

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.3.3 -m "<description of version>" b0cfe24fd22987af91e007327a102b574992ef65
git push origin v0.3.3

Please sign in to comment.