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

chore(shortint): add some flaky/failing doctests as actual tests #685

Merged
merged 1 commit into from
Nov 15, 2023
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: 2 additions & 0 deletions scripts/shortint-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ or test(/^shortint::.*_param${multi_bit}_message_2_carry_3${multi_bit:+"_group_[
or test(/^shortint::.*_param${multi_bit}_message_3_carry_1${multi_bit:+"_group_[0-9]"}(_compact_pk)?_ks_pbs/) \
or test(/^shortint::.*_param${multi_bit}_message_3_carry_2${multi_bit:+"_group_[0-9]"}(_compact_pk)?_ks_pbs/) \
or test(/^shortint::.*_param${multi_bit}_message_3_carry_3${multi_bit:+"_group_[0-9]"}(_compact_pk)?_ks_pbs/) \
or test(/^shortint::.*_ci_run_filter/) \
)\
and not test(~smart_add_and_mul)""" # This test is too slow
else
Expand Down Expand Up @@ -159,6 +160,7 @@ or test(/^shortint::.*_param${multi_bit}_message_3_carry_1${multi_bit:+"_group_[
or test(/^shortint::.*_param${multi_bit}_message_3_carry_2${multi_bit:+"_group_[0-9]"}(_compact_pk)?_ks_pbs/) \
or test(/^shortint::.*_param${multi_bit}_message_3_carry_3${multi_bit:+"_group_[0-9]"}(_compact_pk)?_ks_pbs/) \
or test(/^shortint::.*_param${multi_bit}_message_4_carry_4${multi_bit:+"_group_[0-9]"}(_compact_pk)?_ks_pbs/) \
or test(/^shortint::.*_ci_run_filter/) \
)\
and not test(~smart_add_and_mul)""" # This test is too slow
else
Expand Down
39 changes: 39 additions & 0 deletions tfhe/src/shortint/wopbs/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,3 +171,42 @@ fn generate_lut_modulus_not_power_of_two(params: WopbsParameters) {
assert_eq!(res as usize, (m * m) % message_modulus.0);
}
}

// This test comes from the module file and is flaky/failing as a doctest, checking if it works as a
// standalone test
#[test]
fn test_generate_lut_native_crt_doctest_ci_run_filter() {
use crate::shortint::gen_keys;
use crate::shortint::parameters::parameters_wopbs::WOPBS_PARAM_MESSAGE_3_NORM2_2_KS_PBS;
use crate::shortint::wopbs::WopbsKey;

// Generate the client key and the server key:
let (cks, sks) = gen_keys(WOPBS_PARAM_MESSAGE_3_NORM2_2_KS_PBS);
let wopbs_key = WopbsKey::new_wopbs_key_only_for_wopbs(&cks, &sks);
let message_modulus = 5;
let m = 2;
let mut ct = cks.encrypt_native_crt(m, message_modulus);
let lut = wopbs_key.generate_lut_native_crt(&ct, |x| x * x % message_modulus as u64);
let ct_res = wopbs_key.programmable_bootstrapping_native_crt(&mut ct, &lut);
let res = cks.decrypt_message_native_crt(&ct_res, message_modulus);
assert_eq!(res, (m * m) % message_modulus as u64);
}

// This test comes from the module file and is flaky/failing as a doctest, checking if it works as a
// standalone test
#[test]
fn test_programmable_bootstrapping_native_crt_doctest_ci_run_filter() {
use crate::shortint::gen_keys;
use crate::shortint::parameters::parameters_wopbs::WOPBS_PARAM_MESSAGE_3_NORM2_2_KS_PBS;
use crate::shortint::wopbs::*;

let (cks, sks) = gen_keys(WOPBS_PARAM_MESSAGE_3_NORM2_2_KS_PBS);
let wopbs_key = WopbsKey::new_wopbs_key_only_for_wopbs(&cks, &sks);
let msg = 2;
let modulus = 5;
let mut ct = cks.encrypt_native_crt(msg, modulus);
let lut = wopbs_key.generate_lut_native_crt(&ct, |x| x);
let ct_res = wopbs_key.programmable_bootstrapping_native_crt(&mut ct, &lut);
let res = cks.decrypt_message_native_crt(&ct_res, modulus);
assert_eq!(res, msg);
}
Loading