Skip to content

Commit 7065df8

Browse files
committed
fix and test insert_compressor_between_regions when insert_into=None
1 parent 84593af commit 7065df8

File tree

5 files changed

+62
-3
lines changed

5 files changed

+62
-3
lines changed

.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,5 @@ quimb/_version.py export-subst
1919

2020
# ensure quimb appears as a python project on github
2121
*.ipynb linguist-language=Python
22+
# SCM syntax highlighting & preventing 3-way merges
23+
pixi.lock merge=binary linguist-language=YAML linguist-generated=true

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,3 +127,6 @@ docs/autoapi
127127
# quimb specific
128128
ctg_cache
129129
quimb/_version.py
130+
# pixi environments
131+
.pixi/*
132+
!.pixi/config.toml

docs/changelog.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ Release notes for `quimb`.
1414
- refactor [`TEBDGen`](quimb.tensor.tensor_arbgeom_tebd.TEBDGen) and [`SimpleUpdateGen`](quimb.tensor.tensor_arbgeom_tebd.SimpleUpdateGen)
1515
- [`tn.draw()`](quimb.tensor.drawing.draw_tn): show abelian signature if using `symmray` arrays.
1616

17+
**Bug fixes:**
18+
19+
- fix [`insert_compressor_between_regions`](quimb.tensor.tensor_core.TensorNetwork.insert_compressor_between_regions) when `insert_into is None`.
20+
21+
1722
(whats-new-1-11-2)=
1823
## v1.11.2 (2025-07-30)
1924

quimb/tensor/tensor_core.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9802,7 +9802,7 @@ def insert_compressor_between_regions(
98029802

98039803
# get the connecting indices and corresponding sizes
98049804
bix = bonds(ltn, rtn)
9805-
bix_sizes = [tn.ind_size(ix) for ix in bix]
9805+
bix_sizes = [ltn.ind_size(ix) for ix in bix]
98069806

98079807
if mode == "nystrom":
98089808
# only use
@@ -9887,8 +9887,8 @@ def insert_compressor_between_regions(
98879887

98889888
if insert_into is not None:
98899889
tn = insert_into
9890-
ltn = tn.select(ltags, which=select_which)
9891-
rtn = tn.select(rtags, which=select_which)
9890+
ltn = tn.select(ltags, which=select_which)
9891+
rtn = tn.select(rtags, which=select_which)
98929892

98939893
# finally cut the bonds
98949894
new_lix = [rand_uuid() for _ in bix]

tests/test_tensor/test_tensor_core.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

18721921
class TestTensorNetworkSimplifications:
18731922
def test_rank_simplify(self):

0 commit comments

Comments
 (0)