Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions tfhe/docs/fhe-computation/compute/parameters.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,60 @@ For convenience, aliases are provided for the most used sets of parameters and s


## How to choose the parameter sets

Since tfhe-rs 1.4, there is a `MetaParameterFinder` which enables to search for suitable parameters given some choice of constraints.

```rust
use tfhe::shortint::parameters::{MetaParameterFinder, Log2PFail, Constraint, Version, Backend, NoiseDistributionChoice, NoiseDistributionKind};
use tfhe::{FheUint32, CompressedCiphertextListBuilder, generate_keys, set_server_key};
use tfhe::prelude::*;

fn main() {
// Create a finder with minimal constraints
let mut finder = MetaParameterFinder::new(
// We want parameters that have a failure probability `pfal` that is: pfail <= 2^-64
Constraint::LessThanOrEqual(Log2PFail(-64.0)),
// We want parameters from the version 1.4
Version(1, 4, 0),
// We want parameters meant for CPU execution
Backend::Cpu
);

let parameters = finder
.find()
.expect("Could not find suitable parameters");

let (client_key, server_key) = generate_keys(parameters);


// We can add other constaints:
let finder = finder
// We want to use compression (CompressedCiphertextList)
// So we require parameters that support it
.with_compression(true)
.with_noise_distribution(
// Allow any noise distribution that is not TUniform
NoiseDistributionChoice::allow_all()
.deny(NoiseDistributionKind::TUniform)
);


let parameters = finder
.find()
.expect("Could not find suitable parameters");

let (client_key, server_key) = generate_keys(parameters);

let a = FheUint32::encrypt(1337u32, &client_key);
set_server_key(server_key);
let compressed_list = CompressedCiphertextListBuilder::new()
.push(a)
.build()
.unwrap();
}
```


You can override the default parameters with the `with_custom_parameters(block_parameters)` method of the `Config` object. For example, to use a Gaussian distribution instead of the TUniform one, you can modify your configuration as follows:

```rust
Expand Down
24 changes: 23 additions & 1 deletion tfhe/src/high_level_api/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ use tfhe_versionable::Versionize;
use crate::backward_compatibility::config::ConfigVersions;
use crate::high_level_api::keys::IntegerConfig;
use crate::shortint::parameters::list_compression::CompressionParameters;
use crate::shortint::parameters::{NoiseSquashingCompressionParameters, NoiseSquashingParameters};
use crate::shortint::parameters::{
MetaParameters, NoiseSquashingCompressionParameters, NoiseSquashingParameters,
};

/// The config type
#[derive(Copy, Clone, Debug, serde::Serialize, serde::Deserialize, Versionize)]
Expand Down Expand Up @@ -127,3 +129,23 @@ impl From<ConfigBuilder> for Config {
builder.build()
}
}

impl From<MetaParameters> for Config {
fn from(meta_params: MetaParameters) -> Self {
Self {
inner: IntegerConfig {
block_parameters: meta_params.compute_parameters,
dedicated_compact_public_key_parameters: meta_params
.dedicated_compact_public_key_parameters
.map(|dedicated_p| (dedicated_p.pke_params, dedicated_p.ksk_params)),
compression_parameters: meta_params.compression_parameters,
noise_squashing_parameters: meta_params
.noise_squashing_parameters
.map(|ns_p| ns_p.parameters),
noise_squashing_compression_parameters: meta_params
.noise_squashing_parameters
.and_then(|ns_p| ns_p.compression_parameters),
},
}
}
}
4 changes: 4 additions & 0 deletions tfhe/src/shortint/parameters/classic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,8 @@ impl ClassicPBSParameters {
noise_level,
}
}

pub const fn pbs_order(&self) -> PBSOrder {
self.encryption_key_choice.into_pbs_order()
}
}
Loading
Loading