Concrete analyzes all compiled circuits and calculates some statistics. These statistics can be used to find bottlenecks and compare circuits. Statistics are calculated in terms of basic operations. There are 6 basic operations in Concrete:
clear addition: x + y where x is encrypted and y is clear
encrypted addition: x + y where both x and y are encrypted
clear multiplication: x * y where x is encrypted and y is clear
encrypted negation: -x where x is encrypted
key switch: building block for table lookups
packing key switch: building block for table lookups
programmable bootstrapping: building block for table lookups
You can print all statistics using the show_statistics
configuration option:
This code will print:
Each of these properties can be directly accessed on the circuit (e.g., circuit.programmable_bootstrap_count
).
Circuit analysis also considers tags!
Imagine you have a neural network with 10 layers, each of them tagged. You can easily see the number of additions and multiplications required for matrix multiplications per layer:
Big circuits can take a long time to execute, and waiting for execution to finish without having any indication of its progress can be frustrating. For this reason, progressbar feature is introduced:
When you run this code, you will see a progressbar like:
And as the circuit progresses, this progressbar would fill:
It is not a uniform progressbar. For example, when the progressbar shows 50%, this does not mean that half of the execution is performed in terms of seconds. Instead, it means that half of the nodes in the graph have been calculated. Since different node types can take a different amount of time, this should not be used to get an ETA.
Once the progressbar fills and execution completes, you will see the following figure:
You can convert your compiled circuit into its textual representation by converting it to string:
If you just want to see the output on your terminal, you can directly print it as well:
Formatting is just for debugging purposes. It's not possible to create the circuit back from its textual representation. See How to Deploy if that's your goal.
Drawing functionality requires the installation of the package with the full feature set. See the Installation section to learn how to do that.
You can use the draw
method of your compiled circuit to draw it:
This method will draw the circuit on a temporary PNG file and return the path to this file.
You can show the drawing in a Jupyter notebook, like this:
Or, you can use the show
option of the draw
method to show the drawing with matplotlib
.
Beware that this will clear the matplotlib plots you have.
Lastly, you can save the drawing to a specific path: