Skip to content

Commit c679b5a

Browse files
authored
Merge pull request #234 from openfheorg/dev
Updates to v1.3.1.0
2 parents 07a81b4 + 944a797 commit c679b5a

File tree

11 files changed

+535
-255
lines changed

11 files changed

+535
-255
lines changed

CMakeLists.txt

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,29 @@ project (OpenFHE-Python)
44

55
set(OPENFHE_PYTHON_VERSION_MAJOR 1)
66
set(OPENFHE_PYTHON_VERSION_MINOR 3)
7-
set(OPENFHE_PYTHON_VERSION_PATCH 0)
7+
set(OPENFHE_PYTHON_VERSION_PATCH 1)
88
set(OPENFHE_PYTHON_VERSION_TWEAK 0)
99
set(OPENFHE_PYTHON_VERSION ${OPENFHE_PYTHON_VERSION_MAJOR}.${OPENFHE_PYTHON_VERSION_MINOR}.${OPENFHE_PYTHON_VERSION_PATCH}.${OPENFHE_PYTHON_VERSION_TWEAK})
1010

11+
# OpenFHE version can be specified externally (-DOPENFHE_REQUIRED_VERSION=1.3.1)
12+
if(NOT DEFINED OPENFHE_REQUIRED_VERSION)
13+
set(OPENFHE_REQUIRED_VERSION "1.3.1" CACHE STRING "Required OpenFHE version")
14+
else()
15+
# User provided OPENFHE_REQUIRED_VERSION via -D
16+
message(STATUS "Using user-specified OpenFHE version: ${OPENFHE_REQUIRED_VERSION}")
17+
endif()
18+
1119
set(CMAKE_CXX_STANDARD 17)
1220
option( BUILD_STATIC "Set to ON to include static versions of the library" OFF)
1321

1422
if(APPLE)
1523
set(CMAKE_CXX_VISIBILITY_PRESET default)
1624
endif()
1725

18-
find_package(OpenFHE 1.3.0 REQUIRED)
26+
find_package(OpenFHE ${OPENFHE_REQUIRED_VERSION} REQUIRED)
27+
message(STATUS "Building with OpenFHE version: ${OPENFHE_REQUIRED_VERSION}")
28+
29+
set(PYBIND11_FINDPYTHON ON)
1930
find_package(pybind11 REQUIRED)
2031

2132
# "CMAKE_INTERPROCEDURAL_OPTIMIZATION ON" (ON is the default value) causes link failure. see
@@ -65,20 +76,13 @@ pybind11_add_module(openfhe
6576
### Python installation
6677
# Allow the user to specify the path to Python executable (if not provided, find it)
6778
option(PYTHON_EXECUTABLE_PATH "Path to Python executable" "")
68-
69-
if(NOT PYTHON_EXECUTABLE_PATH)
70-
# Find Python and its development components
71-
find_package(Python REQUIRED COMPONENTS Interpreter Development)
72-
else()
73-
# Set Python_EXECUTABLE to the specified path
79+
if(PYTHON_EXECUTABLE_PATH)
7480
set(Python_EXECUTABLE "${PYTHON_EXECUTABLE_PATH}")
7581
endif()
76-
77-
# Find Python interpreter
78-
find_package(PythonInterp REQUIRED)
82+
find_package(Python REQUIRED COMPONENTS Interpreter Development)
7983

8084
# Check Python version
81-
if(${PYTHON_VERSION_MAJOR} EQUAL 3 AND ${PYTHON_VERSION_MINOR} GREATER_EQUAL 10)
85+
if(${Python_VERSION_MAJOR} EQUAL 3 AND ${Python_VERSION_MINOR} GREATER_EQUAL 10)
8286
execute_process(
8387
COMMAND "${Python_EXECUTABLE}" -c "from sys import exec_prefix; print(exec_prefix)"
8488
OUTPUT_VARIABLE PYTHON_SITE_PACKAGES
@@ -100,3 +104,5 @@ else()
100104
endif()
101105
message("***** INSTALL IS AT ${Python_Install_Location}; to change, run cmake with -DCMAKE_INSTALL_PREFIX=/your/path")
102106
install(TARGETS openfhe LIBRARY DESTINATION ${Python_Install_Location})
107+
install(FILES ${CMAKE_SOURCE_DIR}/__init__.py DESTINATION ${Python_Install_Location})
108+

README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ pip install openfhe==<openfhe_package_version>
2323

2424
Once installed, any python example at https://github.com/openfheorg/openfhe-python/tree/main/examples can be executed.
2525

26-
Note that Ubuntu LTS 20.04, 22.04, and 24.04 are currently supported. `pip uninstal` can be used to uninstall the openfhe package.
26+
Note that Ubuntu LTS 20.04, 22.04, and 24.04 are currently supported. `pip uninstall` can be used to uninstall the openfhe package.
2727

2828
## Running from Docker
2929

@@ -35,7 +35,7 @@ Please see [Instructions for the Docker setup](docker/README.md)
3535

3636
Before building, make sure you have the following dependencies installed:
3737

38-
- [OpenFHE 1.3.0+](https://github.com/openfheorg/openfhe-development) by following the instructions in [OpenFHE Documentation](https://openfhe-development.readthedocs.io/en/latest/sphinx_rsts/intro/installation/installation.html)
38+
- [OpenFHE 1.3.1+](https://github.com/openfheorg/openfhe-development) by following the instructions in [OpenFHE Documentation](https://openfhe-development.readthedocs.io/en/latest/sphinx_rsts/intro/installation/installation.html)
3939
- [Python 3.6+](https://www.python.org/)
4040
- [pybind11](https://pybind11.readthedocs.io/en/stable/installing.html)
4141

@@ -143,8 +143,9 @@ To get familiar with the OpenFHE Python API, check out the examples:
143143
<!-- - [Small-Precison Arbitrary Function Evaluation](examples/binfhe/eval-function.py) -->
144144
- Threshold FHE:
145145
- [Code Example for BGV, BFV, and CKKS](examples/pke/threshold-fhe.py)
146-
- [Simple Interactive Bootstrapping Example](examples/pke/tckks-interactive-mp-bootstrapping.py)
147-
- [Interactive Bootstrapping after Chebyshev Approximation](examples/pke/tckks-interactive-mp-bootstrapping-Chebyschev.py)
146+
- [2-party Interactive Bootstrapping Examples](examples/pke/interactive-bootstrapping.py)
147+
- [Simple n-party Interactive Bootstrapping Example](examples/pke/tckks-interactive-mp-bootstrapping.py)
148+
- [n-party Interactive Bootstrapping after Chebyshev Approximation](examples/pke/tckks-interactive-mp-bootstrapping-Chebyschev.py)
148149
- [Code Example for BFV with 5 parties](examples/pke/threshold-fhe-5p.py)
149150

150151
## OpenFHE Python Wrapper Documentation

__init__.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import os
2+
import ctypes
3+
4+
5+
def load_shared_library(libname, paths):
6+
for path in paths:
7+
lib_path = os.path.join(path, libname)
8+
if os.path.exists(lib_path):
9+
return ctypes.CDLL(lib_path, mode=ctypes.RTLD_GLOBAL)
10+
11+
raise FileNotFoundError(
12+
f"Shared library {libname} not found in {paths}"
13+
)
14+
15+
# Search LD_LIBRARY_PATH
16+
ld_paths = os.environ.get("LD_LIBRARY_PATH", "").split(":")
17+
18+
if not any(ld_paths):
19+
# Path to the bundled `lib/` directory inside site-packages
20+
package_dir = os.path.abspath(os.path.dirname(__file__))
21+
internal_lib_dir = [os.path.join(package_dir, 'lib')]
22+
23+
# Shared libraries required
24+
shared_libs = [
25+
'libgomp.so',
26+
'libOPENFHEcore.so.1',
27+
'libOPENFHEbinfhe.so.1',
28+
'libOPENFHEpke.so.1',
29+
]
30+
31+
for libname in shared_libs:
32+
load_shared_library(libname, internal_lib_dir)
33+
34+
from .openfhe import *
35+
36+
else:
37+
# Shared libraries required
38+
# skip 'libgomp.so' if LD_LIBRARY_PATH is set as we should get it from the libgomp.so location
39+
shared_libs = [
40+
'libOPENFHEcore.so.1',
41+
'libOPENFHEbinfhe.so.1',
42+
'libOPENFHEpke.so.1',
43+
]
44+
45+
for libname in shared_libs:
46+
load_shared_library(libname, ld_paths)
47+
48+
# from .openfhe import *

docs/Makefile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,15 @@ help:
1313

1414
.PHONY: help Makefile
1515

16+
# I got the following warning running "make html":
17+
# WARNING: html_static_path entry '_static' does not exist
18+
# The _static folder in a Sphinx project is used to store custom static files. We must either
19+
# suppress the warning by creating the folder or remove the entry from conf.py ("html_static_path = []").
20+
# Creating the folder may be safer.
21+
html:
22+
@mkdir -p _static
23+
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
24+
1625
# Catch-all target: route all unknown targets to Sphinx using the new
1726
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
1827
%: Makefile

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ def automatic_rescale_demo(scal_tech):
1010
batch_size = 8
1111
parameters = CCParamsCKKSRNS()
1212
parameters.SetMultiplicativeDepth(6)
13-
parameters.SetScalingModSize(90)
13+
parameters.SetScalingModSize(89)
1414
parameters.SetScalingTechnique(scal_tech)
1515
parameters.SetBatchSize(batch_size)
1616

@@ -70,7 +70,7 @@ def manual_rescale_demo(scal_tech):
7070
batch_size = 8
7171
parameters = CCParamsCKKSRNS()
7272
parameters.SetMultiplicativeDepth(5)
73-
parameters.SetScalingModSize(90)
73+
parameters.SetScalingModSize(89)
7474
parameters.SetBatchSize(batch_size)
7575

7676
cc = GenCryptoContext(parameters)
@@ -133,7 +133,7 @@ def hybrid_key_switching_demo1():
133133
batch_size = 8
134134
parameters = CCParamsCKKSRNS()
135135
parameters.SetMultiplicativeDepth(5)
136-
parameters.SetScalingModSize(90)
136+
parameters.SetScalingModSize(89)
137137
parameters.SetBatchSize(batch_size)
138138
parameters.SetScalingTechnique(ScalingTechnique.FIXEDAUTO)
139139
parameters.SetNumLargeDigits(dnum)
@@ -176,7 +176,7 @@ def hybrid_key_switching_demo2():
176176
batch_size = 8
177177
parameters = CCParamsCKKSRNS()
178178
parameters.SetMultiplicativeDepth(5)
179-
parameters.SetScalingModSize(90)
179+
parameters.SetScalingModSize(89)
180180
parameters.SetBatchSize(batch_size)
181181
parameters.SetScalingTechnique(ScalingTechnique.FIXEDAUTO)
182182
parameters.SetNumLargeDigits(dnum)
@@ -219,7 +219,7 @@ def fast_rotation_demo1():
219219
batch_size = 8
220220
parameters = CCParamsCKKSRNS()
221221
parameters.SetMultiplicativeDepth(1)
222-
parameters.SetScalingModSize(90)
222+
parameters.SetScalingModSize(89)
223223
parameters.SetBatchSize(batch_size)
224224

225225
cc = GenCryptoContext(parameters)
@@ -295,7 +295,7 @@ def fast_rotation_demo2():
295295

296296
parameters = CCParamsCKKSRNS()
297297
parameters.SetMultiplicativeDepth(1)
298-
parameters.SetScalingModSize(90)
298+
parameters.SetScalingModSize(89)
299299
parameters.SetBatchSize(batch_size)
300300
parameters.SetScalingTechnique(ScalingTechnique.FIXEDAUTO)
301301
parameters.SetKeySwitchTechnique(KeySwitchTechnique.BV)

0 commit comments

Comments
 (0)