Skip to content

Commit 6e45fa6

Browse files
Changes for the new openfhe-development release (#163)
* Changes for the new openfhe-development release * Fixed test errors and disabled some of the tests for NATIVEINT == 32 --------- Co-authored-by: Dmitriy Suponitskiy <[email protected]>
1 parent 869cdd3 commit 6e45fa6

17 files changed

+66
-41
lines changed

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ To install OpenFHE-python directly to your system, ensure the dependencies are s
3838
pip install "pybind11[global]"
3939
mkdir build
4040
cd build
41-
cmake .. # Alternatively, cmake .. -DOpenFHE_DIR=/path/to/installed/openfhe if you installed OpenFHE elsewhere
41+
cmake .. # Alternatively, cmake .. -DCMAKE_PREFIX_PATH=/path/to/installed/openfhe if you installed OpenFHE elsewhere
4242
make
4343
make install # You may have to run sudo make install
4444
```
@@ -50,11 +50,13 @@ If you see an error saying that one of OpenFHE .so files cannot be found when ru
5050
add the path where the .so files reside to the `PYTHONPATH` environment variable:
5151

5252
```
53-
export PYTHONPATH=(path_to_OpenFHE_so_files):$PYTHONPATH
53+
export PYTHONPATH=(/path/to/installed/openfhe):$PYTHONPATH
5454
```
5555

5656
In some environments (this happens rarely), it may also be necessary to add the OpenFHE libraries path to `LD_LIBRARY_PATH`.
5757

58+
If OpenFHE is not installed in the default location, then both `PYTHONPATH and LD_LIBRARY_PATH` must be set before running any Python example.
59+
5860
#### Conda
5961

6062
Alternatively you can install the library and handle the linking via Conda. Clone the repository, open a terminal in the repo folder and run the following commands:
@@ -73,7 +75,7 @@ Now, you would clone the repository, and run the following commands to install :
7375
```bash
7476
mkdir build
7577
cd build
76-
cmake .. # Add in -DOpenFHE_DIR=/path/to/installed/openfhe if you installed OpenFHE elsewhere
78+
cmake .. # Add in -DCMAKE_PREFIX_PATH=/path/to/installed/openfhe if you installed OpenFHE elsewhere
7779
make
7880
make install # You may have to run sudo make install
7981
```

examples/pke/advanced-real-numbers-128.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,15 @@ def automatic_rescale_demo(scal_tech):
5252
c_res3 = cc.EvalMult(cc.EvalAdd(c18,c9), 0.5) # Final result 3
5353

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

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

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

6666

examples/pke/advanced-real-numbers.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,8 @@ def hybrid_key_switching_demo1():
124124
parameters.SetMultiplicativeDepth(5)
125125
parameters.SetScalingModSize(50)
126126
parameters.SetBatchSize(batch_size)
127-
parameters.SetScalingTechnique(ScalingTechnique.FLEXIBLEAUTO)
127+
if get_native_int()!=128:
128+
parameters.SetScalingTechnique(ScalingTechnique.FLEXIBLEAUTO)
128129
parameters.SetNumLargeDigits(dnum)
129130

130131
cc = GenCryptoContext(parameters)
@@ -167,7 +168,8 @@ def hybrid_key_switching_demo2():
167168
parameters.SetMultiplicativeDepth(5)
168169
parameters.SetScalingModSize(50)
169170
parameters.SetBatchSize(batch_size)
170-
parameters.SetScalingTechnique(ScalingTechnique.FLEXIBLEAUTO)
171+
if get_native_int()!=128:
172+
parameters.SetScalingTechnique(ScalingTechnique.FLEXIBLEAUTO)
171173
parameters.SetNumLargeDigits(dnum)
172174

173175
cc = GenCryptoContext(parameters)
@@ -287,7 +289,8 @@ def fast_rotation_demo2():
287289
parameters.SetMultiplicativeDepth(1)
288290
parameters.SetScalingModSize(50)
289291
parameters.SetBatchSize(batch_size)
290-
parameters.SetScalingTechnique(ScalingTechnique.FLEXIBLEAUTO)
292+
if get_native_int()!=128:
293+
parameters.SetScalingTechnique(ScalingTechnique.FLEXIBLEAUTO)
291294
parameters.SetKeySwitchTechnique(KeySwitchTechnique.BV)
292295
parameters.SetFirstModSize(60)
293296
parameters.SetDigitSize(digit_size)
@@ -361,7 +364,8 @@ def fast_rotation_demo2():
361364

362365

363366
def main():
364-
automatic_rescale_demo(ScalingTechnique.FLEXIBLEAUTO)
367+
if get_native_int()!=128:
368+
automatic_rescale_demo(ScalingTechnique.FLEXIBLEAUTO)
365369
automatic_rescale_demo(ScalingTechnique.FIXEDAUTO)
366370
manual_rescale_demo(ScalingTechnique.FIXEDMANUAL)
367371
hybrid_key_switching_demo1()

examples/pke/scheme-switching.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1002,16 +1002,17 @@ def ArgminViaSchemeSwitchingUnit():
10021002
slots = 32 # sparsely-packed
10031003
batchSize = slots
10041004
numValues = 32
1005-
scTech = FLEXIBLEAUTOEXT
10061005
multDepth = 9 + 3 + 1 + int(log2(numValues)) # 1 for CKKS to FHEW, 13 for FHEW to CKKS, log2(numValues) for argmin
1007-
if scTech == FLEXIBLEAUTOEXT:
1008-
multDepth += 1
10091006

10101007
parameters = CCParamsCKKSRNS()
1008+
if get_native_int()!=128:
1009+
scTech = FLEXIBLEAUTOEXT
1010+
multDepth += 1
1011+
parameters.SetScalingTechnique(scTech)
1012+
10111013
parameters.SetMultiplicativeDepth(multDepth)
10121014
parameters.SetScalingModSize(scaleModSize)
10131015
parameters.SetFirstModSize(firstModSize)
1014-
parameters.SetScalingTechnique(scTech)
10151016
parameters.SetSecurityLevel(sl)
10161017
parameters.SetRingDim(ringDim)
10171018
parameters.SetBatchSize(batchSize)
@@ -1119,16 +1120,17 @@ def ArgminViaSchemeSwitchingAltUnit():
11191120
slots = 32 # sparsely-packed
11201121
batchSize = slots
11211122
numValues = 32
1122-
scTech = FLEXIBLEAUTOEXT
11231123
multDepth = 9 + 3 + 1 + int(log2(numValues)) # 1 for CKKS to FHEW, 13 for FHEW to CKKS, log2(numValues) for argmin
1124-
if scTech == FLEXIBLEAUTOEXT:
1125-
multDepth += 1
11261124

11271125
parameters = CCParamsCKKSRNS()
1126+
if get_native_int()!=128:
1127+
scTech = FLEXIBLEAUTOEXT
1128+
multDepth += 1
1129+
parameters.SetScalingTechnique(scTech)
1130+
11281131
parameters.SetMultiplicativeDepth(multDepth)
11291132
parameters.SetScalingModSize(scaleModSize)
11301133
parameters.SetFirstModSize(firstModSize)
1131-
parameters.SetScalingTechnique(scTech)
11321134
parameters.SetSecurityLevel(sl)
11331135
parameters.SetRingDim(ringDim)
11341136
parameters.SetBatchSize(batchSize)

examples/pke/simple-integers-serial-bgvrns.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ def main_action():
121121
# of the keys. When deserializing a context, OpenFHE checks for the tag and
122122
# if it finds it in the CryptoContext map, it will return the stored version.
123123
# Hence, we need to clear the context and clear the keys.
124-
cryptoContext.ClearEvalMultKeys()
124+
ClearEvalMultKeys()
125125
cryptoContext.ClearEvalAutomorphismKeys()
126126
ReleaseAllContexts()
127127

examples/pke/simple-integers-serial.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ def main_action():
121121
# of the keys. When deserializing a context, OpenFHE checks for the tag and
122122
# if it finds it in the CryptoContext map, it will return the stored version.
123123
# Hence, we need to clear the context and clear the keys.
124-
cryptoContext.ClearEvalMultKeys()
124+
ClearEvalMultKeys()
125125
cryptoContext.ClearEvalAutomorphismKeys()
126126
ReleaseAllContexts()
127127

examples/pke/simple-real-numbers-serial.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,9 @@ def serverSetupAndWrite(multDepth, scaleModSize, batchSize):
142142

143143
def clientProcess():
144144
# clientCC = CryptoContext()
145-
# clientCC.ClearEvalMultKeys()
146145
# clientCC.ClearEvalAutomorphismKeys()
147146
ReleaseAllContexts()
147+
ClearEvalMultKeys()
148148

149149
clientCC, res = DeserializeCryptoContext(datafolder + ccLocation, BINARY)
150150
if not res:

examples/pke/tckks-interactive-mp-bootstrapping-Chebyschev.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ def main():
66
# Same test with different rescaling techniques in CKKS
77
TCKKSCollectiveBoot(FIXEDMANUAL)
88
TCKKSCollectiveBoot(FIXEDAUTO)
9-
TCKKSCollectiveBoot(FLEXIBLEAUTO)
10-
TCKKSCollectiveBoot(FLEXIBLEAUTOEXT)
9+
if get_native_int()!=128:
10+
TCKKSCollectiveBoot(FLEXIBLEAUTO)
11+
TCKKSCollectiveBoot(FLEXIBLEAUTOEXT)
1112

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

examples/pke/tckks-interactive-mp-bootstrapping.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@ def main():
2121
# Same test with different rescaling techniques in CKKS
2222
TCKKSCollectiveBoot(FIXEDMANUAL)
2323
TCKKSCollectiveBoot(FIXEDAUTO)
24-
TCKKSCollectiveBoot(FLEXIBLEAUTO)
25-
TCKKSCollectiveBoot(FLEXIBLEAUTOEXT)
24+
if get_native_int()!=128:
25+
TCKKSCollectiveBoot(FLEXIBLEAUTO)
26+
TCKKSCollectiveBoot(FLEXIBLEAUTOEXT)
2627

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

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

172173
if __name__ == "__main__":
173-
main()
174+
main()

src/include/pke/cryptocontext_wrapper.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,7 @@ const double GetScalingFactorRealWrapper(CryptoContext<DCRTPoly>& self, uint32_t
6565
const uint64_t GetModulusCKKSWrapper(CryptoContext<DCRTPoly>& self);
6666
const ScalingTechnique GetScalingTechniqueWrapper(CryptoContext<DCRTPoly>& self);
6767
const usint GetDigitSizeWrapper(CryptoContext<DCRTPoly>& self);
68+
69+
void ClearEvalMultKeysWrapper();
70+
6871
#endif // OPENFHE_CRYPTOCONTEXT_BINDINGS_H

0 commit comments

Comments
 (0)