Skip to content

Commit 9b614f8

Browse files
add env variable for eps of entropy
1 parent 9bd8721 commit 9b614f8

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

tensorcircuit/quantum.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"""
1010
# pylint: disable=invalid-name
1111

12+
import os
1213
from functools import reduce, partial
1314
import logging
1415
from operator import or_, mul, matmul
@@ -1503,7 +1504,7 @@ def op2tensor(
15031504

15041505

15051506
@op2tensor
1506-
def entropy(rho: Union[Tensor, QuOperator], eps: float = 1e-12) -> Tensor:
1507+
def entropy(rho: Union[Tensor, QuOperator], eps: Optional[float] = None) -> Tensor:
15071508
"""
15081509
Compute the entropy from the given density matrix ``rho``.
15091510
@@ -1541,6 +1542,11 @@ def entanglement2(param, n, nlayers):
15411542
:return: Entropy on the given density matrix.
15421543
:rtype: Tensor
15431544
"""
1545+
eps_env = os.environ.get("TC_QUANTUM_ENTROPY_EPS")
1546+
if eps is None and eps_env is None:
1547+
eps = 1e-12
1548+
elif eps is None and eps_env is not None:
1549+
eps = 10 ** (-int(eps_env))
15441550
rho += eps * backend.cast(backend.eye(rho.shape[-1]), rho.dtype) # type: ignore
15451551
lbd = backend.real(backend.eigh(rho)[0])
15461552
lbd = backend.relu(lbd)

0 commit comments

Comments
 (0)