diff --git a/examples/pke/advanced-real-numbers-128.py b/examples/pke/advanced-real-numbers-128.py index ed758cd..747265f 100644 --- a/examples/pke/advanced-real-numbers-128.py +++ b/examples/pke/advanced-real-numbers-128.py @@ -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) diff --git a/examples/pke/advanced-real-numbers.py b/examples/pke/advanced-real-numbers.py index cbefc7f..b21bc09 100644 --- a/examples/pke/advanced-real-numbers.py +++ b/examples/pke/advanced-real-numbers.py @@ -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) @@ -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) @@ -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) @@ -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() diff --git a/examples/pke/scheme-switching.py b/examples/pke/scheme-switching.py index 1ec6df3..8b8cf94 100644 --- a/examples/pke/scheme-switching.py +++ b/examples/pke/scheme-switching.py @@ -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) @@ -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) diff --git a/examples/pke/tckks-interactive-mp-bootstrapping-Chebyschev.py b/examples/pke/tckks-interactive-mp-bootstrapping-Chebyschev.py index 9606295..9a9f848 100644 --- a/examples/pke/tckks-interactive-mp-bootstrapping-Chebyschev.py +++ b/examples/pke/tckks-interactive-mp-bootstrapping-Chebyschev.py @@ -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!") diff --git a/examples/pke/tckks-interactive-mp-bootstrapping.py b/examples/pke/tckks-interactive-mp-bootstrapping.py index a3b7b2e..762263a 100644 --- a/examples/pke/tckks-interactive-mp-bootstrapping.py +++ b/examples/pke/tckks-interactive-mp-bootstrapping.py @@ -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") @@ -170,4 +171,4 @@ def TCKKSCollectiveBoot(scaleTech): print("\n============================ INTERACTIVE DECRYPTION ENDED ============================\n") if __name__ == "__main__": - main() \ No newline at end of file + main() diff --git a/src/lib/bindings.cpp b/src/lib/bindings.cpp index 0653226..c44ede5 100644 --- a/src/lib/bindings.cpp +++ b/src/lib/bindings.cpp @@ -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 } diff --git a/tests/test_bgv.py b/tests/test_bgv.py index 508580e..a7340b7 100644 --- a/tests/test_bgv.py +++ b/tests/test_bgv.py @@ -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") diff --git a/tests/test_ckks.py b/tests/test_ckks.py index 9437b88..48342c7 100644 --- a/tests/test_ckks.py +++ b/tests/test_ckks.py @@ -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(): @@ -13,14 +14,14 @@ 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) @@ -28,7 +29,7 @@ def ckks_context(): 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) diff --git a/tests/test_cryptocontext.py b/tests/test_cryptocontext.py index 03842e0..a104c85 100644 --- a/tests/test_cryptocontext.py +++ b/tests/test_cryptocontext.py @@ -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 diff --git a/tests/test_examples.py b/tests/test_examples.py index 424e8eb..8d8093a 100644 --- a/tests/test_examples.py +++ b/tests/test_examples.py @@ -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") diff --git a/tests/test_serial_cc.py b/tests/test_serial_cc.py index bad57ef..5a1acf2 100644 --- a/tests/test_serial_cc.py +++ b/tests/test_serial_cc.py @@ -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")