diff --git a/concrete/numpy/compilation/circuit.py b/concrete/numpy/compilation/circuit.py index f3c0d4097..91fa46afe 100644 --- a/concrete/numpy/compilation/circuit.py +++ b/concrete/numpy/compilation/circuit.py @@ -59,10 +59,6 @@ class Circuit: self.virtual = virtual if self.virtual: - print( - "Warning: You are using virtual compilation, " - "which means the evaluation will not be homomorphic." - ) return options = CompilationOptions.new("main") diff --git a/concrete/numpy/compilation/compiler.py b/concrete/numpy/compilation/compiler.py index 85df89d5b..6871f5176 100644 --- a/concrete/numpy/compilation/compiler.py +++ b/concrete/numpy/compilation/compiler.py @@ -278,6 +278,11 @@ class Compiler: """ try: + if virtual and not self.configuration.enable_unsafe_features: + raise RuntimeError( + "Virtual compilation is not allowed without enabling unsafe features" + ) + self._evaluate("Compiling", inputset) assert self.graph is not None diff --git a/tests/compilation/test_compiler.py b/tests/compilation/test_compiler.py index 7c6d88ca9..07d57b446 100644 --- a/tests/compilation/test_compiler.py +++ b/tests/compilation/test_compiler.py @@ -121,8 +121,18 @@ def test_compiler_bad_compile(helpers): assert str(excinfo.value) == "Compiling function 'f' without an inputset is not supported" + configuration.enable_unsafe_features = False -def test_compiler_virtual_compile(helpers, capsys): + with pytest.raises(RuntimeError) as excinfo: + compiler = Compiler(lambda x: x, {"x": "encrypted"}, configuration=configuration) + compiler.compile(virtual=True) + + assert str(excinfo.value) == ( + "Virtual compilation is not allowed without enabling unsafe features" + ) + + +def test_compiler_virtual_compile(helpers): """ Test `compile` method of `Compiler` class with virtual=True. """ @@ -135,10 +145,4 @@ def test_compiler_virtual_compile(helpers, capsys): compiler = Compiler(f, {"x": "encrypted"}, configuration=configuration) circuit = compiler.compile(inputset=range(400), virtual=True) - captured = capsys.readouterr() - assert captured.out.strip() == ( - "Warning: You are using virtual compilation, " - "which means the evaluation will not be homomorphic." - ) - assert circuit.encrypt_run_decrypt(200) == 600