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

Multiply Located Values / Census Polymorphism #29

Merged
merged 44 commits into from
Dec 2, 2024
Merged
Changes from 1 commit
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
06785e6
draft MLV
shumbo Jul 16, 2024
7d44c7e
multicast with MulticastBuilder as an argument
shumbo Jul 21, 2024
49855c1
add example from he-lambda-small paper
shumbo Jul 22, 2024
066d130
WIP: add tests, doesnt' seem to work...
ShapeOfMatter Jul 30, 2024
89bd5ac
integration test WIP
ShapeOfMatter Aug 2, 2024
5d5d980
parallel
shumbo Aug 26, 2024
fc29189
can write fanout choreography
shumbo Aug 28, 2024
039096b
finish fanout
shumbo Aug 28, 2024
e949647
fix self communication bug
shumbo Aug 28, 2024
7fecb01
:recycle:
shumbo Sep 7, 2024
b69cbf6
cleanup
shumbo Sep 7, 2024
33a8e98
give type parameters meaningful names
shumbo Sep 10, 2024
92bbce7
remove singly located values
shumbo Sep 24, 2024
5493fbe
allow enclave to return arbitrary value and make it wrap the value in…
shumbo Oct 2, 2024
f620393
draft fanin
shumbo Oct 9, 2024
f2c4b19
almost finish cardgame
shumbo Oct 15, 2024
a5f3c7e
this type checks but crashes at runtime :sob:
shumbo Oct 15, 2024
df5c39b
fix flatten
shumbo Oct 16, 2024
4083a07
delete outdated document
shumbo Oct 17, 2024
af13e6a
Merge pull request #1 from lsd-ucsc/feat/mlv
ShapeOfMatter Oct 17, 2024
ca7292c
Linting
ShapeOfMatter Oct 17, 2024
c7ff7ea
it runs
ShapeOfMatter Oct 18, 2024
b00cff9
Nominally ready test case.
ShapeOfMatter Oct 19, 2024
cef6781
differential enclaving in booksellers deciders.
ShapeOfMatter Oct 20, 2024
389bd29
clean up old multicast api
shumbo Oct 25, 2024
8e707fb
add `Quire` public API
shumbo Oct 25, 2024
f10fd90
WIP
ShapeOfMatter Oct 25, 2024
f8af01d
Merge remote-tracking branch 'upstream/feat/mlv' into feat/mlv
ShapeOfMatter Oct 25, 2024
08b54a4
probably just missing reflexivity
ShapeOfMatter Oct 25, 2024
7c03eb1
make quire.get_map be more conventional and work. WIP in booksellers.
ShapeOfMatter Oct 30, 2024
eeb3a9c
get booksellers typechecking. Doesn't actually run yet though
ShapeOfMatter Oct 30, 2024
bf3b5ba
implement fanin and fanout on the runner, add test cases
shumbo Oct 31, 2024
35ed1bc
fix broken test
shumbo Oct 31, 2024
c30786b
census polymorphic kvs
ShapeOfMatter Nov 7, 2024
2c1e810
fix answer extrations
ShapeOfMatter Nov 7, 2024
66ff827
`cargo fmt`
shumbo Nov 14, 2024
5df2667
describe multiply located values
shumbo Nov 14, 2024
ffbfdb3
use `unwrap` to unwrap both MLV and Quire
shumbo Nov 24, 2024
2339c94
explain `multicast`
shumbo Nov 28, 2024
16559b4
rewrite efficient conditionals chapter
shumbo Nov 30, 2024
e1484c4
reorder items
shumbo Nov 30, 2024
5ac0739
remove `Superposition`
shumbo Dec 2, 2024
497d18e
comments
shumbo Dec 2, 2024
187e914
bump version
shumbo Dec 2, 2024
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
Prev Previous commit
Next Next commit
implement fanin and fanout on the runner, add test cases
shumbo committed Oct 31, 2024
commit bf3b5ba8b3e204bc54ac90b7426873cc6e4c831a
197 changes: 197 additions & 0 deletions chorus_lib/examples/fanin.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,197 @@
extern crate chorus_lib;

use std::marker::PhantomData;
use std::thread;

use chorus_lib::core::{
ChoreoOp, Choreography, ChoreographyLocation, FanInChoreography, Located, LocationSet, Member,
MultiplyLocated, Projector, Quire, Subset,
};
use chorus_lib::transport::local::{LocalTransport, LocalTransportChannelBuilder};

#[derive(ChoreographyLocation, Debug)]
struct Alice;

#[derive(ChoreographyLocation, Debug)]
struct Bob;

#[derive(ChoreographyLocation, Debug)]
struct Carol;

struct FanIn<L: LocationSet, QS: LocationSet, Alice: ChoreographyLocation, AliceMemberL>
where
Alice: Member<L, AliceMemberL>,
{
phantom: PhantomData<(L, QS, Alice, AliceMemberL)>,
}

impl<L: LocationSet, QS: LocationSet, Alice: ChoreographyLocation, AliceMemberL>
FanIn<L, QS, Alice, AliceMemberL>
where
Alice: Member<L, AliceMemberL>,
{
fn new(_: Alice) -> Self
where
Alice: Member<L, AliceMemberL>,
{
FanIn {
phantom: PhantomData,
}
}
}

impl<L: LocationSet, QS: LocationSet, Alice: ChoreographyLocation, AliceMemberL>
FanInChoreography<String> for FanIn<L, QS, Alice, AliceMemberL>
where
Alice: Member<L, AliceMemberL>,
{
type L = L;
type QS = QS;
type RS = LocationSet!(Alice);

fn run<Q: ChoreographyLocation, QSSubsetL, RSSubsetL, QMemberL, QMemberQS>(
&self,
op: &impl ChoreoOp<Self::L>,
) -> MultiplyLocated<String, Self::RS>
where
Self::QS: Subset<Self::L, QSSubsetL>,
Self::RS: Subset<Self::L, RSSubsetL>,
Q: Member<Self::L, QMemberL>,
Q: Member<Self::QS, QMemberQS>,
{
let msg_at_q = op.locally(Q::new(), |_| {
format!("{} says hi to {}", Q::name(), Alice::name())
});
let msg_at_alice = op.comm(Q::new(), Alice::new(), &msg_at_q);
return msg_at_alice;
}
}

struct MainChoreography;
impl Choreography<Located<Quire<String, LocationSet!(Bob, Carol)>, Alice>> for MainChoreography {
type L = LocationSet!(Alice, Bob, Carol);

fn run(
self,
op: &impl ChoreoOp<Self::L>,
) -> Located<Quire<String, LocationSet!(Bob, Carol)>, Alice> {
let v = op.fanin(<LocationSet!(Bob, Carol)>::new(), FanIn::new(Alice));
op.locally(Alice, |un| {
let m = un.unwrap(&v).get_map();
println!(
"Alice received: \"{}\" from Bob and \"{}\" from Carol",
m.get(Bob::name()).unwrap_or(&String::from("ERROR")),
m.get(Carol::name()).unwrap_or(&String::from("ERROR"))
)
});
return v;
}
}

fn main() {
let transport_channel = LocalTransportChannelBuilder::new()
.with(Alice)
.with(Bob)
.with(Carol)
.build();
let transport_alice = LocalTransport::new(Alice, transport_channel.clone());
let transport_bob = LocalTransport::new(Bob, transport_channel.clone());
let transport_carol = LocalTransport::new(Carol, transport_channel.clone());

let alice_projector = Projector::new(Alice, transport_alice);
let bob_projector = Projector::new(Bob, transport_bob);
let carol_projector = Projector::new(Carol, transport_carol);

let mut handles: Vec<thread::JoinHandle<()>> = Vec::new();
handles.push(
thread::Builder::new()
.name("Alice".to_string())
.spawn(move || {
alice_projector.epp_and_run(MainChoreography);
})
.unwrap(),
);
handles.push(
thread::Builder::new()
.name("Bob".to_string())
.spawn(move || {
bob_projector.epp_and_run(MainChoreography);
})
.unwrap(),
);
handles.push(
thread::Builder::new()
.name("Carol".to_string())
.spawn(move || {
carol_projector.epp_and_run(MainChoreography);
})
.unwrap(),
);
for handle in handles {
handle.join().unwrap();
}
}

#[cfg(test)]
mod tests {
use chorus_lib::core::Runner;

use super::*;

#[test]
fn test_projector() {
let transport_channel = LocalTransportChannelBuilder::new()
.with(Alice)
.with(Bob)
.with(Carol)
.build();
let transport_alice = LocalTransport::new(Alice, transport_channel.clone());
let transport_bob = LocalTransport::new(Bob, transport_channel.clone());
let transport_carol = LocalTransport::new(Carol, transport_channel.clone());

let alice_projector = Projector::new(Alice, transport_alice);
let bob_projector = Projector::new(Bob, transport_bob);
let carol_projector = Projector::new(Carol, transport_carol);

let mut handles: Vec<thread::JoinHandle<()>> = Vec::new();
handles.push(
thread::Builder::new()
.name("Alice".to_string())
.spawn(move || {
let quire_at_alice = alice_projector.epp_and_run(MainChoreography);
let m = alice_projector.unwrap(quire_at_alice).get_map();
assert_eq!(m.get(Bob::name()).unwrap(), "Bob says hi to Alice");
assert_eq!(m.get(Carol::name()).unwrap(), "Carol says hi to Alice");
})
.unwrap(),
);
handles.push(
thread::Builder::new()
.name("Bob".to_string())
.spawn(move || {
bob_projector.epp_and_run(MainChoreography);
})
.unwrap(),
);
handles.push(
thread::Builder::new()
.name("Carol".to_string())
.spawn(move || {
carol_projector.epp_and_run(MainChoreography);
})
.unwrap(),
);
for handle in handles {
handle.join().unwrap();
}
}

#[test]
fn test_runner() {
let runner = Runner::new();
let quire_at_alice = runner.run(MainChoreography);
let m = runner.unwrap(quire_at_alice).get_map();
assert_eq!(m.get(Bob::name()).unwrap(), "Bob says hi to Alice");
assert_eq!(m.get(Carol::name()).unwrap(), "Carol says hi to Alice");
}
}
88 changes: 77 additions & 11 deletions chorus_lib/examples/fanout.rs
Original file line number Diff line number Diff line change
@@ -67,17 +67,22 @@ where
}
}

struct ParallelChoreography;
impl Choreography for ParallelChoreography {
struct MainChoreography;
impl Choreography<(Located<String, Bob>, Located<String, Carol>)> for MainChoreography {
type L = LocationSet!(Alice, Bob, Carol);
fn run(self, op: &impl ChoreoOp<Self::L>) {
let v = op.fanout(<LocationSet!(Bob, Carol)>::new(), FanOut::new(Bob));
op.locally(Bob, |un| {
println!("{}", un.unwrap3(&v));
fn run(self, op: &impl ChoreoOp<Self::L>) -> (Located<String, Bob>, Located<String, Carol>) {
let v = op.fanout(<LocationSet!(Bob, Carol)>::new(), FanOut::new(Alice));
let value_at_bob = op.locally(Bob, |un| {
let v = un.unwrap3(&v);
println!("{}", v);
v.clone()
});
op.locally(Carol, |un| {
println!("{}", un.unwrap3(&v));
let value_at_carol = op.locally(Carol, |un| {
let v = un.unwrap3(&v);
println!("{}", v);
v.clone()
});
return (value_at_bob, value_at_carol);
}
}

@@ -100,27 +105,88 @@ fn main() {
thread::Builder::new()
.name("Alice".to_string())
.spawn(move || {
alice_projector.epp_and_run(ParallelChoreography);
alice_projector.epp_and_run(MainChoreography);
})
.unwrap(),
);
handles.push(
thread::Builder::new()
.name("Bob".to_string())
.spawn(move || {
bob_projector.epp_and_run(ParallelChoreography);
bob_projector.epp_and_run(MainChoreography);
})
.unwrap(),
);
handles.push(
thread::Builder::new()
.name("Carol".to_string())
.spawn(move || {
carol_projector.epp_and_run(ParallelChoreography);
carol_projector.epp_and_run(MainChoreography);
})
.unwrap(),
);
for handle in handles {
handle.join().unwrap();
}
}
#[cfg(test)]
mod tests {
use chorus_lib::core::Runner;

use super::*;

#[test]
fn test_projector() {
let transport_channel = LocalTransportChannelBuilder::new()
.with(Alice)
.with(Bob)
.with(Carol)
.build();
let transport_alice = LocalTransport::new(Alice, transport_channel.clone());
let transport_bob = LocalTransport::new(Bob, transport_channel.clone());
let transport_carol = LocalTransport::new(Carol, transport_channel.clone());

let alice_projector = Projector::new(Alice, transport_alice);
let bob_projector = Projector::new(Bob, transport_bob);
let carol_projector = Projector::new(Carol, transport_carol);

let mut handles: Vec<thread::JoinHandle<()>> = Vec::new();
handles.push(
thread::Builder::new()
.name("Alice".to_string())
.spawn(move || {
alice_projector.epp_and_run(MainChoreography);
})
.unwrap(),
);
handles.push(
thread::Builder::new()
.name("Bob".to_string())
.spawn(move || {
let v = bob_projector.epp_and_run(MainChoreography);
assert_eq!(bob_projector.unwrap(v.0), "Alice says hi to Bob");
})
.unwrap(),
);
handles.push(
thread::Builder::new()
.name("Carol".to_string())
.spawn(move || {
let v = carol_projector.epp_and_run(MainChoreography);
assert_eq!(carol_projector.unwrap(v.1), "Alice says hi to Carol");
})
.unwrap(),
);
for handle in handles {
handle.join().unwrap();
}
}

#[test]
fn test_runner() {
let runner = Runner::new();
let (v1, v2) = runner.run(MainChoreography);
assert_eq!(runner.unwrap(v1), "Alice says hi to Bob");
assert_eq!(runner.unwrap(v2), "Alice says hi to Carol");
}
}
Loading