Skip to content

Commit 2447d37

Browse files
authored
Merge pull request #172 from openfheorg/dev
Updates to v0.8.9
2 parents 867a0bd + c1504f3 commit 2447d37

24 files changed

+563
-92
lines changed

CMakeLists.txt

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ project (OpenFHE-Python)
44

55
set(OPENFHE_PYTHON_VERSION_MAJOR 0)
66
set(OPENFHE_PYTHON_VERSION_MINOR 8)
7-
set(OPENFHE_PYTHON_VERSION_PATCH 8)
7+
set(OPENFHE_PYTHON_VERSION_PATCH 9)
88
set(OPENFHE_PYTHON_VERSION ${OPENFHE_PYTHON_VERSION_MAJOR}.${OPENFHE_PYTHON_VERSION_MINOR}.${OPENFHE_PYTHON_VERSION_PATCH})
99

1010
set(CMAKE_CXX_STANDARD 17)
@@ -14,7 +14,7 @@ if(APPLE)
1414
set(CMAKE_CXX_VISIBILITY_PRESET default)
1515
endif()
1616

17-
find_package(OpenFHE 1.2.0 REQUIRED)
17+
find_package(OpenFHE 1.2.1 REQUIRED)
1818
find_package(pybind11 REQUIRED)
1919

2020
set( CMAKE_CXX_FLAGS ${OpenFHE_CXX_FLAGS} )
@@ -75,20 +75,24 @@ find_package(PythonInterp REQUIRED)
7575

7676
# Check Python version
7777
if(${PYTHON_VERSION_MAJOR} EQUAL 3 AND ${PYTHON_VERSION_MINOR} GREATER_EQUAL 10)
78-
execute_process(
79-
COMMAND "${Python_EXECUTABLE}" -c "from sys import exec_prefix; print(exec_prefix)"
80-
OUTPUT_VARIABLE PYTHON_SITE_PACKAGES
81-
OUTPUT_STRIP_TRAILING_WHITESPACE
82-
)
78+
execute_process(
79+
COMMAND "${Python_EXECUTABLE}" -c "from sys import exec_prefix; print(exec_prefix)"
80+
OUTPUT_VARIABLE PYTHON_SITE_PACKAGES
81+
OUTPUT_STRIP_TRAILING_WHITESPACE
82+
)
8383
else()
84-
execute_process(
85-
COMMAND "${Python_EXECUTABLE}" -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())"
86-
OUTPUT_VARIABLE PYTHON_SITE_PACKAGES
87-
OUTPUT_STRIP_TRAILING_WHITESPACE
88-
)
84+
execute_process(
85+
COMMAND "${Python_EXECUTABLE}" -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())"
86+
OUTPUT_VARIABLE PYTHON_SITE_PACKAGES
87+
OUTPUT_STRIP_TRAILING_WHITESPACE
88+
)
8989
endif()
9090

91-
92-
9391
message(STATUS "Python site packages directory: ${PYTHON_SITE_PACKAGES}")
94-
install(TARGETS openfhe LIBRARY DESTINATION ${PYTHON_SITE_PACKAGES})
92+
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
93+
set(Python_Install_Location "${PYTHON_SITE_PACKAGES}")
94+
else()
95+
set(Python_Install_Location "${CMAKE_INSTALL_PREFIX}")
96+
endif()
97+
message("***** INSTALL IS AT ${Python_Install_Location}; to change, run cmake with -DCMAKE_INSTALL_PREFIX=/your/path")
98+
install(TARGETS openfhe LIBRARY DESTINATION ${Python_Install_Location})

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/simple-real-numbers.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,37 +51,38 @@ def main():
5151
# Step 5: Decryption and output
5252
# Decrypt the result of additions
5353
ptAdd = cc.Decrypt(c_add, keys.secretKey)
54+
print("\nResults of homomorphic additions: ")
55+
print(ptAdd)
5456

5557
# We set the precision to 8 decimal digits for a nicer output.
5658
# If you want to see the error/noise introduced by CKKS, bump it up
5759
# to 15 and it should become visible.
5860

5961
precision = 8
60-
print("Results of homomorphic computations:")
62+
print("\nResults of homomorphic computations:")
6163
result = cc.Decrypt(c1, keys.secretKey)
6264
result.SetLength(batch_size)
63-
print("x1 = " + str(result))
64-
print("Estimated precision in bits: " + str(result.GetLogPrecision()))
65+
print("x1 = " + result.GetFormattedValues(precision))
6566

6667
# Decrypt the result of scalar multiplication
6768
result = cc.Decrypt(c_scalar, keys.secretKey)
6869
result.SetLength(batch_size)
69-
print("4 * x1 = " + str(result))
70+
print("4 * x1 = " + result.GetFormattedValues(precision))
7071

7172
# Decrypt the result of multiplication
7273
result = cc.Decrypt(c_mult, keys.secretKey)
7374
result.SetLength(batch_size)
74-
print("x1 * x2 = " + str(result))
75+
print("x1 * x2 = " + result.GetFormattedValues(precision))
7576

7677
# Decrypt the result of rotations
7778
result = cc.Decrypt(c_rot1, keys.secretKey)
7879
result.SetLength(batch_size)
79-
print("In rotations, very small outputs (~10^-10 here) correspond to 0's:")
80-
print("x1 rotated by 1 = " + str(result))
80+
print("\nIn rotations, very small outputs (~10^-10 here) correspond to 0's:")
81+
print("x1 rotated by 1 = " + result.GetFormattedValues(precision))
8182

8283
result = cc.Decrypt(c_rot2, keys.secretKey)
8384
result.SetLength(batch_size)
84-
print("x1 rotated by -2 = " + str(result))
85+
print("x1 rotated by -2 = " + result.GetFormattedValues(precision))
8586

8687

8788
if __name__ == "__main__":

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

0 commit comments

Comments
 (0)