Skip to content
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

Example: generic tensor network #22

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
*.jl.*.cov
*.jl.cov
*.jl.mem
/Manifest.toml
Manifest.toml
lib
.vscode
Artifact
Expand Down
13 changes: 13 additions & 0 deletions examples/combinatorial-optimization/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[deps]
CUDA = "052768ef-5323-5732-b1bb-66c8b64840ba"
CuTropicalGEMM = "c2b282c3-c9c2-431d-80f7-a1a0561ebe55"
GenericTensorNetworks = "3521c873-ad32-4bb4-b63d-f4f178f42b49"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
TropicalNumbers = "b3a74e9c-7526-4576-a4eb-79c0d4c32334"

[compat]
CUDA = "5"
CuTropicalGEMM = "0.1"
GenericTensorNetworks = "1"
TropicalNumbers = "0.6"
julia = "1.9"
8 changes: 8 additions & 0 deletions examples/combinatorial-optimization/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Solving combinatorial optimization problem with generic tensor networks

## Problem description

We consider solving the maximum independent set problem. Please check [the manual page](https://queracomputing.github.io/GenericTensorNetworks.jl/dev/generated/IndependentSet/) of package [GenericTensorNetworks.jl](https://github.com/QuEraComputing/GenericTensorNetworks.jl) [1] for a detailed description of the problem.

## References
1. Liu, J.-G., Gao, X., Cain, M., Lukin, M. D. & Wang, S.-T. Computing solution space properties of combinatorial optimization problems via generic tensor networks. Preprint at https://doi.org/10.48550/arXiv.2205.03718 (2022).
22 changes: 22 additions & 0 deletions examples/combinatorial-optimization/main.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using GenericTensorNetworks, CUDA, TropicalNumbers, GenericTensorNetworks.Graphs
using CuTropicalGEMM
using Random; Random.seed!(2)

# Create a random 3-regular graph
g = GenericTensorNetworks.random_diagonal_coupled_graph(38, 38, 0.8)

# Create a tensor network representation for the independent set problem on this graph
# Let us specify the tensor network contraction order optimizer to be TreeSA, which is a local search algorithm
tn = IndependentSet(g; optimizer=TreeSA(ntrials=1, niters=5))

# Let us check its contraction complexity
contraction_complexity(tn)

# Let us find the maximum independent set using the tensor network contraction.
# It will use the CuTropicalGEMM library to perform the contraction.
# Please use Float32 type for the best performance.
@time Array(solve(tn, SizeMax(); usecuda=true, T=Float32))
# output: 1.1s

# If you want to use the automatic differentiation based approach to find the optimal solution.
@time solve(tn, SingleConfigMax(; bounded=true); usecuda=true, T=Float32)