Skip to content

Commit

Permalink
Fixed test errors and disabled some of the tests for NATIVEINT == 32
Browse files Browse the repository at this point in the history
  • Loading branch information
dsuponitskiy-duality committed Jul 30, 2024
1 parent 706b783 commit b3c1af8
Show file tree
Hide file tree
Showing 11 changed files with 42 additions and 26 deletions.
6 changes: 3 additions & 3 deletions examples/pke/advanced-real-numbers-128.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,15 @@ def automatic_rescale_demo(scal_tech):
c_res3 = cc.EvalMult(cc.EvalAdd(c18,c9), 0.5) # Final result 3

result1 = cc.Decrypt(c_res1,keys.secretKey)
result.SetLength(batch_size)
result1.SetLength(batch_size)
print("x^18 + x^9 + 1 = ", result1)

result2 = cc.Decrypt(c_res2,keys.secretKey)
result.SetLength(batch_size)
result2.SetLength(batch_size)
print("x^18 + x^9 - 1 = ", result2)

result3 = cc.Decrypt(c_res3,keys.secretKey)
result.SetLength(batch_size)
result3.SetLength(batch_size)
print("0.5 * (x^18 + x^9) = ", result3)


Expand Down
12 changes: 8 additions & 4 deletions examples/pke/advanced-real-numbers.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ def hybrid_key_switching_demo1():
parameters.SetMultiplicativeDepth(5)
parameters.SetScalingModSize(50)
parameters.SetBatchSize(batch_size)
parameters.SetScalingTechnique(ScalingTechnique.FLEXIBLEAUTO)
if get_native_int()!=128:
parameters.SetScalingTechnique(ScalingTechnique.FLEXIBLEAUTO)
parameters.SetNumLargeDigits(dnum)

cc = GenCryptoContext(parameters)
Expand Down Expand Up @@ -167,7 +168,8 @@ def hybrid_key_switching_demo2():
parameters.SetMultiplicativeDepth(5)
parameters.SetScalingModSize(50)
parameters.SetBatchSize(batch_size)
parameters.SetScalingTechnique(ScalingTechnique.FLEXIBLEAUTO)
if get_native_int()!=128:
parameters.SetScalingTechnique(ScalingTechnique.FLEXIBLEAUTO)
parameters.SetNumLargeDigits(dnum)

cc = GenCryptoContext(parameters)
Expand Down Expand Up @@ -287,7 +289,8 @@ def fast_rotation_demo2():
parameters.SetMultiplicativeDepth(1)
parameters.SetScalingModSize(50)
parameters.SetBatchSize(batch_size)
parameters.SetScalingTechnique(ScalingTechnique.FLEXIBLEAUTO)
if get_native_int()!=128:
parameters.SetScalingTechnique(ScalingTechnique.FLEXIBLEAUTO)
parameters.SetKeySwitchTechnique(KeySwitchTechnique.BV)
parameters.SetFirstModSize(60)
parameters.SetDigitSize(digit_size)
Expand Down Expand Up @@ -361,7 +364,8 @@ def fast_rotation_demo2():


def main():
automatic_rescale_demo(ScalingTechnique.FLEXIBLEAUTO)
if get_native_int()!=128:
automatic_rescale_demo(ScalingTechnique.FLEXIBLEAUTO)
automatic_rescale_demo(ScalingTechnique.FIXEDAUTO)
manual_rescale_demo(ScalingTechnique.FIXEDMANUAL)
hybrid_key_switching_demo1()
Expand Down
18 changes: 10 additions & 8 deletions examples/pke/scheme-switching.py
Original file line number Diff line number Diff line change
Expand Up @@ -1002,16 +1002,17 @@ def ArgminViaSchemeSwitchingUnit():
slots = 32 # sparsely-packed
batchSize = slots
numValues = 32
scTech = FLEXIBLEAUTOEXT
multDepth = 9 + 3 + 1 + int(log2(numValues)) # 1 for CKKS to FHEW, 13 for FHEW to CKKS, log2(numValues) for argmin
if scTech == FLEXIBLEAUTOEXT:
multDepth += 1

parameters = CCParamsCKKSRNS()
if get_native_int()!=128:
scTech = FLEXIBLEAUTOEXT
multDepth += 1
parameters.SetScalingTechnique(scTech)

parameters.SetMultiplicativeDepth(multDepth)
parameters.SetScalingModSize(scaleModSize)
parameters.SetFirstModSize(firstModSize)
parameters.SetScalingTechnique(scTech)
parameters.SetSecurityLevel(sl)
parameters.SetRingDim(ringDim)
parameters.SetBatchSize(batchSize)
Expand Down Expand Up @@ -1119,16 +1120,17 @@ def ArgminViaSchemeSwitchingAltUnit():
slots = 32 # sparsely-packed
batchSize = slots
numValues = 32
scTech = FLEXIBLEAUTOEXT
multDepth = 9 + 3 + 1 + int(log2(numValues)) # 1 for CKKS to FHEW, 13 for FHEW to CKKS, log2(numValues) for argmin
if scTech == FLEXIBLEAUTOEXT:
multDepth += 1

parameters = CCParamsCKKSRNS()
if get_native_int()!=128:
scTech = FLEXIBLEAUTOEXT
multDepth += 1
parameters.SetScalingTechnique(scTech)

parameters.SetMultiplicativeDepth(multDepth)
parameters.SetScalingModSize(scaleModSize)
parameters.SetFirstModSize(firstModSize)
parameters.SetScalingTechnique(scTech)
parameters.SetSecurityLevel(sl)
parameters.SetRingDim(ringDim)
parameters.SetBatchSize(batchSize)
Expand Down
5 changes: 3 additions & 2 deletions examples/pke/tckks-interactive-mp-bootstrapping-Chebyschev.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ def main():
# Same test with different rescaling techniques in CKKS
TCKKSCollectiveBoot(FIXEDMANUAL)
TCKKSCollectiveBoot(FIXEDAUTO)
TCKKSCollectiveBoot(FLEXIBLEAUTO)
TCKKSCollectiveBoot(FLEXIBLEAUTOEXT)
if get_native_int()!=128:
TCKKSCollectiveBoot(FLEXIBLEAUTO)
TCKKSCollectiveBoot(FLEXIBLEAUTOEXT)

print("Interactive (3P) Bootstrapping Ciphertext [Chebyshev] (TCKKS) terminated gracefully!")

Expand Down
7 changes: 4 additions & 3 deletions examples/pke/tckks-interactive-mp-bootstrapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ def main():
# Same test with different rescaling techniques in CKKS
TCKKSCollectiveBoot(FIXEDMANUAL)
TCKKSCollectiveBoot(FIXEDAUTO)
TCKKSCollectiveBoot(FLEXIBLEAUTO)
TCKKSCollectiveBoot(FLEXIBLEAUTOEXT)
if get_native_int()!=128:
TCKKSCollectiveBoot(FLEXIBLEAUTO)
TCKKSCollectiveBoot(FLEXIBLEAUTOEXT)

print("Interactive Multi-Party Bootstrapping Ciphertext (TCKKS) terminated gracefully!\n")

Expand Down Expand Up @@ -170,4 +171,4 @@ def TCKKSCollectiveBoot(scaleTech):
print("\n============================ INTERACTIVE DECRYPTION ENDED ============================\n")

if __name__ == "__main__":
main()
main()
4 changes: 3 additions & 1 deletion src/lib/bindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -842,8 +842,10 @@ void bind_crypto_context(py::module &m)
int get_native_int(){
#if NATIVEINT == 128 && !defined(__EMSCRIPTEN__)
return 128;
#elif NATIVEINT == 32
return 32;
#else
return 64;
return 64;
#endif
}

Expand Down
1 change: 1 addition & 0 deletions tests/test_bgv.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import pytest
import openfhe as fhe

pytestmark = pytest.mark.skipif(fhe.get_native_int() == 32, reason="Doesn't work for NATIVE_INT=32")

LOGGER = logging.getLogger("test_bgv")

Expand Down
7 changes: 4 additions & 3 deletions tests/test_ckks.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import pytest
import openfhe as fhe

pytestmark = pytest.mark.skipif(fhe.get_native_int() == 32, reason="Doesn't work for NATIVE_INT=32")

@pytest.fixture(scope="module")
def ckks_context():
Expand All @@ -13,22 +14,22 @@ def ckks_context():
batch_size = 8
parameters = fhe.CCParamsCKKSRNS()
parameters.SetMultiplicativeDepth(5)
if fhe.get_native_int() > 90:
if fhe.get_native_int() == 128:
parameters.SetFirstModSize(89)
parameters.SetScalingModSize(78)
parameters.SetBatchSize(batch_size)
parameters.SetScalingTechnique(fhe.ScalingTechnique.FIXEDAUTO)
parameters.SetNumLargeDigits(2)

elif fhe.get_native_int() > 60:
elif fhe.get_native_int() == 64:
parameters.SetFirstModSize(60)
parameters.SetScalingModSize(56)
parameters.SetBatchSize(batch_size)
parameters.SetScalingTechnique(fhe.ScalingTechnique.FLEXIBLEAUTO)
parameters.SetNumLargeDigits(2)

else:
raise ValueError("Expected a native int size greater than 60.")
raise ValueError("Expected a native int size 64 or 128.")

cc = fhe.GenCryptoContext(parameters)
cc.Enable(fhe.PKESchemeFeature.PKE)
Expand Down
3 changes: 1 addition & 2 deletions tests/test_cryptocontext.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import pytest
import openfhe as fhe

pytestmark = pytest.mark.skipif(fhe.get_native_int() != 128, reason="Only for NATIVE_INT=128")

@pytest.mark.long
@pytest.mark.skipif(fhe.get_native_int() < 80, reason="Only for NATIVE_INT=128")
@pytest.mark.parametrize("scaling", [fhe.FIXEDAUTO, fhe.FIXEDMANUAL])
def test_ckks_context(scaling):
batch_size = 8
Expand Down
3 changes: 3 additions & 0 deletions tests/test_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
import pytest
import tempfile
import shutil
import openfhe as fhe

pytestmark = pytest.mark.skipif(fhe.get_native_int() == 32, reason="Doesn't work for NATIVE_INT=32")

EXAMPLES_SCRIPTS_PATH = os.path.join(Path(__file__).parent.parent, "examples", "pke")

Expand Down
2 changes: 2 additions & 0 deletions tests/test_serial_cc.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

import openfhe as fhe

pytestmark = pytest.mark.skipif(fhe.get_native_int() == 32, reason="Doesn't work for NATIVE_INT=32")

LOGGER = logging.getLogger("test_serial_cc")


Expand Down

0 comments on commit b3c1af8

Please sign in to comment.