This document provides guidance on debugging the compilation process.
Compiler debug and verbose modes
Two configuration options are available to help you understand the compilation process:
compiler_verbose_mode: Prints the compiler passes and shows the transformations applied. It can help identify the crash location if a crash occurs.
compiler_debug_mode: A more detailed version of the verbose mode, providing additional information, particularly useful for diagnosing crashes.
These flags might not work as expected in Jupyter notebooks as they output to stderr directly from C++.
Debug artifacts
Concrete includes an artifact system that simplifies the debugging process by automatically or manually exporting detailed information during compilation failures.
Automatic export
When a compilation fails, artifacts are automatically exported to the .artifacts directory in the working directory. Here's an example of what gets exported when a function fails to compile:
deff(x):return np.sin(x)
This function fails to compile because Concrete does not support floating-point outputs. When you try to compile it, an exception will be raised and the artifacts will be exported automatically. The following files will be generated in the .artifacts directory:
environment.txt: Information about your system setup, including the operating system and Python version.
Traceback (most recent call last):
File "/path/to/your/script.py", line 9, in <module>
circuit = f.compile(inputset)
File "/usr/local/lib/python3.10/site-packages/concrete/fhe/compilation/decorators.py", line 159, in compile
return self.compiler.compile(inputset, configuration, artifacts, **kwargs)
File "/usr/local/lib/python3.10/site-packages/concrete/fhe/compilation/compiler.py", line 437, in compile
mlir = GraphConverter.convert(self.graph)
File "/usr/local/lib/python3.10/site-packages/concrete/fhe/mlir/graph_converter.py", line 677, in convert
GraphConverter._check_graph_convertibility(graph)
File "/usr/local/lib/python3.10/site-packages/concrete/fhe/mlir/graph_converter.py", line 240, in _check_graph_convertibility
raise RuntimeError(message)
RuntimeError: Function you are trying to compile cannot be converted to MLIR
%0 = x # EncryptedScalar<uint3> ∈ [3, 5]
%1 = sin(%0) # EncryptedScalar<float64> ∈ [-0.958924, 0.14112]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ only integer operations are supported
/path/to/your/script.py:6
return %1
Manual exports
Manual exports are mostly used for visualization and demonstrations. Here is how to perform one:
from concrete import fheimport numpy as npartifacts = fhe.DebugArtifacts("/tmp/custom/export/path")@fhe.compiler({"x": "encrypted"})deff(x):return127- (50* (np.sin(x)+1)).astype(np.int64)inputset =range(2**3)circuit = f.compile(inputset, artifacts=artifacts)artifacts.export()
After running the code, you will find the following files under /tmp/custom/export/path directory:
1.initial.graph.txt: The textual representation of the initial computation graph right after tracing.