Skip to content

Commit

Permalink
fix printing
Browse files Browse the repository at this point in the history
  • Loading branch information
GiggleLiu committed Jul 12, 2022
1 parent fd81405 commit feb8f2b
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 15 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "OMEinsumContractionOrders"
uuid = "6f22d1fd-8eed-4bb7-9776-e7d684900715"
authors = ["Jin-Guo Liu", "Pan Zhang"]
version = "0.7.0"
version = "0.7.1"

[deps]
AbstractTrees = "1520ce14-60c1-5f80-bbc7-55ef81b5835c"
Expand Down
2 changes: 1 addition & 1 deletion src/Core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ function AbstractTrees.printnode(io::IO, x::NestedEinsum)
end
AbstractTrees.printnode(io::IO, e::LeafString) = print(io, e.str)
function Base.show(io::IO, e::EinCode)
s = join([_join(ix) for ix in getixs(e)], ", ") * " -> " * _join(getiy(e))
s = join([_join(ix) for ix in getixsv(e)], ", ") * " -> " * _join(getiyv(e))
print(io, s)
end
function Base.show(io::IO, e::NestedEinsum)
Expand Down
22 changes: 11 additions & 11 deletions src/complexity.jl
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#################### compute peak memory ###########################
"""
peak_memory(code, size_dict::Dict)
peak_memory(code, size_dict::Dict) -> Int
Estimate peak memory usage in number of elements.
Estimate peak memory in number of elements.
"""
function peak_memory(code::NestedEinsum, size_dict::Dict)
ixs = getixsv(code.eins)
Expand Down Expand Up @@ -41,24 +41,24 @@ end

###################### Time space complexity ###################
"""
timespace_complexity(eincode, size_dict)
timespace_complexity(eincode, size_dict) -> (tc, sc)
Returns the time and space complexity of the einsum contraction.
The time complexity is defined as `log2(number of element multiplication)`.
The space complexity is defined as `log2(size of the maximum intermediate tensor)`.
The time complexity `tc` is defined as `log2(number of element multiplication)`.
The space complexity `sc` is defined as `log2(size of the maximum intermediate tensor)`.
"""
function timespace_complexity(code, size_dict)
tc,sc,rw = timespacereadwrite_complexity(code, size_dict)
return tc, sc
end

"""
timespacereadwrite_complexity(eincode, size_dict)
timespacereadwrite_complexity(eincode, size_dict) -> (tc, sc, rwc)
Returns the time, space and read-write complexity of the einsum contraction.
The time complexity is defined as `log2(number of element-wise multiplication)`.
The space complexity is defined as `log2(size of the maximum intermediate tensor)`.
The read-write complexity is defined as `log2(the number of read-write operations)`.
The time complexity `tc` is defined as `log2(number of element-wise multiplication)`.
The space complexity `sc` is defined as `log2(size of the maximum intermediate tensor)`.
The read-write complexity `rwc` is defined as `log2(the number of read-write operations)`.
"""
function timespacereadwrite_complexity(ei::NestedEinsum, size_dict)
log2_sizes = Dict([k=>log2(v) for (k,v) in size_dict])
Expand Down Expand Up @@ -129,7 +129,7 @@ end


"""
flop(eincode, size_dict)
flop(eincode, size_dict) -> Int
Returns the number of iterations, which is different with the true floating point operations (FLOP) by a factor of 2.
"""
Expand Down Expand Up @@ -168,7 +168,7 @@ end
uniformsize(code::AbstractEinsum, size) = Dict([l=>size for l in uniquelabels(code)])

"""
label_elimination_order(code)
label_elimination_order(code) -> Vector
Returns a vector of labels sorted by the order they are eliminated in the contraction tree.
The contraction tree is specified by `code`, which e.g. can be a `NestedEinsum` instance.
Expand Down
2 changes: 1 addition & 1 deletion src/interfaces.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
optimize_code(eincode, size_dict, optimizer = GreedyMethod(), simplifier=nothing, permute=true)
optimize_code(eincode, size_dict, optimizer = GreedyMethod(), simplifier=nothing, permute=true) -> optimized_eincode
Optimize the einsum contraction code and reduce the time/space complexity of tensor network contraction.
Returns a `NestedEinsum` instance. Input arguments are
Expand Down
5 changes: 4 additions & 1 deletion test/treesa.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ end
optcode = optimize_greedy(code, uniformsize(code, 2))
tree3 = ExprTree(optcode)
@test tree isa ExprTree
println(tree)
labelmap = Dict([v=>k for (k,v) in _label_dict(code)])
optcode_reconstruct = OMEinsumContractionOrders.NestedEinsum(tree3, labelmap)
@test optcode == optcode_reconstruct
Expand Down Expand Up @@ -78,6 +79,8 @@ end
log2_sizes = rand(n+n÷2) * 2
code = random_regular_eincode(n, 3)
optcode = optimize_greedy(code, uniformsize(code, 2))
println(code)
println(optcode)
tree = ExprTree(optcode)
tc0, sc0, rw0 = tree_timespace_complexity(tree, log2_sizes)
size_dict = Dict([j=>exp2(log2_sizes[j]) for j=1:length(log2_sizes)])
Expand Down Expand Up @@ -227,4 +230,4 @@ end
code = OMEinsumContractionOrders.EinCode(random_regular_eincode_char(20, 3).ixs, ['3','8','2'])
code1 = optimize_tree(code, uniformsize(code, 2); ntrials=1, fixed_slices=['7'])
@test eltype(code1.eins.eins.iy) == Char
end
end

0 comments on commit feb8f2b

Please sign in to comment.