MockupContext#
- class MockupContext#
- init(self: pyhelayers.MockupContext, req: pyhelayers.HeConfigRequirement) None #
Initializes this MockupContext 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 MockupContext : public helayers::TrackingContext#
A class to represent mockup HE context.
It creates mockup ciphertext and plaintext objects that contain non-encrypted values and meta-data, and keep track of the values and meta-data when performing various “mockup” HE operations
Public Functions
-
MockupContext()#
-
inline virtual ~MockupContext()#
-
virtual void init(const HeConfigRequirement &req) override#
Internal use.
-
void setSupportsChainIndices(bool supportsChainIndices)#
Set an indication to whether chain indexes track should be supported.
- Parameters:
supportsChainIndices –
-
virtual std::shared_ptr<AbstractCiphertext> createAbstractCipher() const override#
Do not use. Should be made private.
-
virtual std::shared_ptr<AbstractPlaintext> createAbstractPlain() const override#
Do not use. Should be made private.
-
virtual std::shared_ptr<AbstractEncoder> getEncoder() const override#
Do not use. Should be made private.
-
virtual std::shared_ptr<AbstractBootstrapEvaluator> createAbstractBootstrapEvaluator(const BootstrapConfig &bsConfig) const override#
Do not use. Should be made private.
-
virtual std::shared_ptr<MultiPartyUtils> getMultiPartyUtils() override#
Do not use. Should be made private.
-
virtual std::shared_ptr<MultiPartyUtils> getMultiPartyUtils() const override#
-
inline virtual int slotCount() const override#
The number of slots in each CTile (ciphertext) or PTile (plaintext) created over this context.
-
inline virtual int getTopChainIndex() const override#
Returns the highest available chain index (for schemes where it is applicable).
-
virtual std::shared_ptr<std::vector<uint64_t>> getModulusChain() const override#
Returns the modulus chain: the value of each prime in the chain (where applicable).
Sets the modulus chain: the value of each prime in the chain (where applicable).
-
inline 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).
-
inline virtual int getSecurityLevel() const override#
Returns the security level supplied by this context.
-
virtual void printSignature(std::ostream &out = std::cout) const override#
Prints a summary of library details and configuration params.
- Parameters:
out – [in] output stream to write to
-
virtual void saveSecretKey(std::ostream &out, bool seedOnly = false) override#
Save secret key to the given ostream.
- Parameters:
out – The binary stream to save to.
seedOnly – If true, only the seed used to control the secret key’s randomness will be saved, rather than the whole secret key.
- Throws:
runtime_error – If this HeContext doesn’t have a secret key. i.e. hasSecretKey() is false.
runtime_error – If seedOnly is true but the underlying HeContext does not support secret key I/O using seeds.
-
virtual void loadSecretKey(std::istream &in, bool seedOnly = false) override#
Load secret key from the given istream.
- Parameters:
in – The binary stream to load from.
seedOnly – If true, the seed of the secret key will be loaded from the given binary stream and the secret key will be generated using this seed.
- Throws:
runtime_error – If this HeContext already has a secret key. i.e. hasSecretKey() is true.
runtime_error – If seedOnly is true but the underlying HeContext does not support secret key I/O using seeds.
-
inline virtual std::string getLibraryName() const override#
Returns the name of the underlying library.
-
inline virtual std::string getSchemeName() const override#
Returns the name of the underlying scheme.
-
virtual std::string getSignature() const override#
Returns a signature of the context that distinguishes it enough to be able to load previously stored contexts based on their signatures.
-
virtual bool isConfigRequirementFeasible(const HeConfigRequirement &req) const override#
Internal use.
-
virtual std::shared_ptr<HeContext> clone() const override#
Returns an uninitialized context of the same type.
Used for dynamic type loading among others.
-
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 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 getMaxAllowedBsValue() const override#
Returns the maximal absolute value allowed for values going through a bootstrap operation.
-
void setMaxAllowedValues(const std::vector<double> &maxValues)#
Sets the maximal absolute value allowed for each chain index.
- Parameters:
maxValues – The limitation values to set. Should be in the format of the result of calling “HeContext::getMaxAllowedValues”.
-
void setMaxAllowedBsValue(double maxBsValue)#
Sets the maximal absolute value allowed for values going through a bootstrap operation.
- Parameters:
maxBsValue –
-
void updateSeenValues(const std::vector<std::complex<long double>> &vals, int chainIndex)#
Update the tracking mechanism with an array of newly seen values in a given chain index.
- Parameters:
vals – The values seen.
chainIndex – The chain index of the values.
-
void updateBsSeenValues(const AbstractCiphertext &cipher)#
Update the bootstrap tracking mechanism with newly seen values taken from a given ciphertext.
- Parameters:
cipher – The given ciphertext.
-
const std::vector<double> &getMaxValuesSeen() const#
Returns the maximal absolute values seen so far, for each chain index.
The value in position i corresponds to chain index i.
-
double getHighestSeenToMaxRatio() const#
Returns the highest ratio between the absolute value of any value seen so far and the limitation that applies on it.
Result higher than one means an overflow.
-
double getHighestBsSeenToMaxRatio() const#
Returns the highest ratio between the absolute value of any value seen so far with respect to bootstrap operation, and the limitation that applies on it.
Result higher than one means an overflow.
-
void clearMaxValuesSeen()#
Clears the tracking of values that were seen so far.
-
virtual bool publicFunctionsSupported(const PublicFunctions &publicFunctions) const override#
Returns whether the given PublicFunctions object is supported by this HeContext.
The given PublicFunctions object is assumed to be valid (see also PublicFunctions::validate()).
- Parameters:
publicFunctions – The PublicFunctions object.
-
virtual int getMinChainIndexForBootstrapping() const override#
Assuming this HeContext is bootstrappable, returns the minimum level in which ciphertexts can be bootstrapped.
-
MockupContext()#