refactor(frontend-python): rename Value to ValueDescription

This commit is contained in:
Umut
2023-06-09 14:16:45 +02:00
parent 9c077852bb
commit 8a3e24d204
21 changed files with 167 additions and 145 deletions

View File

@@ -410,13 +410,17 @@ def test_direct_graph_integer_range(helpers):
# pylint: disable=import-outside-toplevel
from concrete.fhe.dtypes import Integer
from concrete.fhe.values import Value
from concrete.fhe.values import ValueDescription
# pylint: enable=import-outside-toplevel
circuit = fhe.Compiler.assemble(
lambda x: x,
{"x": Value(dtype=Integer(is_signed=False, bit_width=8), shape=(), is_encrypted=True)},
{
"x": ValueDescription(
dtype=Integer(is_signed=False, bit_width=8), shape=(), is_encrypted=True
)
},
configuration=helpers.configuration(),
)
assert circuit.graph.integer_range() is None

View File

@@ -7,7 +7,7 @@ import pytest
from concrete.fhe.dtypes import UnsignedInteger
from concrete.fhe.representation import Node
from concrete.fhe.values import ClearScalar, EncryptedScalar, EncryptedTensor, Value
from concrete.fhe.values import ClearScalar, EncryptedScalar, EncryptedTensor, ValueDescription
@pytest.mark.parametrize(
@@ -44,8 +44,8 @@ def test_node_bad_constant(constant, expected_error, expected_message):
pytest.param(
Node.generic(
name="add",
inputs=[Value.of(4), Value.of(10, is_encrypted=True)],
output=Value.of(14),
inputs=[ValueDescription.of(4), ValueDescription.of(10, is_encrypted=True)],
output=ValueDescription.of(14),
operation=lambda x, y: x + y,
),
["abc"],
@@ -56,8 +56,8 @@ def test_node_bad_constant(constant, expected_error, expected_message):
pytest.param(
Node.generic(
name="add",
inputs=[Value.of(4), Value.of(10, is_encrypted=True)],
output=Value.of(14),
inputs=[ValueDescription.of(4), ValueDescription.of(10, is_encrypted=True)],
output=ValueDescription.of(14),
operation=lambda x, y: x + y,
),
["abc", "def"],
@@ -68,8 +68,8 @@ def test_node_bad_constant(constant, expected_error, expected_message):
pytest.param(
Node.generic(
name="add",
inputs=[Value.of([3, 4]), Value.of(10, is_encrypted=True)],
output=Value.of([13, 14]),
inputs=[ValueDescription.of([3, 4]), ValueDescription.of(10, is_encrypted=True)],
output=ValueDescription.of([13, 14]),
operation=lambda x, y: x + y,
),
[[1, 2, 3, 4], 10],
@@ -81,7 +81,7 @@ def test_node_bad_constant(constant, expected_error, expected_message):
Node.generic(
name="unknown",
inputs=[],
output=Value.of(10),
output=ValueDescription.of(10),
operation=lambda: "abc",
),
[],
@@ -93,7 +93,7 @@ def test_node_bad_constant(constant, expected_error, expected_message):
Node.generic(
name="unknown",
inputs=[],
output=Value.of(10),
output=ValueDescription.of(10),
operation=lambda: np.array(["abc", "def"]),
),
[],
@@ -106,7 +106,7 @@ def test_node_bad_constant(constant, expected_error, expected_message):
Node.generic(
name="unknown",
inputs=[],
output=Value.of(10),
output=ValueDescription.of(10),
operation=lambda: [1, (), 3],
),
[],
@@ -118,7 +118,7 @@ def test_node_bad_constant(constant, expected_error, expected_message):
Node.generic(
name="unknown",
inputs=[],
output=Value.of(10),
output=ValueDescription.of(10),
operation=lambda: [1, 2, 3],
),
[],

View File

@@ -6,7 +6,13 @@ import numpy as np
import pytest
from concrete.fhe.dtypes import Float, SignedInteger, UnsignedInteger
from concrete.fhe.values import ClearScalar, ClearTensor, EncryptedScalar, EncryptedTensor, Value
from concrete.fhe.values import (
ClearScalar,
ClearTensor,
EncryptedScalar,
EncryptedTensor,
ValueDescription,
)
@pytest.mark.parametrize(
@@ -15,87 +21,87 @@ from concrete.fhe.values import ClearScalar, ClearTensor, EncryptedScalar, Encry
pytest.param(
True,
True,
Value(dtype=UnsignedInteger(1), shape=(), is_encrypted=True),
ValueDescription(dtype=UnsignedInteger(1), shape=(), is_encrypted=True),
),
pytest.param(
True,
False,
Value(dtype=UnsignedInteger(1), shape=(), is_encrypted=False),
ValueDescription(dtype=UnsignedInteger(1), shape=(), is_encrypted=False),
),
pytest.param(
False,
True,
Value(dtype=UnsignedInteger(1), shape=(), is_encrypted=True),
ValueDescription(dtype=UnsignedInteger(1), shape=(), is_encrypted=True),
),
pytest.param(
False,
False,
Value(dtype=UnsignedInteger(1), shape=(), is_encrypted=False),
ValueDescription(dtype=UnsignedInteger(1), shape=(), is_encrypted=False),
),
pytest.param(
0,
False,
Value(dtype=UnsignedInteger(1), shape=(), is_encrypted=False),
ValueDescription(dtype=UnsignedInteger(1), shape=(), is_encrypted=False),
),
pytest.param(
np.int32(0),
True,
Value(dtype=UnsignedInteger(1), shape=(), is_encrypted=True),
ValueDescription(dtype=UnsignedInteger(1), shape=(), is_encrypted=True),
),
pytest.param(
0.0,
False,
Value(dtype=Float(64), shape=(), is_encrypted=False),
ValueDescription(dtype=Float(64), shape=(), is_encrypted=False),
),
pytest.param(
np.float64(0.0),
True,
Value(dtype=Float(64), shape=(), is_encrypted=True),
ValueDescription(dtype=Float(64), shape=(), is_encrypted=True),
),
pytest.param(
np.float32(0.0),
False,
Value(dtype=Float(32), shape=(), is_encrypted=False),
ValueDescription(dtype=Float(32), shape=(), is_encrypted=False),
),
pytest.param(
np.float16(0.0),
True,
Value(dtype=Float(16), shape=(), is_encrypted=True),
ValueDescription(dtype=Float(16), shape=(), is_encrypted=True),
),
pytest.param(
[True, False, True],
False,
Value(dtype=UnsignedInteger(1), shape=(3,), is_encrypted=False),
ValueDescription(dtype=UnsignedInteger(1), shape=(3,), is_encrypted=False),
),
pytest.param(
[True, False, True],
True,
Value(dtype=UnsignedInteger(1), shape=(3,), is_encrypted=True),
ValueDescription(dtype=UnsignedInteger(1), shape=(3,), is_encrypted=True),
),
pytest.param(
[0, 3, 1, 2],
False,
Value(dtype=UnsignedInteger(2), shape=(4,), is_encrypted=False),
ValueDescription(dtype=UnsignedInteger(2), shape=(4,), is_encrypted=False),
),
pytest.param(
np.array([0, 3, 1, 2], dtype=np.int32),
True,
Value(dtype=UnsignedInteger(2), shape=(4,), is_encrypted=True),
ValueDescription(dtype=UnsignedInteger(2), shape=(4,), is_encrypted=True),
),
pytest.param(
np.array([0.2, 3.4, 1.5, 2.0], dtype=np.float64),
False,
Value(dtype=Float(64), shape=(4,), is_encrypted=False),
ValueDescription(dtype=Float(64), shape=(4,), is_encrypted=False),
),
pytest.param(
np.array([0.2, 3.4, 1.5, 2.0], dtype=np.float32),
True,
Value(dtype=Float(32), shape=(4,), is_encrypted=True),
ValueDescription(dtype=Float(32), shape=(4,), is_encrypted=True),
),
pytest.param(
np.array([0.2, 3.4, 1.5, 2.0], dtype=np.float16),
False,
Value(dtype=Float(16), shape=(4,), is_encrypted=False),
ValueDescription(dtype=Float(16), shape=(4,), is_encrypted=False),
),
],
)
@@ -104,7 +110,7 @@ def test_value_of(value, is_encrypted, expected_result):
Test `of` function of `Value` class.
"""
assert Value.of(value, is_encrypted) == expected_result
assert ValueDescription.of(value, is_encrypted) == expected_result
@pytest.mark.parametrize(
@@ -114,13 +120,13 @@ def test_value_of(value, is_encrypted, expected_result):
"abc",
False,
ValueError,
"Value cannot represent 'abc'",
"Concrete cannot represent 'abc'",
),
pytest.param(
[1, (), 3],
False,
ValueError,
"Value cannot represent [1, (), 3]",
"Concrete cannot represent [1, (), 3]",
),
],
)
@@ -130,7 +136,7 @@ def test_value_bad_of(value, is_encrypted, expected_error, expected_message):
"""
with pytest.raises(expected_error) as excinfo:
Value.of(value, is_encrypted)
ValueDescription.of(value, is_encrypted)
assert str(excinfo.value) == expected_message
@@ -140,22 +146,22 @@ def test_value_bad_of(value, is_encrypted, expected_error, expected_message):
[
pytest.param(
ClearScalar(SignedInteger(5)),
Value(dtype=SignedInteger(5), shape=(), is_encrypted=False),
ValueDescription(dtype=SignedInteger(5), shape=(), is_encrypted=False),
True,
),
pytest.param(
ClearTensor(UnsignedInteger(5), shape=(3, 2)),
Value(dtype=UnsignedInteger(5), shape=(3, 2), is_encrypted=False),
ValueDescription(dtype=UnsignedInteger(5), shape=(3, 2), is_encrypted=False),
True,
),
pytest.param(
EncryptedScalar(SignedInteger(5)),
Value(dtype=SignedInteger(5), shape=(), is_encrypted=True),
ValueDescription(dtype=SignedInteger(5), shape=(), is_encrypted=True),
True,
),
pytest.param(
EncryptedTensor(UnsignedInteger(5), shape=(3, 2)),
Value(dtype=UnsignedInteger(5), shape=(3, 2), is_encrypted=True),
ValueDescription(dtype=UnsignedInteger(5), shape=(3, 2), is_encrypted=True),
True,
),
pytest.param(