diff --git a/concrete/common/debugging/printing.py b/concrete/common/debugging/printing.py index 8187139ce..fc367a2c1 100644 --- a/concrete/common/debugging/printing.py +++ b/concrete/common/debugging/printing.py @@ -82,7 +82,7 @@ def get_printable_graph(opgraph: OPGraph, show_data_types: bool = False) -> str: custom_assert([x[0] for x in list_of_arg_name] == list(range(len(list_of_arg_name)))) # Then, just print the predecessors in the right order - what_to_print += ", ".join([x[1] for x in list_of_arg_name]) + ")" + what_to_print += ", ".join(["%" + x[1] for x in list_of_arg_name]) + ")" # This code doesn't work with more than a single output new_line = f"%{i} = {what_to_print}" diff --git a/tests/numpy/test_compile.py b/tests/numpy/test_compile.py index 6e3d6347b..f0c5aa948 100644 --- a/tests/numpy/test_compile.py +++ b/tests/numpy/test_compile.py @@ -364,7 +364,7 @@ def test_small_inputset_treat_warnings_as_errors(): "# EncryptedTensor, shape=(4,)>" "\n%1 = y " "# EncryptedTensor, shape=(4,)>" - "\n%2 = Dot(0, 1) " + "\n%2 = Dot(%0, %1) " "# EncryptedScalar>" "\nreturn(%2)\n", ), diff --git a/tests/numpy/test_debugging.py b/tests/numpy/test_debugging.py index a7342c485..b19ab4aff 100644 --- a/tests/numpy/test_debugging.py +++ b/tests/numpy/test_debugging.py @@ -40,23 +40,23 @@ def issue_130_c(x, y): @pytest.mark.parametrize( "lambda_f,ref_graph_str", [ - (lambda x, y: x + y, "%0 = x\n%1 = y\n%2 = Add(0, 1)\nreturn(%2)\n"), - (lambda x, y: x - y, "%0 = x\n%1 = y\n%2 = Sub(0, 1)\nreturn(%2)\n"), - (lambda x, y: x + x, "%0 = x\n%1 = Add(0, 0)\nreturn(%1)\n"), + (lambda x, y: x + y, "%0 = x\n%1 = y\n%2 = Add(%0, %1)\nreturn(%2)\n"), + (lambda x, y: x - y, "%0 = x\n%1 = y\n%2 = Sub(%0, %1)\nreturn(%2)\n"), + (lambda x, y: x + x, "%0 = x\n%1 = Add(%0, %0)\nreturn(%1)\n"), ( lambda x, y: x + x - y * y * y + x, - "%0 = x\n%1 = y\n%2 = Add(0, 0)\n%3 = Mul(1, 1)" - "\n%4 = Mul(3, 1)\n%5 = Sub(2, 4)\n%6 = Add(5, 0)\nreturn(%6)\n", + "%0 = x\n%1 = y\n%2 = Add(%0, %0)\n%3 = Mul(%1, %1)" + "\n%4 = Mul(%3, %1)\n%5 = Sub(%2, %4)\n%6 = Add(%5, %0)\nreturn(%6)\n", ), - (lambda x, y: x + 1, "%0 = x\n%1 = Constant(1)\n%2 = Add(0, 1)\nreturn(%2)\n"), - (lambda x, y: 1 + x, "%0 = x\n%1 = Constant(1)\n%2 = Add(0, 1)\nreturn(%2)\n"), - (lambda x, y: (-1) + x, "%0 = x\n%1 = Constant(-1)\n%2 = Add(0, 1)\nreturn(%2)\n"), - (lambda x, y: 3 * x, "%0 = x\n%1 = Constant(3)\n%2 = Mul(0, 1)\nreturn(%2)\n"), - (lambda x, y: x * 3, "%0 = x\n%1 = Constant(3)\n%2 = Mul(0, 1)\nreturn(%2)\n"), - (lambda x, y: x * (-3), "%0 = x\n%1 = Constant(-3)\n%2 = Mul(0, 1)\nreturn(%2)\n"), - (lambda x, y: x - 11, "%0 = x\n%1 = Constant(11)\n%2 = Sub(0, 1)\nreturn(%2)\n"), - (lambda x, y: 11 - x, "%0 = Constant(11)\n%1 = x\n%2 = Sub(0, 1)\nreturn(%2)\n"), - (lambda x, y: (-11) - x, "%0 = Constant(-11)\n%1 = x\n%2 = Sub(0, 1)\nreturn(%2)\n"), + (lambda x, y: x + 1, "%0 = x\n%1 = Constant(1)\n%2 = Add(%0, %1)\nreturn(%2)\n"), + (lambda x, y: 1 + x, "%0 = x\n%1 = Constant(1)\n%2 = Add(%0, %1)\nreturn(%2)\n"), + (lambda x, y: (-1) + x, "%0 = x\n%1 = Constant(-1)\n%2 = Add(%0, %1)\nreturn(%2)\n"), + (lambda x, y: 3 * x, "%0 = x\n%1 = Constant(3)\n%2 = Mul(%0, %1)\nreturn(%2)\n"), + (lambda x, y: x * 3, "%0 = x\n%1 = Constant(3)\n%2 = Mul(%0, %1)\nreturn(%2)\n"), + (lambda x, y: x * (-3), "%0 = x\n%1 = Constant(-3)\n%2 = Mul(%0, %1)\nreturn(%2)\n"), + (lambda x, y: x - 11, "%0 = x\n%1 = Constant(11)\n%2 = Sub(%0, %1)\nreturn(%2)\n"), + (lambda x, y: 11 - x, "%0 = Constant(11)\n%1 = x\n%2 = Sub(%0, %1)\nreturn(%2)\n"), + (lambda x, y: (-11) - x, "%0 = Constant(-11)\n%1 = x\n%2 = Sub(%0, %1)\nreturn(%2)\n"), ( lambda x, y: x + 13 - y * (-21) * y + 44, "%0 = Constant(44)" @@ -64,11 +64,11 @@ def issue_130_c(x, y): "\n%2 = Constant(13)" "\n%3 = y" "\n%4 = Constant(-21)" - "\n%5 = Add(1, 2)" - "\n%6 = Mul(3, 4)" - "\n%7 = Mul(6, 3)" - "\n%8 = Sub(5, 7)" - "\n%9 = Add(8, 0)" + "\n%5 = Add(%1, %2)" + "\n%6 = Mul(%3, %4)" + "\n%7 = Mul(%6, %3)" + "\n%8 = Sub(%5, %7)" + "\n%9 = Add(%8, %0)" "\nreturn(%9)\n", ), # Multiple outputs @@ -78,9 +78,9 @@ def issue_130_c(x, y): "\n%1 = Constant(1)" "\n%2 = Constant(2)" "\n%3 = y" - "\n%4 = Add(0, 1)" - "\n%5 = Add(0, 3)" - "\n%6 = Add(5, 2)" + "\n%4 = Add(%0, %1)" + "\n%5 = Add(%0, %3)" + "\n%6 = Add(%5, %2)" "\nreturn(%4, %6)\n", ), ( @@ -89,28 +89,28 @@ def issue_130_c(x, y): ), ( lambda x, y: (x, x + 1), - "%0 = x\n%1 = Constant(1)\n%2 = Add(0, 1)\nreturn(%0, %2)\n", + "%0 = x\n%1 = Constant(1)\n%2 = Add(%0, %1)\nreturn(%0, %2)\n", ), ( lambda x, y: (x + 1, x + 1), "%0 = x" "\n%1 = Constant(1)" "\n%2 = Constant(1)" - "\n%3 = Add(0, 1)" - "\n%4 = Add(0, 2)" + "\n%3 = Add(%0, %1)" + "\n%4 = Add(%0, %2)" "\nreturn(%3, %4)\n", ), ( issue_130_a, - "%0 = x\n%1 = Constant(1)\n%2 = Add(0, 1)\nreturn(%2, %2)\n", + "%0 = x\n%1 = Constant(1)\n%2 = Add(%0, %1)\nreturn(%2, %2)\n", ), ( issue_130_b, - "%0 = x\n%1 = Constant(1)\n%2 = Sub(0, 1)\nreturn(%2, %2)\n", + "%0 = x\n%1 = Constant(1)\n%2 = Sub(%0, %1)\nreturn(%2, %2)\n", ), ( issue_130_c, - "%0 = Constant(1)\n%1 = x\n%2 = Sub(0, 1)\nreturn(%2, %2)\n", + "%0 = Constant(1)\n%1 = x\n%2 = Sub(%0, %1)\nreturn(%2, %2)\n", ), ], ) @@ -155,12 +155,12 @@ def test_print_and_draw_graph(lambda_f, ref_graph_str, x_y): ( lambda x: LOOKUP_TABLE_FROM_2B_TO_4B[x], {"x": EncryptedScalar(Integer(2, is_signed=False))}, - "%0 = x\n%1 = TLU(0)\nreturn(%1)\n", + "%0 = x\n%1 = TLU(%0)\nreturn(%1)\n", ), ( lambda x: LOOKUP_TABLE_FROM_3B_TO_2B[x + 4], {"x": EncryptedScalar(Integer(2, is_signed=False))}, - "%0 = x\n%1 = Constant(4)\n%2 = Add(0, 1)\n%3 = TLU(2)\nreturn(%3)\n", + "%0 = x\n%1 = Constant(4)\n%2 = Add(%0, %1)\n%3 = TLU(%2)\nreturn(%3)\n", ), ], ) @@ -189,7 +189,7 @@ def test_print_and_draw_graph_with_direct_tlu(lambda_f, params, ref_graph_str): "x": EncryptedTensor(Integer(2, is_signed=False), shape=(3,)), "y": EncryptedTensor(Integer(2, is_signed=False), shape=(3,)), }, - "%0 = x\n%1 = y\n%2 = Dot(0, 1)\nreturn(%2)\n", + "%0 = x\n%1 = y\n%2 = Dot(%0, %1)\nreturn(%2)\n", ), # pylint: enable=unnecessary-lambda ], @@ -223,7 +223,7 @@ def test_print_and_draw_graph_with_dot(lambda_f, params, ref_graph_str): ), "%0 = x # EncryptedScalar>" "\n%1 = y # EncryptedScalar>" - "\n%2 = Add(0, 1) # EncryptedScalar>" + "\n%2 = Add(%0, %1) # EncryptedScalar>" "\nreturn(%2)\n", ), ( @@ -236,7 +236,7 @@ def test_print_and_draw_graph_with_dot(lambda_f, params, ref_graph_str): "# EncryptedScalar>" "\n%1 = y " "# EncryptedScalar>" - "\n%2 = Mul(0, 1) " + "\n%2 = Mul(%0, %1) " "# EncryptedScalar>" "\nreturn(%2)\n", ), @@ -264,7 +264,7 @@ def test_print_with_show_data_types(lambda_f, x_y, ref_graph_str): {"x": EncryptedScalar(Integer(2, is_signed=False))}, "%0 = x " "# EncryptedScalar>" - "\n%1 = TLU(0) " + "\n%1 = TLU(%0) " "# EncryptedScalar>" "\nreturn(%1)\n", ), @@ -275,9 +275,9 @@ def test_print_with_show_data_types(lambda_f, x_y, ref_graph_str): "# EncryptedScalar>" "\n%1 = Constant(4) " "# ClearScalar>" - "\n%2 = Add(0, 1) " + "\n%2 = Add(%0, %1) " "# EncryptedScalar>" - "\n%3 = TLU(2) " + "\n%3 = TLU(%2) " "# EncryptedScalar>" "\nreturn(%3)\n", ), @@ -288,11 +288,11 @@ def test_print_with_show_data_types(lambda_f, x_y, ref_graph_str): "# EncryptedScalar>" "\n%1 = Constant(4) " "# ClearScalar>" - "\n%2 = Add(0, 1) " + "\n%2 = Add(%0, %1) " "# EncryptedScalar>" - "\n%3 = TLU(2) " + "\n%3 = TLU(%2) " "# EncryptedScalar>" - "\n%4 = TLU(3) " + "\n%4 = TLU(%3) " "# EncryptedScalar>" "\nreturn(%4)\n", ), diff --git a/tests/numpy/test_tracing.py b/tests/numpy/test_tracing.py index 95e500c34..e07f73fb9 100644 --- a/tests/numpy/test_tracing.py +++ b/tests/numpy/test_tracing.py @@ -195,12 +195,12 @@ def test_numpy_tracing_tensors(): %4 = Constant([[5 6] [7 8]]) # ClearTensor, shape=(2, 2)> %5 = x # EncryptedTensor, shape=(2, 2)> %6 = Constant([[1 2] [3 4]]) # ClearTensor, shape=(2, 2)> -%7 = Add(5, 6) # EncryptedTensor, shape=(2, 2)> -%8 = Add(4, 7) # EncryptedTensor, shape=(2, 2)> -%9 = Sub(3, 8) # EncryptedTensor, shape=(2, 2)> -%10 = Sub(9, 2) # EncryptedTensor, shape=(2, 2)> -%11 = Mul(10, 1) # EncryptedTensor, shape=(2, 2)> -%12 = Mul(0, 11) # EncryptedTensor, shape=(2, 2)> +%7 = Add(%5, %6) # EncryptedTensor, shape=(2, 2)> +%8 = Add(%4, %7) # EncryptedTensor, shape=(2, 2)> +%9 = Sub(%3, %8) # EncryptedTensor, shape=(2, 2)> +%10 = Sub(%9, %2) # EncryptedTensor, shape=(2, 2)> +%11 = Mul(%10, %1) # EncryptedTensor, shape=(2, 2)> +%12 = Mul(%0, %11) # EncryptedTensor, shape=(2, 2)> return(%12) """.lstrip() @@ -234,12 +234,12 @@ def test_numpy_explicit_tracing_tensors(): %4 = Constant([[5 6] [7 8]]) # ClearTensor, shape=(2, 2)> %5 = x # EncryptedTensor, shape=(2, 2)> %6 = Constant([[1 2] [3 4]]) # ClearTensor, shape=(2, 2)> -%7 = Add(5, 6) # EncryptedTensor, shape=(2, 2)> -%8 = Add(4, 7) # EncryptedTensor, shape=(2, 2)> -%9 = Sub(3, 8) # EncryptedTensor, shape=(2, 2)> -%10 = Sub(9, 2) # EncryptedTensor, shape=(2, 2)> -%11 = Mul(10, 1) # EncryptedTensor, shape=(2, 2)> -%12 = Mul(0, 11) # EncryptedTensor, shape=(2, 2)> +%7 = Add(%5, %6) # EncryptedTensor, shape=(2, 2)> +%8 = Add(%4, %7) # EncryptedTensor, shape=(2, 2)> +%9 = Sub(%3, %8) # EncryptedTensor, shape=(2, 2)> +%10 = Sub(%9, %2) # EncryptedTensor, shape=(2, 2)> +%11 = Mul(%10, %1) # EncryptedTensor, shape=(2, 2)> +%12 = Mul(%0, %11) # EncryptedTensor, shape=(2, 2)> return(%12) """.lstrip()