# Serialize/deserialize evalSumRowKeys and evalSumColKeys in Python

**URL:** <https://openfhe.discourse.group/t/serialize-deserialize-evalsumrowkeys-and-evalsumcolkeys-in-python/1357>\
**Category:** OpenFHE ports/wrappers\
**Created:** [June 14, 2024, 11:47am UTC](https://openfhe.discourse.group/t/serialize-deserialize-evalsumrowkeys-and-evalsumcolkeys-in-python/1357 "2024-06-14T11:47:15Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![oleg.fatyukhin](https://avatars.discourse-cdn.com/v4/letter/o/85e7bf/32.png) [@oleg.fatyukhin](https://openfhe.discourse.group/u/oleg.fatyukhin)\
**Post date:** [June 14, 2024, 11:47am UTC](https://openfhe.discourse.group/t/serialize-deserialize-evalsumrowkeys-and-evalsumcolkeys-in-python/1357/1 "2024-06-14T11:47:16Z")

</div>

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))?

---

<div class="post-metadata">

**Author:** ![ypolyakov](https://yyz1.discourse-cdn.com/flex031/user_avatar/openfhe.discourse.group/ypolyakov/32/47_2.png) [@ypolyakov](https://openfhe.discourse.group/u/ypolyakov)\
**Post date:** [June 18, 2024, 11:30pm UTC](https://openfhe.discourse.group/t/serialize-deserialize-evalsumrowkeys-and-evalsumcolkeys-in-python/1357/2 "2024-06-18T23:30:56Z")

</div>

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](https://github.com/openfheorg/openfhe-python/blob/main/examples/pke/simple-real-numbers-serial.py) for an example).

---

<div class="post-metadata">

**Author:** ![oleg.fatyukhin](https://avatars.discourse-cdn.com/v4/letter/o/85e7bf/32.png) [@oleg.fatyukhin](https://openfhe.discourse.group/u/oleg.fatyukhin)\
**Post date:** [June 19, 2024, 1:55pm UTC](https://openfhe.discourse.group/t/serialize-deserialize-evalsumrowkeys-and-evalsumcolkeys-in-python/1357/3 "2024-06-19T13:55:23Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![oleg.fatyukhin](https://avatars.discourse-cdn.com/v4/letter/o/85e7bf/32.png) [@oleg.fatyukhin](https://openfhe.discourse.group/u/oleg.fatyukhin)\
**Post date:** [June 24, 2024, 8:57am UTC](https://openfhe.discourse.group/t/serialize-deserialize-evalsumrowkeys-and-evalsumcolkeys-in-python/1357/4 "2024-06-24T08:57:59Z")

</div>

Hello! I keep waiting for an answer

---

<div class="post-metadata">

**Author:** ![ypolyakov](https://yyz1.discourse-cdn.com/flex031/user_avatar/openfhe.discourse.group/ypolyakov/32/47_2.png) [@ypolyakov](https://openfhe.discourse.group/u/ypolyakov)\
**Post date:** [June 25, 2024, 9:16pm UTC](https://openfhe.discourse.group/t/serialize-deserialize-evalsumrowkeys-and-evalsumcolkeys-in-python/1357/5 "2024-06-25T21:16:31Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![oleg.fatyukhin](https://avatars.discourse-cdn.com/v4/letter/o/85e7bf/32.png) [@oleg.fatyukhin](https://openfhe.discourse.group/u/oleg.fatyukhin)\
**Post date:** [June 27, 2024, 7:24am UTC](https://openfhe.discourse.group/t/serialize-deserialize-evalsumrowkeys-and-evalsumcolkeys-in-python/1357/6 "2024-06-27T07:24:05Z")

</div>

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.

 ![EvalSumCols_error](https://canada1.discourse-cdn.com/flex031/uploads/openfhe/original/1X/05ee1ac19cafa75bca550b96bba1040f9359732e.jpeg)  
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.

---

<div class="post-metadata">

**Author:** ![ypolyakov](https://yyz1.discourse-cdn.com/flex031/user_avatar/openfhe.discourse.group/ypolyakov/32/47_2.png) [@ypolyakov](https://openfhe.discourse.group/u/ypolyakov)\
**Post date:** [June 30, 2024, 5:23pm UTC](https://openfhe.discourse.group/t/serialize-deserialize-evalsumrowkeys-and-evalsumcolkeys-in-python/1357/7 "2024-06-30T17:23:59Z")

</div>

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](https://openfhe.discourse.group/t/is-there-any-example-about-how-to-use-evalsumrows-evalsumcols/687/2) You can see a python version at [openfhe-logreg-training-examples/enc\_matrix.h at main · openfheorg/openfhe-logreg-training-examples · GitHub](https://github.com/openfheorg/openfhe-logreg-training-examples/blob/main/enc_matrix.h#L56)

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](https://openfheorg.github.io/openfhe-python/html/cryptocontext.html) 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).

---

<div class="post-metadata">

**Author:** ![oleg.fatyukhin](https://avatars.discourse-cdn.com/v4/letter/o/85e7bf/32.png) [@oleg.fatyukhin](https://openfhe.discourse.group/u/oleg.fatyukhin)\
**Post date:** [July 1, 2024, 8:02am UTC](https://openfhe.discourse.group/t/serialize-deserialize-evalsumrowkeys-and-evalsumcolkeys-in-python/1357/8 "2024-07-01T08:02:52Z")

</div>

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