Skip to main content

NFGen: Automatic Non-Linear Function Evaluation Code Generator for General-purpose MPC Platforms

Project description

NFGen

NFGen: Automatic Non-Linear Function Evaluation Code Generator for General-purpose MPC Platforms

Introduction

NFGen is designed to generate non-linear function evaluation code for general-purpose MPC platforms.

The requirement for the underlying MPC platform is three basic routines addition, multiplication and greater-than are provided and these three routines can be composed sequentially.

Example

  1. Import the required package
import sympy as sp
from NFGen.main import generate_nonlinear_config
import NFGen.CodeTemplet.templet as temp
import NFGen.PerformanceModel.time_ops as to
  1. Write the non-linear function definition config (NFD)
platform = "Rep3" # using MP-SPDZ Rep3 protocol as an example.
f = 48
n = 96
profiler_file = './NFGen/PerformanceModel/' + platform + "_kmProfiler.pkl"

# fundenmental functions, indicating they are cipher-text non-linear operations.
def func_reciprocal(x):
        return 1 / x

def func_exp(x, lib=sp):
    return lib.exp(x)

# target function.
def sigmoid(x):
    return 1 * func_reciprocal((1 + func_exp(-x)))

# define NFD
sigmoid_config = {
    "function": sigmoid, # function config.
    "range": (-10, 10),
    "k_max": 10, # set the maximum order.
    "tol": 1e-3, # percision config.
    "ms": 1000, # maximum samples.
    "zero_mask": 1e-6,
    "n": n, # <n, f> fixed-point config.
    "f": f,
    "profiler": profiler_file, # profiler model source file.
    "code_templet": temp.templet_spdz, # spdz templet.
    "code_language": "python", # indicating the templet language.
    "config_file": "./sigmoig_spdz.py", # generated code file.
    "time_dict": to.basic_time[platform], # basic operation time cost.
    # "test_graph": "./graph/" # (optional, need mkdir for this folder first), whether generate the graph showing the approximation and the real function.
}
  1. Generate the evaluation code using NFGen.
# using NFGen to generate the target function code.
generate_nonlinear_config(sigmoid_config)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

NFGen-0.0.2.tar.gz (24.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

NFGen-0.0.2-py3-none-any.whl (28.0 kB view details)

Uploaded Python 3

File details

Details for the file NFGen-0.0.2.tar.gz.

File metadata

  • Download URL: NFGen-0.0.2.tar.gz
  • Upload date:
  • Size: 24.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.8.10

File hashes

Hashes for NFGen-0.0.2.tar.gz
Algorithm Hash digest
SHA256 cbebf175dcbb7df6ebd987bf8c344be242f76a0011716047340522d3c7c9aac3
MD5 292f269f321fdb4ae1f780b4e4df3468
BLAKE2b-256 70780c2a5d543da8c70ae2a633e175a0b7fb15ce8628bf656abb8189dc366375

See more details on using hashes here.

File details

Details for the file NFGen-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: NFGen-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 28.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.8.10

File hashes

Hashes for NFGen-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 e32da082983ba7b6a09913374f169bbfd0eee4f661a37a2ea3c8b6d8368a7a4e
MD5 c3b5441f3f5e73b54fa52c174e2d577b
BLAKE2b-256 c6fc3c53fe7d655b2fcb7a3da6bfb8250f87085bfcea01149a106d92828a6f67

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page