diff --git a/benchmarks/classification.py b/benchmarks/classification.py index 50e46ef393..c4dc82ed71 100644 --- a/benchmarks/classification.py +++ b/benchmarks/classification.py @@ -109,7 +109,7 @@ def main(): # Listing if args.long_list or args.short_list: already_done_models = {} - for (dataset_i, model_class_i, config_i) in all_classification_tasks: + for dataset_i, model_class_i, config_i in all_classification_tasks: config_n = json.dumps(config_i).replace("'", '"') model_name_i = model_class_i.__name__ diff --git a/benchmarks/common.py b/benchmarks/common.py index c06a9e1711..a3445f679c 100644 --- a/benchmarks/common.py +++ b/benchmarks/common.py @@ -274,7 +274,7 @@ def run_and_report_classification_metrics( (f1_score, "f1", "F1Score"), ] - for (metric, metric_id, metric_label) in metric_info: + for metric, metric_id, metric_label in metric_info: run_and_report_metric( y_gt, y_pred, @@ -288,7 +288,7 @@ def run_and_report_regression_metrics(y_gt, y_pred, metric_id_prefix, metric_lab """Run several metrics and report results to progress tracker with computed name and id""" metric_info = [(r2_score, "r2_score", "R2Score"), (mean_squared_error, "MSE", "MSE")] - for (metric, metric_id, metric_label) in metric_info: + for metric, metric_id, metric_label in metric_info: run_and_report_metric( y_gt, y_pred, @@ -768,6 +768,7 @@ def benchmark_name_generator( # - The functions support all models # FIXME: https://github.com/zama-ai/concrete-ml-internal/issues/1866 + # pylint: disable-next=too-many-branches, redefined-outer-name def benchmark_name_to_config( benchmark_name: str, joiner: str = "_" diff --git a/benchmarks/deep_learning.py b/benchmarks/deep_learning.py index a140638c53..dd8c81aaeb 100644 --- a/benchmarks/deep_learning.py +++ b/benchmarks/deep_learning.py @@ -886,7 +886,7 @@ def main(): if args.long_list or args.short_list: # Print the short or long lists if asked and stop printed_models = set() - for (dataset, cnn_class, config) in all_tasks: + for dataset, cnn_class, config in all_tasks: configs = json.dumps(config).replace("'", '"') cnn_name = cnn_class.__name__ diff --git a/benchmarks/glm.py b/benchmarks/glm.py index d2ae5bafcf..b3b2302e24 100644 --- a/benchmarks/glm.py +++ b/benchmarks/glm.py @@ -113,14 +113,20 @@ def get_preprocessor() -> ColumnTransformer: def get_train_test_data(data: pandas.DataFrame) -> Tuple[pandas.DataFrame, pandas.DataFrame]: """Split the data into a train and test set.""" - train_data, test_data, = train_test_split( + ( + train_data, + test_data, + ) = train_test_split( data, test_size=0.2, random_state=0, ) # The test set is reduced for faster FHE runs. - _, test_data, = train_test_split( + ( + _, + test_data, + ) = train_test_split( test_data, test_size=500, random_state=0, diff --git a/benchmarks/regression.py b/benchmarks/regression.py index d5e699b747..d7229c4688 100644 --- a/benchmarks/regression.py +++ b/benchmarks/regression.py @@ -109,7 +109,7 @@ def main(): # Listing if args.long_list or args.short_list: already_done_models = {} - for (dataset_i, model_class_i, config_i) in all_tasks: + for dataset_i, model_class_i, config_i in all_tasks: config_n = json.dumps(config_i).replace("'", '"') model_name_i = model_class_i.__name__ diff --git a/conftest.py b/conftest.py index 1606c8ecbe..6326ddd1a0 100644 --- a/conftest.py +++ b/conftest.py @@ -1,4 +1,5 @@ """PyTest configuration file.""" + import hashlib import json import random diff --git a/docker/release_resources/sanity_check.py b/docker/release_resources/sanity_check.py index 4daab741de..221ef1fc65 100644 --- a/docker/release_resources/sanity_check.py +++ b/docker/release_resources/sanity_check.py @@ -1,4 +1,5 @@ """Sanity checks, to be sure that our package is usable""" + import argparse import random import shutil diff --git a/docs/advanced_examples/KNearestNeighbors.ipynb b/docs/advanced_examples/KNearestNeighbors.ipynb index 8ce433c359..6f6e6ed201 100644 --- a/docs/advanced_examples/KNearestNeighbors.ipynb +++ b/docs/advanced_examples/KNearestNeighbors.ipynb @@ -392,9 +392,11 @@ "def highlight_diff(row):\n", " \"\"\"Custom style function to highlight mismatched predictions.\"\"\"\n", " return [\n", - " \"background-color: yellow\"\n", - " if row[\"Majority vote (Concrete ML)\"] != row[\"Majority vote (scikit-learn)\"]\n", - " else \"\"\n", + " (\n", + " \"background-color: yellow\"\n", + " if row[\"Majority vote (Concrete ML)\"] != row[\"Majority vote (scikit-learn)\"]\n", + " else \"\"\n", + " )\n", " ] * len(row)\n", "\n", "\n", diff --git a/script/actions_utils/escape_quotes.py b/script/actions_utils/escape_quotes.py index e039675e2b..aab5e6cb5a 100644 --- a/script/actions_utils/escape_quotes.py +++ b/script/actions_utils/escape_quotes.py @@ -1,4 +1,5 @@ """Script to escape double quotes within brackets or curly braces.""" + import argparse parser = argparse.ArgumentParser(description="Escape double quotes in a string") diff --git a/script/actions_utils/generate_scripts_benchmark.py b/script/actions_utils/generate_scripts_benchmark.py index aa650e73b6..b9fc97a1b3 100644 --- a/script/actions_utils/generate_scripts_benchmark.py +++ b/script/actions_utils/generate_scripts_benchmark.py @@ -1,4 +1,5 @@ """Script to generate the list of commands to run all benchmarks""" + import argparse import datetime import json diff --git a/script/actions_utils/json_length.py b/script/actions_utils/json_length.py index 3a8ba7f7ff..e9998a4998 100644 --- a/script/actions_utils/json_length.py +++ b/script/actions_utils/json_length.py @@ -1,4 +1,5 @@ """Script to evaluate the length of a json file""" + import argparse import json from pathlib import Path diff --git a/script/actions_utils/monitor.py b/script/actions_utils/monitor.py index 37f8765e12..df6e1b8e72 100644 --- a/script/actions_utils/monitor.py +++ b/script/actions_utils/monitor.py @@ -1,4 +1,5 @@ """Module to generate figure of evolution of Concrete ML-CI time on main for last 4 weeks.""" + import argparse import datetime import json diff --git a/script/actions_utils/pytest_failed_test_report.py b/script/actions_utils/pytest_failed_test_report.py index 7483e3902e..db24dc0524 100755 --- a/script/actions_utils/pytest_failed_test_report.py +++ b/script/actions_utils/pytest_failed_test_report.py @@ -1,4 +1,5 @@ """Pytest JSON report on failed tests utils.""" + import argparse import json from pathlib import Path diff --git a/script/actions_utils/refresh_notebooks_list.py b/script/actions_utils/refresh_notebooks_list.py index 068e108287..0ad74f75cf 100644 --- a/script/actions_utils/refresh_notebooks_list.py +++ b/script/actions_utils/refresh_notebooks_list.py @@ -1,4 +1,5 @@ """Update the list of available notebooks for the refresh_one_notebook GitHib action.""" + import argparse from pathlib import Path diff --git a/script/actions_utils/run_commands.py b/script/actions_utils/run_commands.py index e70545d0ea..561f134ebe 100644 --- a/script/actions_utils/run_commands.py +++ b/script/actions_utils/run_commands.py @@ -1,4 +1,5 @@ """Script to run commands from a json file""" + import argparse import json import subprocess diff --git a/script/doc_utils/gen_supported_ops.py b/script/doc_utils/gen_supported_ops.py index df854dd8b1..da93556e02 100644 --- a/script/doc_utils/gen_supported_ops.py +++ b/script/doc_utils/gen_supported_ops.py @@ -1,4 +1,5 @@ """Update list of supported functions in the doc.""" + import argparse from pathlib import Path diff --git a/script/make_utils/actionlint_check_with_whitelists.py b/script/make_utils/actionlint_check_with_whitelists.py index 88fe5c65c5..e7d3be9be7 100644 --- a/script/make_utils/actionlint_check_with_whitelists.py +++ b/script/make_utils/actionlint_check_with_whitelists.py @@ -1,4 +1,5 @@ """ Check an actionlint log against some whitelists """ + import sys from typing import Set diff --git a/script/make_utils/check_headers.py b/script/make_utils/check_headers.py index a8edfa6282..2cb6f7cba8 100644 --- a/script/make_utils/check_headers.py +++ b/script/make_utils/check_headers.py @@ -1,4 +1,5 @@ """Check that headers linked do indeed exist in target markdown files""" + import os from pathlib import Path diff --git a/script/make_utils/check_issues.py b/script/make_utils/check_issues.py index 137a5d445d..33e5e1d976 100644 --- a/script/make_utils/check_issues.py +++ b/script/make_utils/check_issues.py @@ -1,4 +1,5 @@ """Check linked github issues states""" + import json import re import subprocess diff --git a/script/nbmake_utils/notebook_finalize.py b/script/nbmake_utils/notebook_finalize.py index 8f92758113..250e08c4c2 100644 --- a/script/nbmake_utils/notebook_finalize.py +++ b/script/nbmake_utils/notebook_finalize.py @@ -1,4 +1,5 @@ """Finalize Jupyter notebooks.""" + import argparse import json from pathlib import Path diff --git a/src/concrete/__init__.py b/src/concrete/__init__.py index 18d9e77599..2a31e077a5 100644 --- a/src/concrete/__init__.py +++ b/src/concrete/__init__.py @@ -1,4 +1,5 @@ """Top level import.""" + # Do not modify, this is to have a compatible namespace package # https://packaging.python.org/en/latest/guides/packaging-namespace-packages/ # #pkg-resources-style-namespace-packages diff --git a/src/concrete/ml/common/__init__.py b/src/concrete/ml/common/__init__.py index 2abb9511b5..a6471e854d 100644 --- a/src/concrete/ml/common/__init__.py +++ b/src/concrete/ml/common/__init__.py @@ -1,2 +1,3 @@ """Module for shared data structures and code.""" + from . import check_inputs, debugging, utils diff --git a/src/concrete/ml/common/debugging/__init__.py b/src/concrete/ml/common/debugging/__init__.py index 39f44a2599..d05956f037 100644 --- a/src/concrete/ml/common/debugging/__init__.py +++ b/src/concrete/ml/common/debugging/__init__.py @@ -1,2 +1,3 @@ """Module for debugging.""" + from .custom_assert import assert_false, assert_not_reached, assert_true diff --git a/src/concrete/ml/common/debugging/custom_assert.py b/src/concrete/ml/common/debugging/custom_assert.py index dfb62a4c68..d66e46cd72 100644 --- a/src/concrete/ml/common/debugging/custom_assert.py +++ b/src/concrete/ml/common/debugging/custom_assert.py @@ -1,4 +1,5 @@ """Provide some variants of assert.""" + from typing import Type diff --git a/src/concrete/ml/common/serialization/__init__.py b/src/concrete/ml/common/serialization/__init__.py index ee71e91368..7deb2e1582 100644 --- a/src/concrete/ml/common/serialization/__init__.py +++ b/src/concrete/ml/common/serialization/__init__.py @@ -1,4 +1,5 @@ """Serialization module.""" + import os from torch.nn.modules import activation diff --git a/src/concrete/ml/common/serialization/decoder.py b/src/concrete/ml/common/serialization/decoder.py index c02995e020..f4ca08311e 100644 --- a/src/concrete/ml/common/serialization/decoder.py +++ b/src/concrete/ml/common/serialization/decoder.py @@ -1,4 +1,5 @@ """Custom decoder for serialization.""" + import inspect import json from typing import Any, Dict, Type diff --git a/src/concrete/ml/common/serialization/dumpers.py b/src/concrete/ml/common/serialization/dumpers.py index f5c53d1434..0c8b8f21a0 100644 --- a/src/concrete/ml/common/serialization/dumpers.py +++ b/src/concrete/ml/common/serialization/dumpers.py @@ -1,4 +1,5 @@ """Dump functions for serialization.""" + import json from typing import Any, TextIO diff --git a/src/concrete/ml/common/serialization/encoder.py b/src/concrete/ml/common/serialization/encoder.py index bb8f396d26..b84d35987a 100644 --- a/src/concrete/ml/common/serialization/encoder.py +++ b/src/concrete/ml/common/serialization/encoder.py @@ -1,4 +1,5 @@ """Custom encoder for serialization.""" + import inspect import json from json.encoder import _make_iterencode # type: ignore[attr-defined] diff --git a/src/concrete/ml/common/serialization/loaders.py b/src/concrete/ml/common/serialization/loaders.py index 224f73eaba..d312dcf4f5 100644 --- a/src/concrete/ml/common/serialization/loaders.py +++ b/src/concrete/ml/common/serialization/loaders.py @@ -1,4 +1,5 @@ """Load functions for serialization.""" + import json from typing import IO, Any, Union diff --git a/src/concrete/ml/deployment/__init__.py b/src/concrete/ml/deployment/__init__.py index 9aaa966e87..0099031fb7 100644 --- a/src/concrete/ml/deployment/__init__.py +++ b/src/concrete/ml/deployment/__init__.py @@ -1,2 +1,3 @@ """Module for deployment of the FHE model.""" + from .fhe_client_server import FHEModelClient, FHEModelDev, FHEModelServer diff --git a/src/concrete/ml/deployment/utils.py b/src/concrete/ml/deployment/utils.py index 5829b34cb9..30d2410290 100644 --- a/src/concrete/ml/deployment/utils.py +++ b/src/concrete/ml/deployment/utils.py @@ -3,6 +3,7 @@ - Check if connection possible - Wait for connection to be available (with timeout) """ + import subprocess import time from pathlib import Path diff --git a/src/concrete/ml/onnx/onnx_utils.py b/src/concrete/ml/onnx/onnx_utils.py index 60a8cb02c4..81091cd862 100644 --- a/src/concrete/ml/onnx/onnx_utils.py +++ b/src/concrete/ml/onnx/onnx_utils.py @@ -1,4 +1,5 @@ """Utils to interpret an ONNX model with numpy.""" + # Utils to interpret an ONNX model with numpy. diff --git a/src/concrete/ml/pandas/__init__.py b/src/concrete/ml/pandas/__init__.py index f54414f3f5..179f039911 100644 --- a/src/concrete/ml/pandas/__init__.py +++ b/src/concrete/ml/pandas/__init__.py @@ -1,4 +1,5 @@ """Public API for encrypted data-frames.""" + from pathlib import Path from typing import Hashable, Optional, Sequence, Tuple, Union diff --git a/src/concrete/ml/pandas/_development.py b/src/concrete/ml/pandas/_development.py index 01e5f755db..ab5e3801f6 100644 --- a/src/concrete/ml/pandas/_development.py +++ b/src/concrete/ml/pandas/_development.py @@ -1,4 +1,5 @@ """Define development methods for generating client/server files.""" + import itertools from functools import partial from pathlib import Path diff --git a/src/concrete/ml/pandas/_operators.py b/src/concrete/ml/pandas/_operators.py index 4e8db613a0..432bcf491e 100644 --- a/src/concrete/ml/pandas/_operators.py +++ b/src/concrete/ml/pandas/_operators.py @@ -1,4 +1,5 @@ """Implement Pandas operators in FHE using encrypted data-frames.""" + from typing import Any, Dict, Hashable, List, Optional, Sequence, Tuple, Union import numpy diff --git a/src/concrete/ml/pandas/_processing.py b/src/concrete/ml/pandas/_processing.py index 056b3c9664..f77a979527 100644 --- a/src/concrete/ml/pandas/_processing.py +++ b/src/concrete/ml/pandas/_processing.py @@ -1,4 +1,5 @@ """Define pre-processing and post-processing steps for encrypted data-frames.""" + import copy from collections import defaultdict from typing import Dict, List, Tuple diff --git a/src/concrete/ml/pandas/_utils.py b/src/concrete/ml/pandas/_utils.py index 2c7a6b7f66..388c9fc608 100644 --- a/src/concrete/ml/pandas/_utils.py +++ b/src/concrete/ml/pandas/_utils.py @@ -1,4 +1,5 @@ """Define utility functions for encrypted data-frames.""" + import functools from typing import List, Optional, Tuple, Union diff --git a/src/concrete/ml/pandas/client_engine.py b/src/concrete/ml/pandas/client_engine.py index 37e625119d..98fd5cbbec 100644 --- a/src/concrete/ml/pandas/client_engine.py +++ b/src/concrete/ml/pandas/client_engine.py @@ -1,4 +1,5 @@ """Define the framework used for managing keys (encrypt, decrypt) for encrypted data-frames.""" + from pathlib import Path from typing import Optional, Union diff --git a/src/concrete/ml/pandas/dataframe.py b/src/concrete/ml/pandas/dataframe.py index d4716702dc..18746836b1 100644 --- a/src/concrete/ml/pandas/dataframe.py +++ b/src/concrete/ml/pandas/dataframe.py @@ -1,4 +1,5 @@ """Define the encrypted data-frame framework.""" + import json from pathlib import Path from typing import Dict, Hashable, List, Optional, Sequence, Tuple, Union diff --git a/src/concrete/ml/pytest/__init__.py b/src/concrete/ml/pytest/__init__.py index 577895a2be..76047a2ce5 100644 --- a/src/concrete/ml/pytest/__init__.py +++ b/src/concrete/ml/pytest/__init__.py @@ -1,2 +1,3 @@ """Module which is used to contain common functions for pytest.""" + from . import torch_models, utils diff --git a/src/concrete/ml/pytest/torch_models.py b/src/concrete/ml/pytest/torch_models.py index d2b41e4d9f..cb87f4bf6b 100644 --- a/src/concrete/ml/pytest/torch_models.py +++ b/src/concrete/ml/pytest/torch_models.py @@ -867,9 +867,7 @@ def __init__(self, input_output, activation_function, n_bits=2, disable_bit_chec n_bits_weights = n_bits # Generate the pattern 0, 1, ..., 2^N-1, 0, 1, .. 2^N-1, 0, 1.. - all_weights = numpy.mod( - numpy.arange(numpy.prod(self.fc1.weight.shape)), 2**n_bits_weights - ) + all_weights = numpy.mod(numpy.arange(numpy.prod(self.fc1.weight.shape)), 2**n_bits_weights) # Shuffle the pattern and reshape to weight shape numpy.random.shuffle(all_weights) diff --git a/src/concrete/ml/pytest/utils.py b/src/concrete/ml/pytest/utils.py index 6ab70488ec..f97a34719a 100644 --- a/src/concrete/ml/pytest/utils.py +++ b/src/concrete/ml/pytest/utils.py @@ -1,4 +1,5 @@ """Common functions or lists for test files, which can't be put in fixtures.""" + import copy import io from functools import partial diff --git a/src/concrete/ml/quantization/__init__.py b/src/concrete/ml/quantization/__init__.py index f9c94793e7..b248e4db44 100644 --- a/src/concrete/ml/quantization/__init__.py +++ b/src/concrete/ml/quantization/__init__.py @@ -1,4 +1,5 @@ """Modules for quantization.""" + from .base_quantized_op import QuantizedOp from .post_training import ( PostTrainingAffineQuantization, diff --git a/src/concrete/ml/quantization/base_quantized_op.py b/src/concrete/ml/quantization/base_quantized_op.py index 31c3df90b7..903fc4767f 100644 --- a/src/concrete/ml/quantization/base_quantized_op.py +++ b/src/concrete/ml/quantization/base_quantized_op.py @@ -237,14 +237,14 @@ def dump_dict(self) -> Dict: metadata["_input_idx_to_params_name"] = self._input_idx_to_params_name metadata["_params_that_are_onnx_inputs"] = self._params_that_are_onnx_inputs metadata["_params_that_are_onnx_var_inputs"] = self._params_that_are_onnx_var_inputs - metadata[ - "_params_that_are_required_onnx_inputs" - ] = self._params_that_are_required_onnx_inputs + metadata["_params_that_are_required_onnx_inputs"] = ( + self._params_that_are_required_onnx_inputs + ) metadata["_has_attr"] = self._has_attr metadata["_inputs_not_quantized"] = self._inputs_not_quantized - metadata[ - "quantize_inputs_with_model_outputs_precision" - ] = self.quantize_inputs_with_model_outputs_precision + metadata["quantize_inputs_with_model_outputs_precision"] = ( + self.quantize_inputs_with_model_outputs_precision + ) metadata["produces_graph_output"] = self.produces_graph_output metadata["produces_raw_output"] = self.produces_raw_output metadata["error_tracker"] = self.error_tracker diff --git a/src/concrete/ml/quantization/qat_quantizers.py b/src/concrete/ml/quantization/qat_quantizers.py index 36a9165461..a3705966c6 100644 --- a/src/concrete/ml/quantization/qat_quantizers.py +++ b/src/concrete/ml/quantization/qat_quantizers.py @@ -1,4 +1,5 @@ """Custom Quantization Aware Training Brevitas quantizers.""" + from brevitas.quant.scaled_int import ( IntQuant, MaxStatsScaling, diff --git a/src/concrete/ml/quantization/quantized_module.py b/src/concrete/ml/quantization/quantized_module.py index 07635c60f9..3b61ac816d 100644 --- a/src/concrete/ml/quantization/quantized_module.py +++ b/src/concrete/ml/quantization/quantized_module.py @@ -1,4 +1,5 @@ """QuantizedModule API.""" + import copy import re from functools import partial @@ -145,7 +146,7 @@ def set_reduce_sum_copy(self): to copy the inputs with a PBS to avoid it. """ assert self.quant_layers_dict is not None - for (_, quantized_op) in self.quant_layers_dict.values(): + for _, quantized_op in self.quant_layers_dict.values(): if isinstance(quantized_op, QuantizedReduceSum): quantized_op.copy_inputs = True @@ -369,10 +370,10 @@ def forward( debug_value_tracker: Dict[ str, Dict[Union[int, str], Optional[ONNXOpInputOutputType]] ] = {} - for (_, layer) in self.quant_layers_dict.values(): + for _, layer in self.quant_layers_dict.values(): layer.debug_value_tracker = debug_value_tracker q_y_pred = self.quantized_forward(*q_x, fhe="disable") - for (_, layer) in self.quant_layers_dict.values(): + for _, layer in self.quant_layers_dict.values(): layer.debug_value_tracker = None # De-quantize the output predicted values y_pred = self.dequantize_output(*to_tuple(q_y_pred)) @@ -767,7 +768,7 @@ def bitwidth_and_range_report( return None op_names_to_report: Dict[str, Dict[str, Union[Tuple[int, ...], int]]] = {} - for (_, op_inst) in self.quant_layers_dict.values(): + for _, op_inst in self.quant_layers_dict.values(): # Get the value range of this tag and all its subtags # The potential tags for this op start with the op instance name # and are, sometimes, followed by a subtag starting with a period: diff --git a/src/concrete/ml/quantization/quantized_module_passes.py b/src/concrete/ml/quantization/quantized_module_passes.py index c4e6bfb956..4d5da2ab2e 100644 --- a/src/concrete/ml/quantization/quantized_module_passes.py +++ b/src/concrete/ml/quantization/quantized_module_passes.py @@ -1,4 +1,5 @@ """Optimization passes for QuantizedModules.""" + from collections import defaultdict from typing import DefaultDict, Dict, List, Optional, Tuple @@ -101,7 +102,7 @@ def compute_op_predecessors(self) -> PredecessorsType: # Initialize the list of predecessors with tensors that are graph inputs predecessors: PredecessorsType = defaultdict(list) - for (node_inputs, node_op) in self._qmodule.quant_layers_dict.values(): + for node_inputs, node_op in self._qmodule.quant_layers_dict.values(): # The first input node contains the encrypted data enc_input_node = node_inputs[0] @@ -168,7 +169,7 @@ def detect_patterns(self, predecessors: PredecessorsType) -> PatternDict: valid_paths: PatternDict = {} # pylint: disable-next=too-many-nested-blocks - for (_, node_op) in self._qmodule.quant_layers_dict.values(): + for _, node_op in self._qmodule.quant_layers_dict.values(): # Only work with supported nodes that have a single # encrypted input (not supporting enc x enc matmul) if ( diff --git a/src/concrete/ml/quantization/quantizers.py b/src/concrete/ml/quantization/quantizers.py index 6e194200b3..2807645434 100644 --- a/src/concrete/ml/quantization/quantizers.py +++ b/src/concrete/ml/quantization/quantizers.py @@ -1,4 +1,5 @@ """Quantization utilities for a numpy array/tensor.""" + # pylint: disable=too-many-lines from __future__ import annotations diff --git a/src/concrete/ml/search_parameters/__init__.py b/src/concrete/ml/search_parameters/__init__.py index 4ecfbdcece..2ed29ce06c 100644 --- a/src/concrete/ml/search_parameters/__init__.py +++ b/src/concrete/ml/search_parameters/__init__.py @@ -1,2 +1,3 @@ """Modules for `p_error` search.""" + from .p_error_search import BinarySearch diff --git a/src/concrete/ml/search_parameters/p_error_search.py b/src/concrete/ml/search_parameters/p_error_search.py index d0e9ce4ede..148413533a 100644 --- a/src/concrete/ml/search_parameters/p_error_search.py +++ b/src/concrete/ml/search_parameters/p_error_search.py @@ -50,6 +50,7 @@ If we don't reach the convergence, a user warning is raised. """ + import warnings from collections import OrderedDict from pathlib import Path @@ -478,9 +479,11 @@ def run( self.history.append( OrderedDict( { - k: sum((d[k] for d in simulation_data), []) - if isinstance(simulation_data[0][k], list) - else simulation_data[0][k] + k: ( + sum((d[k] for d in simulation_data), []) + if isinstance(simulation_data[0][k], list) + else simulation_data[0][k] + ) for k in simulation_data[0] } ) diff --git a/src/concrete/ml/sklearn/__init__.py b/src/concrete/ml/sklearn/__init__.py index 3144d8d430..83acbf91c9 100644 --- a/src/concrete/ml/sklearn/__init__.py +++ b/src/concrete/ml/sklearn/__init__.py @@ -1,4 +1,5 @@ """Import sklearn models.""" + from typing import Dict, List, Optional, Union from ..common.debugging.custom_assert import assert_true diff --git a/src/concrete/ml/sklearn/base.py b/src/concrete/ml/sklearn/base.py index d13da2394a..cf8a8e3e1e 100644 --- a/src/concrete/ml/sklearn/base.py +++ b/src/concrete/ml/sklearn/base.py @@ -1,4 +1,5 @@ """Base classes for all estimators.""" + from __future__ import annotations import copy diff --git a/src/concrete/ml/sklearn/glm.py b/src/concrete/ml/sklearn/glm.py index f82d5f2572..1d82330933 100644 --- a/src/concrete/ml/sklearn/glm.py +++ b/src/concrete/ml/sklearn/glm.py @@ -1,4 +1,5 @@ """Implement sklearn's Generalized Linear Models (GLM).""" + from __future__ import annotations from abc import abstractmethod diff --git a/src/concrete/ml/sklearn/linear_model.py b/src/concrete/ml/sklearn/linear_model.py index afd02991da..45218849c9 100644 --- a/src/concrete/ml/sklearn/linear_model.py +++ b/src/concrete/ml/sklearn/linear_model.py @@ -1,4 +1,5 @@ """Implement sklearn linear model.""" + import itertools import time import warnings diff --git a/src/concrete/ml/sklearn/neighbors.py b/src/concrete/ml/sklearn/neighbors.py index e4101eeef5..727529419a 100644 --- a/src/concrete/ml/sklearn/neighbors.py +++ b/src/concrete/ml/sklearn/neighbors.py @@ -1,4 +1,5 @@ """Implement sklearn neighbors model.""" + from typing import Any, Dict, Union import numpy diff --git a/src/concrete/ml/sklearn/qnn_module.py b/src/concrete/ml/sklearn/qnn_module.py index 6c63cb92ce..cadc9e5427 100644 --- a/src/concrete/ml/sklearn/qnn_module.py +++ b/src/concrete/ml/sklearn/qnn_module.py @@ -1,4 +1,5 @@ """Sparse Quantized Neural Network torch module.""" + from typing import Set, Type import brevitas.nn as qnn @@ -112,9 +113,9 @@ def __init__( weight_narrow_range=quant_narrow, narrow_range=quant_narrow, signed=quant_signed, - weight_quant=Int8WeightPerTensorPoT - if power_of_two_scaling - else Int8WeightPerTensorFloat, + weight_quant=( + Int8WeightPerTensorPoT if power_of_two_scaling else Int8WeightPerTensorFloat + ), ) self.features.add_module(quant_name, quantizer) diff --git a/src/concrete/ml/sklearn/rf.py b/src/concrete/ml/sklearn/rf.py index f4521bf06b..e9c119c194 100644 --- a/src/concrete/ml/sklearn/rf.py +++ b/src/concrete/ml/sklearn/rf.py @@ -1,4 +1,5 @@ """Implement RandomForest models.""" + from typing import Any, Dict, Union import numpy diff --git a/src/concrete/ml/sklearn/svm.py b/src/concrete/ml/sklearn/svm.py index 1636a00618..509500b3fd 100644 --- a/src/concrete/ml/sklearn/svm.py +++ b/src/concrete/ml/sklearn/svm.py @@ -1,4 +1,5 @@ """Implement Support Vector Machine.""" + from typing import Any, Dict import sklearn.svm diff --git a/src/concrete/ml/sklearn/tree.py b/src/concrete/ml/sklearn/tree.py index b496d4e473..42965cdcea 100644 --- a/src/concrete/ml/sklearn/tree.py +++ b/src/concrete/ml/sklearn/tree.py @@ -1,4 +1,5 @@ """Implement DecisionTree models.""" + from typing import Any, Dict, Union import numpy diff --git a/src/concrete/ml/sklearn/tree_to_numpy.py b/src/concrete/ml/sklearn/tree_to_numpy.py index b50944319a..14f4ab732c 100644 --- a/src/concrete/ml/sklearn/tree_to_numpy.py +++ b/src/concrete/ml/sklearn/tree_to_numpy.py @@ -1,4 +1,5 @@ """Implements the conversion of a tree model to a numpy function.""" + import math import warnings from typing import Callable, List, Optional, Tuple diff --git a/src/concrete/ml/sklearn/xgb.py b/src/concrete/ml/sklearn/xgb.py index 8f3925fd77..b1c2f403ed 100644 --- a/src/concrete/ml/sklearn/xgb.py +++ b/src/concrete/ml/sklearn/xgb.py @@ -1,4 +1,5 @@ """Implements XGBoost models.""" + import platform import warnings from typing import Any, Dict, List, Optional, Tuple, Union diff --git a/src/concrete/ml/torch/__init__.py b/src/concrete/ml/torch/__init__.py index 1071631be0..0f1620f65f 100644 --- a/src/concrete/ml/torch/__init__.py +++ b/src/concrete/ml/torch/__init__.py @@ -1,2 +1,3 @@ """Modules for torch to numpy conversion.""" + from .numpy_module import NumpyModule diff --git a/src/concrete/ml/torch/numpy_module.py b/src/concrete/ml/torch/numpy_module.py index 0387140bf9..ca94dab12b 100644 --- a/src/concrete/ml/torch/numpy_module.py +++ b/src/concrete/ml/torch/numpy_module.py @@ -1,4 +1,5 @@ """A torch to numpy module.""" + from pathlib import Path from typing import Optional, Tuple, Union diff --git a/src/concrete/ml/version.py b/src/concrete/ml/version.py index 2829fbfe55..97a575f9e1 100644 --- a/src/concrete/ml/version.py +++ b/src/concrete/ml/version.py @@ -1,3 +1,4 @@ """File to manage the version of the package.""" + # Auto-generated by "make set_version" do not modify __version__ = "1.5.0" diff --git a/tests/common/test_custom_assert.py b/tests/common/test_custom_assert.py index 32ddfa2456..9b356427ee 100644 --- a/tests/common/test_custom_assert.py +++ b/tests/common/test_custom_assert.py @@ -1,4 +1,5 @@ """Test custom assert functions.""" + import pytest from concrete.ml.common.debugging.custom_assert import assert_false, assert_not_reached, assert_true diff --git a/tests/common/test_pbs_error_probability_settings.py b/tests/common/test_pbs_error_probability_settings.py index 1eb8748008..85e4128bd1 100644 --- a/tests/common/test_pbs_error_probability_settings.py +++ b/tests/common/test_pbs_error_probability_settings.py @@ -1,4 +1,5 @@ """Tests for the sklearn linear models.""" + import warnings from inspect import signature diff --git a/tests/common/test_serialization.py b/tests/common/test_serialization.py index a38fb80a41..a39adfc038 100644 --- a/tests/common/test_serialization.py +++ b/tests/common/test_serialization.py @@ -3,6 +3,7 @@ Here we test the custom dump(s)/load(s) functions for all supported objects. We also check that serializing unsupported object types properly throws an error. """ + import inspect import io import warnings diff --git a/tests/common/test_similarity_score.py b/tests/common/test_similarity_score.py index 9b5559458f..efc82e3136 100644 --- a/tests/common/test_similarity_score.py +++ b/tests/common/test_similarity_score.py @@ -1,4 +1,5 @@ """Tests for the r2 score test """ + import numpy import pytest diff --git a/tests/common/test_skearn_model_lists.py b/tests/common/test_skearn_model_lists.py index 3062109822..7edaf77d01 100644 --- a/tests/common/test_skearn_model_lists.py +++ b/tests/common/test_skearn_model_lists.py @@ -1,4 +1,5 @@ """Tests lists of models in Concrete ML.""" + from concrete.ml.pytest.utils import MODELS_AND_DATASETS, UNIQUE_MODELS_AND_DATASETS from concrete.ml.sklearn import ( _get_sklearn_all_models, diff --git a/tests/common/test_utils.py b/tests/common/test_utils.py index f94838f4e1..6c0573938b 100644 --- a/tests/common/test_utils.py +++ b/tests/common/test_utils.py @@ -1,4 +1,5 @@ """Test utils functions.""" + import numpy import pandas import pytest diff --git a/tests/common/test_version.py b/tests/common/test_version.py index c2d57bc98e..b036d07ad7 100644 --- a/tests/common/test_version.py +++ b/tests/common/test_version.py @@ -1,4 +1,5 @@ """Testing the version of the package""" + import concrete from concrete import ml diff --git a/tests/deployment/test_deployment.py b/tests/deployment/test_deployment.py index 3567363fc8..3e215e1e58 100644 --- a/tests/deployment/test_deployment.py +++ b/tests/deployment/test_deployment.py @@ -1,4 +1,5 @@ """Test deployment.""" + import io import time import uuid diff --git a/tests/onnx/test_onnx_ops_impl.py b/tests/onnx/test_onnx_ops_impl.py index fcb029d1d8..42922d9c2d 100644 --- a/tests/onnx/test_onnx_ops_impl.py +++ b/tests/onnx/test_onnx_ops_impl.py @@ -1,4 +1,5 @@ """Test custom assert functions.""" + import numpy import pytest diff --git a/tests/pandas/test_pandas.py b/tests/pandas/test_pandas.py index 805359e84f..8a50841355 100644 --- a/tests/pandas/test_pandas.py +++ b/tests/pandas/test_pandas.py @@ -1,4 +1,5 @@ """Tests the encrypted data-frame API abd its coherence with Pandas""" + import re import shutil import tempfile diff --git a/tests/pytest/test_pytest_utils.py b/tests/pytest/test_pytest_utils.py index df4a6ccf46..503dad5c4a 100644 --- a/tests/pytest/test_pytest_utils.py +++ b/tests/pytest/test_pytest_utils.py @@ -1,4 +1,5 @@ """Test pytest utility functions.""" + import numpy import pytest from numpy.random import RandomState diff --git a/tests/quantization/test_compilation.py b/tests/quantization/test_compilation.py index e482a57b33..46e8569b62 100644 --- a/tests/quantization/test_compilation.py +++ b/tests/quantization/test_compilation.py @@ -1,4 +1,5 @@ """Test Neural Networks compilations""" + import numpy import onnx import pytest diff --git a/tests/quantization/test_quantized_module.py b/tests/quantization/test_quantized_module.py index 75f65ca2a5..0599dcad09 100644 --- a/tests/quantization/test_quantized_module.py +++ b/tests/quantization/test_quantized_module.py @@ -1,4 +1,5 @@ """Tests for the quantized module.""" + from functools import partial import numpy diff --git a/tests/quantization/test_quantizers.py b/tests/quantization/test_quantizers.py index c682c0e844..abafc44373 100644 --- a/tests/quantization/test_quantizers.py +++ b/tests/quantization/test_quantizers.py @@ -1,4 +1,5 @@ """Tests for the quantized array/tensors.""" + import numpy import pytest diff --git a/tests/seeding/test_seeding.py b/tests/seeding/test_seeding.py index 57fd4ad52a..49450b276c 100644 --- a/tests/seeding/test_seeding.py +++ b/tests/seeding/test_seeding.py @@ -1,4 +1,5 @@ """Tests for the torch to numpy module.""" + import inspect import random import warnings diff --git a/tests/seeding/test_seeding_system_file_a.py b/tests/seeding/test_seeding_system_file_a.py index 8bbac1bab2..feeffedeee 100644 --- a/tests/seeding/test_seeding_system_file_a.py +++ b/tests/seeding/test_seeding_system_file_a.py @@ -1,4 +1,5 @@ """Tests for the torch to numpy module.""" + import random import numpy diff --git a/tests/seeding/test_seeding_system_file_b.py b/tests/seeding/test_seeding_system_file_b.py index 8bbac1bab2..feeffedeee 100644 --- a/tests/seeding/test_seeding_system_file_b.py +++ b/tests/seeding/test_seeding_system_file_b.py @@ -1,4 +1,5 @@ """Tests for the torch to numpy module.""" + import random import numpy diff --git a/tests/sklearn/test_common.py b/tests/sklearn/test_common.py index 7b70e9cbaa..4f7889878c 100644 --- a/tests/sklearn/test_common.py +++ b/tests/sklearn/test_common.py @@ -1,4 +1,5 @@ """Tests common to all sklearn models.""" + import inspect import warnings diff --git a/tests/sklearn/test_fhe_training.py b/tests/sklearn/test_fhe_training.py index eee4c9281e..5bab260796 100644 --- a/tests/sklearn/test_fhe_training.py +++ b/tests/sklearn/test_fhe_training.py @@ -1,4 +1,5 @@ """Tests training in FHE.""" + import re import warnings diff --git a/tests/sklearn/test_qnn.py b/tests/sklearn/test_qnn.py index 89f190184a..e0123c06f3 100644 --- a/tests/sklearn/test_qnn.py +++ b/tests/sklearn/test_qnn.py @@ -1,4 +1,5 @@ """Tests for the FHE sklearn compatible NNs.""" + from copy import deepcopy from itertools import product @@ -566,7 +567,7 @@ def test_power_of_two_scaling( # Count the number of patterns that were optimized with roundPBS num_round_pbs_layers = 0 - for (_, node_op) in model.quantized_module_.quant_layers_dict.values(): + for _, node_op in model.quantized_module_.quant_layers_dict.values(): if isinstance(node_op, QuantizedMixingOp): num_round_pbs_layers += 1 if node_op.rounding_threshold_bits is not None else 0 lsbs_to_remove = ( @@ -616,7 +617,7 @@ def test_power_of_two_scaling( # Remove rounding in the network to perform inference without the optimization. # We expect a network that was optimized with the power-of-two adapter # to be exactly correct to the non-optimized one - for (_, node_op) in model.quantized_module_.quant_layers_dict.values(): + for _, node_op in model.quantized_module_.quant_layers_dict.values(): if isinstance(node_op, QuantizedMixingOp): node_op.rounding_threshold_bits = None node_op.lsbs_to_remove = None diff --git a/tests/torch/test_brevitas_qat.py b/tests/torch/test_brevitas_qat.py index cf6f70c7e1..1c24d4ec5b 100644 --- a/tests/torch/test_brevitas_qat.py +++ b/tests/torch/test_brevitas_qat.py @@ -532,7 +532,7 @@ def test_brevitas_power_of_two( pot_should_be_applied = not manual_rounding and power_of_two # Count the number of patterns that were optimized with roundPBS num_round_pbs_layers = 0 - for (_, node_op) in quantized_module.quant_layers_dict.values(): + for _, node_op in quantized_module.quant_layers_dict.values(): if isinstance(node_op, QuantizedMixingOp): num_round_pbs_layers += 1 if node_op.rounding_threshold_bits is not None else 0 if pot_should_be_applied: @@ -590,7 +590,7 @@ def test_brevitas_power_of_two( # Remove rounding in the network to perform inference without the optimization. # We expect a network that was optimized with the power-of-two adapter # to be exactly correct to the non-optimized one - for (_, node_op) in quantized_module.quant_layers_dict.values(): + for _, node_op in quantized_module.quant_layers_dict.values(): if isinstance(node_op, QuantizedMixingOp): node_op.rounding_threshold_bits = None node_op.lsbs_to_remove = None diff --git a/tests/torch/test_compile_keras.py b/tests/torch/test_compile_keras.py index 8bf4b065b3..257d4c11d2 100644 --- a/tests/torch/test_compile_keras.py +++ b/tests/torch/test_compile_keras.py @@ -1,4 +1,5 @@ """Tests for Keras models (by conversion to ONNX).""" + import tempfile import warnings from pathlib import Path diff --git a/tests/torch/test_compile_torch.py b/tests/torch/test_compile_torch.py index 8a66434f15..16770c88cc 100644 --- a/tests/torch/test_compile_torch.py +++ b/tests/torch/test_compile_torch.py @@ -1,4 +1,5 @@ """Tests for the torch to numpy module.""" + # pylint: disable=too-many-lines import io import tempfile diff --git a/tests/torch/test_torch_to_numpy.py b/tests/torch/test_torch_to_numpy.py index ab33153b9d..1b121d1b02 100644 --- a/tests/torch/test_torch_to_numpy.py +++ b/tests/torch/test_torch_to_numpy.py @@ -1,4 +1,5 @@ """Tests for the torch to numpy module.""" + from functools import partial import numpy diff --git a/tests/torch/test_training.py b/tests/torch/test_training.py index d0ff304ee2..2c01f2c217 100644 --- a/tests/torch/test_training.py +++ b/tests/torch/test_training.py @@ -1,4 +1,5 @@ """Tests for FHE training.""" + import numpy import torch from sklearn import datasets diff --git a/tests/virtual_lib/test_virtual_lib.py b/tests/virtual_lib/test_virtual_lib.py index 47d73ebb55..7fad61e5ed 100644 --- a/tests/virtual_lib/test_virtual_lib.py +++ b/tests/virtual_lib/test_virtual_lib.py @@ -1,4 +1,5 @@ """Test file for FHE simulation specific tests.""" + import numpy from concrete.fhe.compilation.circuit import Circuit from concrete.fhe.compilation.compiler import Compiler diff --git a/use_case_examples/cifar/cifar_brevitas_finetuning/cifar_utils.py b/use_case_examples/cifar/cifar_brevitas_finetuning/cifar_utils.py index 6136a0c223..56c2397c08 100644 --- a/use_case_examples/cifar/cifar_brevitas_finetuning/cifar_utils.py +++ b/use_case_examples/cifar/cifar_brevitas_finetuning/cifar_utils.py @@ -416,7 +416,6 @@ def torch_inference( device: str = "cpu", verbose: bool = False, ) -> float: - """Returns the `top_k` accuracy. Args: @@ -465,7 +464,6 @@ def fhe_compatibility(model: Callable, data: DataLoader) -> Callable: def mapping_keys(pre_trained_weights: Dict, model: nn.Module, device: str) -> nn.Module: - """ Initialize the quantized model with pre-trained fp32 weights. diff --git a/use_case_examples/cifar/cifar_brevitas_training/evaluate_torch_cml.py b/use_case_examples/cifar/cifar_brevitas_training/evaluate_torch_cml.py index dd5f158aca..d3e2e8b006 100644 --- a/use_case_examples/cifar/cifar_brevitas_training/evaluate_torch_cml.py +++ b/use_case_examples/cifar/cifar_brevitas_training/evaluate_torch_cml.py @@ -118,9 +118,11 @@ def main(args): input_set, n_bits={"model_inputs": 8, "model_outputs": 8}, configuration=cfg, - rounding_threshold_bits={"n_bits": rounding_threshold_bits, "method": "EXACT"} - if rounding_threshold_bits is not None - else None, + rounding_threshold_bits=( + {"n_bits": rounding_threshold_bits, "method": "EXACT"} + if rounding_threshold_bits is not None + else None + ), ) # Print max bit-width in the circuit diff --git a/use_case_examples/deployment/breast_cancer_builtin/client.py b/use_case_examples/deployment/breast_cancer_builtin/client.py index d8ad52bb92..fa2c79af5d 100644 --- a/use_case_examples/deployment/breast_cancer_builtin/client.py +++ b/use_case_examples/deployment/breast_cancer_builtin/client.py @@ -8,6 +8,7 @@ - Collect the data and decrypt it - De-quantize the decrypted results """ + import io import os from pathlib import Path diff --git a/use_case_examples/deployment/cifar_8_bit/client.py b/use_case_examples/deployment/cifar_8_bit/client.py index 2b2cdbf510..a35d669bbb 100644 --- a/use_case_examples/deployment/cifar_8_bit/client.py +++ b/use_case_examples/deployment/cifar_8_bit/client.py @@ -8,6 +8,7 @@ - Collect the data and decrypt it - De-quantize the decrypted results """ + import io import os import sys diff --git a/use_case_examples/deployment/cifar_8_bit/compile.py b/use_case_examples/deployment/cifar_8_bit/compile.py index f7b5eac83b..dc7579d41b 100644 --- a/use_case_examples/deployment/cifar_8_bit/compile.py +++ b/use_case_examples/deployment/cifar_8_bit/compile.py @@ -1,4 +1,5 @@ """Load torch model, compiles it to FHE and exports it""" + import sys import time from pathlib import Path diff --git a/use_case_examples/deployment/sentiment_analysis/train.py b/use_case_examples/deployment/sentiment_analysis/train.py index 02624fa843..d396001d3a 100644 --- a/use_case_examples/deployment/sentiment_analysis/train.py +++ b/use_case_examples/deployment/sentiment_analysis/train.py @@ -1,4 +1,5 @@ """Copy-pasted from use_case_examples/sentiment_analysis_with_transformer""" + import os os.environ["TRANSFORMERS_CACHE"] = "./hf_cache" diff --git a/use_case_examples/hybrid_model/infer_hybrid_llm_generate.py b/use_case_examples/hybrid_model/infer_hybrid_llm_generate.py index f4a8d64d6d..5591fa54e8 100644 --- a/use_case_examples/hybrid_model/infer_hybrid_llm_generate.py +++ b/use_case_examples/hybrid_model/infer_hybrid_llm_generate.py @@ -1,4 +1,5 @@ """Showcase for the hybrid model converter.""" + import json import os import time