mirror of
https://github.com/zama-ai/concrete.git
synced 2026-02-17 08:01:20 -05:00
This commit: + Adds support for a protocol which enables inter-op between concrete, tfhe-rs and potentially other contributors to the fhe ecosystem. + Gets rid of hand-made serialization in the compiler, and client/server libs. + Refactors client/server libs to allow more pre/post processing of circuit inputs/outputs. The protocol is supported by a definition in the shape of a capnp file, which defines different types of objects among which: + ProgramInfo object, which is a precise description of a set of fhe circuit coming from the same compilation (understand function type information), and the associated key set. + *Key objects, which represent secret/public keys used to encrypt/execute fhe circuits. + Value object, which represent values that can be transferred between client and server to support calls to fhe circuits. The hand-rolled serialization that was previously used is completely dropped in favor of capnp in the whole codebase. The client/server libs, are refactored to introduce a modular design for pre-post processing. Reading the ProgramInfo file associated with a compilation, the client and server libs assemble a pipeline of transformers (functions) for pre and post processing of values coming in and out of a circuit. This design properly decouples various aspects of the processing, and allows these capabilities to be safely extended. In practice this commit includes the following: + Defines the specification in a concreteprotocol package + Integrate the compilation of this package as a compiler dependency via cmake + Modify the compiler to use the Encodings objects defined in the protocol + Modify the compiler to emit ProgramInfo files as compilation artifact, and gets rid of the bloated ClientParameters. + Introduces a new Common library containing the functionalities shared between the compiler and the client/server libs. + Introduces a functional pre-post processing pipeline to this common library + Modify the client/server libs to support loading ProgramInfo objects, and calling circuits using Value messages. + Drops support of JIT. + Drops support of C-api. + Drops support of Rust bindings. Co-authored-by: Nikita Frolov <nf@mkmks.org>
77 lines
2.4 KiB
Python
77 lines
2.4 KiB
Python
import pytest
|
|
import numpy as np
|
|
from concrete.compiler.utils import ACCEPTED_NUMPY_UINTS
|
|
from concrete.compiler import ClientSupport
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"garbage",
|
|
[
|
|
pytest.param(None, id="None"),
|
|
pytest.param([0, 1, 2], id="list"),
|
|
pytest.param(0.5, id="float"),
|
|
pytest.param(2**70, id="large int"),
|
|
pytest.param("aze", id="str"),
|
|
pytest.param(np.float64(0.8), id="np.float64"),
|
|
],
|
|
)
|
|
def test_invalid_arg_type(garbage):
|
|
with pytest.raises(TypeError):
|
|
ClientSupport._create_lambda_argument(garbage, signed=False)
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"value",
|
|
[
|
|
pytest.param(5, id="int"),
|
|
pytest.param(np.uint8(5), id="uint8"),
|
|
pytest.param(np.uint16(7), id="uint16"),
|
|
pytest.param(np.uint32(9), id="uint32"),
|
|
pytest.param(np.uint64(1), id="uint64"),
|
|
],
|
|
)
|
|
def test_accepted_ints(value):
|
|
try:
|
|
arg = ClientSupport._create_lambda_argument(value, signed=False)
|
|
except Exception:
|
|
pytest.fail(f"value of type {type(value)} should be supported")
|
|
assert arg.is_scalar(), "should have been a scalar"
|
|
assert arg.get_signed_scalar() == value
|
|
|
|
|
|
# TODO: #495
|
|
@pytest.mark.parametrize(
|
|
"dtype, maxvalue",
|
|
[
|
|
pytest.param(np.uint8, 2**8 - 1, id="uint8"),
|
|
pytest.param(np.uint16, 2**16 - 1, id="uint16"),
|
|
pytest.param(np.uint32, 2**32 - 1, id="uint32"),
|
|
pytest.param(np.uint64, 2**64 - 1, id="uint64"),
|
|
],
|
|
)
|
|
def test_accepted_ndarray(dtype, maxvalue):
|
|
value = np.array([0, 1, 2, maxvalue], dtype=dtype)
|
|
try:
|
|
arg = ClientSupport._create_lambda_argument(value, signed=False)
|
|
except Exception:
|
|
pytest.fail(f"value of type {type(value)} should be supported")
|
|
|
|
assert arg.is_tensor(), "should have been a tensor"
|
|
assert np.all(np.equal(arg.get_tensor_shape(), value.shape))
|
|
assert np.all(
|
|
np.equal(
|
|
value.astype(np.int64),
|
|
np.array(arg.get_signed_tensor_data()).reshape(arg.get_tensor_shape()),
|
|
)
|
|
)
|
|
|
|
|
|
def test_accepted_array_as_scalar():
|
|
value = np.array(7, dtype=np.uint16)
|
|
try:
|
|
arg = ClientSupport._create_lambda_argument(value, signed=False)
|
|
except Exception:
|
|
pytest.fail(f"value of type {type(value)} should be supported")
|
|
assert arg.is_scalar(), "should have been a scalar"
|
|
assert arg.get_signed_scalar() == value
|