Skip to content

Commit

Permalink
test(frontend-python): add tests of assigning circuit.keys
Browse files Browse the repository at this point in the history
  • Loading branch information
umut-sahin committed Nov 10, 2023
1 parent e8ef48f commit af8aa9a
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions frontends/concrete-python/tests/compilation/test_circuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -647,3 +647,37 @@ def test_statistics(function, parameters, expected_statistics, helpers):
Expected {name} to be {expected_value} but it's {getattr(circuit, name)}
""".strip()


def test_setting_keys(helpers):
"""
Tests setting circuit.keys explicitly.
"""

configuration = helpers.configuration()

@fhe.compiler({"x": "encrypted", "y": "encrypted"})
def f(x, y):
return x + y

inputset = [(np.random.randint(0, 2**3), np.random.randint(0, 2**5)) for _ in range(100)]
circuit = f.compile(inputset, configuration.fork(use_insecure_key_cache=False))

circuit.keygen(force=True, seed=100)
keys1 = circuit.keys.serialize()

circuit.keygen(force=True, seed=200)
keys2 = circuit.keys.serialize()

assert keys1 != keys2

sample = circuit.encrypt(3, 5)
output = circuit.run(*sample)

circuit.keys = fhe.Keys.deserialize(keys1)
result = circuit.decrypt(output)
assert result != 8

circuit.keys = fhe.Keys.deserialize(keys2)
result = circuit.decrypt(output)
assert result == 8

0 comments on commit af8aa9a

Please sign in to comment.