mirror of
https://github.com/zama-ai/concrete.git
synced 2026-04-17 03:00:54 -04:00
refactor: concrete-numpy to concrete-python
This commit is contained in:
@@ -1,3 +1,3 @@
|
||||
"""
|
||||
Tests of `concrete.numpy` namespace.
|
||||
Tests of `concrete.fhe` namespace.
|
||||
"""
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
"""
|
||||
Tests of `concrete.numpy.compilation` namespace.
|
||||
Tests of `concrete.fhe.compilation` namespace.
|
||||
"""
|
||||
|
||||
@@ -7,7 +7,7 @@ from pathlib import Path
|
||||
|
||||
import numpy as np
|
||||
|
||||
from concrete.numpy import DebugArtifacts, compiler
|
||||
from concrete.fhe import DebugArtifacts, compiler
|
||||
|
||||
|
||||
def test_artifacts_export(helpers):
|
||||
|
||||
@@ -8,7 +8,7 @@ from pathlib import Path
|
||||
import numpy as np
|
||||
import pytest
|
||||
|
||||
from concrete.numpy import Client, ClientSpecs, EvaluationKeys, LookupTable, Server, compiler
|
||||
from concrete.fhe import Client, ClientSpecs, EvaluationKeys, LookupTable, Server, compiler
|
||||
|
||||
|
||||
def test_circuit_str(helpers):
|
||||
@@ -160,7 +160,7 @@ def test_client_server_api(helpers):
|
||||
server = Server.load(server_path)
|
||||
|
||||
serialized_client_specs = server.client_specs.serialize()
|
||||
client_specs = ClientSpecs.unserialize(serialized_client_specs)
|
||||
client_specs = ClientSpecs.deserialize(serialized_client_specs)
|
||||
|
||||
clients = [
|
||||
Client(client_specs, configuration.insecure_key_cache_location),
|
||||
@@ -173,14 +173,14 @@ def test_client_server_api(helpers):
|
||||
serialized_args = client.specs.serialize_public_args(args)
|
||||
serialized_evaluation_keys = client.evaluation_keys.serialize()
|
||||
|
||||
unserialized_args = server.client_specs.unserialize_public_args(serialized_args)
|
||||
unserialized_evaluation_keys = EvaluationKeys.unserialize(serialized_evaluation_keys)
|
||||
deserialized_args = server.client_specs.deserialize_public_args(serialized_args)
|
||||
deserialized_evaluation_keys = EvaluationKeys.deserialize(serialized_evaluation_keys)
|
||||
|
||||
result = server.run(unserialized_args, unserialized_evaluation_keys)
|
||||
result = server.run(deserialized_args, deserialized_evaluation_keys)
|
||||
serialized_result = server.client_specs.serialize_public_result(result)
|
||||
|
||||
unserialized_result = client.specs.unserialize_public_result(serialized_result)
|
||||
output = client.decrypt(unserialized_result)
|
||||
deserialized_result = client.specs.deserialize_public_result(serialized_result)
|
||||
output = client.decrypt(deserialized_result)
|
||||
|
||||
assert np.array_equal(output, [45, 50, 43])
|
||||
|
||||
@@ -220,7 +220,7 @@ def test_client_server_api_via_mlir(helpers):
|
||||
server = Server.load(server_path)
|
||||
|
||||
serialized_client_specs = server.client_specs.serialize()
|
||||
client_specs = ClientSpecs.unserialize(serialized_client_specs)
|
||||
client_specs = ClientSpecs.deserialize(serialized_client_specs)
|
||||
|
||||
clients = [
|
||||
Client(client_specs, configuration.insecure_key_cache_location),
|
||||
@@ -233,14 +233,14 @@ def test_client_server_api_via_mlir(helpers):
|
||||
serialized_args = client.specs.serialize_public_args(args)
|
||||
serialized_evaluation_keys = client.evaluation_keys.serialize()
|
||||
|
||||
unserialized_args = server.client_specs.unserialize_public_args(serialized_args)
|
||||
unserialized_evaluation_keys = EvaluationKeys.unserialize(serialized_evaluation_keys)
|
||||
deserialized_args = server.client_specs.deserialize_public_args(serialized_args)
|
||||
deserialized_evaluation_keys = EvaluationKeys.deserialize(serialized_evaluation_keys)
|
||||
|
||||
result = server.run(unserialized_args, unserialized_evaluation_keys)
|
||||
result = server.run(deserialized_args, deserialized_evaluation_keys)
|
||||
serialized_result = server.client_specs.serialize_public_result(result)
|
||||
|
||||
unserialized_result = client.specs.unserialize_public_result(serialized_result)
|
||||
output = client.decrypt(unserialized_result)
|
||||
deserialized_result = client.specs.deserialize_public_result(serialized_result)
|
||||
output = client.decrypt(deserialized_result)
|
||||
|
||||
assert np.array_equal(output, [45, 50, 43])
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ Tests of `Compiler` class.
|
||||
import numpy as np
|
||||
import pytest
|
||||
|
||||
from concrete.numpy.compilation import Compiler
|
||||
from concrete.fhe.compilation import Compiler
|
||||
|
||||
|
||||
def test_compiler_bad_init():
|
||||
|
||||
@@ -4,7 +4,7 @@ Tests of `Configuration` class.
|
||||
|
||||
import pytest
|
||||
|
||||
from concrete.numpy.compilation import Configuration
|
||||
from concrete.fhe.compilation import Configuration
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
|
||||
@@ -5,7 +5,7 @@ Tests of `compiler` and `circuit` decorators.
|
||||
import numpy as np
|
||||
import pytest
|
||||
|
||||
import concrete.numpy as cnp
|
||||
from concrete import fhe
|
||||
|
||||
|
||||
def test_compiler_call_and_compile(helpers):
|
||||
@@ -15,7 +15,7 @@ def test_compiler_call_and_compile(helpers):
|
||||
|
||||
configuration = helpers.configuration()
|
||||
|
||||
@cnp.compiler({"x": "encrypted"})
|
||||
@fhe.compiler({"x": "encrypted"})
|
||||
def function(x):
|
||||
return x + 42
|
||||
|
||||
@@ -34,9 +34,9 @@ def test_compiler_verbose_trace(helpers, capsys):
|
||||
"""
|
||||
|
||||
configuration = helpers.configuration()
|
||||
artifacts = cnp.DebugArtifacts()
|
||||
artifacts = fhe.DebugArtifacts()
|
||||
|
||||
@cnp.compiler({"x": "encrypted"})
|
||||
@fhe.compiler({"x": "encrypted"})
|
||||
def function(x):
|
||||
return x + 42
|
||||
|
||||
@@ -62,9 +62,9 @@ def test_compiler_verbose_compile(helpers, capsys):
|
||||
"""
|
||||
|
||||
configuration = helpers.configuration()
|
||||
artifacts = cnp.DebugArtifacts()
|
||||
artifacts = fhe.DebugArtifacts()
|
||||
|
||||
@cnp.compiler({"x": "encrypted"})
|
||||
@fhe.compiler({"x": "encrypted"})
|
||||
def function(x):
|
||||
return x + 42
|
||||
|
||||
@@ -97,8 +97,8 @@ def test_circuit(helpers):
|
||||
Test circuit decorator.
|
||||
"""
|
||||
|
||||
@cnp.circuit({"x": "encrypted"}, helpers.configuration())
|
||||
def circuit1(x: cnp.uint2):
|
||||
@fhe.circuit({"x": "encrypted"}, helpers.configuration())
|
||||
def circuit1(x: fhe.uint2):
|
||||
return x + 42
|
||||
|
||||
helpers.check_str(
|
||||
@@ -115,8 +115,8 @@ return %2
|
||||
|
||||
# ======================================================================
|
||||
|
||||
@cnp.circuit({"x": "encrypted"}, helpers.configuration())
|
||||
def circuit2(x: cnp.tensor[cnp.uint2, 3, 2]):
|
||||
@fhe.circuit({"x": "encrypted"}, helpers.configuration())
|
||||
def circuit2(x: fhe.tensor[fhe.uint2, 3, 2]):
|
||||
return x + 42
|
||||
|
||||
helpers.check_str(
|
||||
@@ -133,12 +133,12 @@ return %2
|
||||
|
||||
# ======================================================================
|
||||
|
||||
@cnp.circuit({"x": "encrypted"}, helpers.configuration())
|
||||
def circuit3(x: cnp.uint3):
|
||||
@fhe.circuit({"x": "encrypted"}, helpers.configuration())
|
||||
def circuit3(x: fhe.uint3):
|
||||
def square(x):
|
||||
return x**2
|
||||
|
||||
return cnp.univariate(square, outputs=cnp.uint7)(x)
|
||||
return fhe.univariate(square, outputs=fhe.uint7)(x)
|
||||
|
||||
helpers.check_str(
|
||||
"""
|
||||
@@ -153,9 +153,9 @@ return %1
|
||||
|
||||
# ======================================================================
|
||||
|
||||
@cnp.circuit({"x": "encrypted"}, helpers.configuration())
|
||||
def circuit4(x: cnp.uint3):
|
||||
return ((np.sin(x) ** 2) + (np.cos(x) ** 2)).astype(cnp.uint3)
|
||||
@fhe.circuit({"x": "encrypted"}, helpers.configuration())
|
||||
def circuit4(x: fhe.uint3):
|
||||
return ((np.sin(x) ** 2) + (np.cos(x) ** 2)).astype(fhe.uint3)
|
||||
|
||||
helpers.check_str(
|
||||
"""
|
||||
@@ -185,8 +185,8 @@ Subgraphs:
|
||||
|
||||
# ======================================================================
|
||||
|
||||
@cnp.circuit({"x": "encrypted"}, helpers.configuration())
|
||||
def circuit5(x: cnp.int2):
|
||||
@fhe.circuit({"x": "encrypted"}, helpers.configuration())
|
||||
def circuit5(x: fhe.int2):
|
||||
return x + 42
|
||||
|
||||
helpers.check_str(
|
||||
@@ -212,13 +212,13 @@ def test_bad_circuit(helpers):
|
||||
|
||||
with pytest.raises(ValueError) as excinfo:
|
||||
|
||||
@cnp.circuit({"x": "encrypted"}, helpers.configuration())
|
||||
@fhe.circuit({"x": "encrypted"}, helpers.configuration())
|
||||
def circuit1(x: int):
|
||||
return x + 42
|
||||
|
||||
assert str(excinfo.value) == (
|
||||
f"Annotation {str(int)} for argument 'x' is not valid "
|
||||
f"(please use a cnp type such as `cnp.uint4` or 'cnp.tensor[cnp.uint4, 3, 2]')"
|
||||
f"(please use an fhe type such as `fhe.uint4` or 'fhe.tensor[fhe.uint4, 3, 2]')"
|
||||
)
|
||||
|
||||
# missing encryption status
|
||||
@@ -226,8 +226,8 @@ def test_bad_circuit(helpers):
|
||||
|
||||
with pytest.raises(ValueError) as excinfo:
|
||||
|
||||
@cnp.circuit({}, helpers.configuration())
|
||||
def circuit2(x: cnp.uint3):
|
||||
@fhe.circuit({}, helpers.configuration())
|
||||
def circuit2(x: fhe.uint3):
|
||||
return x + 42
|
||||
|
||||
assert str(excinfo.value) == (
|
||||
@@ -238,21 +238,21 @@ def test_bad_circuit(helpers):
|
||||
# ----------
|
||||
with pytest.raises(ValueError) as excinfo:
|
||||
|
||||
@cnp.circuit({"x": "encrypted"}, helpers.configuration())
|
||||
def circuit3(x: cnp.uint3):
|
||||
@fhe.circuit({"x": "encrypted"}, helpers.configuration())
|
||||
def circuit3(x: fhe.uint3):
|
||||
return x.astype(np.int64)
|
||||
|
||||
assert str(excinfo.value) == (
|
||||
"`astype` method must be called with a concrete.numpy type "
|
||||
"for direct circuit definition (e.g., value.astype(cnp.uint4))"
|
||||
"`astype` method must be called with an fhe type "
|
||||
"for direct circuit definition (e.g., value.astype(fhe.uint4))"
|
||||
)
|
||||
|
||||
# round
|
||||
# -----
|
||||
with pytest.raises(RuntimeError) as excinfo:
|
||||
|
||||
@cnp.circuit({"x": "encrypted"}, helpers.configuration())
|
||||
def circuit4(x: cnp.uint3):
|
||||
@fhe.circuit({"x": "encrypted"}, helpers.configuration())
|
||||
def circuit4(x: fhe.uint3):
|
||||
return round(x)
|
||||
|
||||
assert str(excinfo.value) == (
|
||||
|
||||
@@ -11,8 +11,8 @@ from typing import Any, Callable, Dict, List, Tuple, Union
|
||||
import numpy as np
|
||||
import pytest
|
||||
|
||||
import concrete.numpy as cnp
|
||||
import tests
|
||||
from concrete import fhe
|
||||
|
||||
tests_directory = os.path.dirname(tests.__file__)
|
||||
|
||||
@@ -56,7 +56,7 @@ def pytest_sessionstart(session):
|
||||
else:
|
||||
key_cache_location = Path(key_cache_location).expanduser().resolve()
|
||||
else:
|
||||
key_cache_location = Path.home().resolve() / ".cache" / "concrete-numpy" / "pytest"
|
||||
key_cache_location = Path.home().resolve() / ".cache" / "concrete-python" / "pytest"
|
||||
|
||||
if key_cache_location:
|
||||
key_cache_location.mkdir(parents=True, exist_ok=True)
|
||||
@@ -98,16 +98,16 @@ class Helpers:
|
||||
"""
|
||||
|
||||
@staticmethod
|
||||
def configuration() -> cnp.Configuration:
|
||||
def configuration() -> fhe.Configuration:
|
||||
"""
|
||||
Get the test configuration to use during testing.
|
||||
|
||||
Returns:
|
||||
cnp.Configuration:
|
||||
fhe.Configuration:
|
||||
test configuration
|
||||
"""
|
||||
|
||||
return cnp.Configuration(
|
||||
return fhe.Configuration(
|
||||
dump_artifacts_on_unexpected_failures=False,
|
||||
enable_unsafe_features=True,
|
||||
use_insecure_key_cache=True,
|
||||
@@ -219,7 +219,7 @@ class Helpers:
|
||||
|
||||
@staticmethod
|
||||
def check_execution(
|
||||
circuit: cnp.Circuit,
|
||||
circuit: fhe.Circuit,
|
||||
function: Callable,
|
||||
sample: Union[Any, List[Any]],
|
||||
retries: int = 1,
|
||||
@@ -229,7 +229,7 @@ class Helpers:
|
||||
Assert that `circuit` is behaves the same as `function` on `sample`.
|
||||
|
||||
Args:
|
||||
circuit (cnp.Circuit):
|
||||
circuit (fhe.Circuit):
|
||||
compiled circuit
|
||||
|
||||
function (Callable):
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
"""
|
||||
Tests of `concrete.numpy.dtypes` namespace.
|
||||
Tests of `concrete.fhe.dtypes` namespace.
|
||||
"""
|
||||
|
||||
@@ -4,7 +4,7 @@ Tests of `Float` data type.
|
||||
|
||||
import pytest
|
||||
|
||||
from concrete.numpy.dtypes import Float
|
||||
from concrete.fhe.dtypes import Float
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
|
||||
@@ -5,7 +5,7 @@ Tests of `Integer` data type.
|
||||
import numpy as np
|
||||
import pytest
|
||||
|
||||
from concrete.numpy.dtypes import Integer, SignedInteger, UnsignedInteger
|
||||
from concrete.fhe.dtypes import Integer, SignedInteger, UnsignedInteger
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
|
||||
@@ -4,8 +4,8 @@ Tests of utilities related to data types.
|
||||
|
||||
import pytest
|
||||
|
||||
from concrete.numpy.dtypes import Float, SignedInteger, UnsignedInteger
|
||||
from concrete.numpy.dtypes.utils import combine_dtypes
|
||||
from concrete.fhe.dtypes import Float, SignedInteger, UnsignedInteger
|
||||
from concrete.fhe.dtypes.utils import combine_dtypes
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
|
||||
@@ -5,7 +5,7 @@ Tests of execution of add operation.
|
||||
import numpy as np
|
||||
import pytest
|
||||
|
||||
import concrete.numpy as cnp
|
||||
from concrete import fhe
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
@@ -77,7 +77,7 @@ def test_constant_add(function, parameters, helpers):
|
||||
parameter_encryption_statuses = helpers.generate_encryption_statuses(parameters)
|
||||
configuration = helpers.configuration()
|
||||
|
||||
compiler = cnp.Compiler(function, parameter_encryption_statuses)
|
||||
compiler = fhe.Compiler(function, parameter_encryption_statuses)
|
||||
|
||||
inputset = helpers.generate_inputset(parameters)
|
||||
circuit = compiler.compile(inputset, configuration)
|
||||
@@ -172,7 +172,7 @@ def test_add(function, parameters, helpers):
|
||||
parameter_encryption_statuses = helpers.generate_encryption_statuses(parameters)
|
||||
configuration = helpers.configuration()
|
||||
|
||||
compiler = cnp.Compiler(function, parameter_encryption_statuses)
|
||||
compiler = fhe.Compiler(function, parameter_encryption_statuses)
|
||||
|
||||
inputset = helpers.generate_inputset(parameters)
|
||||
circuit = compiler.compile(inputset, configuration)
|
||||
|
||||
@@ -4,43 +4,43 @@ Tests of execution of array operation.
|
||||
|
||||
import pytest
|
||||
|
||||
import concrete.numpy as cnp
|
||||
from concrete import fhe
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"function,parameters",
|
||||
[
|
||||
pytest.param(
|
||||
lambda x: cnp.array([x, x + 1, 1]),
|
||||
lambda x: fhe.array([x, x + 1, 1]),
|
||||
{
|
||||
"x": {"range": [0, 10], "status": "encrypted", "shape": ()},
|
||||
},
|
||||
id="cnp.array([x, x + 1, 1])",
|
||||
id="fhe.array([x, x + 1, 1])",
|
||||
),
|
||||
pytest.param(
|
||||
lambda x, y: cnp.array([x, y]),
|
||||
lambda x, y: fhe.array([x, y]),
|
||||
{
|
||||
"x": {"range": [0, 10], "status": "encrypted", "shape": ()},
|
||||
"y": {"range": [0, 10], "status": "clear", "shape": ()},
|
||||
},
|
||||
id="cnp.array([x, y])",
|
||||
id="fhe.array([x, y])",
|
||||
),
|
||||
pytest.param(
|
||||
lambda x, y: cnp.array([[x, y], [y, x]]),
|
||||
lambda x, y: fhe.array([[x, y], [y, x]]),
|
||||
{
|
||||
"x": {"range": [0, 10], "status": "encrypted", "shape": ()},
|
||||
"y": {"range": [0, 10], "status": "clear", "shape": ()},
|
||||
},
|
||||
id="cnp.array([[x, y], [y, x]])",
|
||||
id="fhe.array([[x, y], [y, x]])",
|
||||
),
|
||||
pytest.param(
|
||||
lambda x, y, z: cnp.array([[x, 1], [y, 2], [z, 3]]),
|
||||
lambda x, y, z: fhe.array([[x, 1], [y, 2], [z, 3]]),
|
||||
{
|
||||
"x": {"range": [0, 10], "status": "encrypted", "shape": ()},
|
||||
"y": {"range": [0, 10], "status": "clear", "shape": ()},
|
||||
"z": {"range": [0, 10], "status": "encrypted", "shape": ()},
|
||||
},
|
||||
id="cnp.array([[x, 1], [y, 2], [z, 3]])",
|
||||
id="fhe.array([[x, 1], [y, 2], [z, 3]])",
|
||||
),
|
||||
],
|
||||
)
|
||||
@@ -52,7 +52,7 @@ def test_array(function, parameters, helpers):
|
||||
parameter_encryption_statuses = helpers.generate_encryption_statuses(parameters)
|
||||
configuration = helpers.configuration()
|
||||
|
||||
compiler = cnp.Compiler(function, parameter_encryption_statuses)
|
||||
compiler = fhe.Compiler(function, parameter_encryption_statuses)
|
||||
|
||||
inputset = helpers.generate_inputset(parameters)
|
||||
circuit = compiler.compile(inputset, configuration)
|
||||
|
||||
@@ -4,7 +4,7 @@ Tests of execution of bitwise operations.
|
||||
|
||||
import pytest
|
||||
|
||||
import concrete.numpy as cnp
|
||||
from concrete import fhe
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
@@ -53,7 +53,7 @@ def test_bitwise(function, parameters, helpers):
|
||||
parameter_encryption_statuses = helpers.generate_encryption_statuses(parameters)
|
||||
configuration = helpers.configuration()
|
||||
|
||||
compiler = cnp.Compiler(function, parameter_encryption_statuses)
|
||||
compiler = fhe.Compiler(function, parameter_encryption_statuses)
|
||||
|
||||
inputset = helpers.generate_inputset(parameters)
|
||||
circuit = compiler.compile(inputset, configuration)
|
||||
|
||||
@@ -5,7 +5,7 @@ Tests of execution of broadcast to operation.
|
||||
import numpy as np
|
||||
import pytest
|
||||
|
||||
import concrete.numpy as cnp
|
||||
from concrete import fhe
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
@@ -31,7 +31,7 @@ def test_broadcast_to(from_shape, to_shape, helpers):
|
||||
return np.broadcast_to(x, to_shape)
|
||||
|
||||
configuration = helpers.configuration()
|
||||
compiler = cnp.Compiler(function, {"x": "encrypted"})
|
||||
compiler = fhe.Compiler(function, {"x": "encrypted"})
|
||||
|
||||
inputset = [np.random.randint(0, 2**2, size=from_shape) for _ in range(100)]
|
||||
circuit = compiler.compile(inputset, configuration)
|
||||
|
||||
@@ -4,7 +4,7 @@ Tests of execution of comparison operations.
|
||||
|
||||
import pytest
|
||||
|
||||
import concrete.numpy as cnp
|
||||
from concrete import fhe
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
@@ -81,7 +81,7 @@ def test_comparison(function, parameters, helpers):
|
||||
parameter_encryption_statuses = helpers.generate_encryption_statuses(parameters)
|
||||
configuration = helpers.configuration()
|
||||
|
||||
compiler = cnp.Compiler(function, parameter_encryption_statuses)
|
||||
compiler = fhe.Compiler(function, parameter_encryption_statuses)
|
||||
|
||||
inputset = helpers.generate_inputset(parameters)
|
||||
circuit = compiler.compile(inputset, configuration)
|
||||
@@ -152,7 +152,7 @@ def test_optimized_comparison(function, parameters, helpers):
|
||||
parameter_encryption_statuses = helpers.generate_encryption_statuses(parameters)
|
||||
configuration = helpers.configuration()
|
||||
|
||||
compiler = cnp.Compiler(function, parameter_encryption_statuses)
|
||||
compiler = fhe.Compiler(function, parameter_encryption_statuses)
|
||||
|
||||
inputset = helpers.generate_inputset(parameters)
|
||||
circuit = compiler.compile(inputset, configuration)
|
||||
|
||||
@@ -5,7 +5,7 @@ Tests of execution of concatenate operation.
|
||||
import numpy as np
|
||||
import pytest
|
||||
|
||||
import concrete.numpy as cnp
|
||||
from concrete import fhe
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
@@ -167,7 +167,7 @@ def test_concatenate(function, parameters, helpers):
|
||||
parameter_encryption_statuses = helpers.generate_encryption_statuses(parameters)
|
||||
configuration = helpers.configuration()
|
||||
|
||||
compiler = cnp.Compiler(function, parameter_encryption_statuses)
|
||||
compiler = fhe.Compiler(function, parameter_encryption_statuses)
|
||||
|
||||
inputset = helpers.generate_inputset(parameters)
|
||||
circuit = compiler.compile(inputset, configuration)
|
||||
|
||||
@@ -5,10 +5,10 @@ Tests of execution of convolution operation.
|
||||
import numpy as np
|
||||
import pytest
|
||||
|
||||
import concrete.numpy as cnp
|
||||
import concrete.onnx as connx
|
||||
from concrete.numpy.representation.node import Node
|
||||
from concrete.numpy.tracing.tracer import Tracer
|
||||
from concrete import fhe
|
||||
from concrete.fhe.representation.node import Node
|
||||
from concrete.fhe.tracing.tracer import Tracer
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
@@ -58,13 +58,9 @@ def test_conv2d(input_shape, weight_shape, group, strides, dilations, has_bias,
|
||||
configuration = helpers.configuration()
|
||||
|
||||
weight = np.random.randint(0, 4, size=weight_shape)
|
||||
bias = np.random.randint(0, 4, size=(weight_shape[0],)) if has_bias else None
|
||||
|
||||
if has_bias:
|
||||
bias = np.random.randint(0, 4, size=(weight_shape[0],))
|
||||
else:
|
||||
bias = None
|
||||
|
||||
@cnp.compiler({"x": "encrypted"})
|
||||
@fhe.compiler({"x": "encrypted"})
|
||||
def function(x):
|
||||
return connx.conv(x, weight, bias, strides=strides, dilations=dilations, group=group)
|
||||
|
||||
@@ -131,7 +127,7 @@ def test_conv2d(input_shape, weight_shape, group, strides, dilations, has_bias,
|
||||
1,
|
||||
"NOTSET",
|
||||
ValueError,
|
||||
"strides should be of form (D_stride,) when performing 1D " "convolution, but it's ()",
|
||||
"strides should be of form (D_stride,) when performing 1D convolution, but it's ()",
|
||||
),
|
||||
pytest.param(
|
||||
(1, 1, 4),
|
||||
@@ -388,13 +384,9 @@ def test_bad_conv_compilation(
|
||||
configuration = helpers.configuration()
|
||||
|
||||
weight = np.random.randint(0, 4, size=weight_shape)
|
||||
bias = np.random.randint(0, 4, size=bias_shape) if bias_shape is not None else None
|
||||
|
||||
if bias_shape is not None:
|
||||
bias = np.random.randint(0, 4, size=bias_shape)
|
||||
else:
|
||||
bias = None
|
||||
|
||||
@cnp.compiler({"x": "encrypted"})
|
||||
@fhe.compiler({"x": "encrypted"})
|
||||
def function(x):
|
||||
return connx.conv(
|
||||
x,
|
||||
|
||||
@@ -5,7 +5,7 @@ Tests of execution of direct table lookup operation.
|
||||
import numpy as np
|
||||
import pytest
|
||||
|
||||
import concrete.numpy as cnp
|
||||
from concrete import fhe
|
||||
|
||||
|
||||
def identity_table_lookup_generator(n):
|
||||
@@ -13,7 +13,7 @@ def identity_table_lookup_generator(n):
|
||||
Get identity table lookup function.
|
||||
"""
|
||||
|
||||
return lambda x: cnp.LookupTable(range(2**n))[x]
|
||||
return lambda x: fhe.LookupTable(range(2**n))[x]
|
||||
|
||||
|
||||
def random_table_lookup_1b(x):
|
||||
@@ -22,7 +22,7 @@ def random_table_lookup_1b(x):
|
||||
"""
|
||||
|
||||
# fmt: off
|
||||
table = cnp.LookupTable([10, 12])
|
||||
table = fhe.LookupTable([10, 12])
|
||||
# fmt: on
|
||||
|
||||
return table[x]
|
||||
@@ -34,7 +34,7 @@ def random_table_lookup_2b(x):
|
||||
"""
|
||||
|
||||
# fmt: off
|
||||
table = cnp.LookupTable([3, 8, 22, 127])
|
||||
table = fhe.LookupTable([3, 8, 22, 127])
|
||||
# fmt: on
|
||||
|
||||
return table[x]
|
||||
@@ -46,7 +46,7 @@ def random_table_lookup_3b(x):
|
||||
"""
|
||||
|
||||
# fmt: off
|
||||
table = cnp.LookupTable([30, 52, 125, 23, 17, 12, 90, 4])
|
||||
table = fhe.LookupTable([30, 52, 125, 23, 17, 12, 90, 4])
|
||||
# fmt: on
|
||||
|
||||
return table[x]
|
||||
@@ -58,7 +58,7 @@ def random_table_lookup_4b(x):
|
||||
"""
|
||||
|
||||
# fmt: off
|
||||
table = cnp.LookupTable([30, 52, 125, 23, 17, 12, 90, 4, 21, 51, 22, 15, 53, 100, 75, 90])
|
||||
table = fhe.LookupTable([30, 52, 125, 23, 17, 12, 90, 4, 21, 51, 22, 15, 53, 100, 75, 90])
|
||||
# fmt: on
|
||||
|
||||
return table[x]
|
||||
@@ -70,7 +70,7 @@ def random_table_lookup_5b(x):
|
||||
"""
|
||||
|
||||
# fmt: off
|
||||
table = cnp.LookupTable(
|
||||
table = fhe.LookupTable(
|
||||
[
|
||||
1, 5, 2, 3, 10, 2, 4, 8, 1, 12, 15, 12, 10, 1, 0, 2,
|
||||
4, 3, 8, 7, 10, 11, 6, 13, 9, 0, 2, 1, 15, 11, 12, 5
|
||||
@@ -87,7 +87,7 @@ def random_table_lookup_6b(x):
|
||||
"""
|
||||
|
||||
# fmt: off
|
||||
table = cnp.LookupTable(
|
||||
table = fhe.LookupTable(
|
||||
[
|
||||
95, 74, 11, 83, 24, 116, 28, 75, 26, 85, 114, 121, 91, 123, 78, 69,
|
||||
72, 115, 67, 5, 39, 11, 120, 88, 56, 43, 74, 16, 72, 85, 103, 92,
|
||||
@@ -106,7 +106,7 @@ def random_table_lookup_7b(x):
|
||||
"""
|
||||
|
||||
# fmt: off
|
||||
table = cnp.LookupTable(
|
||||
table = fhe.LookupTable(
|
||||
[
|
||||
13, 58, 38, 58, 15, 15, 77, 86, 80, 94, 108, 27, 126, 60, 65, 95,
|
||||
50, 79, 22, 97, 38, 60, 25, 48, 73, 112, 27, 45, 88, 20, 67, 17,
|
||||
@@ -128,7 +128,7 @@ def negative_identity_table_lookup_generator(n):
|
||||
Get negative identity table lookup function.
|
||||
"""
|
||||
|
||||
return lambda x: cnp.LookupTable([-i for i in range(2**n)])[x]
|
||||
return lambda x: fhe.LookupTable([-i for i in range(2**n)])[x]
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
@@ -166,7 +166,7 @@ def test_direct_table_lookup(bits, function, helpers):
|
||||
# scalar
|
||||
# ------
|
||||
|
||||
compiler = cnp.Compiler(function, {"x": "encrypted"})
|
||||
compiler = fhe.Compiler(function, {"x": "encrypted"})
|
||||
|
||||
inputset = range(2**bits)
|
||||
circuit = compiler.compile(inputset, configuration)
|
||||
@@ -177,7 +177,7 @@ def test_direct_table_lookup(bits, function, helpers):
|
||||
# tensor
|
||||
# ------
|
||||
|
||||
compiler = cnp.Compiler(function, {"x": "encrypted"})
|
||||
compiler = fhe.Compiler(function, {"x": "encrypted"})
|
||||
|
||||
inputset = [np.random.randint(0, 2**bits, size=(3, 2)) for _ in range(100)]
|
||||
circuit = compiler.compile(inputset, configuration)
|
||||
@@ -188,7 +188,7 @@ def test_direct_table_lookup(bits, function, helpers):
|
||||
# negative scalar
|
||||
# ---------------
|
||||
|
||||
compiler = cnp.Compiler(function, {"x": "encrypted"})
|
||||
compiler = fhe.Compiler(function, {"x": "encrypted"})
|
||||
|
||||
inputset = range(-(2 ** (bits - 1)), 2 ** (bits - 1))
|
||||
circuit = compiler.compile(inputset, configuration)
|
||||
@@ -199,7 +199,7 @@ def test_direct_table_lookup(bits, function, helpers):
|
||||
# negative tensor
|
||||
# ---------------
|
||||
|
||||
compiler = cnp.Compiler(function, {"x": "encrypted"})
|
||||
compiler = fhe.Compiler(function, {"x": "encrypted"})
|
||||
|
||||
inputset = [
|
||||
np.random.randint(-(2 ** (bits - 1)), 2 ** (bits - 1), size=(3, 2)) for _ in range(100)
|
||||
@@ -217,10 +217,10 @@ def test_direct_multi_table_lookup(helpers):
|
||||
|
||||
configuration = helpers.configuration()
|
||||
|
||||
square = cnp.LookupTable([i * i for i in range(4)])
|
||||
cube = cnp.LookupTable([i * i * i for i in range(4)])
|
||||
square = fhe.LookupTable([i * i for i in range(4)])
|
||||
cube = fhe.LookupTable([i * i * i for i in range(4)])
|
||||
|
||||
table = cnp.LookupTable(
|
||||
table = fhe.LookupTable(
|
||||
[
|
||||
[square, cube],
|
||||
[cube, square],
|
||||
@@ -231,7 +231,7 @@ def test_direct_multi_table_lookup(helpers):
|
||||
def function(x):
|
||||
return table[x]
|
||||
|
||||
compiler = cnp.Compiler(function, {"x": "encrypted"})
|
||||
compiler = fhe.Compiler(function, {"x": "encrypted"})
|
||||
|
||||
inputset = [np.random.randint(0, 2**2, size=(3, 2)) for _ in range(100)]
|
||||
circuit = compiler.compile(inputset, configuration)
|
||||
@@ -251,7 +251,7 @@ def test_bad_direct_table_lookup(helpers):
|
||||
# -----------
|
||||
|
||||
with pytest.raises(ValueError) as excinfo:
|
||||
cnp.LookupTable([])
|
||||
fhe.LookupTable([])
|
||||
|
||||
assert str(excinfo.value) == "LookupTable cannot be constructed with []"
|
||||
|
||||
@@ -259,7 +259,7 @@ def test_bad_direct_table_lookup(helpers):
|
||||
# -------------
|
||||
|
||||
with pytest.raises(ValueError) as excinfo:
|
||||
cnp.LookupTable([[0, 1], [2, 3]])
|
||||
fhe.LookupTable([[0, 1], [2, 3]])
|
||||
|
||||
assert str(excinfo.value) == "LookupTable cannot be constructed with [[0, 1], [2, 3]]"
|
||||
|
||||
@@ -267,7 +267,7 @@ def test_bad_direct_table_lookup(helpers):
|
||||
# -------------------
|
||||
|
||||
with pytest.raises(ValueError) as excinfo:
|
||||
cnp.LookupTable(["abc", 3.2])
|
||||
fhe.LookupTable(["abc", 3.2])
|
||||
|
||||
assert str(excinfo.value) == "LookupTable cannot be constructed with ['abc', 3.2]"
|
||||
|
||||
@@ -282,10 +282,10 @@ def test_bad_direct_table_lookup(helpers):
|
||||
# simulation with invalid shape
|
||||
# -----------------------------
|
||||
|
||||
square = cnp.LookupTable([i * i for i in range(4)])
|
||||
cube = cnp.LookupTable([i * i * i for i in range(4)])
|
||||
square = fhe.LookupTable([i * i for i in range(4)])
|
||||
cube = fhe.LookupTable([i * i * i for i in range(4)])
|
||||
|
||||
table = cnp.LookupTable(
|
||||
table = fhe.LookupTable(
|
||||
[
|
||||
[square, cube],
|
||||
[cube, square],
|
||||
@@ -301,7 +301,7 @@ def test_bad_direct_table_lookup(helpers):
|
||||
# compilation with float value
|
||||
# ----------------------------
|
||||
|
||||
compiler = cnp.Compiler(random_table_lookup_3b, {"x": "encrypted"})
|
||||
compiler = fhe.Compiler(random_table_lookup_3b, {"x": "encrypted"})
|
||||
|
||||
inputset = [1.5]
|
||||
with pytest.raises(ValueError) as excinfo:
|
||||
@@ -312,7 +312,7 @@ def test_bad_direct_table_lookup(helpers):
|
||||
# compilation with invalid shape
|
||||
# ------------------------------
|
||||
|
||||
compiler = cnp.Compiler(lambda x: table[x], {"x": "encrypted"})
|
||||
compiler = fhe.Compiler(lambda x: table[x], {"x": "encrypted"})
|
||||
|
||||
inputset = [10, 5, 6, 2]
|
||||
with pytest.raises(ValueError) as excinfo:
|
||||
|
||||
@@ -5,7 +5,7 @@ Tests of execution of dot operation.
|
||||
import numpy as np
|
||||
import pytest
|
||||
|
||||
import concrete.numpy as cnp
|
||||
from concrete import fhe
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
@@ -22,15 +22,15 @@ def test_dot(size, helpers):
|
||||
bound = int(np.floor(np.sqrt(127 / size)))
|
||||
cst = np.random.randint(0, bound, size=(size,))
|
||||
|
||||
@cnp.compiler({"x": "encrypted"})
|
||||
@fhe.compiler({"x": "encrypted"})
|
||||
def left_function(x):
|
||||
return np.dot(x, cst)
|
||||
|
||||
@cnp.compiler({"x": "encrypted"})
|
||||
@fhe.compiler({"x": "encrypted"})
|
||||
def right_function(x):
|
||||
return np.dot(cst, x)
|
||||
|
||||
@cnp.compiler({"x": "encrypted"})
|
||||
@fhe.compiler({"x": "encrypted"})
|
||||
def method(x):
|
||||
return x.dot(cst)
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ Tests of execution of iteration of tracer.
|
||||
import numpy as np
|
||||
import pytest
|
||||
|
||||
import concrete.numpy as cnp
|
||||
from concrete import fhe
|
||||
|
||||
|
||||
@pytest.mark.parametrize("shape", [(3,), (3, 2), (3, 2, 4)])
|
||||
@@ -15,13 +15,13 @@ def test_iter(shape, helpers):
|
||||
"""
|
||||
|
||||
def function(x):
|
||||
result = cnp.zeros(x.shape[1:])
|
||||
result = fhe.zeros(x.shape[1:])
|
||||
for value in x:
|
||||
result += value
|
||||
return result
|
||||
|
||||
configuration = helpers.configuration()
|
||||
compiler = cnp.Compiler(function, {"x": "encrypted"})
|
||||
compiler = fhe.Compiler(function, {"x": "encrypted"})
|
||||
|
||||
inputset = [np.random.randint(0, 2**2, size=shape) for _ in range(100)]
|
||||
circuit = compiler.compile(inputset, configuration)
|
||||
|
||||
@@ -5,7 +5,7 @@ Tests of execution of matmul operation.
|
||||
import numpy as np
|
||||
import pytest
|
||||
|
||||
import concrete.numpy as cnp
|
||||
from concrete import fhe
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
@@ -125,19 +125,19 @@ def test_matmul(lhs_shape, rhs_shape, bounds, helpers):
|
||||
lhs_cst = list(np.random.randint(minimum, maximum, size=lhs_shape))
|
||||
rhs_cst = list(np.random.randint(minimum, maximum, size=rhs_shape))
|
||||
|
||||
@cnp.compiler({"x": "encrypted"})
|
||||
@fhe.compiler({"x": "encrypted"})
|
||||
def lhs_operator(x):
|
||||
return x @ rhs_cst
|
||||
|
||||
@cnp.compiler({"x": "encrypted"})
|
||||
@fhe.compiler({"x": "encrypted"})
|
||||
def rhs_operator(x):
|
||||
return lhs_cst @ x
|
||||
|
||||
@cnp.compiler({"x": "encrypted"})
|
||||
@fhe.compiler({"x": "encrypted"})
|
||||
def lhs_function(x):
|
||||
return np.matmul(x, rhs_cst)
|
||||
|
||||
@cnp.compiler({"x": "encrypted"})
|
||||
@fhe.compiler({"x": "encrypted"})
|
||||
def rhs_function(x):
|
||||
return np.matmul(lhs_cst, x)
|
||||
|
||||
|
||||
@@ -5,8 +5,8 @@ Tests of execution of maxpool operation.
|
||||
import numpy as np
|
||||
import pytest
|
||||
|
||||
import concrete.numpy as cnp
|
||||
import concrete.onnx as connx
|
||||
from concrete import fhe
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
@@ -71,7 +71,7 @@ def test_maxpool(
|
||||
|
||||
assert np.array_equal(connx.maxpool(sample_input, **operation), expected_output)
|
||||
|
||||
@cnp.compiler({"x": "encrypted"})
|
||||
@fhe.compiler({"x": "encrypted"})
|
||||
def function(x):
|
||||
return connx.maxpool(x, **operation)
|
||||
|
||||
@@ -321,7 +321,7 @@ def test_bad_maxpool_special(helpers):
|
||||
# compile
|
||||
# -------
|
||||
|
||||
@cnp.compiler({"x": "encrypted"})
|
||||
@fhe.compiler({"x": "encrypted"})
|
||||
def not_compilable(x):
|
||||
return connx.maxpool(x, kernel_shape=(4, 3))
|
||||
|
||||
@@ -334,7 +334,7 @@ def test_bad_maxpool_special(helpers):
|
||||
# clear input
|
||||
# -----------
|
||||
|
||||
@cnp.compiler({"x": "clear"})
|
||||
@fhe.compiler({"x": "clear"})
|
||||
def clear_input(x):
|
||||
return connx.maxpool(x, kernel_shape=(4, 3, 2))
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ Tests of execution of mul operation.
|
||||
import numpy as np
|
||||
import pytest
|
||||
|
||||
import concrete.numpy as cnp
|
||||
from concrete import fhe
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
@@ -67,7 +67,7 @@ def test_constant_mul(function, parameters, helpers):
|
||||
parameter_encryption_statuses = helpers.generate_encryption_statuses(parameters)
|
||||
configuration = helpers.configuration()
|
||||
|
||||
compiler = cnp.Compiler(function, parameter_encryption_statuses)
|
||||
compiler = fhe.Compiler(function, parameter_encryption_statuses)
|
||||
|
||||
inputset = helpers.generate_inputset(parameters)
|
||||
circuit = compiler.compile(inputset, configuration)
|
||||
|
||||
@@ -5,7 +5,7 @@ Tests of execution of neg operation.
|
||||
import numpy as np
|
||||
import pytest
|
||||
|
||||
import concrete.numpy as cnp
|
||||
from concrete import fhe
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
@@ -33,11 +33,11 @@ def test_neg(parameters, helpers):
|
||||
parameter_encryption_statuses = helpers.generate_encryption_statuses(parameters)
|
||||
configuration = helpers.configuration()
|
||||
|
||||
@cnp.compiler(parameter_encryption_statuses)
|
||||
@fhe.compiler(parameter_encryption_statuses)
|
||||
def operator(x):
|
||||
return -x
|
||||
|
||||
@cnp.compiler(parameter_encryption_statuses)
|
||||
@fhe.compiler(parameter_encryption_statuses)
|
||||
def function(x):
|
||||
return np.negative(x)
|
||||
|
||||
|
||||
@@ -6,31 +6,31 @@ import random
|
||||
|
||||
import pytest
|
||||
|
||||
import concrete.numpy as cnp
|
||||
from concrete import fhe
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"function",
|
||||
[
|
||||
pytest.param(
|
||||
lambda x: cnp.one() + x,
|
||||
id="cnp.one() + x",
|
||||
lambda x: fhe.one() + x,
|
||||
id="fhe.one() + x",
|
||||
),
|
||||
pytest.param(
|
||||
lambda x: cnp.ones(()) + x,
|
||||
id="cnp.ones(()) + x",
|
||||
lambda x: fhe.ones(()) + x,
|
||||
id="fhe.ones(()) + x",
|
||||
),
|
||||
pytest.param(
|
||||
lambda x: cnp.ones(10) + x,
|
||||
id="cnp.ones(10) + x",
|
||||
lambda x: fhe.ones(10) + x,
|
||||
id="fhe.ones(10) + x",
|
||||
),
|
||||
pytest.param(
|
||||
lambda x: cnp.ones((10,)) + x,
|
||||
id="cnp.ones((10,)) + x",
|
||||
lambda x: fhe.ones((10,)) + x,
|
||||
id="fhe.ones((10,)) + x",
|
||||
),
|
||||
pytest.param(
|
||||
lambda x: cnp.ones((3, 2)) + x,
|
||||
id="cnp.ones((3, 2)) + x",
|
||||
lambda x: fhe.ones((3, 2)) + x,
|
||||
id="fhe.ones((3, 2)) + x",
|
||||
),
|
||||
],
|
||||
)
|
||||
@@ -40,7 +40,7 @@ def test_ones(function, helpers):
|
||||
"""
|
||||
|
||||
configuration = helpers.configuration()
|
||||
compiler = cnp.Compiler(function, {"x": "encrypted"})
|
||||
compiler = fhe.Compiler(function, {"x": "encrypted"})
|
||||
|
||||
inputset = range(10)
|
||||
circuit = compiler.compile(inputset, configuration)
|
||||
|
||||
@@ -5,7 +5,7 @@ Tests of execution of operations converted to table lookups.
|
||||
import numpy as np
|
||||
import pytest
|
||||
|
||||
import concrete.numpy as cnp
|
||||
from concrete import fhe
|
||||
|
||||
|
||||
def fusable_with_bigger_search(x, y):
|
||||
@@ -360,7 +360,7 @@ def deterministic_unary_function(x):
|
||||
id="x > 50",
|
||||
),
|
||||
pytest.param(
|
||||
lambda x: 50 > x, # pylint: disable=misplaced-comparison-constant
|
||||
lambda x: 50 > x,
|
||||
{
|
||||
"x": {"status": "encrypted", "range": [0, 100]},
|
||||
},
|
||||
@@ -374,7 +374,7 @@ def deterministic_unary_function(x):
|
||||
id="x < 50",
|
||||
),
|
||||
pytest.param(
|
||||
lambda x: 50 < x, # pylint: disable=misplaced-comparison-constant
|
||||
lambda x: 50 < x,
|
||||
{
|
||||
"x": {"status": "encrypted", "range": [0, 100]},
|
||||
},
|
||||
@@ -388,7 +388,7 @@ def deterministic_unary_function(x):
|
||||
id="x >= 50",
|
||||
),
|
||||
pytest.param(
|
||||
lambda x: 50 >= x, # pylint: disable=misplaced-comparison-constant
|
||||
lambda x: 50 >= x,
|
||||
{
|
||||
"x": {"status": "encrypted", "range": [0, 100]},
|
||||
},
|
||||
@@ -402,7 +402,7 @@ def deterministic_unary_function(x):
|
||||
id="x <= 50",
|
||||
),
|
||||
pytest.param(
|
||||
lambda x: 50 <= x, # pylint: disable=misplaced-comparison-constant
|
||||
lambda x: 50 <= x,
|
||||
{
|
||||
"x": {"status": "encrypted", "range": [0, 100]},
|
||||
},
|
||||
@@ -416,7 +416,7 @@ def deterministic_unary_function(x):
|
||||
id="x == 50",
|
||||
),
|
||||
pytest.param(
|
||||
lambda x: 50 == x, # pylint: disable=misplaced-comparison-constant
|
||||
lambda x: 50 == x,
|
||||
{
|
||||
"x": {"status": "encrypted", "range": [0, 100]},
|
||||
},
|
||||
@@ -430,7 +430,7 @@ def deterministic_unary_function(x):
|
||||
id="x != 50",
|
||||
),
|
||||
pytest.param(
|
||||
lambda x: 50 != x, # pylint: disable=misplaced-comparison-constant
|
||||
lambda x: 50 != x,
|
||||
{
|
||||
"x": {"status": "encrypted", "range": [0, 100]},
|
||||
},
|
||||
@@ -551,11 +551,11 @@ def deterministic_unary_function(x):
|
||||
id="x + np.zeros_like(x)",
|
||||
),
|
||||
pytest.param(
|
||||
lambda x: cnp.univariate(deterministic_unary_function)(x),
|
||||
lambda x: fhe.univariate(deterministic_unary_function)(x),
|
||||
{
|
||||
"x": {"status": "encrypted", "range": [0, 10]},
|
||||
},
|
||||
id="cnp.univariate(deterministic_unary_function)(x)",
|
||||
id="fhe.univariate(deterministic_unary_function)(x)",
|
||||
),
|
||||
pytest.param(
|
||||
lambda x: round(np.sqrt(x)),
|
||||
@@ -579,12 +579,12 @@ def deterministic_unary_function(x):
|
||||
id="(2.5 * round(np.sqrt(x), decimals=4)).astype(np.int64)",
|
||||
),
|
||||
pytest.param(
|
||||
lambda x, y: cnp.LookupTable(list(range(32)))[x + y],
|
||||
lambda x, y: fhe.LookupTable(list(range(32)))[x + y],
|
||||
{
|
||||
"x": {"status": "encrypted", "range": [-10, 10]},
|
||||
"y": {"status": "encrypted", "range": [-10, 10]},
|
||||
},
|
||||
id="cnp.LookupTable(list(range(32)))[x + y]",
|
||||
id="fhe.LookupTable(list(range(32)))[x + y]",
|
||||
),
|
||||
pytest.param(
|
||||
lambda x: np.expand_dims(x, axis=0),
|
||||
@@ -691,7 +691,7 @@ def test_others(function, parameters, helpers):
|
||||
parameter_encryption_statuses = helpers.generate_encryption_statuses(parameters)
|
||||
configuration = helpers.configuration()
|
||||
|
||||
compiler = cnp.Compiler(function, parameter_encryption_statuses)
|
||||
compiler = fhe.Compiler(function, parameter_encryption_statuses)
|
||||
|
||||
inputset = helpers.generate_inputset(parameters)
|
||||
circuit = compiler.compile(inputset, configuration)
|
||||
@@ -711,7 +711,7 @@ def test_others(function, parameters, helpers):
|
||||
parameter_encryption_statuses = helpers.generate_encryption_statuses(parameters)
|
||||
configuration = helpers.configuration()
|
||||
|
||||
compiler = cnp.Compiler(function, parameter_encryption_statuses)
|
||||
compiler = fhe.Compiler(function, parameter_encryption_statuses)
|
||||
|
||||
inputset = helpers.generate_inputset(parameters)
|
||||
circuit = compiler.compile(inputset, configuration)
|
||||
@@ -730,7 +730,7 @@ def test_others_bad_fusing(helpers):
|
||||
# two variable inputs
|
||||
# -------------------
|
||||
|
||||
@cnp.compiler({"x": "encrypted", "y": "clear"})
|
||||
@fhe.compiler({"x": "encrypted", "y": "clear"})
|
||||
def function1(x, y):
|
||||
return (10 * (np.sin(x) ** 2) + 10 * (np.cos(y) ** 2)).astype(np.int64)
|
||||
|
||||
@@ -782,7 +782,7 @@ return %13
|
||||
# intermediates with different shape
|
||||
# ----------------------------------
|
||||
|
||||
@cnp.compiler({"x": "encrypted"})
|
||||
@fhe.compiler({"x": "encrypted"})
|
||||
def function2(x):
|
||||
return np.abs(np.sin(x)).reshape((2, 3)).astype(np.int64)
|
||||
|
||||
@@ -816,7 +816,7 @@ return %4
|
||||
# non-fusable operation
|
||||
# ---------------------
|
||||
|
||||
@cnp.compiler({"x": "encrypted"})
|
||||
@fhe.compiler({"x": "encrypted"})
|
||||
def function3(x):
|
||||
return np.abs(np.sin(x)).transpose().astype(np.int64)
|
||||
|
||||
@@ -850,7 +850,7 @@ return %4
|
||||
# integer two variable inputs
|
||||
# ---------------------------
|
||||
|
||||
@cnp.compiler({"x": "encrypted", "y": "clear"})
|
||||
@fhe.compiler({"x": "encrypted", "y": "clear"})
|
||||
def function4(x, y):
|
||||
return np.maximum(x, y)
|
||||
|
||||
@@ -888,15 +888,15 @@ def test_others_bad_univariate(helpers):
|
||||
def bad_univariate(x):
|
||||
return np.array([x, x, x])
|
||||
|
||||
@cnp.compiler({"x": "encrypted"})
|
||||
@fhe.compiler({"x": "encrypted"})
|
||||
def f(x):
|
||||
return cnp.univariate(bad_univariate)(x)
|
||||
return fhe.univariate(bad_univariate)(x)
|
||||
|
||||
with pytest.raises(ValueError) as excinfo:
|
||||
inputset = range(10)
|
||||
f.compile(inputset, configuration)
|
||||
|
||||
helpers.check_str(
|
||||
"Function bad_univariate cannot be used with cnp.univariate",
|
||||
"Function bad_univariate cannot be used with fhe.univariate",
|
||||
str(excinfo.value),
|
||||
)
|
||||
|
||||
@@ -5,7 +5,7 @@ Tests of execution of reshape operation.
|
||||
import numpy as np
|
||||
import pytest
|
||||
|
||||
import concrete.numpy as cnp
|
||||
from concrete import fhe
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
@@ -116,11 +116,11 @@ def test_reshape(shape, newshape, helpers):
|
||||
|
||||
configuration = helpers.configuration()
|
||||
|
||||
@cnp.compiler({"x": "encrypted"})
|
||||
@fhe.compiler({"x": "encrypted"})
|
||||
def function(x):
|
||||
return np.reshape(x, newshape)
|
||||
|
||||
@cnp.compiler({"x": "encrypted"})
|
||||
@fhe.compiler({"x": "encrypted"})
|
||||
def method(x):
|
||||
return x.reshape(newshape)
|
||||
|
||||
@@ -159,7 +159,7 @@ def test_flatten(shape, helpers):
|
||||
|
||||
configuration = helpers.configuration()
|
||||
|
||||
@cnp.compiler({"x": "encrypted"})
|
||||
@fhe.compiler({"x": "encrypted"})
|
||||
def function(x):
|
||||
return x.flatten()
|
||||
|
||||
|
||||
@@ -5,8 +5,8 @@ Tests of execution of round bit pattern operation.
|
||||
import numpy as np
|
||||
import pytest
|
||||
|
||||
import concrete.numpy as cnp
|
||||
from concrete.numpy.representation.utils import format_constant
|
||||
from concrete import fhe
|
||||
from concrete.fhe.representation.utils import format_constant
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
@@ -36,7 +36,7 @@ def test_plain_round_bit_pattern(sample, lsbs_to_remove, expected_output):
|
||||
"""
|
||||
Test round bit pattern in evaluation context.
|
||||
"""
|
||||
assert cnp.round_bit_pattern(sample, lsbs_to_remove=lsbs_to_remove) == expected_output
|
||||
assert fhe.round_bit_pattern(sample, lsbs_to_remove=lsbs_to_remove) == expected_output
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
@@ -67,7 +67,7 @@ def test_bad_plain_round_bit_pattern(
|
||||
"""
|
||||
|
||||
with pytest.raises(expected_error) as excinfo:
|
||||
cnp.round_bit_pattern(sample, lsbs_to_remove=lsbs_to_remove)
|
||||
fhe.round_bit_pattern(sample, lsbs_to_remove=lsbs_to_remove)
|
||||
|
||||
assert str(excinfo.value) == expected_message
|
||||
|
||||
@@ -91,9 +91,9 @@ def test_round_bit_pattern(input_bits, lsbs_to_remove, helpers):
|
||||
Test round bit pattern in evaluation context.
|
||||
"""
|
||||
|
||||
@cnp.compiler({"x": "encrypted"})
|
||||
@fhe.compiler({"x": "encrypted"})
|
||||
def function(x):
|
||||
x_rounded = cnp.round_bit_pattern(x, lsbs_to_remove=lsbs_to_remove)
|
||||
x_rounded = fhe.round_bit_pattern(x, lsbs_to_remove=lsbs_to_remove)
|
||||
return np.abs(50 * np.sin(x_rounded)).astype(np.int64)
|
||||
|
||||
circuit = function.compile([(2**input_bits) - 1], helpers.configuration())
|
||||
@@ -111,12 +111,12 @@ def test_auto_rounding(helpers):
|
||||
# y has the max value of 1999, so it's 11 bits
|
||||
# our target msb is 5 bits, which means we need to remove 6 of the least significant bits
|
||||
|
||||
rounder1 = cnp.AutoRounder(target_msbs=5)
|
||||
rounder1 = fhe.AutoRounder(target_msbs=5)
|
||||
|
||||
@cnp.compiler({"x": "encrypted"})
|
||||
@fhe.compiler({"x": "encrypted"})
|
||||
def function1(x):
|
||||
y = x + 1000
|
||||
z = cnp.round_bit_pattern(y, lsbs_to_remove=rounder1)
|
||||
z = fhe.round_bit_pattern(y, lsbs_to_remove=rounder1)
|
||||
return np.sqrt(z).astype(np.int64)
|
||||
|
||||
inputset1 = range(1000)
|
||||
@@ -130,16 +130,16 @@ def test_auto_rounding(helpers):
|
||||
# y has the max value of 1999, so it's 11 bits
|
||||
# our target msb is 3 bits, which means we need to remove 8 of the least significant bits
|
||||
|
||||
rounder2 = cnp.AutoRounder(target_msbs=3)
|
||||
rounder2 = fhe.AutoRounder(target_msbs=3)
|
||||
|
||||
@cnp.compiler({"x": "encrypted"})
|
||||
@fhe.compiler({"x": "encrypted"})
|
||||
def function2(x):
|
||||
y = x + 1000
|
||||
z = cnp.round_bit_pattern(y, lsbs_to_remove=rounder2)
|
||||
z = fhe.round_bit_pattern(y, lsbs_to_remove=rounder2)
|
||||
return np.sqrt(z).astype(np.int64)
|
||||
|
||||
inputset2 = range(1000)
|
||||
cnp.AutoRounder.adjust(function2, inputset2)
|
||||
fhe.AutoRounder.adjust(function2, inputset2)
|
||||
|
||||
assert rounder2.lsbs_to_remove == 8
|
||||
|
||||
@@ -153,9 +153,9 @@ def test_auto_rounding(helpers):
|
||||
# so we set every 8th entry to a 4-bit value
|
||||
entries3[i] = np.random.randint(0, (2**4) - (2**2))
|
||||
# when this tlu is applied to an 8-bit value with 5-bit msb rounding, result will be 4-bits
|
||||
table3 = cnp.LookupTable(entries3)
|
||||
table3 = fhe.LookupTable(entries3)
|
||||
# and this is the rounder for table1, which should have lsbs_to_remove of 3
|
||||
rounder3 = cnp.AutoRounder(target_msbs=5)
|
||||
rounder3 = fhe.AutoRounder(target_msbs=5)
|
||||
|
||||
# have 2 ** 8 entries during evaluation, it won't matter after compilation
|
||||
entries4 = list(range(2**8))
|
||||
@@ -164,15 +164,15 @@ def test_auto_rounding(helpers):
|
||||
# so we set every 4th entry to an 8-bit value
|
||||
entries4[i] = np.random.randint(2**7, 2**8)
|
||||
# when this tlu is applied to a 4-bit value with 2-bit msb rounding, result will be 8-bits
|
||||
table4 = cnp.LookupTable(entries4)
|
||||
table4 = fhe.LookupTable(entries4)
|
||||
# and this is the rounder for table2, which should have lsbs_to_remove of 2
|
||||
rounder4 = cnp.AutoRounder(target_msbs=2)
|
||||
rounder4 = fhe.AutoRounder(target_msbs=2)
|
||||
|
||||
@cnp.compiler({"x": "encrypted"})
|
||||
@fhe.compiler({"x": "encrypted"})
|
||||
def function3(x):
|
||||
a = cnp.round_bit_pattern(x, lsbs_to_remove=rounder3)
|
||||
a = fhe.round_bit_pattern(x, lsbs_to_remove=rounder3)
|
||||
b = table3[a]
|
||||
c = cnp.round_bit_pattern(b, lsbs_to_remove=rounder4)
|
||||
c = fhe.round_bit_pattern(b, lsbs_to_remove=rounder4)
|
||||
d = table4[c]
|
||||
return d
|
||||
|
||||
@@ -209,11 +209,11 @@ def test_auto_rounding_without_adjustment():
|
||||
Test round bit pattern with auto rounding but without adjustment.
|
||||
"""
|
||||
|
||||
rounder = cnp.AutoRounder(target_msbs=5)
|
||||
rounder = fhe.AutoRounder(target_msbs=5)
|
||||
|
||||
def function(x):
|
||||
y = x + 1000
|
||||
z = cnp.round_bit_pattern(y, lsbs_to_remove=rounder)
|
||||
z = fhe.round_bit_pattern(y, lsbs_to_remove=rounder)
|
||||
return np.sqrt(z).astype(np.int64)
|
||||
|
||||
with pytest.raises(RuntimeError) as excinfo:
|
||||
@@ -231,15 +231,15 @@ def test_auto_rounding_with_empty_inputset():
|
||||
Test round bit pattern with auto rounding but with empty inputset.
|
||||
"""
|
||||
|
||||
rounder = cnp.AutoRounder(target_msbs=5)
|
||||
rounder = fhe.AutoRounder(target_msbs=5)
|
||||
|
||||
def function(x):
|
||||
y = x + 1000
|
||||
z = cnp.round_bit_pattern(y, lsbs_to_remove=rounder)
|
||||
z = fhe.round_bit_pattern(y, lsbs_to_remove=rounder)
|
||||
return np.sqrt(z).astype(np.int64)
|
||||
|
||||
with pytest.raises(ValueError) as excinfo:
|
||||
cnp.AutoRounder.adjust(function, [])
|
||||
fhe.AutoRounder.adjust(function, [])
|
||||
|
||||
assert str(excinfo.value) == "AutoRounders cannot be adjusted with an empty inputset"
|
||||
|
||||
@@ -249,16 +249,16 @@ def test_auto_rounding_recursive_adjustment():
|
||||
Test round bit pattern with auto rounding but with recursive adjustment.
|
||||
"""
|
||||
|
||||
rounder = cnp.AutoRounder(target_msbs=5)
|
||||
rounder = fhe.AutoRounder(target_msbs=5)
|
||||
|
||||
def function(x):
|
||||
cnp.AutoRounder.adjust(function, range(10))
|
||||
fhe.AutoRounder.adjust(function, range(10))
|
||||
y = x + 1000
|
||||
z = cnp.round_bit_pattern(y, lsbs_to_remove=rounder)
|
||||
z = fhe.round_bit_pattern(y, lsbs_to_remove=rounder)
|
||||
return np.sqrt(z).astype(np.int64)
|
||||
|
||||
with pytest.raises(RuntimeError) as excinfo:
|
||||
cnp.AutoRounder.adjust(function, range(10))
|
||||
fhe.AutoRounder.adjust(function, range(10))
|
||||
|
||||
assert str(excinfo.value) == "AutoRounders cannot be adjusted recursively"
|
||||
|
||||
@@ -270,11 +270,11 @@ def test_auto_rounding_construct_in_function():
|
||||
|
||||
def function(x):
|
||||
y = x + 1000
|
||||
z = cnp.round_bit_pattern(y, lsbs_to_remove=cnp.AutoRounder(target_msbs=5))
|
||||
z = fhe.round_bit_pattern(y, lsbs_to_remove=fhe.AutoRounder(target_msbs=5))
|
||||
return np.sqrt(z).astype(np.int64)
|
||||
|
||||
with pytest.raises(RuntimeError) as excinfo:
|
||||
cnp.AutoRounder.adjust(function, range(10))
|
||||
fhe.AutoRounder.adjust(function, range(10))
|
||||
|
||||
assert str(excinfo.value) == (
|
||||
"AutoRounders cannot be constructed during adjustment, "
|
||||
|
||||
@@ -4,7 +4,7 @@ Tests of execution of shift operations.
|
||||
|
||||
import pytest
|
||||
|
||||
import concrete.numpy as cnp
|
||||
from concrete import fhe
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
@@ -45,7 +45,7 @@ def test_left_shift(function, parameters, helpers):
|
||||
parameter_encryption_statuses = helpers.generate_encryption_statuses(parameters)
|
||||
configuration = helpers.configuration()
|
||||
|
||||
compiler = cnp.Compiler(function, parameter_encryption_statuses)
|
||||
compiler = fhe.Compiler(function, parameter_encryption_statuses)
|
||||
|
||||
inputset = helpers.generate_inputset(parameters)
|
||||
circuit = compiler.compile(inputset, configuration)
|
||||
@@ -92,7 +92,7 @@ def test_right_shift(function, parameters, helpers):
|
||||
parameter_encryption_statuses = helpers.generate_encryption_statuses(parameters)
|
||||
configuration = helpers.configuration()
|
||||
|
||||
compiler = cnp.Compiler(function, parameter_encryption_statuses)
|
||||
compiler = fhe.Compiler(function, parameter_encryption_statuses)
|
||||
|
||||
inputset = helpers.generate_inputset(parameters)
|
||||
circuit = compiler.compile(inputset, configuration)
|
||||
@@ -127,7 +127,7 @@ def test_left_shift_coverage(function, parameters, helpers):
|
||||
parameter_encryption_statuses = helpers.generate_encryption_statuses(parameters)
|
||||
configuration = helpers.configuration()
|
||||
|
||||
compiler = cnp.Compiler(function, parameter_encryption_statuses)
|
||||
compiler = fhe.Compiler(function, parameter_encryption_statuses)
|
||||
|
||||
inputset = helpers.generate_inputset(parameters)
|
||||
circuit = compiler.compile(inputset, configuration)
|
||||
@@ -163,7 +163,7 @@ def test_right_shift_coverage(function, parameters, helpers):
|
||||
parameter_encryption_statuses = helpers.generate_encryption_statuses(parameters)
|
||||
configuration = helpers.configuration()
|
||||
|
||||
compiler = cnp.Compiler(function, parameter_encryption_statuses)
|
||||
compiler = fhe.Compiler(function, parameter_encryption_statuses)
|
||||
|
||||
inputset = helpers.generate_inputset(parameters)
|
||||
circuit = compiler.compile(inputset, configuration)
|
||||
|
||||
@@ -5,7 +5,7 @@ Tests of execution of static assignment operation.
|
||||
import numpy as np
|
||||
import pytest
|
||||
|
||||
import concrete.numpy as cnp
|
||||
from concrete import fhe
|
||||
|
||||
|
||||
def assignment_case_0():
|
||||
@@ -483,7 +483,7 @@ def test_static_assignment(shape, function, helpers):
|
||||
"""
|
||||
|
||||
configuration = helpers.configuration()
|
||||
compiler = cnp.Compiler(function, {"x": "encrypted"})
|
||||
compiler = fhe.Compiler(function, {"x": "encrypted"})
|
||||
|
||||
inputset = [np.random.randint(0, 2**7, size=shape) for _ in range(100)]
|
||||
circuit = compiler.compile(inputset, configuration)
|
||||
@@ -506,7 +506,7 @@ def test_bad_static_assignment(helpers):
|
||||
x[1.5] = 0
|
||||
return x
|
||||
|
||||
compiler = cnp.Compiler(f, {"x": "encrypted"})
|
||||
compiler = fhe.Compiler(f, {"x": "encrypted"})
|
||||
|
||||
inputset = [np.random.randint(0, 2**3, size=(3,)) for _ in range(100)]
|
||||
with pytest.raises(ValueError) as excinfo:
|
||||
@@ -521,7 +521,7 @@ def test_bad_static_assignment(helpers):
|
||||
x[slice(1.5, 2.5, None)] = 0
|
||||
return x
|
||||
|
||||
compiler = cnp.Compiler(g, {"x": "encrypted"})
|
||||
compiler = fhe.Compiler(g, {"x": "encrypted"})
|
||||
|
||||
inputset = [np.random.randint(0, 2**3, size=(3,)) for _ in range(100)]
|
||||
with pytest.raises(ValueError) as excinfo:
|
||||
|
||||
@@ -5,7 +5,7 @@ Tests of execution of static indexing operation.
|
||||
import numpy as np
|
||||
import pytest
|
||||
|
||||
import concrete.numpy as cnp
|
||||
from concrete import fhe
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
@@ -159,7 +159,7 @@ def test_static_indexing(shape, function, helpers):
|
||||
"""
|
||||
|
||||
configuration = helpers.configuration()
|
||||
compiler = cnp.Compiler(function, {"x": "encrypted"})
|
||||
compiler = fhe.Compiler(function, {"x": "encrypted"})
|
||||
|
||||
inputset = [np.random.randint(0, 2**5, size=shape) for _ in range(100)]
|
||||
circuit = compiler.compile(inputset, configuration)
|
||||
@@ -178,7 +178,7 @@ def test_bad_static_indexing(helpers):
|
||||
# with float
|
||||
# ----------
|
||||
|
||||
compiler = cnp.Compiler(lambda x: x[1.5], {"x": "encrypted"})
|
||||
compiler = fhe.Compiler(lambda x: x[1.5], {"x": "encrypted"})
|
||||
|
||||
inputset = [np.random.randint(0, 2**3, size=(3,)) for _ in range(100)]
|
||||
with pytest.raises(ValueError) as excinfo:
|
||||
@@ -189,7 +189,7 @@ def test_bad_static_indexing(helpers):
|
||||
# with bad slice
|
||||
# --------------
|
||||
|
||||
compiler = cnp.Compiler(lambda x: x[slice(1.5, 2.5, None)], {"x": "encrypted"})
|
||||
compiler = fhe.Compiler(lambda x: x[slice(1.5, 2.5, None)], {"x": "encrypted"})
|
||||
|
||||
inputset = [np.random.randint(0, 2**3, size=(3,)) for _ in range(100)]
|
||||
with pytest.raises(ValueError) as excinfo:
|
||||
|
||||
@@ -5,7 +5,7 @@ Tests of execution of sub operation.
|
||||
import numpy as np
|
||||
import pytest
|
||||
|
||||
import concrete.numpy as cnp
|
||||
from concrete import fhe
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
@@ -59,7 +59,7 @@ def test_constant_sub(function, parameters, helpers):
|
||||
parameter_encryption_statuses = helpers.generate_encryption_statuses(parameters)
|
||||
configuration = helpers.configuration()
|
||||
|
||||
compiler = cnp.Compiler(function, parameter_encryption_statuses)
|
||||
compiler = fhe.Compiler(function, parameter_encryption_statuses)
|
||||
|
||||
inputset = helpers.generate_inputset(parameters)
|
||||
circuit = compiler.compile(inputset, configuration)
|
||||
@@ -150,7 +150,7 @@ def test_sub(function, parameters, helpers):
|
||||
parameter_encryption_statuses = helpers.generate_encryption_statuses(parameters)
|
||||
configuration = helpers.configuration()
|
||||
|
||||
compiler = cnp.Compiler(function, parameter_encryption_statuses)
|
||||
compiler = fhe.Compiler(function, parameter_encryption_statuses)
|
||||
|
||||
inputset = helpers.generate_inputset(parameters)
|
||||
circuit = compiler.compile(inputset, configuration)
|
||||
|
||||
@@ -5,7 +5,7 @@ Tests of execution of sum operation.
|
||||
import numpy as np
|
||||
import pytest
|
||||
|
||||
import concrete.numpy as cnp
|
||||
from concrete import fhe
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
@@ -111,7 +111,7 @@ def test_sum(function, parameters, helpers):
|
||||
parameter_encryption_statuses = helpers.generate_encryption_statuses(parameters)
|
||||
configuration = helpers.configuration()
|
||||
|
||||
compiler = cnp.Compiler(function, parameter_encryption_statuses)
|
||||
compiler = fhe.Compiler(function, parameter_encryption_statuses)
|
||||
|
||||
inputset = helpers.generate_inputset(parameters)
|
||||
circuit = compiler.compile(inputset, configuration)
|
||||
|
||||
@@ -5,7 +5,7 @@ Tests of execution of transpose operation.
|
||||
import numpy as np
|
||||
import pytest
|
||||
|
||||
import concrete.numpy as cnp
|
||||
from concrete import fhe
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
@@ -69,7 +69,7 @@ def test_transpose(function, parameters, helpers):
|
||||
parameter_encryption_statuses = helpers.generate_encryption_statuses(parameters)
|
||||
configuration = helpers.configuration()
|
||||
|
||||
compiler = cnp.Compiler(function, parameter_encryption_statuses)
|
||||
compiler = fhe.Compiler(function, parameter_encryption_statuses)
|
||||
|
||||
inputset = helpers.generate_inputset(parameters)
|
||||
circuit = compiler.compile(inputset, configuration)
|
||||
|
||||
@@ -6,31 +6,31 @@ import random
|
||||
|
||||
import pytest
|
||||
|
||||
import concrete.numpy as cnp
|
||||
from concrete import fhe
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"function",
|
||||
[
|
||||
pytest.param(
|
||||
lambda x: cnp.zero() + x,
|
||||
id="cnp.zero() + x",
|
||||
lambda x: fhe.zero() + x,
|
||||
id="fhe.zero() + x",
|
||||
),
|
||||
pytest.param(
|
||||
lambda x: cnp.zeros(()) + x,
|
||||
id="cnp.zeros(()) + x",
|
||||
lambda x: fhe.zeros(()) + x,
|
||||
id="fhe.zeros(()) + x",
|
||||
),
|
||||
pytest.param(
|
||||
lambda x: cnp.zeros(10) + x,
|
||||
id="cnp.zeros(10) + x",
|
||||
lambda x: fhe.zeros(10) + x,
|
||||
id="fhe.zeros(10) + x",
|
||||
),
|
||||
pytest.param(
|
||||
lambda x: cnp.zeros((10,)) + x,
|
||||
id="cnp.zeros((10,)) + x",
|
||||
lambda x: fhe.zeros((10,)) + x,
|
||||
id="fhe.zeros((10,)) + x",
|
||||
),
|
||||
pytest.param(
|
||||
lambda x: cnp.zeros((3, 2)) + x,
|
||||
id="cnp.zeros((3, 2)) + x",
|
||||
lambda x: fhe.zeros((3, 2)) + x,
|
||||
id="fhe.zeros((3, 2)) + x",
|
||||
),
|
||||
],
|
||||
)
|
||||
@@ -40,7 +40,7 @@ def test_zeros(function, helpers):
|
||||
"""
|
||||
|
||||
configuration = helpers.configuration()
|
||||
compiler = cnp.Compiler(function, {"x": "encrypted"})
|
||||
compiler = fhe.Compiler(function, {"x": "encrypted"})
|
||||
|
||||
inputset = range(10)
|
||||
circuit = compiler.compile(inputset, configuration)
|
||||
|
||||
@@ -4,14 +4,14 @@ Tests of 'array' extension.
|
||||
|
||||
import pytest
|
||||
|
||||
import concrete.numpy as cnp
|
||||
from concrete import fhe
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"function,parameters,expected_error",
|
||||
[
|
||||
pytest.param(
|
||||
lambda x, y: cnp.array([x, y]),
|
||||
lambda x, y: fhe.array([x, y]),
|
||||
{
|
||||
"x": {"range": [0, 10], "status": "encrypted", "shape": ()},
|
||||
"y": {"range": [0, 10], "status": "encrypted", "shape": (2, 3)},
|
||||
@@ -28,7 +28,7 @@ def test_bad_array(function, parameters, expected_error, helpers):
|
||||
parameter_encryption_statuses = helpers.generate_encryption_statuses(parameters)
|
||||
configuration = helpers.configuration()
|
||||
|
||||
compiler = cnp.Compiler(function, parameter_encryption_statuses)
|
||||
compiler = fhe.Compiler(function, parameter_encryption_statuses)
|
||||
|
||||
with pytest.raises(ValueError) as excinfo:
|
||||
inputset = helpers.generate_inputset(parameters)
|
||||
|
||||
@@ -4,7 +4,7 @@ Tests of 'LookupTable' extension.
|
||||
|
||||
import pytest
|
||||
|
||||
from concrete.numpy import LookupTable
|
||||
from concrete.fhe import LookupTable
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
|
||||
@@ -4,7 +4,7 @@ Tests of 'tag' extension.
|
||||
|
||||
import numpy as np
|
||||
|
||||
import concrete.numpy as cnp
|
||||
from concrete import fhe
|
||||
|
||||
|
||||
def test_tag(helpers):
|
||||
@@ -13,16 +13,16 @@ def test_tag(helpers):
|
||||
"""
|
||||
|
||||
def g(z):
|
||||
with cnp.tag("def"):
|
||||
with fhe.tag("def"):
|
||||
a = 120 - z
|
||||
b = a // 4
|
||||
return b
|
||||
|
||||
@cnp.compiler({"x": "encrypted"})
|
||||
@fhe.compiler({"x": "encrypted"})
|
||||
def f(x):
|
||||
with cnp.tag("abc"):
|
||||
with fhe.tag("abc"):
|
||||
x = x * 2
|
||||
with cnp.tag("foo"):
|
||||
with fhe.tag("foo"):
|
||||
y = x + 42
|
||||
z = np.sqrt(y).astype(np.int64)
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ Tests of 'univariate' extension.
|
||||
|
||||
import pytest
|
||||
|
||||
import concrete.numpy as cnp
|
||||
from concrete import fhe
|
||||
|
||||
|
||||
def test_bad_univariate(helpers):
|
||||
@@ -14,11 +14,11 @@ def test_bad_univariate(helpers):
|
||||
|
||||
with pytest.raises(ValueError) as excinfo:
|
||||
|
||||
@cnp.circuit({"x": "encrypted"}, helpers.configuration())
|
||||
def function(x: cnp.uint3):
|
||||
return cnp.univariate(lambda x: x**2)(x)
|
||||
@fhe.circuit({"x": "encrypted"}, helpers.configuration())
|
||||
def function(x: fhe.uint3):
|
||||
return fhe.univariate(lambda x: x**2)(x)
|
||||
|
||||
assert str(excinfo.value) == (
|
||||
"Univariate extension requires `outputs` argument for direct circuit definition "
|
||||
"(e.g., cnp.univariate(function, outputs=cnp.uint4)(x))"
|
||||
"(e.g., fhe.univariate(function, outputs=fhe.uint4)(x))"
|
||||
)
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
"""
|
||||
Tests of `concrete.numpy.internal` namespace.
|
||||
Tests of `concrete.fhe.internal` namespace.
|
||||
"""
|
||||
|
||||
@@ -4,7 +4,7 @@ Tests of utilities related to the entire project.
|
||||
|
||||
import pytest
|
||||
|
||||
from concrete.numpy.internal.utils import assert_that, unreachable
|
||||
from concrete.fhe.internal.utils import assert_that, unreachable
|
||||
|
||||
|
||||
def test_assert_that():
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
"""
|
||||
Tests of `concrete.numpy.mlir` namespace.
|
||||
Tests of `concrete.fhe.mlir` namespace.
|
||||
"""
|
||||
|
||||
@@ -5,10 +5,8 @@ Tests of `GraphConverter` class.
|
||||
import numpy as np
|
||||
import pytest
|
||||
|
||||
import concrete.numpy as cnp
|
||||
import concrete.onnx as connx
|
||||
|
||||
# pylint: disable=line-too-long
|
||||
from concrete import fhe
|
||||
|
||||
|
||||
def assign(x):
|
||||
@@ -451,7 +449,7 @@ def test_graph_converter_bad_convert(
|
||||
"""
|
||||
|
||||
configuration = helpers.configuration()
|
||||
compiler = cnp.Compiler(function, encryption_statuses)
|
||||
compiler = fhe.Compiler(function, encryption_statuses)
|
||||
|
||||
with pytest.raises(expected_error) as excinfo:
|
||||
compiler.compile(inputset, configuration)
|
||||
@@ -463,7 +461,7 @@ def test_graph_converter_bad_convert(
|
||||
"function,inputset,expected_mlir",
|
||||
[
|
||||
pytest.param(
|
||||
lambda x: 1 + cnp.LookupTable([4, 1, 2, 3])[x] + cnp.LookupTable([4, 1, 2, 3])[x + 1],
|
||||
lambda x: 1 + fhe.LookupTable([4, 1, 2, 3])[x] + fhe.LookupTable([4, 1, 2, 3])[x + 1],
|
||||
range(3),
|
||||
"""
|
||||
|
||||
@@ -492,7 +490,7 @@ def test_constant_cache(function, inputset, expected_mlir, helpers):
|
||||
|
||||
configuration = helpers.configuration()
|
||||
|
||||
compiler = cnp.Compiler(function, {"x": "encrypted"})
|
||||
compiler = fhe.Compiler(function, {"x": "encrypted"})
|
||||
circuit = compiler.compile(inputset, configuration)
|
||||
|
||||
helpers.check_str(expected_mlir, circuit.mlir)
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
"""
|
||||
Tests of `concrete.numpy.representation` namespace.
|
||||
Tests of `concrete.fhe.representation` namespace.
|
||||
"""
|
||||
|
||||
@@ -8,8 +8,8 @@ import re
|
||||
import numpy as np
|
||||
import pytest
|
||||
|
||||
import concrete.numpy as cnp
|
||||
import tests
|
||||
from concrete import fhe
|
||||
|
||||
tests_directory = os.path.dirname(tests.__file__)
|
||||
|
||||
@@ -19,7 +19,7 @@ def g(z):
|
||||
Example function with a tag.
|
||||
"""
|
||||
|
||||
with cnp.tag("def"):
|
||||
with fhe.tag("def"):
|
||||
a = 120 - z
|
||||
b = a // 4
|
||||
return b
|
||||
@@ -30,9 +30,9 @@ def f(x):
|
||||
Example function with nested tags.
|
||||
"""
|
||||
|
||||
with cnp.tag("abc"):
|
||||
with fhe.tag("abc"):
|
||||
x = x * 2
|
||||
with cnp.tag("foo"):
|
||||
with fhe.tag("foo"):
|
||||
y = x + 42
|
||||
z = np.sqrt(y).astype(np.int64)
|
||||
|
||||
@@ -177,7 +177,7 @@ def test_graph_maximum_integer_bit_width(
|
||||
|
||||
configuration = helpers.configuration()
|
||||
|
||||
compiler = cnp.Compiler(function, {"x": "encrypted"})
|
||||
compiler = fhe.Compiler(function, {"x": "encrypted"})
|
||||
graph = compiler.trace(inputset, configuration)
|
||||
|
||||
assert graph.maximum_integer_bit_width(tag_filter, operation_filter) == expected_result
|
||||
@@ -307,7 +307,7 @@ def test_graph_integer_range(
|
||||
|
||||
configuration = helpers.configuration()
|
||||
|
||||
compiler = cnp.Compiler(function, {"x": "encrypted"})
|
||||
compiler = fhe.Compiler(function, {"x": "encrypted"})
|
||||
graph = compiler.trace(inputset, configuration)
|
||||
|
||||
assert graph.integer_range(tag_filter, operation_filter) == expected_result
|
||||
@@ -320,7 +320,7 @@ def test_graph_format_show_lines(helpers):
|
||||
|
||||
configuration = helpers.configuration()
|
||||
|
||||
compiler = cnp.Compiler(f, {"x": "encrypted"})
|
||||
compiler = fhe.Compiler(f, {"x": "encrypted"})
|
||||
graph = compiler.trace(range(10), configuration)
|
||||
|
||||
# pylint: disable=line-too-long
|
||||
|
||||
@@ -5,9 +5,9 @@ Tests of `Node` class.
|
||||
import numpy as np
|
||||
import pytest
|
||||
|
||||
from concrete.numpy.dtypes import UnsignedInteger
|
||||
from concrete.numpy.representation import Node
|
||||
from concrete.numpy.values import ClearScalar, EncryptedScalar, EncryptedTensor, Value
|
||||
from concrete.fhe.dtypes import UnsignedInteger
|
||||
from concrete.fhe.representation import Node
|
||||
from concrete.fhe.values import ClearScalar, EncryptedScalar, EncryptedTensor, Value
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
|
||||
@@ -4,7 +4,7 @@ Tests of utilities related to representation of computation.
|
||||
import numpy as np
|
||||
import pytest
|
||||
|
||||
from concrete.numpy.representation.utils import format_constant
|
||||
from concrete.fhe.representation.utils import format_constant
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
"""
|
||||
Tests of `concrete.numpy.tracing` namespace.
|
||||
Tests of `concrete.fhe.tracing` namespace.
|
||||
"""
|
||||
|
||||
@@ -5,10 +5,10 @@ Tests of `Tracer` class.
|
||||
import numpy as np
|
||||
import pytest
|
||||
|
||||
from concrete.numpy.dtypes import UnsignedInteger
|
||||
from concrete.numpy.tracing import Tracer
|
||||
from concrete.numpy.tracing.typing import uint4
|
||||
from concrete.numpy.values import EncryptedTensor
|
||||
from concrete.fhe.dtypes import UnsignedInteger
|
||||
from concrete.fhe.tracing import Tracer
|
||||
from concrete.fhe.tracing.typing import uint4
|
||||
from concrete.fhe.values import EncryptedTensor
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
@@ -42,8 +42,8 @@ from concrete.numpy.values import EncryptedTensor
|
||||
lambda x: x.astype(uint4),
|
||||
{"x": EncryptedTensor(UnsignedInteger(7), shape=(4,))},
|
||||
ValueError,
|
||||
"`astype` method must be called with a "
|
||||
"numpy type for compilation (e.g., value.astype(np.int64))",
|
||||
"`astype` method must be called with a numpy type "
|
||||
"for compilation (e.g., value.astype(np.int64))",
|
||||
),
|
||||
pytest.param(
|
||||
lambda x: x + 1 if x else x + x,
|
||||
|
||||
@@ -4,7 +4,7 @@ Test type annotations.
|
||||
|
||||
import pytest
|
||||
|
||||
import concrete.numpy as cnp
|
||||
from concrete import fhe
|
||||
|
||||
|
||||
def test_bad_tensor():
|
||||
@@ -17,14 +17,14 @@ def test_bad_tensor():
|
||||
|
||||
with pytest.raises(ValueError) as excinfo:
|
||||
|
||||
def case1(x: cnp.tensor[int]):
|
||||
def case1(x: fhe.tensor[int]):
|
||||
return x
|
||||
|
||||
case1(None)
|
||||
|
||||
assert str(excinfo.value) == (
|
||||
"First argument to tensor annotations should be a "
|
||||
"concrete-numpy data type (e.g., cnp.uint4) not int"
|
||||
"First argument to tensor annotations should be "
|
||||
"an fhe data type (e.g., fhe.uint4) not int"
|
||||
)
|
||||
|
||||
# no shape
|
||||
@@ -32,13 +32,13 @@ def test_bad_tensor():
|
||||
|
||||
with pytest.raises(ValueError) as excinfo:
|
||||
|
||||
def case2(x: cnp.tensor[cnp.uint3]):
|
||||
def case2(x: fhe.tensor[fhe.uint3]):
|
||||
return x
|
||||
|
||||
case2(None)
|
||||
|
||||
assert str(excinfo.value) == (
|
||||
"Tensor annotations should have a shape (e.g., cnp.tensor[cnp.uint4, 3, 2])"
|
||||
"Tensor annotations should have a shape (e.g., fhe.tensor[fhe.uint4, 3, 2])"
|
||||
)
|
||||
|
||||
# bad shape
|
||||
@@ -46,7 +46,7 @@ def test_bad_tensor():
|
||||
|
||||
with pytest.raises(ValueError) as excinfo:
|
||||
|
||||
def case3(x: cnp.tensor[cnp.uint3, 1.5]):
|
||||
def case3(x: fhe.tensor[fhe.uint3, 1.5]):
|
||||
return x
|
||||
|
||||
case3(None)
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
"""
|
||||
Tests of `concrete.numpy.values` namespace.
|
||||
Tests of `concrete.fhe.values` namespace.
|
||||
"""
|
||||
|
||||
@@ -5,8 +5,8 @@ Tests of `Value` class.
|
||||
import numpy as np
|
||||
import pytest
|
||||
|
||||
from concrete.numpy.dtypes import Float, SignedInteger, UnsignedInteger
|
||||
from concrete.numpy.values import ClearScalar, ClearTensor, EncryptedScalar, EncryptedTensor, Value
|
||||
from concrete.fhe.dtypes import Float, SignedInteger, UnsignedInteger
|
||||
from concrete.fhe.values import ClearScalar, ClearTensor, EncryptedScalar, EncryptedTensor, Value
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
|
||||
Reference in New Issue
Block a user