mirror of
https://github.com/zama-ai/concrete.git
synced 2026-04-17 03:00:54 -04:00
chore: rename hdk to concrete first pass
This commit is contained in:
3
.github/workflows/package-watcher.yaml
vendored
3
.github/workflows/package-watcher.yaml
vendored
@@ -21,4 +21,5 @@ jobs:
|
||||
https://api.github.com/orgs/zama-ai/packages/container/zamalang-compiler/versions \
|
||||
--env_img_url \
|
||||
https://api.github.com/orgs/zama-ai/packages/container/hdk-env/versions \
|
||||
--token ${{ secrets.BOT_TOKEN }}
|
||||
--token ${{ secrets.BOT_TOKEN }} \
|
||||
--org-repo ${{ github.repository }}
|
||||
|
||||
2
.gitignore
vendored
2
.gitignore
vendored
@@ -135,5 +135,5 @@ dmypy.json
|
||||
# pytest-benchmark results
|
||||
.benchmarks
|
||||
|
||||
# HDK compilation artifacts
|
||||
# concrete compilation artifacts
|
||||
.artifacts
|
||||
|
||||
22
Makefile
22
Makefile
@@ -2,6 +2,7 @@ SHELL:=/bin/bash
|
||||
|
||||
DEV_DOCKER_IMG:=hdk:dev
|
||||
DEV_DOCKERFILE:=docker/Dockerfile.hdk-dev
|
||||
SRC_DIR:=concrete
|
||||
|
||||
setup_env:
|
||||
poetry install
|
||||
@@ -17,12 +18,12 @@ sync_env:
|
||||
|
||||
python_format:
|
||||
poetry run env bash ./script/source_format/format_python.sh \
|
||||
--dir hdk --dir tests --dir benchmarks
|
||||
--dir $(SRC_DIR) --dir tests --dir benchmarks
|
||||
.PHONY: python_format
|
||||
|
||||
check_python_format:
|
||||
poetry run env bash ./script/source_format/format_python.sh \
|
||||
--dir hdk --dir tests --dir benchmarks --check
|
||||
--dir $(SRC_DIR) --dir tests --dir benchmarks --check
|
||||
.PHONY: check_python_format
|
||||
|
||||
check_strip_nb:
|
||||
@@ -34,7 +35,7 @@ pylint:
|
||||
.PHONY: pylint
|
||||
|
||||
pylint_src:
|
||||
poetry run pylint --rcfile=pylintrc hdk
|
||||
poetry run pylint --rcfile=pylintrc $(SRC_DIR)
|
||||
.PHONY: pylint_src
|
||||
|
||||
pylint_tests:
|
||||
@@ -49,7 +50,7 @@ pylint_benchmarks:
|
||||
|
||||
flake8:
|
||||
poetry run flake8 --max-line-length 100 --per-file-ignores="__init__.py:F401" \
|
||||
hdk/ tests/ benchmarks/
|
||||
$(SRC_DIR)/ tests/ benchmarks/
|
||||
.PHONY: flake8
|
||||
|
||||
python_linting: pylint flake8
|
||||
@@ -67,18 +68,19 @@ pcc_internal: check_python_format check_strip_nb python_linting mypy_ci pydocsty
|
||||
.PHONY: pcc_internal
|
||||
|
||||
pytest:
|
||||
poetry run pytest -svv --cov=hdk --cov-report=term-missing:skip-covered --cov-report=xml tests/
|
||||
poetry run pytest -svv \
|
||||
--cov=$(SRC_DIR) --cov-report=term-missing:skip-covered --cov-report=xml tests/
|
||||
.PHONY: pytest
|
||||
|
||||
# Not a huge fan of ignoring missing imports, but some packages do not have typing stubs
|
||||
mypy:
|
||||
poetry run mypy -p hdk --ignore-missing-imports
|
||||
poetry run mypy -p $(SRC_DIR) --ignore-missing-imports
|
||||
.PHONY: mypy
|
||||
|
||||
# Friendly target to run mypy without ignoring missing stubs and still have errors messages
|
||||
# Allows to see which stubs we are missing
|
||||
mypy_ns:
|
||||
poetry run mypy -p hdk
|
||||
poetry run mypy -p $(SRC_DIR)
|
||||
.PHONY: mypy_ns
|
||||
|
||||
mypy_test:
|
||||
@@ -118,7 +120,7 @@ docker_start:
|
||||
docker run --rm -it \
|
||||
-p 8888:8888 \
|
||||
--env DISPLAY=host.docker.internal:0 \
|
||||
--volume /"$$(pwd)":/hdk \
|
||||
--volume /"$$(pwd)":/src \
|
||||
$(DEV_DOCKER_IMG)
|
||||
.PHONY: docker_start
|
||||
|
||||
@@ -130,7 +132,7 @@ docker_bas: docker_build_and_start
|
||||
|
||||
docs: clean_docs
|
||||
@# Generate the auto summary of documentations
|
||||
poetry run sphinx-apidoc -o docs/_apidoc hdk
|
||||
poetry run sphinx-apidoc -o docs/_apidoc $(SRC_DIR)
|
||||
|
||||
@# Docs
|
||||
cd docs && poetry run $(MAKE) html SPHINXOPTS='-W --keep-going'
|
||||
@@ -150,7 +152,7 @@ build_and_open_docs: clean_docs docs open_docs
|
||||
|
||||
pydocstyle:
|
||||
@# From http://www.pydocstyle.org/en/stable/error_codes.html
|
||||
poetry run pydocstyle hdk --convention google --add-ignore=D1,D202
|
||||
poetry run pydocstyle $(SRC_DIR) --convention google --add-ignore=D1,D202
|
||||
.PHONY: pydocstyle
|
||||
|
||||
strip_nb:
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# hdk
|
||||
# concretefhe
|
||||
|
||||
Homomorphic Development Framework - collection of tools to FHE all the things
|
||||
Concrete Framework Python API - collection of tools to FHE all the things
|
||||
|
||||
Developers can take a look at [ARCHITECTURE.md](docs/dev/ARCHITECTURE.md) to get the big picture and [GETTING-STARTED.md](docs/dev/GETTING-STARTED.md) to start developing.
|
||||
Developers can take a look at [GETTING-STARTED.md](docs/dev/GETTING-STARTED.md) to get all the relevant informations on the project.
|
||||
|
||||
@@ -4,7 +4,7 @@ import itertools
|
||||
|
||||
import pytest
|
||||
|
||||
import hdk.numpy as hnp
|
||||
import concrete.numpy as hnp
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
"""Converter functions from HDKIR to MLIR.
|
||||
"""Converter functions from the common IR to MLIR.
|
||||
|
||||
Converter functions all have the same signature `converter(node, preds, ir_to_mlir_node, ctx)`
|
||||
- `node`: IntermediateNode to be converted
|
||||
@@ -30,13 +30,13 @@ from ..representation import intermediate as ir
|
||||
|
||||
|
||||
class MLIRConverter:
|
||||
"""Converter of the HDKIR to MLIR."""
|
||||
"""Converter of the common IR to MLIR."""
|
||||
|
||||
def __init__(self, conversion_functions: dict) -> None:
|
||||
"""Instantiate a converter with a given set of converters.
|
||||
|
||||
Args:
|
||||
conversion_functions (dict): mapping HDKIR nodes to functions that generate MLIR.
|
||||
conversion_functions (dict): mapping common IR nodes to functions that generate MLIR.
|
||||
every function should have 4 arguments:
|
||||
- node (IntermediateNode): the node itself to be converted
|
||||
- operands (IntermediateNode): predecessors of node ordered as operands
|
||||
@@ -97,8 +97,8 @@ class MLIRConverter:
|
||||
# unsigned integer are considered signless in the compiler
|
||||
return IntegerType.get_signless(bit_width)
|
||||
|
||||
def hdk_value_to_mlir_type(self, value: values.BaseValue) -> MLIRType:
|
||||
"""Convert an HDK value to its corresponding MLIR Type.
|
||||
def common_value_to_mlir_type(self, value: values.BaseValue) -> MLIRType:
|
||||
"""Convert a common value to its corresponding MLIR Type.
|
||||
|
||||
Args:
|
||||
value: value to convert
|
||||
@@ -147,7 +147,7 @@ class MLIRConverter:
|
||||
# collect inputs
|
||||
with InsertionPoint(module.body):
|
||||
func_types = [
|
||||
self.hdk_value_to_mlir_type(input_node.inputs[0])
|
||||
self.common_value_to_mlir_type(input_node.inputs[0])
|
||||
for input_node in op_graph.get_ordered_inputs()
|
||||
]
|
||||
|
||||
@@ -17,7 +17,7 @@ from ..common.data_types.floats import Float
|
||||
from ..common.data_types.integers import Integer
|
||||
from ..common.values import BaseValue, ScalarValue, TensorValue
|
||||
|
||||
NUMPY_TO_HDK_DTYPE_MAPPING: Dict[numpy.dtype, BaseDataType] = {
|
||||
NUMPY_TO_COMMON_DTYPE_MAPPING: Dict[numpy.dtype, BaseDataType] = {
|
||||
numpy.dtype(numpy.int32): Integer(32, is_signed=True),
|
||||
numpy.dtype(numpy.int64): Integer(64, is_signed=True),
|
||||
numpy.dtype(numpy.uint32): Integer(32, is_signed=False),
|
||||
@@ -26,8 +26,8 @@ NUMPY_TO_HDK_DTYPE_MAPPING: Dict[numpy.dtype, BaseDataType] = {
|
||||
numpy.dtype(numpy.float64): Float(64),
|
||||
}
|
||||
|
||||
SUPPORTED_NUMPY_DTYPES = tuple(NUMPY_TO_HDK_DTYPE_MAPPING)
|
||||
SUPPORTED_NUMPY_DTYPES_CLASS_TYPES = tuple(dtype.type for dtype in NUMPY_TO_HDK_DTYPE_MAPPING)
|
||||
SUPPORTED_NUMPY_DTYPES = tuple(NUMPY_TO_COMMON_DTYPE_MAPPING)
|
||||
SUPPORTED_NUMPY_DTYPES_CLASS_TYPES = tuple(dtype.type for dtype in NUMPY_TO_COMMON_DTYPE_MAPPING)
|
||||
|
||||
SUPPORTED_DTYPE_MSG_STRING = ", ".join(sorted(str(dtype) for dtype in SUPPORTED_NUMPY_DTYPES))
|
||||
|
||||
@@ -46,9 +46,9 @@ def convert_numpy_dtype_to_base_data_type(numpy_dtype: DTypeLike) -> BaseDataTyp
|
||||
"""
|
||||
# Normalize numpy_dtype
|
||||
normalized_numpy_dtype = numpy.dtype(numpy_dtype)
|
||||
corresponding_hdk_dtype = NUMPY_TO_HDK_DTYPE_MAPPING.get(normalized_numpy_dtype, None)
|
||||
corresponding_common_dtype = NUMPY_TO_COMMON_DTYPE_MAPPING.get(normalized_numpy_dtype, None)
|
||||
|
||||
if corresponding_hdk_dtype is None:
|
||||
if corresponding_common_dtype is None:
|
||||
raise ValueError(
|
||||
f"Unsupported numpy type: {numpy_dtype} ({normalized_numpy_dtype}), "
|
||||
f"supported numpy types: "
|
||||
@@ -56,7 +56,7 @@ def convert_numpy_dtype_to_base_data_type(numpy_dtype: DTypeLike) -> BaseDataTyp
|
||||
)
|
||||
|
||||
# deepcopy to avoid having the value from the dict modified
|
||||
return deepcopy(corresponding_hdk_dtype)
|
||||
return deepcopy(corresponding_common_dtype)
|
||||
|
||||
|
||||
def convert_base_data_type_to_numpy_dtype(common_dtype: BaseDataType) -> numpy.dtype:
|
||||
@@ -1,14 +1,16 @@
|
||||
FROM ghcr.io/zama-ai/hdk-env
|
||||
|
||||
RUN echo "source /hdk/.docker_venv/bin/activate" >> /root/.bashrc && \
|
||||
ENV SRC_DIR_NAME=src
|
||||
|
||||
RUN echo "source /${SRC_DIR_NAME}/.docker_venv/bin/activate" >> /root/.bashrc && \
|
||||
echo "if [[ \"\$?\" != \"0\" ]]; then" >> /root/.bashrc && \
|
||||
echo " python3 -m venv /hdk/.docker_venv" >> /root/.bashrc && \
|
||||
echo " source /hdk/.docker_venv/bin/activate" >> /root/.bashrc && \
|
||||
echo " cd /hdk/ && make setup_env" >> /root/.bashrc && \
|
||||
echo " python3 -m venv /${SRC_DIR_NAME}/.docker_venv" >> /root/.bashrc && \
|
||||
echo " source /${SRC_DIR_NAME}/.docker_venv/bin/activate" >> /root/.bashrc && \
|
||||
echo " cd /${SRC_DIR_NAME}/ && make setup_env" >> /root/.bashrc && \
|
||||
echo "fi" >> /root/.bashrc && \
|
||||
echo "export LD_PRELOAD=/compiler/build/lib/Runtime/libZamalangRuntime.so" >> /root/.bashrc && \
|
||||
echo "export MPLBACKEND=TkAgg" >> /root/.bashrc
|
||||
|
||||
WORKDIR /hdk
|
||||
WORKDIR /${SRC_DIR_NAME}
|
||||
|
||||
ENTRYPOINT ["/bin/bash", "-l"]
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
# Compilation Pipeline In Depth
|
||||
|
||||
## What is HDK?
|
||||
## What is concretefhe?
|
||||
|
||||
`HDK` is a framework for developing homomorphic applications.
|
||||
`concretefhe` is the python API of the `concrete` framework for developing homomorphic applications.
|
||||
One of its essential functionalities is to transform Python functions to their `MLIR` equivalent.
|
||||
Unfortunately, not all python functions can be converted due to the limits of current product (we are in the alpha stage), or sometimes due to inherent restrictions of FHE itself.
|
||||
However, one can already build interesting and impressing use cases, and more will be available in further versions of the framework.
|
||||
@@ -10,8 +10,8 @@ However, one can already build interesting and impressing use cases, and more wi
|
||||
## How can I use it?
|
||||
|
||||
```python
|
||||
# Import necessary HDK components
|
||||
import hdk.numpy as hnp
|
||||
# Import necessary concrete components
|
||||
import concrete.numpy as hnp
|
||||
|
||||
# Define the function to homomorphize
|
||||
def f(x, y):
|
||||
@@ -104,7 +104,7 @@ Tracing is also responsible for indicating whether the values in the node would
|
||||
|
||||
The goal of topological transforms is to make more functions compilable.
|
||||
|
||||
With the current version of `HDK` floating point inputs and floating point outputs are not supported.
|
||||
With the current version of `concrete` floating point inputs and floating point outputs are not supported.
|
||||
However, if the floating points operations are intermediate operations, they can sometimes be fused into a single table lookup from integer to integer thanks to some specific transforms.
|
||||
|
||||
Let's take a closer look at the transforms we perform today.
|
||||
|
||||
@@ -34,7 +34,7 @@ The simplified graph of operations with the float subgraph condensed in an `Arbi
|
||||
|
||||

|
||||
|
||||
## How is it done in HDK?
|
||||
## How is it done in concretefhe?
|
||||
|
||||
The first step consists in detecting where we go from floating point computation back to integers. This allows to identify the potential terminal node of the float subgraph we are going to fuse.
|
||||
|
||||
|
||||
@@ -2,11 +2,11 @@
|
||||
|
||||
## Preparation
|
||||
|
||||
Before you can start improving `hdk` you need to set up your development environment! This section will show how you can do that.
|
||||
Before you can start improving `concretefhe` you need to set up your development environment! This section will show how you can do that.
|
||||
|
||||
### Installing Python v3.8
|
||||
|
||||
`hdk` is a `Python` library. So `Python` should be installed to develop `hdk`. `v3.8` is recommended because our CI also uses `v3.8`.
|
||||
`concretefhe` is a `Python` library. So `Python` should be installed to develop `concretefhe`. `v3.8` is recommended because our CI also uses `v3.8`.
|
||||
|
||||
You can follow [this](https://realpython.com/installing-python/) guide to install it (alternatively you can google `how to install python 3.8`).
|
||||
|
||||
@@ -41,10 +41,10 @@ On Windows check [this GitHub gist](https://gist.github.com/evanwill/0207876c324
|
||||
|
||||
### Cloning repository
|
||||
|
||||
Now, it's time to get the source code of `hdk`. You can use the following command to do that.
|
||||
Now, it's time to get the source code of `concretefhe`. You can use the following command to do that.
|
||||
|
||||
```shell
|
||||
git clone https://github.com/zama-ai/hdk.git
|
||||
git clone https://github.com/zama-ai/concretefhe-internal.git
|
||||
```
|
||||
|
||||
### Setting up environment
|
||||
@@ -52,7 +52,7 @@ git clone https://github.com/zama-ai/hdk.git
|
||||
We are going to make use of virtual environments. This helps to keep the project isolated from other `Python` projects in the system. The following commands will create a new virtual environment under the project directory and install dependencies to it.
|
||||
|
||||
```shell
|
||||
cd hdk
|
||||
cd concrete
|
||||
make setup_env
|
||||
```
|
||||
|
||||
@@ -95,9 +95,9 @@ In this section we will go over some terms that we use throughout the project.
|
||||
|
||||
## Module Structure
|
||||
|
||||
In this section, we will discuss the module structure of hdk briefly. You are encouraged to check individual `.py` files to learn more!
|
||||
In this section, we will discuss the module structure of concretefhe briefly. You are encouraged to check individual `.py` files to learn more!
|
||||
|
||||
- hdk
|
||||
- concrete
|
||||
- common: types and utilities that can be used by multiple frontends (e.g., numpy, torch)
|
||||
- bounds_measurement: utilities for determining bounds of intermediate representation
|
||||
- compilation: type definitions related to compilation (e.g., compilation config, compilation artifacts)
|
||||
@@ -106,7 +106,7 @@ In this section, we will discuss the module structure of hdk briefly. You are en
|
||||
- extensions: utilities that provide special functionality to our users
|
||||
- representation: type definitions of intermediate representation
|
||||
- tracing: utilities for generic function tracing used during intermediate representation creation
|
||||
- numpy: numpy frontend of hdk
|
||||
- numpy: numpy frontend of concrete
|
||||
|
||||
## Working in Docker
|
||||
|
||||
@@ -140,7 +140,7 @@ Install Xming and use Xlaunch:
|
||||
|
||||
### Logging in and building the image
|
||||
|
||||
Docker image of `hdk` is based on another docker image provided by the compiler team. Once you have access to this repository you should be able to launch the commands to build the dev docker image with `make docker_build`.
|
||||
Docker image of `concretefhe` is based on another docker image provided by the compiler team. Once you have access to this repository you should be able to launch the commands to build the dev docker image with `make docker_build`.
|
||||
|
||||
Upon joining to the team, you need to log in using the following command:
|
||||
|
||||
@@ -162,7 +162,7 @@ After you finish your work, you can leave the docker by using the `exit` command
|
||||
|
||||
Now, you have a working environment, and you know what is where in the project.
|
||||
|
||||
There are two ways to contribute to HDK:
|
||||
There are two ways to contribute to `concretefhe`:
|
||||
- you can open issues to report bugs, typos and suggest ideas
|
||||
- you can ask to become an official contributor by emailing hello@zama.ai. Only approved contributors can send pull requests, so please make sure to get in touch before you do!
|
||||
|
||||
@@ -185,7 +185,7 @@ git checkout -b fix/tracing_indexing_42
|
||||
|
||||
### Before committing
|
||||
|
||||
Each commit to `hdk` should be comformant to the standards decided by the team. Conformance can be checked using the following commands.
|
||||
Each commit to `concretefhe` should be comformant to the standards decided by the team. Conformance can be checked using the following commands.
|
||||
|
||||
```shell
|
||||
make -k pcc
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
"source": [
|
||||
"# Quantized Linear Regression\n",
|
||||
"\n",
|
||||
"Currently, **hdk** only supports unsigned integers up to 7-bits. Nevertheless, we want to evaluate a linear regression model with it. Luckily, we can make use of **quantization** to overcome this limitation!"
|
||||
"Currently, **concrete** only supports unsigned integers up to 7-bits. Nevertheless, we want to evaluate a linear regression model with it. Luckily, we can make use of **quantization** to overcome this limitation!"
|
||||
],
|
||||
"metadata": {}
|
||||
},
|
||||
@@ -547,7 +547,7 @@
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"source": [
|
||||
"### Let's import the hdk numpy package now!"
|
||||
"### Let's import the concrete numpy package now!"
|
||||
],
|
||||
"metadata": {}
|
||||
},
|
||||
@@ -555,7 +555,7 @@
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"source": [
|
||||
"import hdk.numpy as hnp"
|
||||
"import concrete.numpy as hnp"
|
||||
],
|
||||
"outputs": [],
|
||||
"metadata": {}
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
"source": [
|
||||
"# Quantized Logistic Regression\n",
|
||||
"\n",
|
||||
"Currently, **hdk** only supports unsigned integers up to 7-bits. Nevertheless, we want to evaluate a logistic regression model with it. Luckily, we can make use of **quantization** to overcome this limitation!"
|
||||
"Currently, **concrete** only supports unsigned integers up to 7-bits. Nevertheless, we want to evaluate a logistic regression model with it. Luckily, we can make use of **quantization** to overcome this limitation!"
|
||||
],
|
||||
"metadata": {}
|
||||
},
|
||||
@@ -642,7 +642,7 @@
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"source": [
|
||||
"### Let's import the hdk numpy package now!"
|
||||
"### Let's import the concrete numpy package now!"
|
||||
],
|
||||
"metadata": {}
|
||||
},
|
||||
@@ -650,7 +650,7 @@
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"source": [
|
||||
"import hdk.numpy as hnp"
|
||||
"import concrete.numpy as hnp"
|
||||
],
|
||||
"outputs": [],
|
||||
"metadata": {}
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
[tool.poetry]
|
||||
name = "hdk"
|
||||
name = "concretefhe"
|
||||
version = "0.1.0"
|
||||
description = "Zama Homomorphic Development frameworK"
|
||||
authors = ["Arthur Meyre <arthur.meyre@zama.ai>"]
|
||||
description = "Concrete Framework Python API"
|
||||
authors = ["A. Meyre", "U. Sahin", "A. Benaissa", "B. Chevallier", "Zama Team"]
|
||||
packages = [
|
||||
{ include = "concrete" },
|
||||
]
|
||||
|
||||
[tool.poetry.dependencies]
|
||||
python = ">=3.7,<3.10"
|
||||
|
||||
@@ -5,6 +5,7 @@ set -e
|
||||
BASE_IMG_ENDPOINT_URL=
|
||||
ENV_IMG_ENDPOINT_URL=
|
||||
TOKEN=
|
||||
ORG_REPO=
|
||||
|
||||
while [ -n "$1" ]
|
||||
do
|
||||
@@ -24,6 +25,11 @@ do
|
||||
TOKEN="$1"
|
||||
;;
|
||||
|
||||
"--org-repo" )
|
||||
shift
|
||||
ORG_REPO="$1"
|
||||
;;
|
||||
|
||||
*)
|
||||
echo "Unknown param : $1"
|
||||
exit -1
|
||||
@@ -63,7 +69,7 @@ if [[ "${BASE_IMG_DATE}" -ge "${ENV_IMG_DATE}" ]]; then
|
||||
-X POST \
|
||||
-H "Accept: application/vnd.github.v3+json" \
|
||||
-H "Authorization: token ${TOKEN}" \
|
||||
https://api.github.com/repos/zama-ai/hdk/dispatches \
|
||||
https://api.github.com/repos/${ORG_REPO}/dispatches \
|
||||
-d '{"event_type":"rebuild-docker"}'
|
||||
else
|
||||
echo "Image up to date, nothing to do."
|
||||
|
||||
@@ -4,11 +4,13 @@ from typing import Tuple
|
||||
|
||||
import pytest
|
||||
|
||||
from hdk.common.bounds_measurement.dataset_eval import eval_op_graph_bounds_on_dataset
|
||||
from hdk.common.data_types.floats import Float
|
||||
from hdk.common.data_types.integers import Integer
|
||||
from hdk.common.values import EncryptedScalar
|
||||
from hdk.numpy.tracing import trace_numpy_function
|
||||
from concrete.common.bounds_measurement.dataset_eval import (
|
||||
eval_op_graph_bounds_on_dataset,
|
||||
)
|
||||
from concrete.common.data_types.floats import Float
|
||||
from concrete.common.data_types.integers import Integer
|
||||
from concrete.common.values import EncryptedScalar
|
||||
from concrete.numpy.tracing import trace_numpy_function
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
|
||||
@@ -3,10 +3,10 @@
|
||||
import tempfile
|
||||
from pathlib import Path
|
||||
|
||||
from hdk.common.compilation import CompilationArtifacts
|
||||
from hdk.common.data_types.integers import UnsignedInteger
|
||||
from hdk.common.values import EncryptedScalar
|
||||
from hdk.numpy.compile import compile_numpy_function
|
||||
from concrete.common.compilation import CompilationArtifacts
|
||||
from concrete.common.data_types.integers import UnsignedInteger
|
||||
from concrete.common.values import EncryptedScalar
|
||||
from concrete.numpy.compile import compile_numpy_function
|
||||
|
||||
|
||||
def test_artifacts_export():
|
||||
|
||||
@@ -5,10 +5,10 @@ from inspect import signature
|
||||
import numpy
|
||||
import pytest
|
||||
|
||||
from hdk.common.compilation import CompilationConfiguration
|
||||
from hdk.common.data_types.integers import Integer
|
||||
from hdk.common.values import EncryptedScalar
|
||||
from hdk.numpy.compile import compile_numpy_function_into_op_graph
|
||||
from concrete.common.compilation import CompilationConfiguration
|
||||
from concrete.common.data_types.integers import Integer
|
||||
from concrete.common.values import EncryptedScalar
|
||||
from concrete.numpy.compile import compile_numpy_function_into_op_graph
|
||||
|
||||
|
||||
def no_fuse(x):
|
||||
|
||||
@@ -2,16 +2,16 @@
|
||||
|
||||
import pytest
|
||||
|
||||
from hdk.common.data_types.base import BaseDataType
|
||||
from hdk.common.data_types.dtypes_helpers import (
|
||||
from concrete.common.data_types.base import BaseDataType
|
||||
from concrete.common.data_types.dtypes_helpers import (
|
||||
find_type_to_hold_both_lossy,
|
||||
mix_values_determine_holding_dtype,
|
||||
value_is_encrypted_scalar_integer,
|
||||
value_is_encrypted_scalar_unsigned_integer,
|
||||
)
|
||||
from hdk.common.data_types.floats import Float
|
||||
from hdk.common.data_types.integers import Integer
|
||||
from hdk.common.values import (
|
||||
from concrete.common.data_types.floats import Float
|
||||
from concrete.common.data_types.integers import Integer
|
||||
from concrete.common.values import (
|
||||
BaseValue,
|
||||
ClearScalar,
|
||||
ClearTensor,
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
import pytest
|
||||
|
||||
from hdk.common.data_types.floats import Float, Float32, Float64
|
||||
from concrete.common.data_types.floats import Float, Float32, Float64
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
|
||||
@@ -4,7 +4,7 @@ import random
|
||||
|
||||
import pytest
|
||||
|
||||
from hdk.common.data_types.integers import (
|
||||
from concrete.common.data_types.integers import (
|
||||
Integer,
|
||||
SignedInteger,
|
||||
UnsignedInteger,
|
||||
|
||||
@@ -6,10 +6,10 @@ from typing import Callable, Optional, Tuple, Union
|
||||
|
||||
import pytest
|
||||
|
||||
from hdk.common.data_types.base import BaseDataType
|
||||
from hdk.common.data_types.floats import Float
|
||||
from hdk.common.data_types.integers import Integer
|
||||
from hdk.common.values import ClearTensor, EncryptedTensor, TensorValue
|
||||
from concrete.common.data_types.base import BaseDataType
|
||||
from concrete.common.data_types.floats import Float
|
||||
from concrete.common.data_types.integers import Integer
|
||||
from concrete.common.values import ClearTensor, EncryptedTensor, TensorValue
|
||||
|
||||
|
||||
class DummyDtype(BaseDataType):
|
||||
|
||||
@@ -3,10 +3,10 @@
|
||||
import tempfile
|
||||
from pathlib import Path
|
||||
|
||||
from hdk.common.data_types.integers import Integer
|
||||
from hdk.common.debugging import draw_graph
|
||||
from hdk.common.values import EncryptedScalar
|
||||
from hdk.numpy.compile import compile_numpy_function_into_op_graph
|
||||
from concrete.common.data_types.integers import Integer
|
||||
from concrete.common.debugging import draw_graph
|
||||
from concrete.common.values import EncryptedScalar
|
||||
from concrete.numpy.compile import compile_numpy_function_into_op_graph
|
||||
|
||||
|
||||
def test_draw_graph_with_saving():
|
||||
|
||||
@@ -5,12 +5,12 @@ from copy import deepcopy
|
||||
import networkx as nx
|
||||
import pytest
|
||||
|
||||
from hdk.common import is_a_power_of_2
|
||||
from hdk.common.data_types.integers import Integer
|
||||
from hdk.common.extensions.table import LookupTable
|
||||
from hdk.common.representation import intermediate as ir
|
||||
from hdk.common.values import EncryptedScalar
|
||||
from hdk.numpy import tracing
|
||||
from concrete.common import is_a_power_of_2
|
||||
from concrete.common.data_types.integers import Integer
|
||||
from concrete.common.extensions.table import LookupTable
|
||||
from concrete.common.representation import intermediate as ir
|
||||
from concrete.common.values import EncryptedScalar
|
||||
from concrete.numpy import tracing
|
||||
|
||||
|
||||
def test_lookup_table_size_constraints():
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
"""Test converter functions"""
|
||||
import pytest
|
||||
|
||||
from hdk.common.data_types.floats import Float
|
||||
from hdk.common.data_types.integers import Integer
|
||||
from hdk.common.mlir.converters import add, apply_lut, constant, dot, mul, sub
|
||||
from hdk.common.values import ClearScalar, EncryptedScalar
|
||||
from concrete.common.data_types.floats import Float
|
||||
from concrete.common.data_types.integers import Integer
|
||||
from concrete.common.mlir.converters import add, apply_lut, constant, dot, mul, sub
|
||||
from concrete.common.values import ClearScalar, EncryptedScalar
|
||||
|
||||
|
||||
class MockNode:
|
||||
|
||||
@@ -8,12 +8,12 @@ from mlir.ir import IntegerType, Location, RankedTensorType, UnrankedTensorType
|
||||
from zamalang import compiler
|
||||
from zamalang.dialects import hlfhe
|
||||
|
||||
from hdk.common.data_types.integers import Integer
|
||||
from hdk.common.extensions.table import LookupTable
|
||||
from hdk.common.mlir import V0_OPSET_CONVERSION_FUNCTIONS, MLIRConverter
|
||||
from hdk.common.values import ClearScalar, EncryptedScalar
|
||||
from hdk.common.values.tensors import ClearTensor, EncryptedTensor
|
||||
from hdk.numpy.compile import compile_numpy_function_into_op_graph
|
||||
from concrete.common.data_types.integers import Integer
|
||||
from concrete.common.extensions.table import LookupTable
|
||||
from concrete.common.mlir import V0_OPSET_CONVERSION_FUNCTIONS, MLIRConverter
|
||||
from concrete.common.values import ClearScalar, EncryptedScalar
|
||||
from concrete.common.values.tensors import ClearTensor, EncryptedTensor
|
||||
from concrete.numpy.compile import compile_numpy_function_into_op_graph
|
||||
|
||||
|
||||
def add(x, y):
|
||||
@@ -212,21 +212,21 @@ def test_mlir_converter(func, args_dict, args_ranges):
|
||||
compiler.round_trip(mlir_result)
|
||||
|
||||
|
||||
def test_hdk_encrypted_integer_to_mlir_type():
|
||||
def test_concrete_encrypted_integer_to_mlir_type():
|
||||
"""Test conversion of EncryptedScalar into MLIR"""
|
||||
value = EncryptedScalar(Integer(7, is_signed=False))
|
||||
converter = MLIRConverter(V0_OPSET_CONVERSION_FUNCTIONS)
|
||||
eint = converter.hdk_value_to_mlir_type(value)
|
||||
eint = converter.common_value_to_mlir_type(value)
|
||||
assert eint == hlfhe.EncryptedIntegerType.get(converter.context, 7)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("is_signed", [True, False])
|
||||
def test_hdk_clear_integer_to_mlir_type(is_signed):
|
||||
def test_concrete_clear_integer_to_mlir_type(is_signed):
|
||||
"""Test conversion of ClearScalar into MLIR"""
|
||||
value = ClearScalar(Integer(5, is_signed=is_signed))
|
||||
converter = MLIRConverter(V0_OPSET_CONVERSION_FUNCTIONS)
|
||||
with converter.context:
|
||||
int_mlir = converter.hdk_value_to_mlir_type(value)
|
||||
int_mlir = converter.common_value_to_mlir_type(value)
|
||||
if is_signed:
|
||||
assert int_mlir == IntegerType.get_signed(5)
|
||||
else:
|
||||
@@ -243,12 +243,12 @@ def test_hdk_clear_integer_to_mlir_type(is_signed):
|
||||
(-1, 5),
|
||||
],
|
||||
)
|
||||
def test_hdk_clear_tensor_integer_to_mlir_type(is_signed, shape):
|
||||
def test_concrete_clear_tensor_integer_to_mlir_type(is_signed, shape):
|
||||
"""Test conversion of ClearTensor into MLIR"""
|
||||
value = ClearTensor(Integer(5, is_signed=is_signed), shape)
|
||||
converter = MLIRConverter(V0_OPSET_CONVERSION_FUNCTIONS)
|
||||
with converter.context, Location.unknown():
|
||||
tensor_mlir = converter.hdk_value_to_mlir_type(value)
|
||||
tensor_mlir = converter.common_value_to_mlir_type(value)
|
||||
if is_signed:
|
||||
element_type = IntegerType.get_signed(5)
|
||||
else:
|
||||
@@ -269,12 +269,12 @@ def test_hdk_clear_tensor_integer_to_mlir_type(is_signed, shape):
|
||||
(-1, 5),
|
||||
],
|
||||
)
|
||||
def test_hdk_encrypted_tensor_integer_to_mlir_type(shape):
|
||||
def test_concrete_encrypted_tensor_integer_to_mlir_type(shape):
|
||||
"""Test conversion of EncryptedTensor into MLIR"""
|
||||
value = EncryptedTensor(Integer(6, is_signed=False), shape)
|
||||
converter = MLIRConverter(V0_OPSET_CONVERSION_FUNCTIONS)
|
||||
with converter.context, Location.unknown():
|
||||
tensor_mlir = converter.hdk_value_to_mlir_type(value)
|
||||
tensor_mlir = converter.common_value_to_mlir_type(value)
|
||||
element_type = hlfhe.EncryptedIntegerType.get(converter.context, 6)
|
||||
if shape is None:
|
||||
expected_type = UnrankedTensorType.get(element_type)
|
||||
@@ -283,12 +283,12 @@ def test_hdk_encrypted_tensor_integer_to_mlir_type(shape):
|
||||
assert tensor_mlir == expected_type
|
||||
|
||||
|
||||
def test_failing_hdk_to_mlir_type():
|
||||
def test_failing_concrete_to_mlir_type():
|
||||
"""Test failing conversion of an unsupported type into MLIR"""
|
||||
value = "random"
|
||||
converter = MLIRConverter(V0_OPSET_CONVERSION_FUNCTIONS)
|
||||
with pytest.raises(TypeError, match=r"can't convert value of type .* to MLIR type"):
|
||||
converter.hdk_value_to_mlir_type(value)
|
||||
converter.common_value_to_mlir_type(value)
|
||||
|
||||
|
||||
# pylint: enable=no-name-in-module,no-member
|
||||
|
||||
@@ -5,11 +5,11 @@ from inspect import signature
|
||||
import numpy
|
||||
import pytest
|
||||
|
||||
from hdk.common.data_types.integers import Integer
|
||||
from hdk.common.optimization.topological import fuse_float_operations
|
||||
from hdk.common.values import EncryptedScalar
|
||||
from hdk.numpy import tracing
|
||||
from hdk.numpy.tracing import trace_numpy_function
|
||||
from concrete.common.data_types.integers import Integer
|
||||
from concrete.common.optimization.topological import fuse_float_operations
|
||||
from concrete.common.values import EncryptedScalar
|
||||
from concrete.numpy import tracing
|
||||
from concrete.numpy.tracing import trace_numpy_function
|
||||
|
||||
|
||||
def no_fuse(x):
|
||||
|
||||
@@ -3,10 +3,15 @@
|
||||
import numpy
|
||||
import pytest
|
||||
|
||||
from hdk.common.data_types.floats import Float
|
||||
from hdk.common.data_types.integers import Integer
|
||||
from hdk.common.representation import intermediate as ir
|
||||
from hdk.common.values import ClearScalar, ClearTensor, EncryptedScalar, EncryptedTensor
|
||||
from concrete.common.data_types.floats import Float
|
||||
from concrete.common.data_types.integers import Integer
|
||||
from concrete.common.representation import intermediate as ir
|
||||
from concrete.common.values import (
|
||||
ClearScalar,
|
||||
ClearTensor,
|
||||
EncryptedScalar,
|
||||
EncryptedTensor,
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
|
||||
@@ -4,11 +4,11 @@ from copy import deepcopy
|
||||
|
||||
import pytest
|
||||
|
||||
from hdk.common import check_op_graph_is_integer_program, is_a_power_of_2
|
||||
from hdk.common.data_types.floats import Float64
|
||||
from hdk.common.data_types.integers import Integer
|
||||
from hdk.common.values import EncryptedScalar
|
||||
from hdk.numpy.tracing import trace_numpy_function
|
||||
from concrete.common import check_op_graph_is_integer_program, is_a_power_of_2
|
||||
from concrete.common.data_types.floats import Float64
|
||||
from concrete.common.data_types.integers import Integer
|
||||
from concrete.common.values import EncryptedScalar
|
||||
from concrete.numpy.tracing import trace_numpy_function
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
|
||||
@@ -4,7 +4,7 @@ from typing import Any, Dict, List
|
||||
|
||||
import pytest
|
||||
|
||||
from hdk.common.tracing.tracing_helpers import prepare_function_parameters
|
||||
from concrete.common.tracing.tracing_helpers import prepare_function_parameters
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
|
||||
@@ -5,7 +5,7 @@ import networkx as nx
|
||||
import networkx.algorithms.isomorphism as iso
|
||||
import pytest
|
||||
|
||||
from hdk.common.representation.intermediate import (
|
||||
from concrete.common.representation.intermediate import (
|
||||
ALL_IR_NODES,
|
||||
Add,
|
||||
ArbitraryFunction,
|
||||
|
||||
@@ -5,12 +5,12 @@ import random
|
||||
import numpy
|
||||
import pytest
|
||||
|
||||
from hdk.common.compilation import CompilationConfiguration
|
||||
from hdk.common.data_types.integers import Integer
|
||||
from hdk.common.debugging import draw_graph, get_printable_graph
|
||||
from hdk.common.extensions.table import LookupTable
|
||||
from hdk.common.values import EncryptedScalar, EncryptedTensor
|
||||
from hdk.numpy.compile import (
|
||||
from concrete.common.compilation import CompilationConfiguration
|
||||
from concrete.common.data_types.integers import Integer
|
||||
from concrete.common.debugging import draw_graph, get_printable_graph
|
||||
from concrete.common.extensions.table import LookupTable
|
||||
from concrete.common.values import EncryptedScalar, EncryptedTensor
|
||||
from concrete.numpy.compile import (
|
||||
compile_numpy_function,
|
||||
compile_numpy_function_into_op_graph,
|
||||
)
|
||||
|
||||
@@ -3,11 +3,11 @@
|
||||
import numpy
|
||||
import pytest
|
||||
|
||||
from hdk.common.data_types.integers import Integer
|
||||
from hdk.common.debugging import draw_graph, get_printable_graph
|
||||
from hdk.common.extensions.table import LookupTable
|
||||
from hdk.common.values import ClearScalar, EncryptedScalar, EncryptedTensor
|
||||
from hdk.numpy import tracing
|
||||
from concrete.common.data_types.integers import Integer
|
||||
from concrete.common.debugging import draw_graph, get_printable_graph
|
||||
from concrete.common.extensions.table import LookupTable
|
||||
from concrete.common.values import ClearScalar, EncryptedScalar, EncryptedTensor
|
||||
from concrete.numpy import tracing
|
||||
|
||||
LOOKUP_TABLE_FROM_2B_TO_4B = LookupTable([9, 2, 4, 11])
|
||||
LOOKUP_TABLE_FROM_3B_TO_2B = LookupTable([0, 1, 3, 2, 2, 3, 1, 0])
|
||||
|
||||
@@ -3,9 +3,9 @@
|
||||
import numpy
|
||||
import pytest
|
||||
|
||||
from hdk.common.data_types.floats import Float
|
||||
from hdk.common.data_types.integers import Integer
|
||||
from hdk.numpy.np_dtypes_helpers import (
|
||||
from concrete.common.data_types.floats import Float
|
||||
from concrete.common.data_types.integers import Integer
|
||||
from concrete.numpy.np_dtypes_helpers import (
|
||||
convert_base_data_type_to_numpy_dtype,
|
||||
convert_numpy_dtype_to_base_data_type,
|
||||
)
|
||||
|
||||
@@ -4,11 +4,16 @@ import networkx as nx
|
||||
import numpy
|
||||
import pytest
|
||||
|
||||
from hdk.common.data_types.floats import Float
|
||||
from hdk.common.data_types.integers import Integer
|
||||
from hdk.common.representation import intermediate as ir
|
||||
from hdk.common.values import ClearScalar, ClearTensor, EncryptedScalar, EncryptedTensor
|
||||
from hdk.numpy import tracing
|
||||
from concrete.common.data_types.floats import Float
|
||||
from concrete.common.data_types.integers import Integer
|
||||
from concrete.common.representation import intermediate as ir
|
||||
from concrete.common.values import (
|
||||
ClearScalar,
|
||||
ClearTensor,
|
||||
EncryptedScalar,
|
||||
EncryptedTensor,
|
||||
)
|
||||
from concrete.numpy import tracing
|
||||
|
||||
OPERATIONS_TO_TEST = [ir.Add, ir.Sub, ir.Mul]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user