Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
16 changes: 8 additions & 8 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "TensorAlgebra"
uuid = "68bd88dc-f39d-4e12-b2ca-f046b68fcc6a"
authors = ["ITensor developers <[email protected]> and contributors"]
version = "0.4.3"
version = "0.4.4"

[deps]
ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a"
Expand All @@ -13,20 +13,20 @@ TensorProducts = "decf83d6-1968-43f4-96dc-fdb3fe15fc6d"
TupleTools = "9d95972d-f1c8-5527-a6e0-b4b365fa01f6"
TypeParameterAccessors = "7e5a90cf-f82e-492e-a09b-e3e26432c138"

[weakdeps]
TensorOperations = "6aa20fa7-93e2-5fca-9bc0-fbd0db3c71a2"

[extensions]
TensorAlgebraTensorOperationsExt = "TensorOperations"

[compat]
ArrayLayouts = "1.10.4"
BlockArrays = "1.7.2"
EllipsisNotation = "1.8.0"
LinearAlgebra = "1.10"
MatrixAlgebraKit = "0.2, 0.3, 0.4"
TensorProducts = "0.1.5"
TensorOperations = "5"
TensorProducts = "0.1.5"
TupleTools = "1.6.0"
TypeParameterAccessors = "0.2.1, 0.3, 0.4"
julia = "1.10"

[weakdeps]
TensorOperations = "6aa20fa7-93e2-5fca-9bc0-fbd0db3c71a2"

[extensions]
TensorAlgebraTensorOperationsExt = "TensorOperations"
12 changes: 6 additions & 6 deletions benchmark/benchmarks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ Ts = (Float64, ComplexF64)
algs = (TensorAlgebra.Matricize(),)

for alg in algs
alg_suite = contraction_suite[alg] = BenchmarkGroup()
for T in Ts
alg_suite[T] = BenchmarkGroup()
alg_suite = contraction_suite[alg] = BenchmarkGroup()
for T in Ts
alg_suite[T] = BenchmarkGroup()

for (i, line) in enumerate(eachline(CONTRACTIONS_PATH))
alg_suite[T][i] = generate_contract_benchmark(line; T, alg)
for (i, line) in enumerate(eachline(CONTRACTIONS_PATH))
alg_suite[T][i] = generate_contract_benchmark(line; T, alg)
end
end
end
end
126 changes: 63 additions & 63 deletions benchmark/contractions.jl
Original file line number Diff line number Diff line change
@@ -1,75 +1,75 @@
function extract_contract_labels(contraction::AbstractString)
symbolsC = match(r"C\[([^\]]*)\]", contraction)
labelsC = split(symbolsC.captures[1], ","; keepempty=false)
symbolsA = match(r"A\[([^\]]*)\]", contraction)
labelsA = split(symbolsA.captures[1], ","; keepempty=false)
symbolsB = match(r"B\[([^\]]*)\]", contraction)
labelsB = split(symbolsB.captures[1], ","; keepempty=false)
return labelsC, labelsA, labelsB
symbolsC = match(r"C\[([^\]]*)\]", contraction)
labelsC = split(symbolsC.captures[1], ","; keepempty = false)
symbolsA = match(r"A\[([^\]]*)\]", contraction)
labelsA = split(symbolsA.captures[1], ","; keepempty = false)
symbolsB = match(r"B\[([^\]]*)\]", contraction)
labelsB = split(symbolsB.captures[1], ","; keepempty = false)
return labelsC, labelsA, labelsB
end

function generate_contract_benchmark(
line::AbstractString; elt=Float64, alg=default_contract_alg(), do_alpha=true, do_beta=true
)
line_split = split(line, " & ")
@assert length(line_split) == 2 "Invalid line format:\n$line"
contraction, sizes = line_split
line::AbstractString; elt = Float64, alg = default_contract_alg(), do_alpha = true, do_beta = true
)
line_split = split(line, " & ")
@assert length(line_split) == 2 "Invalid line format:\n$line"
contraction, sizes = line_split

# extract labels
labelsC, labelsA, labelsB = map(Tuple, extract_contract_labels(contraction))
# pA, pB, pC = TensorOperations.contract_indices(
# tuple(labelsA...), tuple(labelsB...), tuple(labelsC...)
# )
# extract labels
labelsC, labelsA, labelsB = map(Tuple, extract_contract_labels(contraction))
# pA, pB, pC = TensorOperations.contract_indices(
# tuple(labelsA...), tuple(labelsB...), tuple(labelsC...)
# )

# extract sizes
subsizes = Dict{String,Int}()
for (label, sz) in split.(split(sizes, "; "; keepempty=false), Ref(":"))
subsizes[label] = parse(Int, sz)
end
szA = getindex.(Ref(subsizes), labelsA)
szB = getindex.(Ref(subsizes), labelsB)
szC = getindex.(Ref(subsizes), labelsC)
setup_tensors() = (rand(elt, szA...), rand(elt, szB...), rand(elt, szC...))
# extract sizes
subsizes = Dict{String, Int}()
for (label, sz) in split.(split(sizes, "; "; keepempty = false), Ref(":"))
subsizes[label] = parse(Int, sz)
end
szA = getindex.(Ref(subsizes), labelsA)
szB = getindex.(Ref(subsizes), labelsB)
szC = getindex.(Ref(subsizes), labelsC)
setup_tensors() = (rand(elt, szA...), rand(elt, szB...), rand(elt, szC...))

if do_alpha && do_beta
α, β = rand(elt, 2)
return @benchmarkable(
contract!($alg, C, $labelsC, A, $labelsA, B, $labelsB, $α, $β),
setup = ((A, B, C) = $setup_tensors()),
evals = 1
)
elseif do_alpha
α = rand(elt)
return @benchmarkable(
contract!($alg, C, $labelsC, A, $labelsA, B, $labelsB, $α),
setup = ((A, B, C) = $setup_tensors()),
evals = 1
)
elseif do_beta
β = rand(elt)
return @benchmarkable(
contract!($alg, C, $labelsC, A, $labelsA, B, $labelsB, true, $β),
setup = ((A, B, C) = $setup_tensors()),
evals = 1
)
else
return @benchmarkable(
contract!($alg, C, $labelsC, A, $labelsA, B, $labelsB),
setup = ((A, B, C) = $setup_tensors()),
evals = 1
)
end
if do_alpha && do_beta
α, β = rand(elt, 2)
return @benchmarkable(
contract!($alg, C, $labelsC, A, $labelsA, B, $labelsB, $α, $β),
setup = ((A, B, C) = $setup_tensors()),
evals = 1
)
elseif do_alpha
α = rand(elt)
return @benchmarkable(
contract!($alg, C, $labelsC, A, $labelsA, B, $labelsB, $α),
setup = ((A, B, C) = $setup_tensors()),
evals = 1
)
elseif do_beta
β = rand(elt)
return @benchmarkable(
contract!($alg, C, $labelsC, A, $labelsA, B, $labelsB, true, $β),
setup = ((A, B, C) = $setup_tensors()),
evals = 1
)
else
return @benchmarkable(
contract!($alg, C, $labelsC, A, $labelsA, B, $labelsB),
setup = ((A, B, C) = $setup_tensors()),
evals = 1
)
end
end

function compute_contract_ops(line::AbstractString)
line_split = split(line, " & ")
@assert length(line_split) == 2 "Invalid line format:\n$line"
_, sizes = line_split
line_split = split(line, " & ")
@assert length(line_split) == 2 "Invalid line format:\n$line"
_, sizes = line_split

# extract sizes
subsizes = Dict{String,Int}()
for (label, sz) in split.(split(sizes, "; "; keepempty=false), Ref("="))
subsizes[label] = parse(Int, sz)
end
return prod(collect(values(subsizes)))
# extract sizes
subsizes = Dict{String, Int}()
for (label, sz) in split.(split(sizes, "; "; keepempty = false), Ref("="))
subsizes[label] = parse(Int, sz)
end
return prod(collect(values(subsizes)))
end
22 changes: 11 additions & 11 deletions docs/make.jl
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
using TensorAlgebra: TensorAlgebra
using Documenter: Documenter, DocMeta, deploydocs, makedocs

DocMeta.setdocmeta!(TensorAlgebra, :DocTestSetup, :(using TensorAlgebra); recursive=true)
DocMeta.setdocmeta!(TensorAlgebra, :DocTestSetup, :(using TensorAlgebra); recursive = true)

include("make_index.jl")

makedocs(;
modules=[TensorAlgebra],
authors="ITensor developers <[email protected]> and contributors",
sitename="TensorAlgebra.jl",
format=Documenter.HTML(;
canonical="https://itensor.github.io/TensorAlgebra.jl",
edit_link="main",
assets=["assets/favicon.ico", "assets/extras.css"],
),
pages=["Home" => "index.md", "Reference" => "reference.md"],
modules = [TensorAlgebra],
authors = "ITensor developers <[email protected]> and contributors",
sitename = "TensorAlgebra.jl",
format = Documenter.HTML(;
canonical = "https://itensor.github.io/TensorAlgebra.jl",
edit_link = "main",
assets = ["assets/favicon.ico", "assets/extras.css"],
),
pages = ["Home" => "index.md", "Reference" => "reference.md"],
)

deploydocs(;
repo="github.com/ITensor/TensorAlgebra.jl", devbranch="main", push_preview=true
repo = "github.com/ITensor/TensorAlgebra.jl", devbranch = "main", push_preview = true
)
16 changes: 8 additions & 8 deletions docs/make_index.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@ using Literate: Literate
using TensorAlgebra: TensorAlgebra

function ccq_logo(content)
include_ccq_logo = """
include_ccq_logo = """
```@raw html
<img class="display-light-only" src="assets/CCQ.png" width="20%" alt="Flatiron Center for Computational Quantum Physics logo."/>
<img class="display-dark-only" src="assets/CCQ-dark.png" width="20%" alt="Flatiron Center for Computational Quantum Physics logo."/>
```
"""
content = replace(content, "{CCQ_LOGO}" => include_ccq_logo)
return content
content = replace(content, "{CCQ_LOGO}" => include_ccq_logo)
return content
end

Literate.markdown(
joinpath(pkgdir(TensorAlgebra), "examples", "README.jl"),
joinpath(pkgdir(TensorAlgebra), "docs", "src");
flavor=Literate.DocumenterFlavor(),
name="index",
postprocess=ccq_logo,
joinpath(pkgdir(TensorAlgebra), "examples", "README.jl"),
joinpath(pkgdir(TensorAlgebra), "docs", "src");
flavor = Literate.DocumenterFlavor(),
name = "index",
postprocess = ccq_logo,
)
16 changes: 8 additions & 8 deletions docs/make_readme.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@ using Literate: Literate
using TensorAlgebra: TensorAlgebra

function ccq_logo(content)
include_ccq_logo = """
include_ccq_logo = """
<picture>
<source media="(prefers-color-scheme: dark)" width="20%" srcset="docs/src/assets/CCQ-dark.png">
<img alt="Flatiron Center for Computational Quantum Physics logo." width="20%" src="docs/src/assets/CCQ.png">
</picture>
"""
content = replace(content, "{CCQ_LOGO}" => include_ccq_logo)
return content
content = replace(content, "{CCQ_LOGO}" => include_ccq_logo)
return content
end

Literate.markdown(
joinpath(pkgdir(TensorAlgebra), "examples", "README.jl"),
joinpath(pkgdir(TensorAlgebra));
flavor=Literate.CommonMarkFlavor(),
name="README",
postprocess=ccq_logo,
joinpath(pkgdir(TensorAlgebra), "examples", "README.jl"),
joinpath(pkgdir(TensorAlgebra));
flavor = Literate.CommonMarkFlavor(),
name = "README",
postprocess = ccq_logo,
)
2 changes: 1 addition & 1 deletion examples/README.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# # TensorAlgebra.jl
#
#
# [![Stable](https://img.shields.io/badge/docs-stable-blue.svg)](https://itensor.github.io/TensorAlgebra.jl/stable/)
# [![Dev](https://img.shields.io/badge/docs-dev-blue.svg)](https://itensor.github.io/TensorAlgebra.jl/dev/)
# [![Build Status](https://github.com/ITensor/TensorAlgebra.jl/actions/workflows/Tests.yml/badge.svg?branch=main)](https://github.com/ITensor/TensorAlgebra.jl/actions/workflows/Tests.yml?query=branch%3Amain)
Expand Down
Loading