Skip to content

time and space complexity for reduced problems #68

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

Merged
merged 4 commits into from
Aug 16, 2023
Merged
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
1 change: 1 addition & 0 deletions src/GenericTensorNetworks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export Matching, is_matching
export SetPacking, is_set_packing
export SetCovering, is_set_covering
export OpenPitMining, is_valid_mining, print_mining
export ReducedProblem, target_problem, extract_result

# Interfaces
export solve, SizeMax, SizeMin, PartitionFunction, CountingAll, CountingMax, CountingMin, GraphPolynomial, SingleConfigMax, SingleConfigMin, ConfigsAll, ConfigsMax, ConfigsMin, Single
Expand Down
9 changes: 8 additions & 1 deletion src/networks/Reduced.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
"""
$TYPEDEF

Graph problem that solved by reducing to another one. Interfaces are
- [`target_problem`](@ref), get the target problem to be reduced to.
- [`extract_result`](@ref), extract the result from the returned value of the target problem solver.
"""
abstract type ReducedProblem <: GraphProblem end

"""
Expand All @@ -17,4 +24,4 @@ function extract_result end
# fixedvertices(r::ReducedProblem) = fixedvertices(target_problem(r))
# labels(r::ReducedProblem) = labels(target_problem(r))
# terms(r::ReducedProblem) = terms(target_problem(r))
# get_weights(gp::ReducedProblem, label) = get_weights(target_problem(r))
# get_weights(gp::ReducedProblem, label) = get_weights(target_problem(r))
6 changes: 3 additions & 3 deletions src/networks/SpinGlass.jl
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ function extract_result(sg::SpinGlass, res::Union{Polynomial{BS,X}, LaurentPolyn
return lres * LaurentPolynomial{BS,X}([one(eltype(res.coeffs))], -sumJ + sumh)
end

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

Expand Down Expand Up @@ -88,4 +88,4 @@ function spinglass_energy(g::SimpleGraph, config; J=NoWeight(), h=ZeroWeight())
eng += s[v] * h[i]
end
return eng
end
end
1 change: 1 addition & 0 deletions src/networks/networks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ include("HyperSpinGlass.jl")

# forward the time, space and readwrite complexity
OMEinsum.contraction_complexity(gp::GraphProblem) = contraction_complexity(gp.code, uniformsize(gp.code, nflavor(gp)))
OMEinsum.contraction_complexity(gp::ReducedProblem) = contraction_complexity(target_problem(gp))
# the following two interfaces will be deprecated
OMEinsum.timespace_complexity(gp::GraphProblem) = timespace_complexity(gp.code, uniformsize(gp.code, nflavor(gp)))
OMEinsum.timespacereadwrite_complexity(gp::GraphProblem) = timespacereadwrite_complexity(gp.code, uniformsize(gp.code, nflavor(gp)))
Expand Down
3 changes: 2 additions & 1 deletion test/networks/SpinGlass.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ using GenericTensorNetworks, Test, Graphs
J = rand(15)
h = randn(10) .* 0.5
gp = SpinGlass(g; h, J)
@test contraction_complexity(gp).sc <= 5
M = zeros(10, 10)
for (e,j) in zip(edges(g), J)
M[e.src, e.dst] = j
Expand Down Expand Up @@ -38,4 +39,4 @@ using GenericTensorNetworks, Test, Graphs
poly = solve(gp, GraphPolynomial())[]
@test poly.m[] == sorted_energies[1]
@test poly.n[] == sorted_energies[end]
end
end