diff --git a/.gitignore b/.gitignore index bf3e102..a47f070 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,7 @@ *.jl.*.cov *.jl.cov *.jl.mem -/Manifest.toml +Manifest.toml lib .vscode Artifact diff --git a/examples/combinatorial-optimization/Project.toml b/examples/combinatorial-optimization/Project.toml new file mode 100644 index 0000000..01586a8 --- /dev/null +++ b/examples/combinatorial-optimization/Project.toml @@ -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" diff --git a/examples/combinatorial-optimization/README.md b/examples/combinatorial-optimization/README.md new file mode 100644 index 0000000..f476289 --- /dev/null +++ b/examples/combinatorial-optimization/README.md @@ -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). diff --git a/examples/combinatorial-optimization/main.jl b/examples/combinatorial-optimization/main.jl new file mode 100644 index 0000000..cc0457a --- /dev/null +++ b/examples/combinatorial-optimization/main.jl @@ -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) \ No newline at end of file