HeConfigRequirement#
- class HeConfigRequirement#
A class used to construct an HeContext with certain requirements (e.g. security_level, integerPartPrecision).
- property automatic_bootstrapping#
Whether bootstrapping is applied automatically to prevent runtime errors resulting from executing a chain index consuming operation on a ciphertext with too small chain index. The logic for deciding the bootstrapping points is scheme and library specific. But, in general, the bootstrappings are delayed as much as possible. This flag can only be set to true if this HeContext supports bootstrapping.
- property bootstrappable#
Whether CTiles created by the HeContext will be bootstrappable. Setting this flag to true will lead to the creation of a BootstrapEvaluator object upon the initialization of the HeContext. Note that this BootstrapEvaluator creation increases the runtime of the initialization.
- property fractional_part_precision#
The required fractional part precision.
- get_multi_party_config(self: pyhelayers.HeConfigRequirement) helayers::MultiPartyConfig #
Get the optional configuration related to Multi-Party HE setups.
- Return type:
MultiPartyConfig.
- Raises:
RuntimeError – if the HeConfigRequirement object does not have a MultiPartyConfig object.
- static insecure(num_slots: int, multiplication_depth: int, fractional_part_precision: int = -1, integer_part_precision: int = -1) pyhelayers.HeConfigRequirement #
Returns an object with an insecure configuration.
- Parameters:
num_slots – The required number of slots.
multiplication_depth – The required multiplication depth.
fractional_part_precision – The required fractional part precision.
integer_part_precision – The required integer part precision.
- property integer_part_precision#
The required integer part precision.
- property multiplication_depth#
The required multiplication depth.
- property num_slots#
The required number of slots.
- property public_functions#
This member specifies which functionalities will be supported by the public keys of the HeContext
- property security_level#
The required security level.
- set_multi_party_config(self: pyhelayers.HeConfigRequirement, mp_config: helayers::MultiPartyConfig) None #
Set optional configuration related to Multi-Party HE setups.
- Parameters:
mp_config (MultiPartyConfig.) – The multi-party configuration object.
-
struct HeConfigRequirement : public helayers::SaveableBasic#
A class for configuring HeContext objects.
See documentation in each field below.
General instructions for CKKS scheme:
numSlots should be a power of 2, typically in the range 1024 … 65536.
integerPartPrecision is typically in the range 0 … 20.
fractionalPartPrecision is typically in the range 20 … 50.
multiplicationDepth depends on the computation planned. If you need a computation that requires n layers of multiplications, then set this value here. For small values (e.g., n<10) this should work efficiently. For large values, see the ‘bootstrappable’ option below.
bootstrappable: set this to true for computations that require a lot of multiplication depth, typically more than 20. For depth in the range 10-20 you can experiment which works better, with bootstrappable true or false. Even if bootstrappable is set to true, you still need to set the multiplication depth. Different values of it in the range 4-20 may produce different bootstrappable configurations. Note that generally turning on this flag creates significantly larger keys and slower setup time. Bootstrapping can be called manually using CTile’s bootstrap method, or turn on automaticBootstrapping to have it called automatically when necessary.
securityLevel: typical values are 128, 192, and 256. Default is 128.
Troubleshooting:
Bootstrapping is not supported by all underlying libraries, or by the HElayers wrapper for that library. Currently HElayers supports bootstrapping using HEaaN and Lattigo.
Some combination of values may not satisfy the securityLevel constraint specified (or the default 128). To solve that, try increasing numSlots, or decreasing multiplicationDepth, fractionalPartPrecision, and integerPartPrecision.
Some combinations of integerPartPrecision and fractionalPartPrecision may cause errors related to choosing appropriate prime numbers. This may happen for values that are too low or too high. Try values closer to the typical values of integerPartPrecision=10 and fractionalPartPrecision=40.
To create toy setups with no security guarantees, use the
insecure
static method instead of the constructor.
Public Functions
-
HeConfigRequirement()#
A constructor.
-
HeConfigRequirement(int numSlots, int multiplicationDepth, int fractionalPartPrecision, int integerPartPrecision, int securityLevel = 128)#
A constructor.
- Parameters:
numSlots – The required number of slots.
multiplicationDepth – The required multiplication depth.
fractionalPartPrecision – The required fractional part precision.
integerPartPrecision – The required integer part precision.
securityLevel – The required security level.
-
void assertComplete() const#
Asserts the five main attributes of an HE config requirement are populated: securityLevel, numSlots, multiplicationDepth, fractionalPartPrecision and integerPartPrecision.
-
int getNumRotationKeys() const#
Returns the number of rotation keys required by this HE config requirement.
-
void toJson(JsonWrapper &jw, const std::string &prefix) const#
Populates the content of this object into a JSON wrapper.
- Parameters:
jw – The JSON wrapper to populate.
prefix – An optional prefix. Attributes will be written as a sub-tree under this given prefix.
-
void fromJson(const JsonWrapper &jw, const std::string &prefix)#
Populates this object from a JSON wrapper.
- Parameters:
jw – The JSON wrapper to populate from.
prefix – An optional prefix. Attributes will be taken from a sub-tree under this given prefix.
-
virtual std::streamoff save(std::ostream &stream) const override#
Saves this object to a stream in binary form.
Returns the number of bytes written to the output stream.
- Parameters:
stream – [in] output stream to write to
-
virtual std::streamoff load(std::istream &stream) override#
Loads this object from the given stream.
Returns the number of bytes read from the input stream.
- Parameters:
stream – [in] input stream to read from
-
virtual void debugPrint(const std::string &title = "", Verbosity verbosity = VERBOSITY_REGULAR, std::ostream &out = std::cout) const override#
Prints the content of this object.
- Parameters:
title – Text to add to the print
verbosity – Verbosity level
out – Output stream
-
bool operator==(const HeConfigRequirement &other) const#
operator== between this and a given other.
- Parameters:
other – The given other.
-
bool operator!=(const HeConfigRequirement &other) const#
operator!= between this and a given other.
- Parameters:
other – The given other.
Public Members
-
int numSlots = -1#
The number of slots in a ciphertext.
For example, if it is set to 4096 it means each CTile (ciphertext) will contain 4096 numbers.
-
int multiplicationDepth = -1#
The required multiplication depth.
For example, multiplication depth of 2 will allow a computation involving two multiplications performed one after the other.
-
int fractionalPartPrecision = -1#
The required fractional part precision.
This is the number of bits each number will have in its fractional part. For example, a value of 40 means it will have an accuracy of about 2^-40. Note that actual accuracy in a computation might be lower than that, as the computation itself adds further noise.
-
int integerPartPrecision = -1#
The required integer part precision.
This is the number of bits each number will have in its integer part. For example, a value of 10 means the numbers will be in the range -2^10 … 2^10. Numbers outside this range might produce errors.
-
int securityLevel = 128#
The required security level.
-
bool bootstrappable = false#
Whether CTile objects (ciphertexts) created by the HeContext will be bootstrappable.
Setting this flag to true will allow performing computation of arbitrary multiplication depth. Note that this feature is not supported yet by all underlying back-end libraries, or not yet integrated with HElayers for all underlying back-ends.
-
bool automaticBootstrapping = false#
Whether bootstrapping is applied automatically to prevent runtime errors resulting from executing a chain index consuming operation on a ciphertext with too small chain index.
The logic for deciding the bootstrapping points is scheme and library specific. But, in general, the bootstrappings are delayed as much as possible. This flag can only be set to true if this HeContext supports bootstrapping.
-
DeviceType defaultDeviceType = DEVICE_CPU#
The default device type of the ciphertexts and plaintexts that will be generated using the HeContext.
-
int defaultDeviceId = 0#
The default device ID of the ciphertexts and plaintexts that will be generated using the HeContext.
Relevant only when defaultDeviceType is DEVICE_GPU.
-
bool hybridDeviceUtilization = false#
Policy of hybrid utilization of devices of different types.
Such policy is only applicable for DEVICE_CPU as the default device type. In such policy, the GPU may be utilized alongside CPU for parts of the computation (e.g., for performing bootstraps).
-
std::optional<BootstrapConfig> bootstrapConfig#
If bootstrappable flag is set to true, this optional member can be used to set the bootstrap configuration.
If this member is empty and
bootstrappable
flag is true, a default bootstrap configuration will be used.
-
std::optional<MultiPartyConfig> multiPartyConfig#
Optional configuration related to Multi-Party HE setups.
Public Static Functions
-
static HeConfigRequirement insecure(int numSlots, int multiplicationDepth = RunStats::MAX_CHAIN_INDEX, int fractionalPartPrecision = -1, int integerPartPrecision = -1)#
Returns an object with an insecure configuration.
- Parameters:
numSlots – The required number of slots.
multiplicationDepth – The required multiplication depth.
fractionalPartPrecision – The required fractional part precision.
integerPartPrecision – The required integer part precision.