11# ########### Sampling ############
2+ """
3+ $TYPEDEF
4+
5+ ### Fields
6+ $TYPEDFIELDS
7+
8+ The sampled configurations are stored in `samples`, which is a vector of vector.
9+ `labels` is a vector of variable names for labeling configurations.
10+ The `setmask` is an boolean indicator to denote whether the sampling process of a variable is complete.
11+ """
212struct Samples{L}
313 samples:: Vector{Vector{Int}}
414 labels:: Vector{L}
@@ -18,7 +28,7 @@ idx4labels(totalset, labels) = map(v->findfirst(==(v), totalset), labels)
1828"""
1929$(TYPEDSIGNATURES)
2030
21- The backward rule for tropical einsum .
31+ The backward process for sampling configurations .
2232
2333* `ixs` and `xs` are labels and tensor data for input tensors,
2434* `iy` and `y` are labels and tensor data for the output tensor,
@@ -72,7 +82,7 @@ function sample(tn::TensorNetworkModel, n::Int; usecuda = false)::Samples
7282 # forward compute and cache intermediate results.
7383 cache = cached_einsum (tn. code, xs, size_dict)
7484 # initialize `y̅` as the initial batch of samples.
75- labels = OMEinsum . uniquelabels (tn. code )
85+ labels = get_vars (tn)
7686 iy = getiyv (tn. code)
7787 setmask = falses (length (labels))
7888 idx = map (l-> findfirst (== (l), labels), iy)
@@ -86,7 +96,7 @@ function sample(tn::TensorNetworkModel, n::Int; usecuda = false)::Samples
8696 samples = Samples (configs, labels, setmask)
8797 # back-propagate
8898 generate_samples (tn. code, cache, samples, size_dict)
89- return samples
99+ return samples. samples
90100end
91101
92102function generate_samples (code:: NestedEinsum , cache:: CacheTree{T} , samples, size_dict:: Dict ) where {T}
0 commit comments