-
Notifications
You must be signed in to change notification settings - Fork 15
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
Ms/equivarinat matrices #99
Conversation
|
thank you - I'll take a look asap. |
I'm looking into the read/write issue now. |
Regarding the name, I think EquivariantMatrix is too general - it doesn't encode the specific symmetry. How about |
Another thing I've noticed is that you've based it off a fairly old commit. You'll need to rebase it onto the latest |
You'll see there that |
This is mostly done. However,
Would you mind taking a brief look at that (I think this might be much easier for you to resolve since you know the parts of the code well), or alternatively, we could meet at the beginning of next week? |
Error message:
It happens in this line: push!(vals, U[irow, icol]) The computed cc |
I fixed other parts of the code so that now there is no conversion required! It all seems to work now. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks mostly ok, just a few more smaller things to address please. Can you then also add the new tests to the test suite please?
The zero-correlation implementation looks roughly ok, but I added a small comment.
real(φ::EuclideanMatrix) = EuclideanMatrix(φ.val) | ||
complex(φ::EuclideanMatrix) = EuclideanMatrix(φ.val) | ||
real(φ::EuclideanMatrix) = EuclideanMatrix(real.(φ.val)) | ||
complex(φ::EuclideanMatrix) = EuclideanMatrix(complex(φ.val)) | ||
complex(::Type{EuclideanMatrix{T}}) where {T} = EuclideanMatrix{complex(T)} | ||
|
||
+(x::SMatrix{3}, y::EuclideanMatrix) = EuclideanMatrix(x + y.val) | ||
Base.convert(::Type{SMatrix{3, 3, T, 9}}, φ::EuclideanMatrix) where {T} = convert(SMatrix{3, 3, T, 9}, φ.val) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
where is this needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure, I kind of copied the implementations of EuclideanVector
here... Should I check, or should we introduce a new abstract type to avoid code redundancy?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, leave it for now.
src/properties.jl
Outdated
struct EuclideanMatrix{T} <: AbstractProperty where T<:Real | ||
val::SMatrix{3, 3, Complex{T}, 9} | ||
struct EuclideanMatrix{T} <: AbstractProperty | ||
val::SMatrix{3, 3, T, 9} | ||
end | ||
|
||
Base.show(io::IO, φ::EuclideanMatrix) = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure about this stype of printing; it suggests 3 vectors rather than one matrix. Would it be ok to print it similarly to the spherical matrix, but with an "e" label instead of a "y" label? (yes, I also don't like the "m" label)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done! But I am wondering whether we should have a different label than the label of Euclidean vectors? (Since EuclideanMatrix satisfies a different equivariance property.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it can be clear from the context that it is a matrix. If it were e and then three vectors then I would be confused.
if length(bb) == 0 # no zero-correlations allowed | ||
return false | ||
end | ||
if length(bb) == 1 #MS: Not sure if this should be here |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't remember the issue - same with EuclideanVector. If codes run ok, leave it for now but file an issue to investigate this. Do you have an idea?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code runs. Issue is filed (issue #100)!
src/properties.jl
Outdated
: coco_zeros(phi, l, m, μ, T, A) ) | ||
|
||
|
||
coco_init(::EuclideanMatrix{CT}) where {CT<:Real} = [EuclideanMatrix{CT}(SMatrix{3,3,Float64,9}([1.0,0,0,0,1.0,0,0,0,1.0]))] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you want
EuclideanMatrix{CT}(SMatrix{3,3,CT}([1.0,0,0,0,1.0,0,0,0,1.0]))
If I remember correctly this is the implementation for zero-correlations. So you are right that identity is the only zero-correlation there is, but you probably need to specify the right eltype.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
included in issue #100
: coco_zeros(phi, l, m, μ, T, A) ) | ||
|
||
|
||
coco_init(::EuclideanMatrix{CT}) where {CT<:Real} = [EuclideanMatrix{CT}(SMatrix{3,3,Float64,9}([1.0,0,0,0,1.0,0,0,0,1.0]))] | ||
#coco_init(::EuclideanMatrix{CT}) where {CT<:Real} = [EuclideanMatrix(SMatrix{3,3,Complex{CT},9}([1.0,0,0,0,1.0,0,0,0,1.0]))] | ||
coco_type(φ::EuclideanMatrix) = typeof(complex(φ)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so this confuses me now. In the previous commit the CCs there were produced were all real. But here you are saying they should be complex. So which is it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is all very confusing! But I know for sure that the coupling coefficients should be complex (same as in the implementation of EuclideanVector
). Thus, my understanding is that both the coco_init
function as well as the coco_zeros
function should return complex valued matrices.
coco_type(φ::EuclideanMatrix) = typeof(complex(φ)) | ||
coco_type(::Type{EuclideanMatrix{T}}) where {T} = EuclideanMatrix{complex(T)} | ||
|
||
# This is slightly different from implementation in EuclideanVector! | ||
coco_zeros(::EuclideanMatrix, ll, mm, kk, T, A) = EuclideanMatrix.(zeros(SMatrix{3, 3, Complex{T}, 9},9)) | ||
coco_zeros(φ::EuclideanMatrix, ll, mm, kk, T, A) = zeros(typeof(complex(φ)), 9) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here, why are you enforcing complex CCs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s.a.
sorry, just pushed a fix for a small bug that I noticed today in the morning. |
- updated implementation of EuclideanVector (moved elementary rotation coefficients to dictionary and changed format) - updated dictionary for elementary rotation coefficients to inlclude l=0,1,2 All tests pass, there are now non-symmetric matrix valued basis functions, BUT the complex part is still not negligible.
-new filter added to basis selectors - utils.SymmetricBond_basis extended to include symmetry option for bond sign flip - renamed "test_basisselectors.jl"
@cortner I think this PR is ready to merge. Do you approve? |
I will take a look. We will also need to merge in the latest main branch, or rebase. |
@cortner: I just merged the upstream/main into this branch. |
Argghh... it's not obvious to me how to fix the newly appearing error after merging with upstream/main! |
I wil try - no promises about time-scale |
what error? I only get a warning? |
This one: ERROR: LoadError: MethodError: namedtuple(::Tuple{}) is ambiguous. Candidates:
namedtuple(names::Tuple{Vararg{Symbol, N}}) where N in NamedTupleTools at /Users/msachs2/.julia/packages/NamedTupleTools/GZxRn/src/NamedTupleTools.jl:196
namedtuple(names::Tuple{Vararg{String, N}}) where N in NamedTupleTools at /Users/msachs2/.julia/packages/NamedTupleTools/GZxRn/src/NamedTupleTools.jl:198
Possible fix, define
namedtuple(::Tuple{})
Stacktrace:
[1] select(nt::NamedTuple{(:be, :n, :l, :m), Tuple{Symbol, Int64, Int64, Int64}}, ks::Tuple{})
@ NamedTupleTools ~/.julia/packages/NamedTupleTools/GZxRn/src/NamedTupleTools.jl:270
[2] _broadcast_getindex_evalf
@ ./broadcast.jl:648 [inlined]
[3] _broadcast_getindex
@ ./broadcast.jl:621 [inlined]
[4] getindex
@ ./broadcast.jl:575 [inlined]
[5] copy
@ ./broadcast.jl:922 [inlined]
[6] materialize
@ ./broadcast.jl:883 [inlined]
[7] _sparsify_component!(basis1p::ACE.EllipsoidBondEnvelope{Float64}, keep::Vector{NamedTuple{(:be, :n, :l, :m), Tuple{Symbol, Int64, Int64, Int64}}})
@ ACE ~/.julia/dev/ACE/src/product_1pbasis.jl:297
[8] sparsify!(basis1p::ACE.Product1pBasis{4, Tuple{Categorical1pBasis{:be, :be, 2, Symbol}, ACE.Rn1pBasis{Float64, PolyTransform{Int64, Float64}, ACE.OrthPolys.OrthPolyBasis{Float64}, :rr, :n, ACE.DState{NamedTuple{(:rr,), Tuple{SVector{3, Float64}}}}}, ACE.Ylm1pBasis{Float64, :rr, :l, :m, ACE.DState{NamedTuple{(:rr,), Tuple{SVector{3, ComplexF64}}}}}, ACE.EllipsoidBondEnvelope{Float64}}, ComplexF64}, keep::Vector{NamedTuple})
@ ACE ~/.julia/dev/ACE/src/product_1pbasis.jl:277
[9] clean_1pbasis!(basis::PIBasis{ACE.Product1pBasis{4, Tuple{Categorical1pBasis{:be, :be, 2, Symbol}, ACE.Rn1pBasis{Float64, PolyTransform{Int64, Float64}, ACE.OrthPolys.OrthPolyBasis{Float64}, :rr, :n, ACE.DState{NamedTuple{(:rr,), Tuple{SVector{3, Float64}}}}}, ACE.Ylm1pBasis{Float64, :rr, :l, :m, ACE.DState{NamedTuple{(:rr,), Tuple{SVector{3, ComplexF64}}}}}, ACE.EllipsoidBondEnvelope{Float64}}, ComplexF64}, typeof(real), Float64, ComplexF64})
@ ACE ~/.julia/dev/ACE/src/pibasis.jl:221
[10] clean_pibasis!(basis::ACE.SymmetricBasis{PIBasis{ACE.Product1pBasis{4, Tuple{Categorical1pBasis{:be, :be, 2, Symbol}, ACE.Rn1pBasis{Float64, PolyTransform{Int64, Float64}, ACE.OrthPolys.OrthPolyBasis{Float64}, :rr, :n, ACE.DState{NamedTuple{(:rr,), Tuple{SVector{3, Float64}}}}}, ACE.Ylm1pBasis{Float64, :rr, :l, :m, ACE.DState{NamedTuple{(:rr,), Tuple{SVector{3, ComplexF64}}}}}, ACE.EllipsoidBondEnvelope{Float64}}, ComplexF64}, typeof(real), Float64, ComplexF64}, ACE.Invariant{Float64}, ACE.O3{:l, :m}, typeof(real), ACE.Invariant{Float64}}; atol::Float64)
@ ACE ~/.julia/dev/ACE/src/symmbasis.jl:250
[11] clean_pibasis!(basis::ACE.SymmetricBasis{PIBasis{ACE.Product1pBasis{4, Tuple{Categorical1pBasis{:be, :be, 2, Symbol}, ACE.Rn1pBasis{Float64, PolyTransform{Int64, Float64}, ACE.OrthPolys.OrthPolyBasis{Float64}, :rr, :n, ACE.DState{NamedTuple{(:rr,), Tuple{SVector{3, Float64}}}}}, ACE.Ylm1pBasis{Float64, :rr, :l, :m, ACE.DState{NamedTuple{(:rr,), Tuple{SVector{3, ComplexF64}}}}}, ACE.EllipsoidBondEnvelope{Float64}}, ComplexF64}, typeof(real), Float64, ComplexF64}, ACE.Invariant{Float64}, ACE.O3{:l, :m}, typeof(real), ACE.Invariant{Float64}})
@ ACE ~/.julia/dev/ACE/src/symmbasis.jl:243
[12] ACE.SymmetricBasis(φ::ACE.Invariant{Float64}, symgrp::ACE.O3{:l, :m}, pibasis::PIBasis{ACE.Product1pBasis{4, Tuple{Categorical1pBasis{:be, :be, 2, Symbol}, ACE.Rn1pBasis{Float64, PolyTransform{Int64, Float64}, ACE.OrthPolys.OrthPolyBasis{Float64}, :rr, :n, ACE.DState{NamedTuple{(:rr,), Tuple{SVector{3, Float64}}}}}, ACE.Ylm1pBasis{Float64, :rr, :l, :m, ACE.DState{NamedTuple{(:rr,), Tuple{SVector{3, ComplexF64}}}}}, ACE.EllipsoidBondEnvelope{Float64}}, ComplexF64}, typeof(real), Float64, ComplexF64}, _real::Function)
@ ACE ~/.julia/dev/ACE/src/symmbasis.jl:176
[13] #SymmetricBasis#313
@ ~/.julia/dev/ACE/src/symmbasis.jl:103 [inlined]
[14] ACE.SymmetricBasis(φ::ACE.Invariant{Float64}, basis1p::ACE.Product1pBasis{4, Tuple{Categorical1pBasis{:be, :be, 2, Symbol}, ACE.Rn1pBasis{Float64, PolyTransform{Int64, Float64}, ACE.OrthPolys.OrthPolyBasis{Float64}, :rr, :n, ACE.DState{NamedTuple{(:rr,), Tuple{SVector{3, Float64}}}}}, ACE.Ylm1pBasis{Float64, :rr, :l, :m, ACE.DState{NamedTuple{(:rr,), Tuple{SVector{3, ComplexF64}}}}}, ACE.EllipsoidBondEnvelope{Float64}}, ComplexF64}, symgrp::ACE.O3{:l, :m}, Bsel::ACE.CategorySparseBasis; isreal::Bool, kwargs::Base.Iterators.Pairs{Symbol, ACE.Utils.var"#5#7", Tuple{Symbol}, NamedTuple{(:filterfun,), Tuple{ACE.Utils.var"#5#7"}}})
@ ACE ~/.julia/dev/ACE/src/symmbasis.jl:96
[15] #SymmetricBasis#310
@ ~/.julia/dev/ACE/src/symmbasis.jl:85 [inlined]
[16] SymmetricBond_basis(ϕ::ACE.Invariant{Float64}, env::ACE.EllipsoidBondEnvelope{Float64}, Bsel::SparseBasis; RnYlm::Nothing, bondsymmetry::Nothing, kwargs::Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
@ ACE.Utils ~/.julia/dev/ACE/src/utils.jl:97
[17] SymmetricBond_basis(ϕ::ACE.Invariant{Float64}, env::ACE.EllipsoidBondEnvelope{Float64}, Bsel::SparseBasis)
@ ACE.Utils ~/.julia/dev/ACE/src/utils.jl:78
[18] top-level scope
@ ~/.julia/dev/ACE/test/test_bondbasisselectors.jl:38
in expression starting at /Users/msachs2/.julia/dev/ACE/test/test_bondbasisselectors.jl:36 This is the error I get on my own computer. But I presume that the error encountered in 4b82aec is the same. |
ok, I can reproduce |
Ok - the problem is here:
you are trying to create a symmetric basis but it isn't a basis, so the basis spec contains only empty tuples. That's a weird edge case and I'm not even sure I want to allow this... Is this every going to occur outside of a test? |
See here : once we sparsity (in this case just "clean up") ...
I can't "select" a subset of the basis specs because there is no spec. It is at odds with the entire design of the basis framework. |
I can see in the error message that the spec is empty but I don't yet understand why this is the case? I create a special basis selector within the call of |
It’s just a multiplier by itself - it isn’t multiplying a basis |
Any thoughts on this? Maybe there is a way to just change the tests? Or do you need me to figure out a way around this? I'M just a bit overwhelmed right now - sorry for the delay. |
All tests asserting the equivariance properties of
EuclidianMatrix
pass with tol = 1E-15.The test
println(@test(all(test_fio(basis; warntype = false))))
(see line 41 in test/test_EquivariantMatrix.jl) does NOT pass...