@@ -1868,6 +1868,55 @@ def test_tn_isel_rand(self):
18681868 xs = mps .to_dense ().ravel ()
18691869 assert not any (np .allclose (rx , x ) for x in xs )
18701870
1871+ def test_insert_compressor_between_regions (self ):
1872+ inputs = ["abgl" , "gfhim" , "bcdfe" , "iekj" ]
1873+ tags = ["A" , "C" , "B" , "D" ]
1874+ size_dict = {ix : 2 for ix in set ("" .join (inputs ))}
1875+ ts = [
1876+ qtn .rand_tensor (
1877+ [size_dict [k ] for k in term ], inds = term , tags = [tag ]
1878+ )
1879+ for term , tag in zip (inputs , tags )
1880+ ]
1881+ tn = qtn .TensorNetwork (ts )
1882+ gh = tn .geometry_hash ()
1883+
1884+ # compute the svd via explicit contraction of the whole tensor
1885+ td = tn .contract ()
1886+ tn_ex = td .split (["a" , "l" , "c" , "d" ], max_bond = 4 )
1887+ d1 = tn_ex .distance (tn )
1888+
1889+ # test inserting into parallel network
1890+ tn_other = tn .copy ()
1891+ tn .insert_compressor_between_regions_ (
1892+ ["A" , "B" ], ["C" , "D" ], max_bond = 4 , insert_into = tn_other
1893+ )
1894+ assert tn .geometry_hash () == gh
1895+ assert tn_other .num_tensors == 6
1896+ d = tn_other .distance (tn )
1897+ assert d == pytest .approx (d1 )
1898+
1899+ # test not-inplace
1900+ tn_other = tn .insert_compressor_between_regions (
1901+ ["A" , "B" ],
1902+ ["C" , "D" ],
1903+ max_bond = 4 ,
1904+ )
1905+ assert tn .geometry_hash () == gh
1906+ assert tn_other .num_tensors == 6
1907+ d = tn_other .distance (tn )
1908+ assert d == pytest .approx (d1 )
1909+
1910+ # test inplace
1911+ tn_other = tn .copy ()
1912+ tn_other .insert_compressor_between_regions_ (
1913+ ["A" , "B" ], ["C" , "D" ], max_bond = 4
1914+ )
1915+ assert tn_other .geometry_hash () != gh
1916+ assert tn_other .num_tensors == 6
1917+ d = tn_other .distance (tn )
1918+ assert d == pytest .approx (d1 )
1919+
18711920
18721921class TestTensorNetworkSimplifications :
18731922 def test_rank_simplify (self ):
0 commit comments