1+ module TestSetup
2+
3+ export unitarity_test, rand_object, random_fusion, eval_show
4+
15using MultiTensorKit
26using TensorKitSectors
37using Random
@@ -6,8 +10,7 @@ const MTK = MultiTensorKit
610
711Random. seed! (1234 )
812
9- function unitarity_test (as:: Vector{I} , bs:: Vector{I} ,
10- cs:: Vector{I} ) where {I<: BimoduleSector }
13+ function unitarity_test (as:: Vector{I} , bs:: Vector{I} ,cs:: Vector{I} ) where {I <: BimoduleSector } # abstractvector?
1114 @assert all (a. j == b. i for a in as, b in bs)
1215 @assert all (b. j == c. i for b in bs, c in cs)
1316
@@ -19,14 +22,12 @@ function unitarity_test(as::Vector{I}, bs::Vector{I},
1922 for e in es
2023 for f in fs
2124 Fs = Fsymbol (a, b, c, d, e, f)
22- push! (Fblocks,
23- reshape (Fs,
24- (size (Fs, 1 ) * size (Fs, 2 ),
25- size (Fs, 3 ) * size (Fs, 4 ))))
25+ push! (Fblocks, reshape (Fs, (size (Fs, 1 ) * size (Fs, 2 ),
26+ size (Fs, 3 ) * size (Fs, 4 ))))
2627 end
2728 end
2829 F = hvcat (length (fs), Fblocks... )
29- isapprox (F' * F, one (F); atol= 1e -12 , rtol= 1e -12 ) || return false
30+ isapprox (F' * F, one (F); atol = 1.0e -12 , rtol = 1.0e -12 ) || return false
3031 end
3132 end
3233 return true
@@ -37,47 +38,41 @@ all_objects(::Type{<:BimoduleSector}, i::Int, j::Int) = [I(i, j, k) for k in 1:M
3738function rand_object (I:: Type{<:BimoduleSector} , i:: Int , j:: Int )
3839 obs = all_objects (I, i, j)
3940 ob = rand (obs)
40- if i == j
41- while ob == one (ob) # unit of any fusion cat avoided
42- ob = rand (obs)
43- end
41+ while isunit (ob) # unit of any fusion cat avoided
42+ ob = rand (obs)
4443 end
44+
4545 return ob
4646end
4747
48- function random_fusion (I:: Type{<:BimoduleSector} , i:: Int , j:: Int , N:: Int ) # for fusion tree tests
48+ function random_fusion (I:: Type{<:BimoduleSector} , i:: Int , j:: Int , :: Val{N} ) where {N} # for fusion tree tests
49+ N == 1 && return (rand_object (I, i, j),)
50+ tail = random_fusion (I, i, j, Val (N - 1 ))
51+ counter = 0
52+
4953 Cs = all_objects (I, i, i)
5054 Ds = all_objects (I, j, j)
5155 Ms = all_objects (I, i, j)
5256 Mops = all_objects (I, j, i)
5357 allobs = vcat (Cs, Ds, Ms, Mops)
58+ s = rand (allobs)
5459
55- in = nothing
56- out = nothing
57- while in === nothing
58- out = ntuple (n -> rand (allobs), N)
59- try
60- in = rand (collect (⊗ (out... )))
61- catch e
62- if isa (e, AssertionError)
63- in = nothing
64- else
65- rethrow (e)
66- end
67- end
60+ while isempty (⊗ (s, first (tail))) && counter < 40
61+ counter += 1
62+ s = (counter < 40 ) ? rand (allobs) : leftunit (first (tail))
6863 end
69- return out
64+ return (s, tail ... )
7065end
7166
72- # for fusion tree merge test
73- function safe_tensor_product (x :: I , y :: I ) where {I <: BimoduleSector }
74- try
75- return x ⊗ y
76- catch e
77- if e isa AssertionError
78- return nothing
79- else
80- rethrow (e )
81- end
82- end
83- end
67+ """
68+ eval_show(x)
69+
70+ Use `show` to generate a string representation of `x`, then parse and evaluate the resulting expression.
71+ """
72+ function eval_show (x)
73+ str = sprint (show, x; context = ( :module => @__MODULE__ ))
74+ ex = Meta . parse (str)
75+ return eval (ex )
76+ end
77+
78+ end # end of module TestSetup
0 commit comments