Skip to content

Commit

Permalink
QuantumNumbers submodule
Browse files Browse the repository at this point in the history
  • Loading branch information
mtfishman committed Apr 28, 2024
1 parent a396f8b commit de0e4ac
Show file tree
Hide file tree
Showing 11 changed files with 473 additions and 399 deletions.
38 changes: 18 additions & 20 deletions src/ITensors.jl
Original file line number Diff line number Diff line change
Expand Up @@ -52,22 +52,24 @@ module ITensors
include("usings.jl")
include("utils.jl")
include("lib/ContractionSequenceOptimization/src/ContractionSequenceOptimization.jl")
# TODO: `using .ContractionSequenceOptimization: ContractionSequenceOptimization`.
# TODO: `using .ContractionSequenceOptimization: ContractionSequenceOptimization, ...`.
using .ContractionSequenceOptimization
include("lib/LazyApply/src/LazyApply.jl")
# TODO: `using .LazyApply: LazyApply`.
# TODO: `using .LazyApply: LazyApply, ...`.
using .LazyApply
include("lib/Ops/src/Ops.jl")
# TODO: `using .Ops: Ops`.
# TODO: `using .Ops: Ops, ...`.
using .Ops
using .Ops: Ops, Op, Trotter
import .Ops: sites, name
export Trotter
include("exports.jl")
include("imports.jl")
include("global_variables.jl")
# TODO: Move to `lib/LastVals/src/LastVals.jl`.
include("lastval.jl")
include("lib/SmallStrings/src/SmallStrings.jl")
using .SmallStrings: SmallStrings, IntChar, Tag, isint, isnull
using .SmallStrings: SmallStrings, IntChar, SmallString, Tag, isint, isnull
include("readwrite.jl")
# TODO: Move to `lib/Nots/src/Nots.jl`.
include("not.jl")
Expand All @@ -79,13 +81,16 @@ include("index.jl")
include("set_operations.jl")
include("indexset.jl")
include("itensor.jl")
# TODO: Move to `lib/Names/src/Names.jl`.
include("name.jl")
export val
# TODO: Move to `lib/Vals/src/Vals.jl`.
include("val.jl")
export val
# include("lib/QuantumNumbers/src/QuantumNumbers.jl")
# using .QuantumNumbers: QN
# export QN
include("lib/QuantumNumbers/src/QuantumNumbers.jl")
using .QuantumNumbers: QN
export QN
include("qn/flux.jl")
include("qn/qn.jl")
include("oneitensor.jl")
include("tensor_operations/tensor_algebra.jl")
include("tensor_operations/matrix_algebra.jl")
Expand Down Expand Up @@ -124,8 +129,7 @@ export OpName,
ops,
state,
val
# TODO: Move to `lib/ITensorsSiteTypesExt/src/ITensorsSiteTypesExt.jl`.
include("ITensorsSiteTypesExt.jl")
include("lib/ITensorsSiteTypesExt/src/ITensorsSiteTypesExt.jl")
include("broadcast.jl")
include("tensor_operations/matrix_decomposition.jl")
include("adapt.jl")
Expand All @@ -135,24 +139,18 @@ include("qn/qnindex.jl")
include("qn/qnindexset.jl")
include("qn/qnitensor.jl")
include("nullspace.jl")

# TODO: Move to `lib/ITensorsOpsExt/src/ITensorsOpsExt.jl`?
include("lib/Ops/ops_itensor.jl")
include("lib/ITensorsOpsExt/src/ITensorsOpsExt.jl")
include("fermions/fermions.jl")

include("lib/ITensorMPS/src/ITensorMPS.jl")
# TODO: `using .ITensorMPS: ITensorMPS, ...`.
# TODO: `using .ITensorMPS: ITensorMPS, ...` and
# explicit export list.
@reexport using .ITensorMPS
include("lib/ITensorsNamedDimsArraysExt/src/ITensorsNamedDimsArraysExt.jl")
using .ITensorsNamedDimsArraysExt: ITensorsNamedDimsArraysExt

# TODO: Move into `Ops`.
include("lib/Ops/trotter.jl")

include("lib/ITensorChainRules/src/ITensorChainRules.jl")
include("lib/ITensorNetworkMaps/src/ITensorNetworkMaps.jl")
include("lib/ITensorVisualizationCore/src/ITensorVisualizationCore.jl")
# TODO: `using .ITensorVisualizationCore: ITensorVisualizationCore`.
# TODO: `using .ITensorVisualizationCore: ITensorVisualizationCore, ...`.
using .ITensorVisualizationCore
using .ITensorVisualizationCore:
@visualize,
Expand Down
7 changes: 0 additions & 7 deletions src/exports.jl
Original file line number Diff line number Diff line change
Expand Up @@ -211,13 +211,6 @@ export
Prod,
coefficient,

# Ops/Ops.jl
Ops,
Op,

# Ops/trotter.jl
Trotter,

# physics/autompo.jl
AutoMPO,
OpSum,
Expand Down
1 change: 1 addition & 0 deletions src/fermions/fermions.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using .QuantumNumbers: QN, QNVal

"""
parity_sign(P)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using NDTensors: using_auto_fermion
using ..Ops: Op

# TODO: Deprecate.
const AutoMPO = OpSum
Expand Down
79 changes: 79 additions & 0 deletions src/lib/ITensorsOpsExt/src/ITensorsOpsExt.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
module ITensorsOpsExt
using ITensors: ITensors, ITensor, Index, apply, dag, hascommoninds, swapprime
using ..LazyApply: LazyApply, Applied, Exp, Prod, Scaled, Sum, argument, coefficient
using LinearAlgebra: UniformScaling, I
using ..Ops: Op
using ..SiteTypes: SiteTypes, op

function SiteTypes.op(I::UniformScaling, s::Index...)
return I.λ * op("Id", s...)
end

function ITensors.ITensor(o::Op, s::Vector{<:Index})
return op(o.which_op, map(n -> s[n], o.sites)...; o.params...)
end

function ITensors.ITensor(o::Scaled, s::Vector{<:Index})
c = coefficient(o)
if isreal(c)
c = real(c)
end
return c * ITensor(argument(o), s)
end

function ITensors.ITensor(o::Prod, s::Vector{<:Index})
T = ITensor(true)
for a in o.args[1]
Tₙ = ITensor(a, s)
# TODO: Implement this logic inside `apply`
if hascommoninds(T, Tₙ)
T = T(Tₙ)
else
T *= Tₙ
end
end
return T
end

function ITensors.ITensor(o::Sum, s::Vector{<:Index})
T = ITensor()
for a in o.args[1]
T += ITensor(a, s)
end
return T
end

function ITensors.ITensor(o::Exp, s::Vector{<:Index})
return exp(ITensor(argument(o), s))
end

function ITensors.ITensor(o::LazyApply.Adjoint, s::Vector{<:Index})
return swapprime(dag(ITensor(o', s)), 0 => 1)
end

function LazyApply.Sum{ITensor}(o::Sum, s::Vector{<:Index})
return Applied(sum, (map(oₙ -> ITensor(oₙ, s), only(o.args)),))
end

function LazyApply.Prod{ITensor}(o::Prod, s::Vector{<:Index})
return Applied(prod, (map(oₙ -> ITensor(oₙ, s), only(o.args)),))
end

function LazyApply.Prod{ITensor}(o::Scaled{C,Prod{Op}}, s::Vector{<:Index}) where {C}
t = Prod{ITensor}(argument(o), s)
t1 = coefficient(o) * only(t.args)[1]
return Applied(prod, (vcat([t1], only(t.args)[2:end]),))
end

function ITensors.apply(o::Prod{ITensor}, v::ITensor; kwargs...)
ov = v
for oₙ in reverse(only(o.args))
ov = apply(oₙ, ov; kwargs...)
end
return ov
end

function (o::Prod{ITensor})(v::ITensor; kwargs...)
return apply(o, v; kwargs...)
end
end
File renamed without changes.
Loading

0 comments on commit de0e4ac

Please sign in to comment.