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

need a tick-based version of defer_signal #966

Closed
jhellerstein opened this issue Nov 20, 2023 · 6 comments
Closed

need a tick-based version of defer_signal #966

jhellerstein opened this issue Nov 20, 2023 · 6 comments
Assignees
Labels
enhancement New feature or request hydroflow syntax Hydroflow's custom surface syntax P2 Medium priority
Milestone

Comments

@jhellerstein
Copy link
Contributor

jhellerstein commented Nov 20, 2023

E.g. I only want to send the most recent result of a fold when I receive a message, not all values of the fold.

        // make data arrive across multiple ticks
        source_iter([()]) -> items;
        source_iter([(), ()]) -> defer_tick() -> items;
        source_iter([(), (), ()]) -> defer_tick() -> defer_tick() -> items;
        
        // drive the ticks quickly
        source_interval(Duration::from_millis(100)) -> null();
        // occasionally trip the signal
        source_interval(Duration::from_secs(1)) -> [signal]gate;

        items = union() -> fold(|| 0, |accum: &mut u32, _item| *accum += 1) -> [input]gate;
        gate = defer_signal() -> for_each(|x| println!("{:?}", x));

With the current defer_signal it buffers up all inputs across ticks, so I will print out all the counts 1, 2, 3. If I had defer_signal::<'tick> I'd only output the most recent count when a signal arrives.

Not sure defer_signal::<'tick> is a good name, but I can't think of a better name that encompasses both.

@MingweiSamuel MingweiSamuel added hydroflow syntax Hydroflow's custom surface syntax enhancement New feature or request labels Jan 8, 2024
@jhellerstein jhellerstein self-assigned this Jan 8, 2024
@jhellerstein jhellerstein added this to the 0.6 Release milestone Jan 8, 2024
@jhellerstein jhellerstein modified the milestones: 0.6 Release, 0.7 Release Jan 29, 2024
@MingweiSamuel MingweiSamuel added the P2 Medium priority label Feb 26, 2024
@MingweiSamuel
Copy link
Member

This has some interesting semantics. Really only correct on a cumulative edge

@jhellerstein
Copy link
Contributor Author

It's unclear what semantics we want.

On reflection, we actually have two independent settings here:

  1. Do we empty the buffer on new input?
  2. Do we empty the buffer on new signal?

The current implementation is {input: no, signal: no}.

At least three more possibilities:

  1. {input: yes, signal: yes}: only produce output if the [input] and [signal] ports both have data in the current tick, producing only the [input] that arrived in this tick. This is equivalent to cross_join::<'tick, 'tick>.
  2. {input: yes, signal: no}: in a tick when data arrives on the [input] port, replace the contents of the buffer with the new data from [input] in this tick. On [signal], stream out a copy of whatever data is in the buffer.
  3. {input: no, signal: yes}: in a tick when data arrives on the [input] port, append the contents of the buffer with the new data from [input] in this tick. On [signal], stream out whatever data is in the buffer and empty the buffer.

Note that the last 2 are not equivalent to any cross_join, due to the data-driven (not tick-driven) replacement of input data.

I move that we close this issue as WontFix, and open a design issue for defer in the context of the new state and tick logic to come in a future release.

@jhellerstein
Copy link
Contributor Author

Ps: all of these semantics can be implemented with combos of persist_mut and cross_join, though it's annoying/inefficient to delete everything from a persist_mut.

@MingweiSamuel
Copy link
Member

defer_signal clears on {input: no, signal: yes} (drains the buffer on signal). Same as 3.

  1. {input: yes, signal: yes} is only equivalent to cross_join::<'tick, 'tick>() if the signal only arrives one time in the tick

@MingweiSamuel
Copy link
Member

Concur to close this (for now)

@jhellerstein
Copy link
Contributor Author

Closing as WontFix, replace with #1219

@jhellerstein jhellerstein closed this as not planned Won't fix, can't repro, duplicate, stale May 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request hydroflow syntax Hydroflow's custom surface syntax P2 Medium priority
Projects
None yet
Development

No branches or pull requests

2 participants