Skip to content

Commit e48c470

Browse files
add protection for full traceout
1 parent 0004fa4 commit e48c470

File tree

3 files changed

+10
-0
lines changed

3 files changed

+10
-0
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
- Fix quafu provider
1616

17+
- Raise ValueError for `FGSSimulator` when traced out sites correspond the full system
18+
1719
## 1.0.1
1820

1921
### Fixed

tensorcircuit/fgs.py

+2
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,8 @@ def get_reduced_cmatrix(self, subsystems_to_trace_out: List[int]) -> Tensor:
181181
subsystems_to_trace_out = []
182182
keep = [i for i in range(self.L) if i not in subsystems_to_trace_out]
183183
keep += [i + self.L for i in range(self.L) if i not in subsystems_to_trace_out]
184+
if len(keep) == 0: # protect from empty keep
185+
raise ValueError("the full system is traced out, no subsystems to keep")
184186
keep = backend.convert_to_tensor(keep)
185187

186188
def slice_(a: Tensor) -> Tensor:

tests/test_fgs.py

+6
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,12 @@ def asymmetric_hopping_jw(J, gamma, i, j, L):
5959
)
6060

6161

62+
def test_full_trace():
63+
c = tc.FGSSimulator(4)
64+
with pytest.raises(ValueError):
65+
c.entropy([0, 1, 2, 3])
66+
67+
6268
@pytest.mark.parametrize("backend", [lf("npb"), lf("tfb"), lf("jaxb")])
6369
def test_otoc(backend, highp):
6470
c = tc.FGSSimulator(4, [0, 1])

0 commit comments

Comments
 (0)