Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mz/enable all doctest warnings #1418

Merged
merged 3 commits into from
Sep 12, 2024
Merged
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
2 changes: 0 additions & 2 deletions tfhe/benches/integer/zk_pke.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![allow(dead_code)]

#[path = "../utilities.rs"]
mod utilities;

Expand Down
8 changes: 4 additions & 4 deletions tfhe/docs/fundamentals/compress.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ This example shows how to compress a ciphertext encrypting messages over 16 bits

```rust
use tfhe::prelude::*;
use tfhe::{ConfigBuilder, generate_keys, set_server_key, CompressedFheUint16};
use tfhe::{ConfigBuilder, generate_keys, CompressedFheUint16};

fn main() {
let config = ConfigBuilder::default().build();
Expand Down Expand Up @@ -131,7 +131,7 @@ This example shows how to compress the server keys:
```rust
use tfhe::prelude::*;
use tfhe::{
generate_keys, set_server_key, ClientKey, CompressedServerKey, ConfigBuilder, FheUint8,
set_server_key, ClientKey, CompressedServerKey, ConfigBuilder, FheUint8,
};

fn main() {
Expand Down Expand Up @@ -176,7 +176,7 @@ This issue has been identified and will be addressed in future releases.

```rust
use tfhe::prelude::*;
use tfhe::{ConfigBuilder, generate_keys, set_server_key, FheUint8, CompressedPublicKey};
use tfhe::{ConfigBuilder, generate_keys, FheUint8, CompressedPublicKey};

fn main() {
let config = ConfigBuilder::default().build();
Expand Down Expand Up @@ -204,7 +204,7 @@ This example shows how to use compressed compact public keys:
```rust
use tfhe::prelude::*;
use tfhe::{
generate_keys, set_server_key, CompactCiphertextList, CompressedCompactPublicKey,
generate_keys, CompactCiphertextList, CompressedCompactPublicKey,
ConfigBuilder, FheUint8,
};

Expand Down
11 changes: 4 additions & 7 deletions tfhe/docs/fundamentals/serialization.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use tfhe::prelude::*;
fn main() -> Result<(), Box<dyn std::error::Error>>{
let config = ConfigBuilder::default().build();

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

let msg1 = 1;
let msg2 = 0;
Expand Down Expand Up @@ -96,7 +96,6 @@ Here is an example:
// main.rs

use tfhe::conformance::ParameterSetConformant;
use tfhe::integer::parameters::RadixCiphertextConformanceParams;
use tfhe::prelude::*;
use tfhe::safe_deserialization::{safe_deserialize_conformant, safe_serialize};
use tfhe::shortint::parameters::{PARAM_MESSAGE_2_CARRY_2_KS_PBS, PARAM_MESSAGE_2_CARRY_2_PBS_KS};
Expand All @@ -107,14 +106,12 @@ use tfhe::{
};

fn main() {
let config = ConfigBuilder::default().build();

let params_1 = PARAM_MESSAGE_2_CARRY_2_KS_PBS;
let params_2 = PARAM_MESSAGE_2_CARRY_2_PBS_KS;

let (client_key, server_key) = generate_keys(
ConfigBuilder::with_custom_parameters(params_1).build()
);
let config = ConfigBuilder::with_custom_parameters(params_1).build();

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

let conformance_params_1 = FheUint8ConformanceParams::from(params_1);
let conformance_params_2 = FheUint8ConformanceParams::from(params_2);
Expand Down
10 changes: 5 additions & 5 deletions tfhe/docs/getting_started/operations.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {

let mut a = FheUint8::try_encrypt(clear_a, &keys)?;
let mut b = FheUint8::try_encrypt(clear_b, &keys)?;
let mut c = FheUint8::try_encrypt(clear_c, &keys)?;
let c = FheUint8::try_encrypt(clear_c, &keys)?;
let mut d = FheInt8::try_encrypt(clear_d, &keys)?;


Expand Down Expand Up @@ -193,8 +193,8 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
let clear_a: i8 = -121;
let clear_b: i8 = 87;

let mut a = FheInt8::try_encrypt(clear_a, &keys)?;
let mut b = FheInt8::try_encrypt(clear_b, &keys)?;
let a = FheInt8::try_encrypt(clear_a, &keys)?;
let b = FheInt8::try_encrypt(clear_b, &keys)?;

let greater = a.gt(&b);
let greater_or_equal = a.ge(&b);
Expand Down Expand Up @@ -241,8 +241,8 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
let clear_a:u8 = 164;
let clear_b:u8 = 212;

let mut a = FheUint8::try_encrypt(clear_a, &keys)?;
let mut b = FheUint8::try_encrypt(clear_b, &keys)?;
let a = FheUint8::try_encrypt(clear_a, &keys)?;
let b = FheUint8::try_encrypt(clear_b, &keys)?;

let min = a.min(&b);
let max = a.max(&b);
Expand Down
4 changes: 2 additions & 2 deletions tfhe/docs/guides/public_key.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ This example shows how to use classical public keys.

```rust
use tfhe::prelude::*;
use tfhe::{ConfigBuilder, generate_keys, set_server_key, FheUint8, PublicKey};
use tfhe::{ConfigBuilder, generate_keys, FheUint8, PublicKey};

fn main() {
let config = ConfigBuilder::default().build();
Expand All @@ -38,7 +38,7 @@ For more information on using compact public keys to encrypt data and generate a
```rust
use tfhe::prelude::*;
use tfhe::{
generate_keys, set_server_key, CompactCiphertextList, CompactPublicKey, ConfigBuilder, FheUint8,
generate_keys, CompactCiphertextList, CompactPublicKey, ConfigBuilder, FheUint8,
};


Expand Down
3 changes: 0 additions & 3 deletions tfhe/docs/guides/rayon_crate.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ This document describes how to use Rayon for parallel processing in **TFHE-rs**,
The high-level API requires to call `set_server_key` on each thread where computations need to be done. So a first attempt to use Rayon with **TFHE-rs** might look like this:

```rust
use rayon::prelude::*;
use tfhe::prelude::*;
use tfhe::{ConfigBuilder, set_server_key, FheUint8, generate_keys};

Expand Down Expand Up @@ -51,7 +50,6 @@ However, due to Rayon's work-stealing mechanism and **TFHE-rs'** internals, this
The correct way is to call `rayon::broadcast` as follows:

```rust
use rayon::prelude::*;
use tfhe::prelude::*;
use tfhe::{ConfigBuilder, set_server_key, FheUint8, generate_keys};

Expand Down Expand Up @@ -95,7 +93,6 @@ fn main() {
For applications that need to operate concurrently on data from different clients and require each client to use multiple threads, you need to create separate Rayon thread pools:

```rust
use rayon::prelude::*;
use tfhe::prelude::*;
use tfhe::{ConfigBuilder, set_server_key, FheUint8, generate_keys};

Expand Down
7 changes: 3 additions & 4 deletions tfhe/docs/guides/zk-pok.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
set_server_key(server_key);

// Verify the ciphertexts
let mut expander =
proven_compact_list.verify_and_expand(public_zk_params, &public_key, &metadata)?;
let expander = proven_compact_list.verify_and_expand(public_zk_params, &public_key, &metadata)?;

let a: tfhe::FheUint64 = expander.get(0).unwrap()?;
let b: tfhe::FheUint64 = expander.get(1).unwrap()?;

Expand Down Expand Up @@ -119,8 +119,7 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
set_server_key(server_key);

// Verify the ciphertexts
let mut expander =
proven_compact_list.verify_and_expand(public_zk_params, &public_key, &metadata)?;
let expander = proven_compact_list.verify_and_expand(public_zk_params, &public_key, &metadata)?;
let a: tfhe::FheUint64 = expander.get(0).unwrap()?;
let b: tfhe::FheUint64 = expander.get(1).unwrap()?;

Expand Down
20 changes: 8 additions & 12 deletions tfhe/docs/references/fine-grained-apis/boolean/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,6 @@ fn main() {
Once the encrypted inputs are on the **server side**, the `server_key` can be used to homomorphically execute the desired Boolean circuit:

```rust
use std::fs::File;
use std::io::{Write, Read};
use tfhe::boolean::prelude::*;

fn main() {
Expand All @@ -154,28 +152,28 @@ fn main() {
let encoded_1: Vec<u8> = bincode::serialize(&ct_1).unwrap();
let encoded_2: Vec<u8> = bincode::serialize(&ct_2).unwrap();

//---------------------------- ON SERVER SIDE ----------------------------
//---------------------------- ON SERVER SIDE ----------------------------

// We deserialize the ciphertexts:
// We deserialize the ciphertexts:
let ct_1: Ciphertext = bincode::deserialize(&encoded_1[..])
.expect("failed to deserialize");
let ct_2: Ciphertext = bincode::deserialize(&encoded_2[..])
.expect("failed to deserialize");

// We use the server key to execute the boolean circuit:
// if ((NOT ct_2) NAND (ct_1 AND ct_2)) then (NOT ct_2) else (ct_1 AND ct_2)
// We use the server key to execute the boolean circuit:
// if ((NOT ct_2) NAND (ct_1 AND ct_2)) then (NOT ct_2) else (ct_1 AND ct_2)
let ct_3 = server_key.not(&ct_2);
let ct_4 = server_key.and(&ct_1, &ct_2);
let ct_5 = server_key.nand(&ct_3, &ct_4);
let ct_6 = server_key.mux(&ct_5, &ct_3, &ct_4);

// Then we serialize the output of the circuit:
// Then we serialize the output of the circuit:
let encoded_output: Vec<u8> = bincode::serialize(&ct_6)
.expect("failed to serialize output");

// ...
// And we send the output to the client
// ...
// ...
// And we send the output to the client
// ...
}
```

Expand All @@ -184,8 +182,6 @@ fn main() {
Once the encrypted output is on the client side, the `client_key` can be used to decrypt it:

```rust
use std::fs::File;
use std::io::{Write, Read};
use tfhe::boolean::prelude::*;

fn main() {
Expand Down
38 changes: 18 additions & 20 deletions tfhe/docs/references/fine-grained-apis/boolean/parameters.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,23 @@ You can also create your own set of parameters. This is an `unsafe` operation as
use tfhe::boolean::prelude::*;

fn main() {
// WARNING: might be insecure and/or incorrect
// You can create your own set of parameters
let parameters = unsafe {
BooleanParameters::new(
LweDimension(586),
GlweDimension(2),
PolynomialSize(512),
DynamicDistribution::new_gaussian_from_std_dev(
StandardDev(0.00008976167396834998),
),
DynamicDistribution::new_gaussian_from_std_dev(
StandardDev(0.00000002989040792967434),
),
DecompositionBaseLog(8),
DecompositionLevelCount(2),
DecompositionBaseLog(2),
DecompositionLevelCount(5),
EncryptionKeyChoice::Small,
)
};
// WARNING: might be insecure and/or incorrect
// You can create your own set of parameters
let parameters = BooleanParameters::new(
LweDimension(586),
GlweDimension(2),
PolynomialSize(512),
DynamicDistribution::new_gaussian_from_std_dev(
StandardDev(0.00008976167396834998),
),
DynamicDistribution::new_gaussian_from_std_dev(
StandardDev(0.00000002989040792967434),
),
DecompositionBaseLog(8),
DecompositionLevelCount(2),
DecompositionBaseLog(2),
DecompositionLevelCount(5),
EncryptionKeyChoice::Small,
);
}
```
4 changes: 2 additions & 2 deletions tfhe/docs/references/fine-grained-apis/integer/operations.md
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,8 @@ fn main() {

// We use the client key to encrypt two messages:
let mut ct_1 = client_key.encrypt(msg1);
let mut ct_2 = client_key.encrypt(msg2);
let mut ct_3 = client_key.encrypt(msg3);
let ct_2 = client_key.encrypt(msg2);
let ct_3 = client_key.encrypt(msg3);

server_key.scalar_mul_assign_parallelized(&mut ct_1, scalar);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ fn main() {

// We use the client key to encrypt two messages:
let mut ct_1 = client_key.encrypt(msg1);
let mut ct_2 = client_key.encrypt(msg2);
let ct_2 = client_key.encrypt(msg2);

server_key.scalar_mul_assign(&mut ct_1, scalar);
server_key.sub_assign(&mut ct_1, &ct_2);
Expand Down Expand Up @@ -334,8 +334,6 @@ fn main() {

let msg1 = 3;

let modulus = client_key.parameters.message_modulus().0;

// We use the private client key to encrypt a message:
let ct_1 = client_key.encrypt(msg1);

Expand Down
46 changes: 23 additions & 23 deletions tfhe/docs/references/fine-grained-apis/shortint/parameters.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,28 +55,28 @@ use tfhe::shortint::prelude::*;
use tfhe::shortint::parameters::DynamicDistribution;

fn main() {
let param = unsafe {
ClassicPBSParameters::new(
LweDimension(656),
GlweDimension(2),
PolynomialSize(512),
DynamicDistribution::new_gaussian_from_std_dev(
StandardDev(0.000034119201269311964),
),
DynamicDistribution::new_gaussian_from_std_dev(
StandardDev(0.00000004053919869756513),
),
DecompositionBaseLog(8),
DecompositionLevelCount(2),
DecompositionBaseLog(3),
DecompositionLevelCount(4),
MessageModulus(4),
CarryModulus(1),
MaxNoiseLevel::new(2),
2.0f64.powi(-40),
CiphertextModulus::new_native(),
EncryptionKeyChoice::Big,
)
};
// WARNING: might be insecure and/or incorrect
// You can create your own set of parameters
let param = ClassicPBSParameters::new(
LweDimension(656),
GlweDimension(2),
PolynomialSize(512),
DynamicDistribution::new_gaussian_from_std_dev(
StandardDev(0.000034119201269311964),
),
DynamicDistribution::new_gaussian_from_std_dev(
StandardDev(0.00000004053919869756513),
),
DecompositionBaseLog(8),
DecompositionLevelCount(2),
DecompositionBaseLog(3),
DecompositionLevelCount(4),
MessageModulus(4),
CarryModulus(1),
MaxNoiseLevel::new(2),
2.0f64.powi(-40),
CiphertextModulus::new_native(),
EncryptionKeyChoice::Big,
);
}
```
14 changes: 10 additions & 4 deletions tfhe/docs/tutorials/ascii_fhe_string.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ The `FheAsciiString::encrypt` function performs data validation to ensure the in
In FHE operations, direct branching on encrypted values is not possible. However, you can evaluate a boolean condition to obtain the desired outcome. Here is an example to check and convert the 'char' to a lowercase without using a branch:

```rust
pub const UP_LOW_DISTANCE: u8 = 32;
#![allow(dead_code)]

const UP_LOW_DISTANCE: u8 = 32;

fn to_lower(c: u8) -> u8 {
if c > 64 && c < 91 {
Expand All @@ -49,7 +51,9 @@ fn to_lower(c: u8) -> u8 {
You can remove the branch this way:

```rust
pub const UP_LOW_DISTANCE: u8 = 32;
#![allow(dead_code)]

const UP_LOW_DISTANCE: u8 = 32;

fn to_lower(c: u8) -> u8 {
c + ((c > 64) as u8 & (c < 91) as u8) * UP_LOW_DISTANCE
Expand All @@ -59,10 +63,12 @@ fn to_lower(c: u8) -> u8 {
This method can adapt to operations on homomorphic integers:

```rust
#![allow(dead_code)]

use tfhe::prelude::*;
use tfhe::FheUint8;

pub const UP_LOW_DISTANCE: u8 = 32;
const UP_LOW_DISTANCE: u8 = 32;

fn to_lower(c: &FheUint8) -> FheUint8 {
c + FheUint8::cast_from(c.gt(64) & c.lt(91)) * UP_LOW_DISTANCE
Expand All @@ -75,7 +81,7 @@ Full example:
use tfhe::prelude::*;
use tfhe::{generate_keys, set_server_key, ClientKey, ConfigBuilder, FheUint8};

pub const UP_LOW_DISTANCE: u8 = 32;
const UP_LOW_DISTANCE: u8 = 32;

struct FheAsciiString {
bytes: Vec<FheUint8>,
Expand Down
Loading
Loading