What does SetNumLargeDigits do?

Hi, I’m new to OpenFHE, so I’m experimenting with some of the parameters. I’m just wondering what SetNumLargeDigits does?

Sample code

CCParams<CryptoContextCKKSRNS> parameters;
parameters.SetSecurityLevel(HEStd_128_classic);
parameters.SetRingDim(1 << 16);
parameters.SetBatchSize(1 << 15);

// parameters.SetNumLargeDigits(3); // Gives back a "The specified ring dimension (65536) does not comply with HE standards recommendation (131072)." error. It seems related to the 128 bit security.
// parameters.SetNumLargeDigits(7); // Gives back a "HYBRID key switching parameters: Can't appropriately distribute 30 towers into 7 digits. Please select different number of digits." Related to the multiplicative depth of 29 and also the default KeySwitch Technique
// parameters.SetNumLargeDigits(15); // Doesn't error out

parameters.SetScalingModSize(52);
parameters.SetScalingTechnique(FLEXIBLEAUTO);
parameters.SetFirstModSize(55);
parameters.SetMultiplicativeDepth(29);

CryptoContext<DCRTPoly> cryptoContext = GenCryptoContext(parameters);

I tried different parameters for it, and it seems to have a big effect on whether it errors out. I’ve shown what errors I see above. Could someone explain the observations and how it affects performance?

Thanks in advance.

NumLargeDigits is a key-switching parameter that determines the number of large digits into which a ciphertext is decomposed during key switching. This parameter influences the noise introduced by key switching, the size of the expanded ciphertext modulus, and runtime performance.

As it affects the ciphertext modulus size, it may cause security degradation, necessitating a larger ring dimension to maintain the required security level. This explains “Error 1” you observed above.

Certain values of the parameters cause undesired decomposition patterns and cannot be used as observed in “Error 2”.

The library does checks to filter proper values for the parameter, but you are advised to leave it at the default (which sets it to 3).

Details about key switching and how NumLargeDigits affects it can be found here, where the authors use dnum to refer to NumLargeDigits.

Thanks for the detailed answer! I will look into the paper.