Sorry to bother you, but I’ve encountered two issues related to maximum.
I guess their root causes may not be the same, and I think my usage should be correct?
The outputs are quite confusing.
Iusse 1:
When I use multiplication operations before maximum, the output results become incorrect.
from concrete import fhe
import numpy as np
@fhe.compiler({"x": "encrypted", "y": "encrypted", "z": "encrypted", "w": "encrypted"})
def debug_foo(x, y, z, w):
res1 = x * y
res2 = z * w
final = np.maximum(res1, res2)
return final
if __name__ == "__main__":
x, y = -39, 74
z, w = -38, 75
expect_result = debug_foo(x, y, z, w)
print(f"expect result: {expect_result}")
inputset = fhe.inputset(fhe.int8, fhe.int8, fhe.int8, fhe.int8)
circuit = debug_foo.compile(inputset)
circuit.keygen()
encrypted_x, encrypted_y, encrypted_z, encrypted_w = circuit.encrypt(x, y, z, w)
encrypted_result = circuit.run(encrypted_x, encrypted_y, encrypted_z, encrypted_w)
result = circuit.decrypt(encrypted_result)
print(f"concrete result: {result}")
The output is:
expect result: -2850
concrete result: -7542
Issue 2:
When I use multiplication operations after maximum, the output also becomes incorrect.
from concrete import fhe
import numpy as np
configuration = fhe.Configuration()
@fhe.compiler({"x": "encrypted", "y": "encrypted"})
def debug_foo(x, y):
x = fhe.hint(x, bit_width=8)
y = fhe.hint(y, bit_width=8)
var2 = 14 + y
var3 = var2 * 2
var4 = 7
var5 = np.minimum(var3, var4)
var6 = var5 * -5
var7 = np.maximum(var5, var6)
var8 = var7 * -6
return var8
if __name__ == "__main__":
x, y = -12, 13
expect_result = debug_foo(x, y)
print(f"expect result: {expect_result}")
inputset = fhe.inputset(fhe.int8, fhe.int8)
circuit = debug_foo.compile(inputset, configuration=configuration)
circuit.keygen()
encrypted_x, encrypted_y = circuit.encrypt(x, y)
encrypted_result = circuit.run(encrypted_x, encrypted_y)
result = circuit.decrypt(encrypted_result)
print(f"concrete result: {result}")
The output is:
expect result: -42
concrete result: -2562
Additionally, I checked the value of v7, and the output was correct. This may suggest that this issue might lie in the final multiplication operation, rather than being directly related to maximum as in Issue 1?
# output of v7
expect result: 7
concrete result: 7