fhelium.bootstrap
CKKS full-slot bootstrapping composed from ordinary Eager operations.
plan returns a BootstrapPlan holding every component choice (modulus raise, CoeffsToSlots, EvalMod, SlotsToCoeffs) and its depth placement. create_evaluation_keys provisions the keys the plan requires, bootstrap refreshes a ciphertext, and prepare returns a caller-owned PreparedBootstrap for repeated execution and capture. Key arguments default to engine.keys. The step functions (modulus_raise, coeffs_to_slots, split_real_imag, eval_mod, merge_real_imag, slots_to_coeffs) evaluate one step each for custom compositions.
BootstrapPlan
class View source
BootstrapPlan(source_depth: int, raise_target_depth: int, input_scale: float, coeffs_to_slots: tuple[LinearTransform, ...], coeffs_to_slots_plan: Any, eval_mod: Any, slots_to_coeffs: tuple[LinearTransform, ...], slots_to_coeffs_plan: Any, target_scales: tuple[float, ...], normalization_factor: float = 1.0, modulus_raise: Any = field(default_factory=Centered), message_domain: Literal['complex', 'real'] = 'complex', batch_branches: bool = True, compress_diagonals: bool = True, basis_conversion: Literal['exact', 'crt', 'normalized_crt'] = 'exact')Full-slot bootstrap composition for one CKKS configuration.
The refresh evaluates, in order: modulus raise from source_depth to raise_target_depth; CoeffsToSlots stages normalization_factor is one); real/imaginary split by conjugation; EvalMod eval_mod on each branch; merge with the monomial input_scale, source basis product message_domain="real" evaluates only
The raised value satisfies modulus_raise_bound reports the deterministic worst case of
Plaintext constants are encoded so each multiplication reaches target_scales[d+1]; the default schedule is fhelium.bootstrap.bootstrap evaluates it.
coeffs_to_slots_plan, slots_to_coeffs_plan and eval_mod may be any objects following the linear-plan protocol of fhelium.algorithms.linear and the reduction protocol of fhelium.bootstrap.periodic. The plan reads their declared required_depths for depth placement and their rotation offsets and relinearization depths for key requirements; it calls their evaluate methods with one fhelium.algorithms.Arithmetic on target_scales. fhelium.bootstrap.prepare runs these calls once to record keys and encoded materials, and the prepared object repeats the same calls on the recorded entries.
Attributes
| Name | Type | Default/value |
|---|---|---|
source_depth | int | |
raise_target_depth | int | |
input_scale | float | |
coeffs_to_slots | tuple[LinearTransform, ...] | |
coeffs_to_slots_plan | Any | |
eval_mod | Any | |
slots_to_coeffs | tuple[LinearTransform, ...] | |
slots_to_coeffs_plan | Any | |
target_scales | tuple[float, ...] | |
normalization_factor | float | 1.0 |
modulus_raise | Any | field(default_factory=Centered) |
message_domain | Literal['complex', 'real'] | 'complex' |
batch_branches | bool | True |
compress_diagonals | bool | True |
basis_conversion | Literal['exact', 'crt', 'normalized_crt'] | 'exact' |
cts_depth
property
cts_depth: intstc_depth
property
stc_depth: intnormalization_depths
property
normalization_depths: intDepths of the separate
output_depth
property
output_depth: intDepth of the refreshed ciphertext.
consumed_depths
property
consumed_depths: intDepth transitions consumed after the modulus raise.
refresh_window
property
refresh_window: intTransitions available between the output and the next bootstrap input.
modulus_raise_bound
property
modulus_raise_bound: float | NoneWorst-case
Typical coefficients of eval_mod.input_bound for comparison.
stages
method
def stages() -> tuple[BootstrapStage, ...]: ...Return each step's depth transition and output scale.
required_rotations
property
required_rotations: tuple[int, ...]Normalized signed
key_steps
method
def key_steps(strategy: str='all_required') -> tuple[int, ...]: ...Rotation steps provisioned by a key strategy.
all_required stores one key per transform rotation; signed_power_of_two stores signed powers of two that compose them; signed_power_of_two_with_baby_steps adds direct BSGS baby keys.
key_requirements
method
def key_requirements(strategy: str='all_required') -> EvaluationKeyRequirements: ...Rotation, relinearization and conjugation capabilities of the plan.
BootstrapStage
class View source
BootstrapStage(name: str, input_depth: int, output_depth: int, output_scale: float)One step of a plan: its name and depth/scale placement.
Attributes
| Name | Type | Default/value |
|---|---|---|
name | str | |
input_depth | int | |
output_depth | int | |
output_scale | float |
Centered
class View source
Centered()Extend each component's centered representative from
For a source ciphertext
Encapsulated
class View source
Encapsulated(intermediate_weight: int, moddown_rounding: Literal['nearest', 'floor'] = 'nearest')Raise through an intermediate secret
The source ciphertext is key-switched from intermediate_weight is required; fhelium.bootstrap.create_evaluation_keys samples fhelium.values.EncapsulationKey values to the inventory. The auxiliary primes are the largest P primes: one low prime, one guard prime and further return primes until their product reaches
Attributes
| Name | Type | Default/value |
|---|---|---|
intermediate_weight | int | |
moddown_rounding | Literal['nearest', 'floor'] | 'nearest' |
PreparedBootstrap
class View source
PreparedBootstrap(algorithm: _CoreAlgorithm, materials: _CoreMaterials, input_signature: ValueSignature, device: torch.device)Caller-owned encoded constants, diagonals and selected keys for one plan.
fhelium.bootstrap.prepare creates it for one input signature and device. Calling it refreshes an input without encoding or key selection, so Eager execution, fhelium.compile capture and CUDA Graph replay read only the prepared materials. Drop the object, or call close after closing Graphs that use it, to release them.
plan
property
plan: Anyevaluation_keys
property
evaluation_keys: EvaluationKeySetReference inventory of the selected evaluation keys.
diagonal_bytes
property
diagonal_bytes: intBytes of the encoded transform diagonals.
constant_bytes
property
constant_bytes: intBytes of the encoded scalar and monomial constants.
refresh
method
def refresh(value: Ciphertext) -> Ciphertext: ...Refresh value without the signature check: entry to the source depth and input scale, the core algorithm, and restoration of the entry ratio.
close
method
def close() -> None: ...Release materials after every Graph using this object is closed.
bootstrap
function View source
def bootstrap(engine, ciphertext, plan: BootstrapPlan | None=None, *, keys=None, prepared=None): ...Refresh a coefficient-domain ciphertext at depth plan.source_depth.
An input below the source depth first reaches it with mod_switch_to_depth. The source-basis value plan.input_scale; the output at plan.output_depth records actual scale prepared, its materials are used and plan/keys are not consulted; otherwise constants and diagonals are encoded and keys selected from keys (default engine.keys) for this call.
coeffs_to_slots
function View source
def coeffs_to_slots(engine, ciphertext, plan: BootstrapPlan, *, keys=None): ...Apply
create_evaluation_keys
function View source
def create_evaluation_keys(engine, plan: BootstrapPlan, secret_key, *, into=None, rotation_key_strategy: str='all_required', device=None): ...Add the keys required by plan to an inventory and return it.
into defaults to engine.keys. Rotation keys follow rotation_key_strategy (see BootstrapPlan.key_steps); keys already present in into with a compatible layout are reused. Relinearization and conjugation keys are added when missing. An Encapsulated raise also adds its low and return key-switch keys, sampling the intermediate secret internally.
eval_mod
function View source
def eval_mod(engine, real, imaginary, plan: BootstrapPlan, *, keys=None): ...Apply plan.eval_mod to one or both branches (batched when plan.batch_branches).
merge_real_imag
function View source
def merge_real_imag(engine, real, imaginary, plan: BootstrapPlan): ...Return
modulus_raise
function View source
def modulus_raise(engine, ciphertext, plan: BootstrapPlan, *, keys=None): ...Raise a source-basis ciphertext to plan.raise_target_depth.
periodic
module
fhelium.bootstrap.periodic
plan
function View source
def plan(engine, preset: Profile='3/38', *, intermediate_weight: int | None=None, modulus_raise: Any=None, message_domain: Literal['complex', 'real']='complex', eval_mod: Any=None, polynomial_plan: Any=None, coeffs_to_slots_plan: Any=None, slots_to_coeffs_plan: Any=None, giant_step_reduction: Literal['aggregate', 'independent'] | None=None, product_implementation: str | None='auto', product_chunk_size: int | None=16, batch_branches: bool=True, compress_diagonals: bool=True, input_scale: float | None=None, target_scales: tuple[float, ...] | None=None, basis_conversion: Literal['exact', 'crt', 'normalized_crt'] | None=None) -> BootstrapPlan: ...Construct the default plan of a cosine EvalMod profile for engine's chain.
The input is at max_depth, the raise targets depth 0 and the output depth equals the plan's consumed depth. The default input_scale is iterations/seed degree: "7/44" ("8/28" and "8/28-s2c3" (binary seed evaluation, independent giant-step quotients, two or three STC stages) and "3/30" ("3/38" (default, -boot presets are built for, has four CTS stages with the normalization folded into the last, a degree-38 seed expanded analytically in Chebyshev form (fhelium.bootstrap.periodic.CosineExpansion) and evaluated by fhelium.algorithms.polynomial.RecursiveChebyshevPlan, three STC stages, basis_conversion="normalized_crt", input_scale equal to basis_conversion="exact". intermediate_weight=h selects Encapsulated with intermediate secret weight Centered. Keyword arguments replace individual choices; dataclasses.replace on the result changes any field afterwards.
prepare
function View source
def prepare(engine, plan: BootstrapPlan, like, *, keys=None) -> PreparedBootstrap: ...Encode the plan's constants and diagonals and select its keys once.
Keys are selected from keys, by default engine.keys. like fixes the input signature (depth, scale, batch shape, device); preparation refreshes it once and discards the output. Call before CUDA Graph capture.
slots_to_coeffs
function View source
def slots_to_coeffs(engine, ciphertext, plan: BootstrapPlan, *, keys=None): ...Apply
split_real_imag
function View source
def split_real_imag(engine, ciphertext, plan: BootstrapPlan, *, keys=None): ...Return None for real messages.
Multiplication by