# Random independent set with GenericTensorNetworks.jl

**URL:** <https://discourse.julialang.org/t/random-independent-set-with-generictensornetworks-jl/127900>\
**Category:** Graphs\
**Created:** [April 10, 2025, 1:08am UTC](https://discourse.julialang.org/t/random-independent-set-with-generictensornetworks-jl/127900 "2025-04-10T01:08:58Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![slwu89](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/slwu89/32/217323_2.png) [@slwu89](https://discourse.julialang.org/u/slwu89)\
**Post date:** [April 10, 2025, 1:08am UTC](https://discourse.julialang.org/t/random-independent-set-with-generictensornetworks-jl/127900/1 "2025-04-10T01:08:58Z")

</div>

Hi @1115, I’m looking at the GenericTensorNetworks.jl package, and I a question regarding finding a single maximum independent set [Independent set problem · GenericTensorNetworks.jl](https://queracomputing.github.io/GenericTensorNetworks.jl/dev/generated/IndependentSet/#1.-Finding-Optimal-Solutions), is the solution sampled uniformly at random from the possible solutions? Some tests seem to indicate no but I want to ask to make sure. If the answer is no, is there an efficient way to randomly sample a single maximum independent set?

---

<div class="post-metadata">

**Author:** ![1115](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/1115/32/4465_2.png) [@1115](https://discourse.julialang.org/u/1115)\
**Post date:** [April 10, 2025, 11:31am UTC](https://discourse.julialang.org/t/random-independent-set-with-generictensornetworks-jl/127900/2 "2025-04-10T11:31:01Z")

</div>

I can confirm that the configuration is not uniformly sampled. If you want to get a set of uniform sampled configurations in the low energy landscape, the following page has relevant information:

> **[Sum product tree representation · GenericTensorNetworks.jl](https://queracomputing.github.io/GenericTensorNetworks.jl/dev/sumproduct/)**
>
> Documentation for GenericTensorNetworks.jl.

---

<div class="post-metadata">

**Author:** ![slwu89](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/slwu89/32/217323_2.png) [@slwu89](https://discourse.julialang.org/u/slwu89)\
**Post date:** [April 15, 2025, 3:35pm UTC](https://discourse.julialang.org/t/random-independent-set-with-generictensornetworks-jl/127900/3 "2025-04-15T15:35:14Z")

</div>

Thanks, I tried it out but got an error with the following MWE:

```julia
using Graphs, GenericTensorNetworks

graph = SimpleGraph()
Graphs.add_vertices!(graph, 7)
for e in [(1,2),(1,3),(1,4),(2,3),(2,5),(3,4),(3,5),(4,6),(5,7),(6,7)]
    Graphs.add_edge!(graph, e...)
end

tensor_prob = GenericTensorNetwork(IndependentSet(graph); optimizer=TreeSA())
tensor_tree = solve(tensor_prob, ConfigsMax(; tree_storage=true))[]
generate_samples(tensor_tree, 1)

```

Here is the error:

```julia
ERROR: MethodError: no method matching generate_samples(::CountingTropical{Float64, SumProductTree{OnehotVec{7, 2}}}, ::Int64)
The function `generate_samples` exists, but no method is defined for this combination of argument types.

Closest candidates are:
  generate_samples(::SumProductTree{ET}, ::Int64) where ET
   @ GenericTensorNetworks ~/.julia/packages/GenericTensorNetworks/0ojFL/src/arithematics.jl:734

```

---

<div class="post-metadata">

**Author:** ![1115](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/1115/32/4465_2.png) [@1115](https://discourse.julialang.org/u/1115)\
**Post date:** [April 20, 2025, 4:36pm UTC](https://discourse.julialang.org/t/random-independent-set-with-generictensornetworks-jl/127900/4 "2025-04-20T16:36:53Z")

</div>

Repost the answer on GitHub:

```julia
julia> generate_samples(tensor_tree.c, 1)
1-element Vector{StaticBitVector{7, 1}}:
 1000110

```

The `generate_samples` must be applied on a `SumProductTree` instance.

---

<div class="post-metadata">

**Author:** ![slwu89](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/slwu89/32/217323_2.png) [@slwu89](https://discourse.julialang.org/u/slwu89)\
**Post date:** [April 20, 2025, 4:47pm UTC](https://discourse.julialang.org/t/random-independent-set-with-generictensornetworks-jl/127900/5 "2025-04-20T16:47:38Z")

</div>

Thank you, I marked it as solved.
