fhelium.engine.ckks_rescale
CKKS rescaling and the bootstrap structural-base transition.
CkksRescaler
class View source
CkksRescaler(*, engine_id: str, device: torch.device, public_level_count: int, rns_runtime: RnsRuntime, montgomery_parameters: MontgomeryParameters, dropped_q_inverses_montgomery_by_level: list[torch.Tensor], assert_engine_ciphertext: Callable[[Ciphertext], None], ciphertext_from_components: Callable[..., Ciphertext], rescale_to_next_output_scale: Callable[..., float])Execute one-prime CKKS rescale transitions for an engine.
Each transition divides by the leading active Q prime
rescale_to_next_levelandrescale_to_next_level_operate only on public CKKS levels;_rescale_final_public_level_to_structural_baseperforms the one additional private transition needed immediately before bootstrap modulus raising.
rescale_to_next_level
method
def rescale_to_next_level(ct: Ciphertext, rounding: Literal['nearest', 'floor']='nearest') -> Ciphertext: ...Drop the current scale prime at an ordinary public CKKS level.
Rescaling divides by the leading active Q prime and removes that RNS row. For each component,
Q input produces
Public rescaling stops before the one-prime structural basis. This method returns new ciphertext storage; rescale_to_next_level_ mutates its ciphertext argument.
Parameters
ct: Coefficient-domain, standard-residue ciphertext over the engine's full active Q or QP layout.rounding:"nearest"for nearest-integer division or"floor"for the least-nonnegative-residue quotient.
Returns
A new coefficient-domain standard ciphertext at ct.level + 1 with unchanged component count, batch shape, Q/QP basis, engine integral dtype/device, exact prime_ids=ct.prime_ids[1:], and canonical residues in ct is unchanged and output storage is independent.
Raises
MaximumLevelError: If no further public rescale level exists.InvalidScaleError: If the output scale is invalid.ValueError: If the ciphertext state is incompatible with rescaling.
rescale_to_next_level_
method
def rescale_to_next_level_(ct: Ciphertext, rounding: Literal['nearest', 'floor']='nearest') -> Ciphertext: ...In-place form of rescale_to_next_level.
Native kernels update the remaining RNS rows through views into ct.data. This method then narrows the dense tensor by one row and updates level, scale, and prime_ids. The returned object is ct itself; aliases must therefore be treated as mutated.
The quotient and actual-scale equations are identical to rescale_to_next_level. Aliases observe updated surviving rows, narrowed ct.data, level, scale, and exact prime_ids. The narrowed tensor remains a view of the original allocation.