Skip to content

Commit

Permalink
Merge pull request #5 from farm-ng/devel
Browse files Browse the repository at this point in the history
feat: zip & nudge actor, proc-macro improvements
  • Loading branch information
strasdat authored Jan 29, 2024
2 parents 48bb0bd + aa5db4e commit 478c3b8
Show file tree
Hide file tree
Showing 39 changed files with 1,880 additions and 713 deletions.
15 changes: 9 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,28 @@ name = "hollywood"
description = "hollywood actor framework"
edition = "2021"
include = [
"**/*.rs",
"Cargo.toml",
"**/*.rs",
"Cargo.toml",
]
license = "Apache-2.0"
keywords = ["actor", "compute", "graph", "pipeline"]
license = "Apache-2.0"
readme = "README.md"
repository = "https://github.com/farm-ng/hollywood/"
version = "0.3.0"
version = "0.4.0"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
async-trait = "0.1.51"
drawille = "0.3.0"
grid = "0.13.0"
hollywood_macros = { version = "0.3.0", path = "hollywood_macros" }
hollywood_macros = {version = "0.4.0", path = "hollywood_macros"}
# hollywood intends to use only very basic features of nalgebra, hence
# future versions of nalgebra before the major < 1.0 release are likely to work
nalgebra = ">= 0.32, <1.0"
petgraph = "0.6.3"
rand = "0.8.4"
rand_distr = "0.4.3"
# executor feature needed
tokio = { version = "1.28.0", features = ["full"] }
tokio = {version = "1.28.0", features = ["full"]}
tokio-stream = "0.1.14"
4 changes: 3 additions & 1 deletion examples/moving_average.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ use hollywood::actors::{Periodic, Printer};
use hollywood::compute::Context;
use hollywood::core::{FromPropState, NullState};

use hollywood::example_actors::moving_average::{MovingAverage, MovingAverageProp, MovingAverageState};
use hollywood::example_actors::moving_average::{
MovingAverage, MovingAverageProp, MovingAverageState,
};

///
pub async fn run_moving_average_example() {
Expand Down
34 changes: 34 additions & 0 deletions examples/nudge.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
use hollywood::actors::printer::PrinterProp;
use hollywood::actors::{Nudge, Printer};
use hollywood::compute::Context;
use hollywood::core::*;

pub async fn run_tick_print_example() {
let pipeline = Context::configure(&mut |context| {
let mut nudge = Nudge::<String>::new(context, "nudge".to_owned());
let mut nudge_printer = Printer::<String>::from_prop_and_state(
context,
PrinterProp {
topic: "nudge: ".to_string(),
},
NullState::default(),
);
nudge
.outbound
.nudge
.connect(context, &mut nudge_printer.inbound.printable);
});

pipeline.print_flow_graph();
pipeline.run().await;
}

fn main() {
tokio::runtime::Builder::new_multi_thread()
.enable_all()
.build()
.unwrap()
.block_on(async {
run_tick_print_example().await;
})
}
57 changes: 40 additions & 17 deletions examples/one_dim_robot.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
use hollywood::actors::printer::PrinterProp;
use hollywood::actors::zip::ZipPair;
use hollywood::actors::Periodic;
use hollywood::actors::Printer;
use hollywood::actors::Zip3;
use hollywood::compute::Context;
use hollywood::core::*;
use hollywood::example_actors::one_dim_robot::draw::DrawState;

use hollywood::example_actors::one_dim_robot::filter::FilterState;
use hollywood::example_actors::one_dim_robot::{
DrawActor, Filter, NamedFilterState, Robot, Sim, SimState, Stamped,
};

async fn run_robot_example() {
let pipeline = Context::configure(&mut |context| {
let mut timer = Periodic::new_with_period(context, 0.25);
let mut timer = Periodic::new_with_period(context, 0.1);
let mut sim = Sim::from_prop_and_state(
context,
NullProp {},
SimState {
shutdown_time: 10.0,
shutdown_time: 15.0,
time: 0.0,
seq: 0,
true_robot: Robot {
position: -2.0,
velocity: 0.4,
Expand All @@ -40,8 +43,9 @@ async fn run_robot_example() {
NullState::default(),
);

let mut draw_actor =
DrawActor::from_prop_and_state(context, NullProp {}, DrawState::default());
let mut zip = Zip3::new_default_init_state(context, NullProp {});

let mut draw = DrawActor::new_default_init_state(context, NullProp {});

timer
.outbound
Expand All @@ -54,28 +58,47 @@ async fn run_robot_example() {
sim.outbound
.noisy_range
.connect(context, &mut filter.inbound.noisy_range);
sim.outbound
.true_robot
.connect(context, &mut draw_actor.inbound.true_pos);
sim.outbound
.true_range
.connect(context, &mut draw_actor.inbound.true_range);
sim.outbound.true_robot.connect_with_adapter(
context,
|x| ZipPair {
key: x.seq,
value: x,
},
&mut zip.inbound.item0,
);
sim.outbound.true_range.connect_with_adapter(
context,
|x| ZipPair {
key: x.seq,
value: x,
},
&mut zip.inbound.item1,
);
sim.outbound
.true_robot
.connect(context, &mut truth_printer.inbound.printable);


sim.request.ping_pong.connect(context, &mut filter.inbound.ping_pong_request);
sim.request
.ping_pong
.connect(context, &mut filter.inbound.ping_pong_request);
context.register_cancel_requester(&mut sim.outbound.cancel_request);

filter
.outbound
.updated_state
.connect(context, &mut filter_state_printer.inbound.printable);
filter
.outbound
.updated_state
.connect(context, &mut draw_actor.inbound.filter_est);
filter.outbound.updated_state.connect_with_adapter(
context,
|x| ZipPair {
key: x.state.seq,
value: x,
},
&mut zip.inbound.item2,
);

zip.outbound
.zipped
.connect(context, &mut draw.inbound.zipped);
});

pipeline.print_flow_graph();
Expand Down
10 changes: 5 additions & 5 deletions examples/print_ticks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ pub async fn run_tick_print_example() {
},
NullState::default(),
);
timer
.outbound
.time_stamp
.connect(context, &mut time_printer.inbound.printable);

timer.outbound.time_stamp.connect_with_adapter(
context,
|t| 10.0 * t,
&mut time_printer.inbound.printable,
);
});

pipeline.print_flow_graph();
Expand Down
55 changes: 55 additions & 0 deletions examples/zip.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
use hollywood::actors::printer::PrinterProp;
use hollywood::actors::zip::{Tuple2, ZipPair};
use hollywood::actors::{periodic, Printer, Zip2};
use hollywood::compute::Context;
use hollywood::core::*;

pub async fn run_tick_print_example() {
let pipeline = Context::configure(&mut |context| {
let mut periodic = periodic::Periodic::new_with_period(context, 1.0);

let mut zip =
Zip2::<u64, String, String>::new_default_init_state(context, NullProp::default());
let mut printer = Printer::<Tuple2<u64, String, String>>::from_prop_and_state(
context,
PrinterProp {
topic: "zipped".to_string(),
},
NullState::default(),
);

periodic.outbound.time_stamp.connect_with_adapter(
context,
|t| ZipPair {
key: t as u64,
value: "hello".to_string(),
},
&mut zip.inbound.item0,
);
periodic.outbound.time_stamp.connect_with_adapter(
context,
|t| ZipPair {
key: 2 * t as u64,
value: "world".to_string(),
},
&mut zip.inbound.item1,
);

zip.outbound
.zipped
.connect(context, &mut printer.inbound.printable);
});

pipeline.print_flow_graph();
pipeline.run().await;
}

fn main() {
tokio::runtime::Builder::new_multi_thread()
.enable_all()
.build()
.unwrap()
.block_on(async {
run_tick_print_example().await;
})
}
12 changes: 6 additions & 6 deletions hollywood_macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@ name = "hollywood_macros"
description = "Macros for the Hollywood actor framework"
edition = "2021"
include = [
"**/*.rs",
"Cargo.toml",
"**/*.rs",
"Cargo.toml",
]
license = "Apache-2.0"
keywords = ["actor", "compute", "graph", "pipeline"]
license = "Apache-2.0"
readme = "../README.md"
repository = "https://github.com/farm-ng/hollywood/tree/main/hollywood_macros"
version = "0.3.0"
version = "0.4.0"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[lib]
proc-macro = true

[dependencies]
convert_case = "0.6.0"
proc-macro2 = "1.0"
quote = "1.0.9"
syn = { version = "2.0.18", features = ["full"] }

syn = {version = "2.0.18", features = ["full"]}
1 change: 1 addition & 0 deletions hollywood_macros/src/actors.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod zip;
Loading

0 comments on commit 478c3b8

Please sign in to comment.