First commit with layout for Latttice GPU code

This commit is contained in:
Alberto Ramos 2021-07-13 22:12:55 +02:00
commit 5bb4f28c8b
9 changed files with 747 additions and 0 deletions

146
src/Groups/GroupSU2.jl Normal file
View file

@ -0,0 +1,146 @@
###
### "THE BEER-WARE LICENSE":
### Alberto Ramos wrote this file. As long as you retain this
### notice you can do whatever you want with this stuff. If we meet some
### day, and you think this stuff is worth it, you can buy me a beer in
### return. <alberto.ramos@cern.ch>
###
### file: GroupSU2.jl
### created: Sun Jul 11 17:23:12 2021
###
#
# SU(2) group elements represented trough Cayley-Dickson
# construction
# https://en.wikipedia.org/wiki/Cayley%E2%80%93Dickson_construction
import Base.:*, Base.:+, Base.:-,Base.:/,Base.:\
struct SU2 <: Group
t1::ComplexF64
t2::ComplexF64
end
SU2() = SU2(1.0, 0.0)
inverse(b::SU2) = SU2(conj(b.t1), -b.t2)
dag(a::SU2) = inverse(a)
norm(a::SU2) = sqrt(abs2(a.t1) + abs2(a.t2))
tr(g::SU2) = 2.0*real(a.t1)
"""
function normalize(a::SU2)
Return a normalized element of `SU(2)`
"""
function normalize(a::SU2)
dr = sqrt(abs2(a.t1) + abs2(a.t2))
if (dr == 0.0)
return SU2(0.0)
end
return SU2(a.t1/dr,a.t2/dr)
end
Base.:+(a::SU2,b::SU2) = SU2(a.t1+b.t1,a.t2+b.t2)
Base.:-(a::SU2,b::SU2) = SU2(a.t1-b.t1,a.t2-b.t2)
Base.:*(a::SU2,b::SU2) = SU2(a.t1*b.t1-a.t2*conj(b.t2),a.t1*b.t2+a.t2*conj(b.t1))
Base.:/(a::SU2,b::SU2) = SU2(a.t1*conj(b.t1)+a.t2*conj(b.t2),-a.t1*b.t2+a.t2*b.t1)
Base.:\(a::SU2,b::SU2) = SU2(conj(a.t1)*b.t1+a.t2*conj(b.t2),conj(a.t1)*b.t2-a.t2*conj(b.t1))
Base.:+(a::SU2) = SU2(a.t1,a.t2)
Base.:-(a::SU2) = SU2(-a.t1,-a.t2)
struct SU2alg <: Algebra
t1::Float64
t2::Float64
t3::Float64
end
SU2alg(x::Real) = SU2alg(x,0.0,0.0)
SU2alg(v::Vector) = SU2alg(v[1],v[2],v[3])
projalg(g::SU2) = SU2alg(imag(g.t1), real(g.t2), imag(g.t2))
dot(a::SU2alg, b::SU2alg) = a.t1*b.t1 + a.t2*b.t2 + a.t3*b.t3
Base.:+(a::SU2alg) = SU2alg(a.t1,a.t2,a.t3)
Base.:-(a::SU2alg) = SU2alg(-a.t1,-a.t2,-a.t3)
Base.:+(a::SU2alg,b::SU2alg) = SU2alg(a.t1+b.t1,a.t2+b.t2,a.t3+b.t3)
Base.:-(a::SU2alg,b::SU2alg) = SU2alg(a.t1-b.t1,a.t2-b.t2,a.t3-b.t3)
Base.:*(a::SU2alg,b::Real) = SU2alg(a.t1*b,a.t2*b,a.t3*b)
Base.:*(b::Real,a::SU2alg) = SU2alg(a.t1*b,a.t2*b,a.t3*b)
Base.:/(a::SU2alg,b::Real) = SU2alg(a.t1/b,a.t2/b,a.t3/b)
"""
function Base.exp(a::SU2alg, t::Number=1)
Computes `exp(a)`
"""
function Base.exp(a::SU2alg)
rm = sqrt( a.t1^2+a.t2^2+a.t3^2 )/2.0
if (abs(rm) < 0.05)
rms = rm^2/2.0
ca = 1.0 - rms *(1.0 - (rms/6.0 )*(1.0 - rms/15.0))
sa = 0.5 - rms/6.0*(1.0 - (rms/10.0)*(1.0 - rms/21.0))
else
ca = cos(rm)
sa = sin(rm)/(2.0*rm)
end
return SU2(complex(ca,sa*a.t1),complex(sa*a.t2,sa*a.t3))
end
function Base.exp(a::SU2alg, t::Number)
rm = t*sqrt( a.t1^2+a.t2^2+a.t3^2 )/2.0
if (abs(rm) < 0.05)
rms = rm^2/2.0
ca = 1.0 - rms *(1.0 - (rms/6.0 )*(1.0 - rms/15.0))
sa = t*(0.5 - rms/6.0*(1.0 - (rms/10.0)*(1.0 - rms/21.0)))
else
ca = cos(rm)
sa = t*sin(rm)/(2.0*rm)
end
return SU2(complex(ca,sa*a.t1),complex(sa*a.t2,sa*a.t3))
end
"""
function expm(g::SU2, a::SU2alg)
Computes `exp(a)*g`
"""
function expm(g::SU2, a::SU2alg)
rm = sqrt( a.t1^2+a.t2^2+a.t3^2 )/2.0
if (abs(rm) < 0.05)
rms = rm^2/2.0
ca = 1.0 - rms *(1.0 - (rms/6.0 )*(1.0 - rms/15.0))
sa = 0.5 - rms/6.0*(1.0 - (rms/10.0)*(1.0 - rms/21.0))
else
ca = cos(rm)
sa = sin(rm)/(2.0*rm)
end
return SU2(complex(ca,sa*a.t1)*g.t1-complex(sa*a.t2,sa*a.t3)*conj(g.t2),
complex(ca,sa*a.t1)*g.t2+complex(sa*a.t2,sa*a.t3)*conj(g.t1))
end
"""
function expm(g::SU2, a::SU2alg, t::Float64)
Computes `exp(t*a)*g`
"""
function expm(g::SU2, a::SU2alg, t::Float64)
rm = t*sqrt( a.t1^2+a.t2^2+a.t3^2 )/2.0
if (abs(rm) < 0.05)
rms = rm^2/2.0
ca = 1.0 - rms *(1.0 - (rms/6.0 )*(1.0 - rms/15.0))
sa = t*(0.5 - rms/6.0*(1.0 - (rms/10.0)*(1.0 - rms/21.0)))
else
ca = cos(rm)
sa = t*sin(rm)/(2.0*rm)
end
return SU2(complex(ca,sa*a.t1)*g.t1-complex(sa*a.t2,sa*a.t3)*conj(g.t2),
complex(ca,sa*a.t1)*g.t2+complex(sa*a.t2,sa*a.t3)*conj(g.t1))
end

48
src/Groups/GroupSU3.jl Normal file
View file

@ -0,0 +1,48 @@
###
### "THE BEER-WARE LICENSE":
### Alberto Ramos wrote this file. As long as you retain this
### notice you can do whatever you want with this stuff. If we meet some
### day, and you think this stuff is worth it, you can buy me a beer in
### return. <alberto.ramos@cern.ch>
###
### file: GroupSU3.jl
### created: Sun Jul 11 17:23:02 2021
###
#
# Use memory efficient representation: Only store
# first two rows
#
# a.u31 = a.u12*conj(a.u23) - a.u13*conj(a.u22)
# a.u32 = a.u13*conj(a.u21) - a.u11*conj(a.u23)
# a.u33 = a.u11*conj(a.u22) - a.u12*conj(a.u21)
#
import Base.:*, Base.:+, Base.:-,Base.:/,Base.:\
struct SU3 <: Group
u11::ComplexF64
u12::ComplexF64
u13::ComplexF64
u21::ComplexF64
u22::ComplexF64
u23::ComplexF64
end
SU3() = SU3(1,0,0,0,1,0)
inverse(a::SU3) = SU3(conj(a.u11),conj(a.u21),conj(a.u12*conj(a.u23) - a.u13*conj(a.u22)),
conj(a.u12),conj(a.u22),conj(a.u13*conj(a.u21) - a.u11*conj(a.u23)))
dag(a::SU3) = inverse(a)
tr(g::SU3) = a.u11+a.u22+a.u11*conj(a.u22)-a.u12*conj(a.u21)
function Base.:*(a::SU3,b::SU3)
bu31 = (b.u12*conj(a.u23) - b.u13*conj(b.u22))
bu32 = (b.u13*conj(b.u21) - b.u11*conj(b.u23))
bu33 = (b.u11*conj(b.u22) - b.u12*conj(b.u21))
return SU3(a.u11*b.u11 + a.u12*b.u21 + a.u13*bu31,
a.u11*b.u12 + a.u12*b.u22 + a.u13*bu32,
a.u11*b.u13 + a.u12*b.u23 + a.u13*bu33,
a.u21*b.u11 + a.u22*b.u21 + a.u23*bu31,
a.u21*b.u12 + a.u22*b.u22 + a.u23*bu32,
a.u21*b.u13 + a.u22*b.u23 + a.u23*bu33)
end

28
src/Groups/Groups.jl Normal file
View file

@ -0,0 +1,28 @@
###
### "THE BEER-WARE LICENSE":
### Alberto Ramos wrote this file. As long as you retain this
### notice you can do whatever you want with this stuff. If we meet some
### day, and you think this stuff is worth it, you can buy me a beer in
### return. <alberto.ramos@cern.ch>
###
### file: Groups.jl
### created: Sun Jul 11 18:02:16 2021
###
module Groups
abstract type Group end
abstract type Algebra end
include("GroupSU2.jl")
export SU2, SU2alg, dag, normalize, inverse, tr, projalg, norm
export dot, expm, exp
include("GroupSU3.jl")
end # module