Skip to content

Commit

Permalink
party one doing preproc
Browse files Browse the repository at this point in the history
  • Loading branch information
Anne Dorte Spangsberg committed Jun 3, 2024
1 parent 7592b33 commit c485eab
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 17 deletions.
4 changes: 3 additions & 1 deletion pycare/caring.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,6 @@ class Engine:
:param my_addr: the address to listen on
:param horsepower: the addresses to connect to
"""
def setup(my_addr: str, *others: str) -> Engine: ...
def setup(path_to_pre: str, my_addr: str, *others: str) -> Engine: ...

def preproc(num_of_shares: int, paths_to_pre: list[str])
2 changes: 1 addition & 1 deletion pycare/examples/test1.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# However for starters, and testing purposses ONLY we will allow party 1 to do it
# and save it where both party one and party two can find it.

# TODO: pycare.do_preproc
caring.preproc(12, "./context1.bin,./context2.bin")
engine = caring.setup("./context1.bin", "127.0.0.1:1234", "127.0.0.1:1235")

res = engine.sum(2.5)
Expand Down
16 changes: 7 additions & 9 deletions pycare/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ struct Engine(Option<AdderEngine>);
/// Setup a MPC addition engine connected to the given sockets.
#[pyfunction]
#[pyo3(signature = (path_to_pre, my_addr, *others))]
// TODO: the setup needs a path to the preprocessed values.
// TODO-continued: It should be resived here, in a format that works for python,
// TODO-continued and then changed into a format that works for rust, - setup_engine expects a path.

fn setup(path_to_pre: &str, my_addr: &str, others: &Bound<'_, PyTuple>) -> PyResult<Engine> {
let others : Vec<_> = others.iter().map(|x| x.extract::<String>().unwrap().clone())
Expand All @@ -23,12 +20,12 @@ fn setup(path_to_pre: &str, my_addr: &str, others: &Bound<'_, PyTuple>) -> PyRes
}
}

// TODO: needs to know for how many parties
// TODO-continued: - maybe also an address for where to save the files?
// TODO-continued: - or to whom it should be distributed?
// TODO-continued: for now we will hardcode the adresses - and do the distribution via the shared filesystem - this is ONLY for testing.
fn do_preproc(){
// TODO fill out
/// Calculate and save the preprocessing
#[pyfunction]
#[pyo3(signature = (number_of_shares, paths_to_pre))]
fn preproc( number_of_shares: usize, paths_to_pre: &str){
let paths_to_pre = paths_to_pre.split(",").collect();
do_preproc(paths_to_pre, vec![number_of_shares, number_of_shares]);
}


Expand Down Expand Up @@ -57,6 +54,7 @@ impl Engine {
#[pymodule]
fn caring(_py: Python, m: &Bound<'_, PyModule>) -> PyResult<()> {
m.add_function(wrap_pyfunction!(setup, m)?)?;
m.add_function(wrap_pyfunction!(preproc, m)?)?;
m.add_class::<Engine>()?;
Ok(())
}
Expand Down
12 changes: 6 additions & 6 deletions wecare/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,11 @@ pub fn setup_engine(my_addr: &str, others: &[impl AsRef<str>], file_name: &Path)
Ok(engine)
}

pub fn do_preproc(filenames: Vec<&str>){
pub fn do_preproc(filenames: Vec<&str>, number_of_shares: Vec<usize>){
assert_eq!(filenames.len(), number_of_shares.len());
let file_names = vec![Path::new(filenames[0]), Path::new(filenames[1])];
let known_to_each = vec![2, 2];
let number_of_triplets = 2;
let known_to_each = vec![number_of_shares[0], number_of_shares[1]];
let number_of_triplets = 0;
let num = to_offset(0.0);
preprocessing::write_preproc_to_file(
file_names,
Expand Down Expand Up @@ -184,7 +185,7 @@ mod test {
#[test]
fn sunshine() {
use std::thread;
do_preproc(vec!["src/context1.bin", "src/context2.bin"]);
do_preproc(vec!["src/context1.bin", "src/context2.bin"], vec![1,1]);
let t1 = thread::spawn(|| {
println!("[1] Setting up...");
let mut engine = setup_engine("127.0.0.1:1234", &["127.0.0.1:1235"], Path::new("src/context1.bin") ).unwrap();
Expand Down Expand Up @@ -213,8 +214,7 @@ mod test {
#[test]
fn sunshine_for_two() {
use std::thread;
//do_preproc();
do_preproc(vec!["src/context3.bin", "src/context4.bin"]);
do_preproc(vec!["src/context3.bin", "src/context4.bin"], vec![2,2]);
let t1 = thread::spawn(|| {
println!("[1] Setting up...");
let mut engine = setup_engine("127.0.0.1:2234", &["127.0.0.1:2235"], Path::new("src/context3.bin") ).unwrap();
Expand Down

0 comments on commit c485eab

Please sign in to comment.