refactor: rename run method of the circuit to encrypt_run_decrypt

This commit is contained in:
Umut
2022-04-06 15:45:27 +02:00
parent fdd3efa2ce
commit 72c13c54be
5 changed files with 16 additions and 16 deletions

View File

@@ -58,7 +58,7 @@ circuit = add.compile(inputset)
examples = [(3, 4), (1, 2), (7, 7), (0, 0)]
for example in examples:
result = circuit.run(*example)
result = circuit.encrypt_run_decrypt(*example)
print(f"Evaluation of {' + '.join(map(str, example))} homomorphically = {result}")
```

View File

@@ -60,15 +60,15 @@ class Circuit:
return self.graph.draw(show, horizontal, save_to)
def run(
def encrypt_run_decrypt(
self,
*args: Union[int, np.ndarray],
) -> Union[int, np.ndarray, Tuple[Union[int, np.ndarray], ...]]:
"""
Encrypt inputs, evaluate the circuit, and decrypt the outputs in one go.
Encrypt inputs, run the circuit, and decrypt the outputs in one go.
Args:
*args (List[Union[int, numpy.ndarray]]):
*args (Union[int, numpy.ndarray]):
inputs to the engine
Returns:

View File

@@ -64,17 +64,17 @@ Here is the graph from the previous code block drawn with `draw`:
## Performing homomorphic evaluation
You can use `.run(...)` method of `Circuit` to perform fully homomorphic evaluation. Here are some examples:
You can use `.encrypt_run_decrypt(...)` method of `Circuit` to perform fully homomorphic evaluation. Here are some examples:
<!--pytest-codeblocks:cont-->
```python
circuit.run(3, 4)
circuit.encrypt_run_decrypt(3, 4)
# 7
circuit.run(1, 2)
circuit.encrypt_run_decrypt(1, 2)
# 3
circuit.run(7, 7)
circuit.encrypt_run_decrypt(7, 7)
# 14
circuit.run(0, 0)
circuit.encrypt_run_decrypt(0, 0)
# 0
```

View File

@@ -78,7 +78,7 @@ def test_circuit_bad_run(helpers):
# ---------------
with pytest.raises(ValueError) as excinfo:
circuit.run(1)
circuit.encrypt_run_decrypt(1)
assert str(excinfo.value) == "Expected 2 inputs but got 1"
@@ -86,7 +86,7 @@ def test_circuit_bad_run(helpers):
# ----------------
with pytest.raises(ValueError) as excinfo:
circuit.run(1, 2, 3)
circuit.encrypt_run_decrypt(1, 2, 3)
assert str(excinfo.value) == "Expected 2 inputs but got 3"
@@ -94,7 +94,7 @@ def test_circuit_bad_run(helpers):
# ------------------------
with pytest.raises(ValueError) as excinfo:
circuit.run(-1, 11)
circuit.encrypt_run_decrypt(-1, 11)
assert str(excinfo.value) == (
"Expected argument 0 to be EncryptedScalar<uint4> but it's EncryptedScalar<int1>"
@@ -104,7 +104,7 @@ def test_circuit_bad_run(helpers):
# ------------------------
with pytest.raises(ValueError) as excinfo:
circuit.run(1, -11)
circuit.encrypt_run_decrypt(1, -11)
assert str(excinfo.value) == (
"Expected argument 1 to be EncryptedScalar<uint5> but it's EncryptedScalar<int5>"
@@ -114,7 +114,7 @@ def test_circuit_bad_run(helpers):
# ---------------------
with pytest.raises(ValueError) as excinfo:
circuit.run(100, 10)
circuit.encrypt_run_decrypt(100, 10)
assert str(excinfo.value) == (
"Expected argument 0 to be EncryptedScalar<uint4> but it's EncryptedScalar<uint7>"
@@ -124,7 +124,7 @@ def test_circuit_bad_run(helpers):
# ---------------------
with pytest.raises(ValueError) as excinfo:
circuit.run(1, 100)
circuit.encrypt_run_decrypt(1, 100)
assert str(excinfo.value) == (
"Expected argument 1 to be EncryptedScalar<uint5> but it's EncryptedScalar<uint7>"

View File

@@ -236,7 +236,7 @@ class Helpers:
for i in range(retries):
expected = function(*sample)
actual = circuit.run(*sample)
actual = circuit.encrypt_run_decrypt(*sample)
if not isinstance(expected, tuple):
expected = (expected,)