DebugContext#
- class DebugContext#
- property diff_threshold#
- init(self: pyhelayers.DebugContext, req: pyhelayers.HeConfigRequirement) None #
Initializes this DebugContext according the given requirement.
- Parameters:
req – an HeConfigRequirement object, indicating the required configuration parameters (e.g. securityLevel, numSlots).
- Raises:
RuntimeError – If it is not possible to fulfill the given requirement, or if the context is already initalized.
-
class DebugContext : public helayers::HeContext#
A class to represent an HeContext meant for debug purposes.
The CTiles it creates wrap two ciphertexts, encrypted with two possibly different schemes. The difference between the values of the two ciphertexts is checked after each operation, and in case this difference surpasses a certain certain threshold, an error will be thrown. This class can be used, for example, to wrap a MockupCiphertext along with another ciphertext and verify that the values of the later ciphertext are close to the mockup one after each operation.
Public Functions
-
DebugContext(HeContext &h1, HeContext &h2, double diffThreshold = 1e-5, bool printLog = false)#
A constructor.
- Parameters:
h1 – The first HeContext.
h2 – The second HeContext.
diffThreshold – The maximal allowed difference between the values of two ciphertexts of a DebugCiphertext created with this DebugContext.
printLog – Whether to print a log of operations.
-
virtual ~DebugContext()#
-
virtual void init(const HeConfigRequirement &req) override#
initializes the two HeContexts of this DebugContext, using the given requirements.
-
virtual std::shared_ptr<AbstractCiphertext> createAbstractCipher() const override#
Returns a pointer to a DebugCiphertext, initialized with this DebugContext.
-
virtual std::shared_ptr<AbstractPlaintext> createAbstractPlain() const override#
Returns a pointer to a DebugPlaintext, initialized with this DebugContext.
-
virtual std::shared_ptr<AbstractEncoder> getEncoder() const override#
Returns a pointer to a DebugEncoder, initialized with this DebugContext.
-
virtual int slotCount() const override#
The number of slots in each CTile (ciphertext) or PTile (plaintext) created over this context.
-
virtual int getTopChainIndex() const override#
Returns the highest available chain index (for schemes where it is applicable).
-
virtual bool hasSecretKey() const override#
Returns whether this context contains a secret key.
If not, decryption and other operations relying on decryption will not be available (will throw an exception).
-
virtual int getSecurityLevel() const override#
Returns the security level supplied by this context.
-
virtual std::string getSignature() const override#
Returns a signature that identifies the first HeContext wrapped with this DebugContext.
-
virtual void printSignature(std::ostream &out) const override#
Prints a summary of library details and configuration params of the two wrapped HeContexts.
- Parameters:
out – output stream to write to
-
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
-
virtual std::shared_ptr<std::vector<uint64_t>> getModulusChain() const override#
Returns the modulus chain of the first HeContext wrapped by this DebugContext.
-
virtual void saveSecretKey(std::ostream &out, bool seedOnly = false) override#
Saves the secret keys of the two wrapped HeContexts to a stream in binary form.
- Parameters:
out – Output stream to write to.
-
virtual void loadSecretKey(std::istream &in, bool seedOnly = false) override#
Loads the secret keys of the two wrapped HeContexts from the given istream,.
- Parameters:
in – Input stream to load frin.
-
inline double getDiffThreshold() const#
Returns the maximal allowed difference between the values of two ciphertexts of a DebugCiphertext created with this DebugContext.
-
inline bool getPrintLog() const#
Returns whether log is printed.
-
inline void setDiffThreshold(double v)#
Sets the maximal allowed difference threshold to the given value.
This threshold specifies the maximal allowed difference between the values of two ciphertexts o a DebugCiphertext created with this DebugContext.
- Parameters:
v – The difference threshold value to be set.
-
inline void setPrintLog(bool val)#
Sets log-printed flag value.
-
virtual void setDefaultDevice(DeviceType type, int deviceId, bool hybridUtilization) override#
Sets the default device of the ciphertexts and plaintexts generated using this HeContext, and the hybrid devices utilization policy.
- Parameters:
type – [in] The device type.
deviceId – [in] The device ID.
hybridUtilization – [in] Whether a policy of hybrid utilization of devices of different types shall be applied. 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).
-
virtual void setDefaultScale(double v) override#
Sets the default scale of the two wrapped HeContexts to the given value.
- Parameters:
v – The default scale value to be set.
-
inline virtual double getDefaultScale() const override#
Returns the default scale.
-
inline virtual std::string getLibraryName() const override#
Returns a string specifying the names of the underlying libraries.
-
inline virtual std::string getSchemeName() const override#
Returns a string specifying the names of the underlying schemes.
-
virtual bool isConfigRequirementFeasible(const HeConfigRequirement &req) const override#
Returns true if the received configuration requirement is feasible under the first HeContext wrapped with this DebugContext, and false otherwise.
- Parameters:
req – The requirement to check its feasibility.
-
virtual int getBestFeasibleFractionalPartPrecision(const HeConfigRequirement &req) const override#
Returns the best feasible fraction part precision under the given configuration requirement and according to the first HeContext wrapped with this DebugContext.
req The requirement to get best fractional part precision for.
-
virtual int getBestFeasibleMulDepth(const HeConfigRequirement &req) const override#
Returns the best feasible multiplication depth under the given configuration requirement and according to the first HeContext wrapped with this DebugContext.
req The requirement to get best multiplication depth for.
-
virtual std::vector<double> getMaxAllowedValues() const override#
Returns the maximal absolute value allowed for each chain index.
Values lower than the threshold are guaranteed to not produce overflows. The value in position i corresponds to the limit for chain index i.
-
virtual double getAccurateScale(int chainIndex) const override#
Returns the accurate scale to be used for a given chain index.
Only supported when accurate scaling mode is enabled. Cannot be called before the context is initialized.
- Parameters:
chainIndex – the chain index to get the scale of.
- Throws:
runtime_error – If this SealCkksContext is not initialized.
runtime_error – If accurate scaling is not enabled.
-
virtual double getMaxAllowedValueByRange(int high, int low) const override#
Returns the maximal absolute value allowed for values that may be in any chain index within a range that’s defined between a given low and high chain indexes.
- Parameters:
high – The higher chain index in the range.
low – The lower chain index in the range.
-
virtual double getMaxAllowedValue(int chainIndex) const override#
Returns the maximal absolute value allowed for values in a given chain index.
- Parameters:
chainIndex – The given chain index.
-
virtual double getMaxAllowedBsValue() const override#
Returns the maximal absolute value allowed for values going through a bootstrap operation.
-
virtual int getMinChainIndexForBootstrapping() const override#
Assuming this HeContext is bootstrappable, returns the minimum level in which ciphertexts can be bootstrapped.
-
virtual int getChainIndexAfterBootstrapping() const override#
Assuming this HeContext is bootstrappable, returns the level of ciphertexts after bootstrapping.
-
virtual BootstrapConfig getBootstrapChainIndexes(const HeConfigRequirement &req) const override#
Returns a bootstrap config object with two chain index values: the minimum level in which ciphertexts can be bootstrapped and the level of ciphertexts after bootstrapping.
- Parameters:
req – The requirement, must indicate a bootstrappable object.
-
virtual int getMinSupportedNumSlots() const override#
Returns the minimal number of slots supported by this HE context.
-
virtual int getMaxSupportedNumSlots() const override#
Returns the maximal number of slots supported by this HE context.
-
virtual bool publicFunctionsSupported(const PublicFunctions &publicFunctions) const override#
Returns true if the given PublicFunctions object is supported by the first HeContexts and false otherwise.
- Parameters:
publicFunctions – The publicFunctions object.
-
DebugContext(HeContext &h1, HeContext &h2, double diffThreshold = 1e-5, bool printLog = false)#