Skip to content

ValueError: encrypted1 and encrypted2 parameter mismatch #269

@EchizenG

Description

@EchizenG

Description
Two ciphertexts' parameters cannot be matched even after applying HE.align_mod_n_scale() and HE.mod_switch_to_next().
For the follwing code, I check the value for z and c075 at line of term1 = z * c075 (before running this code). it shows this:

(Pdb) p z
<Pyfhel Ciphertext at 0x768eff7a8950, scheme=ckks, size=2/2, scale_bits=30, mod_level=1>
(Pdb) p c075
<Pyfhel Ciphertext at 0x768effdb6720, scheme=ckks, size=2/2, scale_bits=30, mod_level=1>

which looks good but once I continue to execute this line, it will reports ValueError: encrypted1 and encrypted2 parameter mismatch

I also tried HE.align_mod_n_scale(c075, z). However, at the same position, the debug info is like this:

(Pdb) p z
<Pyfhel Ciphertext at 0x78d173a688b0, scheme=ckks, size=2/2, scale_bits=30, mod_level=1>
(Pdb) p c075
<Pyfhel Ciphertext at 0x78d174076680, scheme=ckks, size=2/2, scale_bits=30, mod_level=0>

I checked related issues such as #240 and #224 but doesn't work.

Thank you!

Code To Reproduce Error

from Pyfhel import Pyfhel, PyCtxt
import numpy as np
from typing import Sequence, Tuple, Optional


seq = np.array([3.2, 5.1, -0.4, 5.1, 2.0], dtype=float)
alpha = 0.181818

HE = Pyfhel()
HE.contextGen(
    scheme='CKKS',
    n=2**14, 
    scale=2**30,
    qi_sizes=[60, 40, 40, 40, 40, 40, 60],  # 7 levels is comfy for: z^2, z^3, + rotations & adds
    sec=128,
)
HE.keyGen();

enc_v  = HE.encryptFrac(seq)
c075 = HE.encryptFrac(np.full(HE.get_nSlots(), 0.75, dtype=np.float64))

z = enc_v * alpha
z.set_scale(HE.scale)

# HE.align_mod_n_scale(c075, z)
HE.mod_switch_to_next(c075)
term1 = z * c075

Expected behavior
term1 can be calculated.

Setup:

  • OS: Ubuntu
  • Python: 3.8.5
  • C compiler version: GCC 7.3.0
  • Pyfhel Version: 3.5.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions