Serialize/deserialize evalSumRowKeys and evalSumColKeys in Python

Hello! Please, help me! How can I serialize/deserialize the openfhe.EvalKeyMap structure to a file in Python? More specifically, how to serialize/deserialize evalSumRowKeys (evalSumRowKeys = cryptocontext.EvalSumRowsKeyGen(keys.sKey, rowSize=rSize)) and evalSumColKeys (evalSumColKeys = cryptocontext.EvalSumColsKeyGen(keys.sKey))?

All automorphism keys (include EvalSumRows and EvalSumCols keys) can be serialized using SerializeEvalAutomorphismKey and deserialized using DeserializeEvalAutomorphismKey (please see openfhe-python/examples/pke/simple-real-numbers-serial.py at main · openfheorg/openfhe-python · GitHub for an example).

I’m sorry, but the question remains.
The example in the link shows the serialization/deserialization of cryptocontext EvalAutomorphism keys, but evalSumRowKeys and evalSumColKeys do not belong to the cryptocontext, they are independent keys, as I understand it. Just like a private and public key pair is generated by the cryptocontext.KeyGen(), but is not contained in it and is serialized/deserialized independently of the cryptocontext.
If I’m wrong and these keys are contained in the cryptocontext, how can I access them after deserialization to pass them to the EncLogRegCalculateGradient(…, evalSumRowKeys, evalSumColKeys, …) function?

Hello! I keep waiting for an answer

Hi. EvalSum* methods now work with the automorphism map in the crypto context. There were also problems in v1.1.4 that we fixed. I suggest trying v1.2.0 (from the main branch) and v0.8.8 of the python wrapper (also from the main branch). Please let me know if you are still having problems with the new version.

Thanks for the answer. I deployed v1.2.0 and v0.8.8 of the python wrapper. But the Cryptocontext.EvalSumRows and Cryptocontext.EvalSumCols methods still require the openfhe.EvalKeyMap structure to be specified as the third parameter.


In the previous post it was stated that in v1.2.0 all automorphism keys are contained within the cryptocontext. Please tell me what to pass as the third parameter to these methods? How to extract the necessary keys from the cryptocontext? Please give an example in the form of lines of code, and not just words.

Internally, EvalSumColsKeyGen amd EvalSumRowsKeyGen add automorphism keys to the cryptocontext authomorphism map. But for backwards (API) compatibility (we did not want to change API yet), they still return a map with keys. In other words, the following examples still works: Is there any example about how to use EvalSumRows/EvalSumCols? - #2 by Caesar You can see a python version at openfhe-logreg-training-examples/enc_matrix.h at main · openfheorg/openfhe-logreg-training-examples · GitHub

For instance, you can deserialize the EvalSumRows and EvalSumCols keys (they will get added to the internal autmorphism map). Then you can pass a pointer to the automorphism map as either EvalSumRows or EvalSumCols keys. You can access the (full automorphism) map using GetEvalSumKeyMap (see CryptoContext — openfhe-python 0.8.0 documentation for more information on the method).

You can also use (De)SerializeEvalAutomorphismKey method to (de)serialize all automorphism keys at once (not always the most efficient method but it is simpler). EvalAtIndex, EvalRotate, and all EvalSum* methods use this automorphism map for all operations. The map can be read from the crypto context usng GetEvalSumKeyMap (as described in the paragraph above).

Thank you very much! Now everything is clear, focusing on the GetEvalSumKeyMap method was very useful, now everything works!