docs: add an example with explicit compiler api to readme

This commit is contained in:
Umut
2022-04-08 11:18:28 +03:00
parent 19cc683ead
commit aa9753ef12

View File

@@ -42,7 +42,7 @@ To install Concrete Numpy from PyPi, run the following:
You can find more detailed installation instructions in [installing.md](docs/user/basics/installing.md)
## A simple example: numpy addition in FHE
## A simple example
```python
import concrete.numpy as cnp
@@ -62,6 +62,26 @@ for example in examples:
print(f"Evaluation of {' + '.join(map(str, example))} homomorphically = {result}")
```
if you have a function object that you cannot decorate, you can use the explicit compiler API instead
```python
import concrete.numpy as cnp
def add(x, y):
return x + y
compiler = cnp.Compiler(add, {"x": "encrypted", "y": "encrypted"})
inputset = [(2, 3), (0, 0), (1, 6), (7, 7), (7, 1), (3, 2), (6, 1), (1, 7), (4, 5), (5, 4)]
print(f"Compiling...")
circuit = compiler.compile(inputset)
examples = [(3, 4), (1, 2), (7, 7), (0, 0)]
for example in examples:
result = circuit.encrypt_run_decrypt(*example)
print(f"Evaluation of {' + '.join(map(str, example))} homomorphically = {result}")
```
# For developers
### Project setup