Relation between ring dimension, batch size, num slots and length

Hi!
I use OpenFHE to perform some simple numerical simulations. And I have questions to the naming and meaning of several parameters used in OpenFHE. It would be great if someone could clarify it me.

Is a batch size used to configure a CryptoContext in parameters.SetBatchSize(batchSize); the same as num slots used to create Plaintext in cryptoContext->MakeCKKSPackedPlaintext(x, 1, depth - 1, nullptr, numSlots);? Are their interchangeable or have to be the same?

Which relation do batch size and num slots have to ring dimension and length of data vector. ( length of data vector could be not a power of two, unlike three other parameters)

Thank you in advance!

In the CKKS scheme, slots * 2 = dimension. The maximum value of batch size is slots. (Only in CKKS scheme, BGV/BFV is different from CKKS)
I think the remainder is filled with 0 when the length of vector is less than batch size.

When the number of slots is specified during MakeCKKSPackedPlaintext, that number of slots is set for a specific plaintext/ciphertext. The batch size is the global (default) setting for all ciphertexts in the cryptocontext.

Thank you very much!
Could you also take look at following questions? Just to ensure, that I’m configure num_slots and batch_size in effective way.

  • Can num_slots be greater than the originally specified batch_size?
  • What is the motivation is to create Plaintexts with different num_slots from a single CryptoContext (CC)? Are there performance benefits?
  • Is it possible to do arithmetic with plaintext/ciphertests of different num_slots?
  • If the previous question was answered with “yes”, and the one before that with “better performance”, is there any reason to not always set num_slots to the smallest power-of-two such that the data fits?

Example for the last question: If batchSize == 128 , but my data is either length == 30 or length == 50 , should I just always set num_slots to 32 and 64 respectively?

  • Can num_slots be greater than the originally specified batch_size?

Yes

  • What is the motivation is to create Plaintexts with different num_slots from a single CryptoContext (CC)? Are there performance benefits?

Primarily for CKKS bootstrapping (it gets slightly cheaper for a smaller number of slots). Also the approximation error is smaller in some operations when working with more sparse ciphertexts.

  • Is it possible to do arithmetic with plaintext/ciphertests of different num_slots?

No, it does not make sense (in the same binary operation)

OK, so just to confirm I understood it correctly:

  • The technical maximum number of slots for CKKS-based encoding is GetRingDimension()/2 (inherent in CKKS)
  • When specifying batchSize for CCParams, …
    • it is used as one of the factors to determine the required ring dimension
    • it is used to set the default number of slots for newly created Plaintexts/Ciphertexts
  • Using GetSlots on a plaintext (or its derived ciphertext) created without specifying slots in MakeCKKSPackedPlaintext, results in the number of slots equal to the batch size
  • Using SetSlots on a plaintext or before creating a ciphertext allows one to dynamically reduce the number of slots.
  • Using SetSlots after a ciphertext was created to change the number of slots generally leads to a broken ciphertext unless manually.

At least this is what I have found from experimentation…