From 6226ecef64a77fef5a6b3d37b56b12cba7cfc48f Mon Sep 17 00:00:00 2001 From: aquint-zama Date: Fri, 19 Apr 2024 16:26:45 +0200 Subject: [PATCH] chore(frontend-python): update black dev dependency --- .../concrete/fhe/compilation/circuit.py | 14 +-- .../concrete/fhe/compilation/client.py | 14 +-- .../concrete/fhe/compilation/compiler.py | 16 +-- .../concrete/fhe/compilation/configuration.py | 8 +- .../concrete/fhe/compilation/module.py | 14 +-- .../concrete/fhe/mlir/context.py | 8 +- .../concrete/fhe/mlir/converter.py | 4 +- .../examples/game_of_life/game_of_life.py | 2 +- .../concrete-python/requirements.dev.txt | 2 +- .../tests/compilation/test_circuit.py | 4 +- .../tests/compilation/test_configuration.py | 10 +- .../tests/compilation/test_program.py | 1 + .../tests/mlir/test_converter.py | 100 +++++++++++------- .../tests/representation/test_utils.py | 1 + 14 files changed, 116 insertions(+), 82 deletions(-) diff --git a/frontends/concrete-python/concrete/fhe/compilation/circuit.py b/frontends/concrete-python/concrete/fhe/compilation/circuit.py index d4fc79fb36..0468eaf6e8 100644 --- a/frontends/concrete-python/concrete/fhe/compilation/circuit.py +++ b/frontends/concrete-python/concrete/fhe/compilation/circuit.py @@ -158,12 +158,14 @@ def simulate(self, *args: Any) -> Any: exporter = SimulatedValueExporter.new(self.simulator.client_specs.client_parameters) exported = [ - None - if arg is None - else Value( - exporter.export_tensor(position, arg.flatten().tolist(), list(arg.shape)) - if isinstance(arg, np.ndarray) and arg.shape != () - else exporter.export_scalar(position, int(arg)) + ( + None + if arg is None + else Value( + exporter.export_tensor(position, arg.flatten().tolist(), list(arg.shape)) + if isinstance(arg, np.ndarray) and arg.shape != () + else exporter.export_scalar(position, int(arg)) + ) ) for position, arg in enumerate(ordered_validated_args) ] diff --git a/frontends/concrete-python/concrete/fhe/compilation/client.py b/frontends/concrete-python/concrete/fhe/compilation/client.py index c77e13aa18..d5268969d3 100644 --- a/frontends/concrete-python/concrete/fhe/compilation/client.py +++ b/frontends/concrete-python/concrete/fhe/compilation/client.py @@ -143,12 +143,14 @@ def encrypt( exporter = ValueExporter.new(keyset, self.specs.client_parameters, function_name) exported = [ - None - if arg is None - else Value( - exporter.export_tensor(position, arg.flatten().tolist(), list(arg.shape)) - if isinstance(arg, np.ndarray) and arg.shape != () - else exporter.export_scalar(position, int(arg)) + ( + None + if arg is None + else Value( + exporter.export_tensor(position, arg.flatten().tolist(), list(arg.shape)) + if isinstance(arg, np.ndarray) and arg.shape != () + else exporter.export_scalar(position, int(arg)) + ) ) for position, arg in enumerate(ordered_sanitized_args) ] diff --git a/frontends/concrete-python/concrete/fhe/compilation/compiler.py b/frontends/concrete-python/concrete/fhe/compilation/compiler.py index 9125ad1124..99ac0c76b1 100644 --- a/frontends/concrete-python/concrete/fhe/compilation/compiler.py +++ b/frontends/concrete-python/concrete/fhe/compilation/compiler.py @@ -347,9 +347,11 @@ def trace( self.artifacts = ( artifacts if artifacts is not None - else DebugArtifacts() - if self.configuration.dump_artifacts_on_unexpected_failures - else None + else ( + DebugArtifacts() + if self.configuration.dump_artifacts_on_unexpected_failures + else None + ) ) try: @@ -447,9 +449,11 @@ def compile( self.artifacts = ( artifacts if artifacts is not None - else DebugArtifacts() - if self.configuration.dump_artifacts_on_unexpected_failures - else None + else ( + DebugArtifacts() + if self.configuration.dump_artifacts_on_unexpected_failures + else None + ) ) try: diff --git a/frontends/concrete-python/concrete/fhe/compilation/configuration.py b/frontends/concrete-python/concrete/fhe/compilation/configuration.py index 55c0c796b9..3d89409eda 100644 --- a/frontends/concrete-python/concrete/fhe/compilation/configuration.py +++ b/frontends/concrete-python/concrete/fhe/compilation/configuration.py @@ -1233,9 +1233,11 @@ def fork( args = locals() return Configuration( **{ - name: getattr(self, name) - if isinstance(args[name], Configuration.Keep) - else args[name] + name: ( + getattr(self, name) + if isinstance(args[name], Configuration.Keep) + else args[name] + ) for name in get_type_hints(Configuration.__init__) } ) diff --git a/frontends/concrete-python/concrete/fhe/compilation/module.py b/frontends/concrete-python/concrete/fhe/compilation/module.py index 9ed654053e..9ba41335df 100644 --- a/frontends/concrete-python/concrete/fhe/compilation/module.py +++ b/frontends/concrete-python/concrete/fhe/compilation/module.py @@ -128,12 +128,14 @@ def simulate(self, *args: Any) -> Any: self.runtime.server.client_specs.client_parameters, self.name ) exported = [ - None - if arg is None - else Value( - exporter.export_tensor(position, arg.flatten().tolist(), list(arg.shape)) - if isinstance(arg, np.ndarray) and arg.shape != () - else exporter.export_scalar(position, int(arg)) + ( + None + if arg is None + else Value( + exporter.export_tensor(position, arg.flatten().tolist(), list(arg.shape)) + if isinstance(arg, np.ndarray) and arg.shape != () + else exporter.export_scalar(position, int(arg)) + ) ) for position, arg in enumerate(ordered_validated_args) ] diff --git a/frontends/concrete-python/concrete/fhe/mlir/context.py b/frontends/concrete-python/concrete/fhe/mlir/context.py index 982fd30a7c..4a2316b0aa 100644 --- a/frontends/concrete-python/concrete/fhe/mlir/context.py +++ b/frontends/concrete-python/concrete/fhe/mlir/context.py @@ -2368,9 +2368,11 @@ def index_static( size = 1 stride = 1 offset = int( - indexing_element - if indexing_element >= 0 - else indexing_element + dimension_size, + ( + indexing_element + if indexing_element >= 0 + else indexing_element + dimension_size + ), ) offsets.append(offset) diff --git a/frontends/concrete-python/concrete/fhe/mlir/converter.py b/frontends/concrete-python/concrete/fhe/mlir/converter.py index dba0dee7ff..7c8859cd0e 100644 --- a/frontends/concrete-python/concrete/fhe/mlir/converter.py +++ b/frontends/concrete-python/concrete/fhe/mlir/converter.py @@ -749,9 +749,7 @@ def tlu(self, ctx: Context, node: Node, preds: List[Conversion]) -> Conversion: if variable_input.bit_width > original_bit_width: bit_width_difference = variable_input.bit_width - original_bit_width - shifter = ctx.constant( - ctx.i(variable_input.bit_width + 1), 2**bit_width_difference - ) + shifter = ctx.constant(ctx.i(variable_input.bit_width + 1), 2**bit_width_difference) variable_input = ctx.mul(variable_input.type, variable_input, shifter) variable_input = ctx.reinterpret(variable_input, bit_width=truncated_bit_width) diff --git a/frontends/concrete-python/examples/game_of_life/game_of_life.py b/frontends/concrete-python/examples/game_of_life/game_of_life.py index c1d2c5c662..060060584d 100644 --- a/frontends/concrete-python/examples/game_of_life/game_of_life.py +++ b/frontends/concrete-python/examples/game_of_life/game_of_life.py @@ -526,7 +526,7 @@ def main(): global_p_error=None, # 2**log2_global_p_error, p_error=2**log2_p_error, bitwise_strategy_preference=fhe.BitwiseStrategy.ONE_TLU_PROMOTED, - verbose=args.verbose_compilation + verbose=args.verbose_compilation, # parameter_selection_strategy=fhe.ParameterSelectionStrategy.MULTI, # single_precision=False, ) diff --git a/frontends/concrete-python/requirements.dev.txt b/frontends/concrete-python/requirements.dev.txt index 33e1ab6287..1f2eedfe14 100644 --- a/frontends/concrete-python/requirements.dev.txt +++ b/frontends/concrete-python/requirements.dev.txt @@ -5,7 +5,7 @@ pytest-randomly==3.15.0 pytest-xdist==3.2.1 pytest==7.2.2 -black==23.1.0 +black==24.4.0 isort==5.12.0 mypy==1.1.1 diff --git a/frontends/concrete-python/tests/compilation/test_circuit.py b/frontends/concrete-python/tests/compilation/test_circuit.py index f9b41206fc..950fe54047 100644 --- a/frontends/concrete-python/tests/compilation/test_circuit.py +++ b/frontends/concrete-python/tests/compilation/test_circuit.py @@ -402,9 +402,7 @@ def test_circuit_run_with_unused_arg(helpers): def f(x, y): # pylint: disable=unused-argument return x + 10 - inputset = [ - (np.random.randint(2**3, 2**4), np.random.randint(2**4, 2**5)) for _ in range(100) - ] + inputset = [(np.random.randint(2**3, 2**4), np.random.randint(2**4, 2**5)) for _ in range(100)] circuit = f.compile(inputset, configuration) with pytest.raises(ValueError, match="Expected 2 inputs but got 1"): diff --git a/frontends/concrete-python/tests/compilation/test_configuration.py b/frontends/concrete-python/tests/compilation/test_configuration.py index 3fbf7b50fb..a17c500ea5 100644 --- a/frontends/concrete-python/tests/compilation/test_configuration.py +++ b/frontends/concrete-python/tests/compilation/test_configuration.py @@ -230,7 +230,8 @@ def test_configuration_bad_fork(kwargs, expected_error, expected_message): main.%1 == main.%4 """, - """ + ( + """ main.%0 = 3 main.%1 = 8 @@ -240,8 +241,8 @@ def test_configuration_bad_fork(kwargs, expected_error, expected_message): main.max = 8 """ - if USE_MULTI_PRECISION - else """ + if USE_MULTI_PRECISION + else """ main.%0 = 8 main.%1 = 8 @@ -250,7 +251,8 @@ def test_configuration_bad_fork(kwargs, expected_error, expected_message): main.%4 = 8 main.max = 8 - """, + """ + ), ), ], ) diff --git a/frontends/concrete-python/tests/compilation/test_program.py b/frontends/concrete-python/tests/compilation/test_program.py index 9838f0beb2..aaabb84809 100644 --- a/frontends/concrete-python/tests/compilation/test_program.py +++ b/frontends/concrete-python/tests/compilation/test_program.py @@ -1,6 +1,7 @@ """ Tests of everything related to multi-circuit. """ + import tempfile import numpy as np diff --git a/frontends/concrete-python/tests/mlir/test_converter.py b/frontends/concrete-python/tests/mlir/test_converter.py index e6269968d6..223d4fa2bd 100644 --- a/frontends/concrete-python/tests/mlir/test_converter.py +++ b/frontends/concrete-python/tests/mlir/test_converter.py @@ -531,7 +531,8 @@ def assign(x, y): {"x": "encrypted", "y": "encrypted"}, [(100_000, 300_000)], RuntimeError, - """ + ( + """ Function you are trying to compile cannot be compiled @@ -544,8 +545,8 @@ def assign(x, y): return %2 """ # noqa: E501 - if USE_MULTI_PRECISION - else """ + if USE_MULTI_PRECISION + else """ Function you are trying to compile cannot be compiled @@ -558,14 +559,16 @@ def assign(x, y): ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ but only up to 16-bit bitwise operations are supported return %2 - """, # noqa: E501 + """ + ), # noqa: E501 ), pytest.param( lambda x, y: x != y, {"x": "encrypted", "y": "encrypted"}, [(300_000, 100_000)], RuntimeError, - """ + ( + """ Function you are trying to compile cannot be compiled @@ -578,8 +581,8 @@ def assign(x, y): return %2 """ # noqa: E501 - if USE_MULTI_PRECISION - else """ + if USE_MULTI_PRECISION + else """ Function you are trying to compile cannot be compiled @@ -592,14 +595,16 @@ def assign(x, y): ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ but only up to 16-bit comparison operations are supported return %2 - """, # noqa: E501 + """ + ), # noqa: E501 ), pytest.param( lambda x, y: x >= y, {"x": "encrypted", "y": "encrypted"}, [(300_000, 100_000)], RuntimeError, - """ + ( + """ Function you are trying to compile cannot be compiled @@ -612,8 +617,8 @@ def assign(x, y): return %2 """ # noqa: E501 - if USE_MULTI_PRECISION - else """ + if USE_MULTI_PRECISION + else """ Function you are trying to compile cannot be compiled @@ -626,14 +631,16 @@ def assign(x, y): ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ but only up to 16-bit comparison operations are supported return %2 - """, # noqa: E501 + """ + ), # noqa: E501 ), pytest.param( lambda x, y: x << y, {"x": "encrypted", "y": "encrypted"}, [(100_000, 20)], RuntimeError, - """ + ( + """ Function you are trying to compile cannot be compiled @@ -647,8 +654,8 @@ def assign(x, y): return %2 """ # noqa: E501 - if USE_MULTI_PRECISION - else """ + if USE_MULTI_PRECISION + else """ Function you are trying to compile cannot be compiled @@ -662,14 +669,16 @@ def assign(x, y): ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ this shift operation resulted in 37-bits but only up to 16-bit shift operations are supported return %2 - """, # noqa: E501 + """ + ), # noqa: E501 ), pytest.param( lambda x, y: x * y, {"x": "encrypted", "y": "encrypted"}, [(100_000, 20)], RuntimeError, - """ + ( + """ Function you are trying to compile cannot be compiled @@ -684,8 +693,8 @@ def assign(x, y): return %2 """ # noqa: E501 - if USE_MULTI_PRECISION - else """ + if USE_MULTI_PRECISION + else """ Function you are trying to compile cannot be compiled @@ -699,7 +708,8 @@ def assign(x, y): ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ but only up to 16-bit encrypted multiplications are supported return %2 - """, # noqa: E501 + """ + ), # noqa: E501 ), pytest.param( lambda x, y: np.dot(x, y), @@ -711,7 +721,8 @@ def assign(x, y): ) ], RuntimeError, - """ + ( + """ Function you are trying to compile cannot be compiled @@ -726,8 +737,8 @@ def assign(x, y): return %2 """ # noqa: E501 - if USE_MULTI_PRECISION - else """ + if USE_MULTI_PRECISION + else """ Function you are trying to compile cannot be compiled @@ -741,7 +752,8 @@ def assign(x, y): ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ but only up to 16-bit encrypted dot products are supported return %2 - """, # noqa: E501 + """ + ), # noqa: E501 ), pytest.param( lambda x, y: x @ y, @@ -759,7 +771,8 @@ def assign(x, y): ) ], RuntimeError, - """ + ( + """ Function you are trying to compile cannot be compiled @@ -774,8 +787,8 @@ def assign(x, y): return %2 """ # noqa: E501 - if USE_MULTI_PRECISION - else """ + if USE_MULTI_PRECISION + else """ Function you are trying to compile cannot be compiled @@ -789,7 +802,8 @@ def assign(x, y): ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ but only up to 16-bit encrypted matrix multiplications are supported return %2 - """, # noqa: E501 + """ + ), # noqa: E501 ), pytest.param( lambda x, y: np.dot(x, y), @@ -859,7 +873,8 @@ def assign(x, y): ) ], RuntimeError, - """ + ( + """ Function you are trying to compile cannot be compiled @@ -873,8 +888,8 @@ def assign(x, y): return %2 """ # noqa: E501 - if USE_MULTI_PRECISION - else """ + if USE_MULTI_PRECISION + else """ Function you are trying to compile cannot be compiled @@ -888,7 +903,8 @@ def assign(x, y): table shape should have been (8,) return %2 - """, # noqa: E501 + """ + ), # noqa: E501 ), pytest.param( lambda x, y, z: fhe.multivariate(lambda x, y, z: x + y // z)(x, y, z), @@ -928,7 +944,8 @@ def assign(x, y): ) ], RuntimeError, - """ + ( + """ Function you are trying to compile cannot be compiled @@ -941,8 +958,8 @@ def assign(x, y): return %2 """ # noqa: E501 - if USE_MULTI_PRECISION - else """ + if USE_MULTI_PRECISION + else """ Function you are trying to compile cannot be compiled @@ -955,7 +972,8 @@ def assign(x, y): ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ but only up to 16-bit minimum operation is supported return %2 - """, # noqa: E501 + """ + ), # noqa: E501 ), pytest.param( lambda x, y: np.maximum(x, y), @@ -967,7 +985,8 @@ def assign(x, y): ) ], RuntimeError, - """ + ( + """ Function you are trying to compile cannot be compiled @@ -980,8 +999,8 @@ def assign(x, y): return %2 """ # noqa: E501 - if USE_MULTI_PRECISION - else """ + if USE_MULTI_PRECISION + else """ Function you are trying to compile cannot be compiled @@ -994,7 +1013,8 @@ def assign(x, y): ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ but only up to 16-bit maximum operation is supported return %2 - """, # noqa: E501 + """ + ), # noqa: E501 ), pytest.param( lambda x: fhe.truncate_bit_pattern(x, lsbs_to_remove=2), diff --git a/frontends/concrete-python/tests/representation/test_utils.py b/frontends/concrete-python/tests/representation/test_utils.py index ed83b5c8bc..b55219d43a 100644 --- a/frontends/concrete-python/tests/representation/test_utils.py +++ b/frontends/concrete-python/tests/representation/test_utils.py @@ -1,6 +1,7 @@ """ Tests of utilities related to representation of computation. """ + import numpy as np import pytest