From b93e916b1c7857029c868fc9dfe0efd0e06ca96b Mon Sep 17 00:00:00 2001 From: Umut Date: Mon, 4 Oct 2021 12:05:25 +0300 Subject: [PATCH] docs(user): create printing and drawing howto --- docs/index.rst | 1 + docs/user/howto/PRINTING_AND_DRAWING.md | 49 +++++++++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 docs/user/howto/PRINTING_AND_DRAWING.md diff --git a/docs/index.rst b/docs/index.rst index 7ddeea81a..e0e38bb9b 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -24,6 +24,7 @@ Concrete Framework's documentation :caption: How to user/howto/COMPILING_AND_EXECUTING.md + user/howto/PRINTING_AND_DRAWING.md user/howto/REDUCE_NEEDED_PRECISION.md user/howto/DEBUG_SUPPORT_SUBMIT_ISSUES.md user/howto/FAQ.md diff --git a/docs/user/howto/PRINTING_AND_DRAWING.md b/docs/user/howto/PRINTING_AND_DRAWING.md new file mode 100644 index 000000000..c660d9c47 --- /dev/null +++ b/docs/user/howto/PRINTING_AND_DRAWING.md @@ -0,0 +1,49 @@ +# Printing and Drawing + +Sometimes, it can be useful to print or draw fhe circuits, we provide methods to just do that. Please read [Compiling and Executing](../howto/COMPILING_AND_EXECUTING.md) before reading further to see how you can compile your function into an fhe circuit. + +## Printing + +To print your circuit, you can do the following: + + +```python +print(circuit) +``` + +## Drawing + +To draw your circuit, you can do the following: + + +```python +drawing = circuit.draw() +``` + +This method will draw the circuit on a temporary PNG file and return the path to this file. + +To show the drawing, you can use the following code in a jupyter notebook. + + +```python +from PIL import Image +drawing = Image.open(circuit.draw()) +drawing.show() +drawing.close() +``` + +Additionally, 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. + + +```python +circuit.draw(show=True) +``` + +Lastly, you can save the drawing to a specific path like this: + + +```python +destination = "/tmp/path/of/your/choice.png" +drawing = circuit.draw(save_to=destination) +assert drawing == destination +```