feat: add various properties about the circuit

This commit is contained in:
Umut
2022-09-12 15:49:54 +02:00
parent ba3ea5f04d
commit 593abc6d9a
3 changed files with 109 additions and 0 deletions

View File

@@ -161,3 +161,45 @@ class Circuit:
"""
self.server.cleanup()
@property
def complexity(self) -> float:
"""
Get complexity of the circuit.
"""
return self.server.complexity
@property
def size_of_secret_keys(self) -> int:
"""
Get size of the secret keys of the circuit.
"""
return self.server.size_of_secret_keys
@property
def size_of_bootstrap_keys(self) -> int:
"""
Get size of the bootstrap keys of the circuit.
"""
return self.server.size_of_bootstrap_keys
@property
def size_of_keyswitch_keys(self) -> int:
"""
Get size of the key switch keys of the circuit.
"""
return self.server.size_of_keyswitch_keys
@property
def size_of_inputs(self) -> int:
"""
Get size of the inputs of the circuit.
"""
return self.server.size_of_inputs
@property
def size_of_outputs(self) -> int:
"""
Get size of the outputs of the circuit.
"""
return self.server.size_of_outputs

View File

@@ -9,6 +9,7 @@ from pathlib import Path
from typing import List, Optional, Union
from concrete.compiler import (
CompilationFeedback,
CompilationOptions,
EvaluationKeys,
JITCompilationResult,
@@ -36,6 +37,7 @@ class Server:
_output_dir: Optional[tempfile.TemporaryDirectory]
_support: Union[JITSupport, LibrarySupport]
_compilation_result: Union[JITCompilationResult, LibraryCompilationResult]
_compilation_feedback: CompilationFeedback
_server_lambda: Union[JITLambda, LibraryLambda]
_mlir: Optional[str]
@@ -54,6 +56,7 @@ class Server:
self._output_dir = output_dir
self._support = support
self._compilation_result = compilation_result
self._compilation_feedback = self._support.load_compilation_feedback(compilation_result)
self._server_lambda = server_lambda
self._mlir = None
@@ -252,3 +255,45 @@ class Server:
if self._output_dir is not None:
self._output_dir.cleanup()
@property
def complexity(self) -> float:
"""
Get complexity of the compiled program.
"""
return self._compilation_feedback.complexity
@property
def size_of_secret_keys(self) -> int:
"""
Get size of the secret keys of the compiled program.
"""
return self._compilation_feedback.total_secret_keys_size
@property
def size_of_bootstrap_keys(self) -> int:
"""
Get size of the bootstrap keys of the compiled program.
"""
return self._compilation_feedback.total_bootstrap_keys_size
@property
def size_of_keyswitch_keys(self) -> int:
"""
Get size of the key switch keys of the compiled program.
"""
return self._compilation_feedback.total_keyswitch_keys_size
@property
def size_of_inputs(self) -> int:
"""
Get size of the inputs of the compiled program.
"""
return self._compilation_feedback.total_inputs_size
@property
def size_of_outputs(self) -> int:
"""
Get size of the outputs of the compiled program.
"""
return self._compilation_feedback.total_output_size

View File

@@ -38,6 +38,28 @@ return %2
)
def test_circuit_feedback(helpers):
"""
Test feedback properties of `Circuit` class.
"""
configuration = helpers.configuration()
@compiler({"x": "encrypted", "y": "encrypted"})
def f(x, y):
return x + y
inputset = [(np.random.randint(0, 2**4), np.random.randint(0, 2**5)) for _ in range(100)]
circuit = f.compile(inputset, configuration)
assert isinstance(circuit.complexity, float)
assert isinstance(circuit.size_of_secret_keys, int)
assert isinstance(circuit.size_of_bootstrap_keys, int)
assert isinstance(circuit.size_of_keyswitch_keys, int)
assert isinstance(circuit.size_of_inputs, int)
assert isinstance(circuit.size_of_outputs, int)
def test_circuit_bad_run(helpers):
"""
Test `run` method of `Circuit` class with bad parameters.