mirror of
https://github.com/zama-ai/concrete.git
synced 2026-02-08 19:44:57 -05:00
feat: add error probability properties to circuits
This commit is contained in:
@@ -203,3 +203,17 @@ class Circuit:
|
||||
Get size of the outputs of the circuit.
|
||||
"""
|
||||
return self.server.size_of_outputs
|
||||
|
||||
@property
|
||||
def p_error(self) -> int:
|
||||
"""
|
||||
Get probability of error for each simple TLU (on a scalar).
|
||||
"""
|
||||
return self.server.p_error
|
||||
|
||||
@property
|
||||
def global_p_error(self) -> int:
|
||||
"""
|
||||
Get the probability of having at least one simple TLU error during the entire execution.
|
||||
"""
|
||||
return self.server.global_p_error
|
||||
|
||||
@@ -317,3 +317,17 @@ class Server:
|
||||
Get size of the outputs of the compiled program.
|
||||
"""
|
||||
return self._compilation_feedback.total_output_size
|
||||
|
||||
@property
|
||||
def p_error(self) -> int:
|
||||
"""
|
||||
Get the probability of error for each simple TLU (on a scalar).
|
||||
"""
|
||||
return self._compilation_feedback.p_error
|
||||
|
||||
@property
|
||||
def global_p_error(self) -> int:
|
||||
"""
|
||||
Get the probability of having at least one simple TLU error during the entire execution.
|
||||
"""
|
||||
return self._compilation_feedback.global_p_error
|
||||
|
||||
@@ -35,12 +35,15 @@ def test_circuit_feedback(helpers):
|
||||
|
||||
configuration = helpers.configuration()
|
||||
|
||||
p_error = 0.1
|
||||
global_p_error = 0.05
|
||||
|
||||
@compiler({"x": "encrypted", "y": "encrypted"})
|
||||
def f(x, y):
|
||||
return x + y
|
||||
return np.sqrt(((x + y) ** 2) + 10).astype(np.int64)
|
||||
|
||||
inputset = [(np.random.randint(0, 2**4), np.random.randint(0, 2**5)) for _ in range(100)]
|
||||
circuit = f.compile(inputset, configuration)
|
||||
inputset = [(np.random.randint(0, 2**2), np.random.randint(0, 2**2)) for _ in range(100)]
|
||||
circuit = f.compile(inputset, configuration, p_error=p_error, global_p_error=global_p_error)
|
||||
|
||||
assert isinstance(circuit.complexity, float)
|
||||
assert isinstance(circuit.size_of_secret_keys, int)
|
||||
@@ -48,6 +51,11 @@ def test_circuit_feedback(helpers):
|
||||
assert isinstance(circuit.size_of_keyswitch_keys, int)
|
||||
assert isinstance(circuit.size_of_inputs, int)
|
||||
assert isinstance(circuit.size_of_outputs, int)
|
||||
assert isinstance(circuit.p_error, float)
|
||||
assert isinstance(circuit.global_p_error, float)
|
||||
|
||||
assert circuit.p_error <= p_error
|
||||
assert circuit.global_p_error <= global_p_error
|
||||
|
||||
|
||||
def test_circuit_bad_run(helpers):
|
||||
|
||||
Reference in New Issue
Block a user