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

OpSum to TTN refactor #166

Merged
merged 19 commits into from
May 10, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/ITensorNetworks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ include("solvers/local_solvers/contract.jl")
include("solvers/local_solvers/linsolve.jl")
include("treetensornetworks/abstracttreetensornetwork.jl")
include("treetensornetworks/treetensornetwork.jl")
include("treetensornetworks/matelem.jl")
include("treetensornetworks/qnarrelem.jl")
include("treetensornetworks/opsum_to_ttn.jl")
emstoudenmire marked this conversation as resolved.
Show resolved Hide resolved
include("treetensornetworks/projttns/abstractprojttn.jl")
include("treetensornetworks/projttns/projttn.jl")
Expand Down
7 changes: 6 additions & 1 deletion src/apply.jl
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,12 @@ function ITensors.apply(
end

function ITensors.apply(
o⃗::Scaled, ψ::AbstractITensorNetwork; normalize=false, ortho=false, apply_kwargs...
o⃗::Scaled,
ψ::AbstractITensorNetwork;
cutoff=nothing,
normalize=false,
ortho=false,
apply_kwargs...,
)
return maybe_real(Ops.coefficient(o⃗)) *
apply(Ops.argument(o⃗), ψ; cutoff, maxdim, normalize, ortho, apply_kwargs...)
Expand Down
41 changes: 41 additions & 0 deletions src/treetensornetworks/matelem.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@

#
# MatElem
#

struct MatElem{T}
Copy link
Member

Choose a reason for hiding this comment

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

We could just use FillArrays.OneElement for this can get rid of this type: https://juliaarrays.github.io/FillArrays.jl/stable/#FillArrays.OneElement. Not needed for this PR, I added a note about it to #117.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, this is for sure. Good to know.

row::Int
col::Int
val::T
end

#function Base.show(io::IO,m::MatElem)
# print(io,"($(m.row),$(m.col),$(m.val))")
#end

function toMatrix(els::Vector{MatElem{T}})::Matrix{T} where {T}
nr = 0
nc = 0
for el in els
nr = max(nr, el.row)
nc = max(nc, el.col)
end
M = zeros(T, nr, nc)
for el in els
M[el.row, el.col] = el.val
end
return M
end

function Base.:(==)(m1::MatElem{T}, m2::MatElem{T})::Bool where {T}
return (m1.row == m2.row && m1.col == m2.col && m1.val == m2.val)
end

function Base.isless(m1::MatElem{T}, m2::MatElem{T})::Bool where {T}
if m1.row != m2.row
return m1.row < m2.row
elseif m1.col != m2.col
return m1.col < m2.col
end
return m1.val < m2.val
end
Loading
Loading