fhelium.engine.ckks_plaintext_codec
CKKS message and Plaintext conversion for one local engine.
CkksPlaintextCodec
class View source
CkksPlaintextCodec(*, config: CkksConfig, context: CkksContextSpec, device: torch.device, rng: Csprng, rns_layout: RnsLayout, rns_runtime: RnsRuntime, galois_generator: int, engine_id: str, validate_public_level: Callable[[object], int])Convert slots through typed CKKS plaintext representations.
The codec owns the semantic path
and the inverse slot embedding for decoding. Encoding returns exact integer coefficients; RNS reduction is a separate transition. Decoding accepts exact integer coefficients or bounded binary64 approximate decrypt coefficients, never unreconstructed RNS rows.
num_slots
property
num_slots: intSemantic CKKS slot count fixed by the bound configuration.
plaintext
method
def plaintext(message, *, level: int=0, scale=None) -> Plaintext: ...Create an unencoded slots-only Plaintext.
No embedding or quantization occurs. The input is detached, cloned, and moved to the engine device while preserving its inferred dtype and shape; a later encode interprets the final axis as slots and preserves leading batch axes. The value records level and actual scale prime_ids.
encode
method
def encode(message, *, level: int=0, scale=None) -> Plaintext: ...Encode slots into one integer-coefficient plaintext.
This produces
independently of the selected RNS level. The functional result is exact integer_coefficients with layout [*batch, coefficient], final extent prime_ids. Use integer_coefficients_to_rns for modular reduction.
integer_coefficients_to_rns
method
def integer_coefficients_to_rns(plaintext: Plaintext, *, modulus_basis: ModulusBasis='Q') -> Plaintext: ...Reduce exact integer coefficients to standard RNS.
For each exact active row prime_ids[i] with modulus [*batch, coefficient] becomes [*batch, limb, coefficient] with engine integral dtype/device and final extent prime_ids map every limb row. Level and actual scale are preserved. No NTT, Montgomery conversion, rounding, or CRT reconstruction occurs, and the functional output does not alias input coefficient storage.
decode
method
def decode(plaintext: Plaintext, *, is_real: bool=False): ...Decode exact or approximate coefficients into CPU slots.
For coefficient data
The accepted payload is exact integral integer_coefficients or finite torch.float64 approximate_coefficients, each with layout [*batch, coefficient], final extent [*batch, slot], final extent is_real=True selects its real part.