Skip to content

Commit 44eb45f

Browse files
authored
time and space complexity for reduced problems (#68)
* time and space complexity for reduced problems * export reduced problem interfaces * update networks * update
1 parent deb722d commit 44eb45f

File tree

5 files changed

+15
-5
lines changed

5 files changed

+15
-5
lines changed

src/GenericTensorNetworks.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ export Matching, is_matching
5252
export SetPacking, is_set_packing
5353
export SetCovering, is_set_covering
5454
export OpenPitMining, is_valid_mining, print_mining
55+
export ReducedProblem, target_problem, extract_result
5556

5657
# Interfaces
5758
export solve, SizeMax, SizeMin, PartitionFunction, CountingAll, CountingMax, CountingMin, GraphPolynomial, SingleConfigMax, SingleConfigMin, ConfigsAll, ConfigsMax, ConfigsMin, Single

src/networks/Reduced.jl

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
"""
2+
$TYPEDEF
3+
4+
Graph problem that solved by reducing to another one. Interfaces are
5+
- [`target_problem`](@ref), get the target problem to be reduced to.
6+
- [`extract_result`](@ref), extract the result from the returned value of the target problem solver.
7+
"""
18
abstract type ReducedProblem <: GraphProblem end
29

310
"""
@@ -17,4 +24,4 @@ function extract_result end
1724
# fixedvertices(r::ReducedProblem) = fixedvertices(target_problem(r))
1825
# labels(r::ReducedProblem) = labels(target_problem(r))
1926
# terms(r::ReducedProblem) = terms(target_problem(r))
20-
# get_weights(gp::ReducedProblem, label) = get_weights(target_problem(r))
27+
# get_weights(gp::ReducedProblem, label) = get_weights(target_problem(r))

src/networks/SpinGlass.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ function extract_result(sg::SpinGlass, res::Union{Polynomial{BS,X}, LaurentPolyn
5959
return lres * LaurentPolynomial{BS,X}([one(eltype(res.coeffs))], -sumJ + sumh)
6060
end
6161

62-
# the configurations are not changed
63-
for ET in [:SumProductTree, :ConfigSampler, :ConfigEnumerator, :Real]
62+
# the configurations are not changed, vectors are treated as configurations
63+
for ET in [:SumProductTree, :ConfigSampler, :ConfigEnumerator, :Real, :AbstractVector]
6464
@eval extract_result(sg::SpinGlass, res::T) where T <: $(ET) = res
6565
end
6666

@@ -88,4 +88,4 @@ function spinglass_energy(g::SimpleGraph, config; J=NoWeight(), h=ZeroWeight())
8888
eng += s[v] * h[i]
8989
end
9090
return eng
91-
end
91+
end

src/networks/networks.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ include("HyperSpinGlass.jl")
139139

140140
# forward the time, space and readwrite complexity
141141
OMEinsum.contraction_complexity(gp::GraphProblem) = contraction_complexity(gp.code, uniformsize(gp.code, nflavor(gp)))
142+
OMEinsum.contraction_complexity(gp::ReducedProblem) = contraction_complexity(target_problem(gp))
142143
# the following two interfaces will be deprecated
143144
OMEinsum.timespace_complexity(gp::GraphProblem) = timespace_complexity(gp.code, uniformsize(gp.code, nflavor(gp)))
144145
OMEinsum.timespacereadwrite_complexity(gp::GraphProblem) = timespacereadwrite_complexity(gp.code, uniformsize(gp.code, nflavor(gp)))

test/networks/SpinGlass.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ using GenericTensorNetworks, Test, Graphs
55
J = rand(15)
66
h = randn(10) .* 0.5
77
gp = SpinGlass(g; h, J)
8+
@test contraction_complexity(gp).sc <= 5
89
M = zeros(10, 10)
910
for (e,j) in zip(edges(g), J)
1011
M[e.src, e.dst] = j
@@ -38,4 +39,4 @@ using GenericTensorNetworks, Test, Graphs
3839
poly = solve(gp, GraphPolynomial())[]
3940
@test poly.m[] == sorted_energies[1]
4041
@test poly.n[] == sorted_energies[end]
41-
end
42+
end

0 commit comments

Comments
 (0)