feat: raise error if tracers are tried to be converted to bool

This commit is contained in:
Umut
2023-02-23 13:44:50 +01:00
parent 3bbb0c2aa3
commit 8d89614d8a
2 changed files with 12 additions and 0 deletions

View File

@@ -175,6 +175,12 @@ class Tracer:
def __hash__(self) -> int:
return id(self)
def __bool__(self) -> bool:
# pylint: disable=invalid-bool-returned
message = "Branching within circuits is not possible"
raise RuntimeError(message)
@staticmethod
def sanitize(value: Any) -> Any:
"""

View File

@@ -45,6 +45,12 @@ from concrete.numpy.values import EncryptedTensor
"`astype` method must be called with a "
"numpy type for compilation (e.g., value.astype(np.int64))",
),
pytest.param(
lambda x: x + 1 if x else x + x,
{"x": EncryptedTensor(UnsignedInteger(7), shape=())},
RuntimeError,
"Branching within circuits is not possible",
),
],
)
def test_tracer_bad_trace(function, parameters, expected_error, expected_message):