• Stars
    star
    161
  • Rank 233,470 (Top 5 %)
  • Language
    Julia
  • License
    MIT License
  • Created almost 5 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Functional reactive programming extensions library for Julia

Reactive extensions library for Julia

Documentation Build Status

Rocket.jl is a Julia package for reactive programming using Observables, to make it easier to work with asynchronous data.

In order to achieve best performance and convenient API Rocket.jl combines Observer pattern, Actor model and Functional programming.

Inspired by RxJS and ReactiveX communities.

Rocket.jl has been designed with a focus on performance and modularity.

The essential concepts in Rocket.jl are:

  • Observable: represents a collection of future messages (data or/and events).
  • Actor: is an object that knows how to react on incoming messages delivered by the Observable.
  • Subscription: represents a teardown logic which might be useful for cancelling the execution of an Observable.
  • Operators: are objects that enable a functional programming style to dealing with collections with operations like map, filter, reduce, etc.
  • Subject: the way of multicasting a message to multiple Observers.

Quick start

For a quick start and basic introduction take a look at the demo folder and Quick Start notebook.

using Rocket, Compose, IJulia ; set_default_graphic_size(35cm, 2cm)
function draw_ball(t)
    IJulia.clear_output(true)
    x = -exp(-0.01t) + 1                     # x coordinate
    y = -abs(exp(-0.04t)*(cos(0.1t))) + 0.83 # y coordinate
    display(compose(context(), circle(x, y, 0.01)))
end
source = interval(20) |> take(200) # Take only first 200 emissions

subscription = subscribe!(source, draw_ball)

Alt Text

unsubscribe!(subscription) # It is possible to unsubscribe before the stream ends    
IJulia.clear_output(false);

Documentation

Full documentation is available at BIASlab website.

It is also possible to build a documentation locally. Just execute

$ julia make.jl

in the docs/ directory to build a local version of the documentation.

First example

Normally you use an arrays for processing some data.

for value in array_of_values
    doSomethingWithMyData(value)
end

In Rocket.jl you will use an observable.

subscription = subscribe!(source_of_values, lambda(
    on_next     = (data)  -> doSomethingWithMyData(data),
    on_error    = (error) -> doSomethingWithAnError(error),
    on_complete = ()      -> println("Completed!")
))

At some point of time you may decide to stop listening for new messages.

unsubscribe!(subscription)

Actors

To process messages from an observable you have to define an Actor that know how to react on incoming messages.

struct MyActor <: Rocket.Actor{Int} end

Rocket.on_next!(actor::MyActor, data::Int) = doSomethingWithMyData(data)
Rocket.on_error!(actor::MyActor, error)    = doSomethingWithAnError(error)
Rocket.on_complete!(actor::MyActor)        = println("Completed!")

Actor can also have its own local state

struct StoreActor{D} <: Rocket.Actor{D}
    values :: Vector{D}

    StoreActor{D}() where D = new(Vector{D}())
end

Rocket.on_next!(actor::StoreActor{D}, data::D) where D = push!(actor.values, data)
Rocket.on_error!(actor::StoreActor, error)             = doSomethingWithAnError(error)
Rocket.on_complete!(actor::StoreActor)                 = println("Completed: $(actor.values)")

For debugging purposes you can use a general LambdaActor actor or just pass a function object as an actor in subscribe! function.

Operators

What makes Rocket.jl powerful is its ability to help you process, transform and modify the messages flow through your observables using Operators.

List of all available operators can be found in the documentation (link).

squared_int_values = source_of_int_values |> map(Int, (d) -> d ^ 2)
subscribe!(squared_int_values, lambda(
    on_next = (data) -> println(data)
))

Rocket.jl is fast

Rocket.jl has been designed with a focus on efficiency, scalability and maximum performance. Below is a benchmark comparison between Rocket.jl, Signals.jl, Reactive.jl and Observables.jl in Julia v1.8.5 (see versioninfo below).

We test map and filter operators latency in application to a finite stream of integers. Code is available in demo folder.

Rocket.jl outperforms Observables.jl, Reactive.jl and Signals.jl significantly in terms of execution times and memory consumption both in synchronous and asynchronous modes.

Rocket.jl vs Reactive.jl

Rocket.jl vs Signals.jl

Rocket.jl vs Observables.jl

versioninfo()
Julia Version 1.8.5
Commit 17cfb8e65ea (2023-01-08 06:45 UTC)
Platform Info:
  OS: macOS (arm64-apple-darwin21.5.0)
  CPU: 10 × Apple M2 Pro
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-13.0.1 (ORCJIT, apple-m1)
  Threads: 1 on 6 virtual cores
] status
  [510215fc] Observables v0.5.4
  [a223df75] Reactive v0.8.3
  [df971d30] Rocket v1.6.0 
  [6303bc30] Signals v1.2.0

More Repositories

1

RxInfer.jl

Julia package for automated Bayesian inference on a factor graph with reactive message passing
Jupyter Notebook
179
star
2

ForneyLab.jl

Julia package for automatically generating Bayesian inference algorithms through message passing on Forney-style factor graphs.
Julia
150
star
3

ReactiveMP.jl

High-performance reactive message-passing based Bayesian inference engine
Julia
79
star
4

hugo-academic-group

An academic group website theme for Hugo.
HTML
54
star
5

GraphPPL.jl

DSL for probabilistic models specification and probabilistic programming.
Julia
18
star
6

RxEnvironments.jl

Reactive environments for self-learning agents
Julia
15
star
7

biaslab-hugo

Repository with content of BIASlab website for Hugo static site generator.
HTML
12
star
8

LAIF

Experiments with deriving epistemics aware message passing algos
Julia
6
star
9

MultiAgentTrajectoryPlanning

Experiments of the "Multi-Agent Trajectory Planning with NUV Priors" paper
Julia
6
star
10

ai_workshop_2020

Code to run potential based agents and generate figures for the submission to the 2020 Workshop on Active Inference
Julia
6
star
11

ExponentialFamily.jl

Julia
5
star
12

AIDA

Julia
5
star
13

RxAgent-Zoo

Archive of active inference agents based on reactive message passing.
Jupyter Notebook
5
star
14

PrincipledPruningBNN

Jupyter Notebook
5
star
15

ReactiveMP_JuliaCon2021

ReactiveMP JuliaCon2021 presentation notebooks
Julia
3
star
16

LCSS2024-NARXEFE

Code, figures, animations for a NARX-EFE based agent.
Jupyter Notebook
3
star
17

nsi-silverbox

Online system identification in Silverbox by minimising free energy
Jupyter Notebook
2
star
18

SituatedSoundscaping

Derivations and experiments of the "A Bayesian Modeling Approach to Situated Design of Personalized Soundscaping Algorithms" paper, published in the MDPI journal of Applied Sciences in the special issue on AI, Machine Learning and Deep Learning in Signal Processing, 2021.
Julia
2
star
19

IWAI2020-onlinesysid

Code and experiments for IWAI 2020 submission on online system identification
HTML
1
star
20

rxinfer-website

Repository with content of RxInfer website for Hugo static site generator.
JavaScript
1
star
21

CDC-2022

Experiments and derivations for CDC2022 paper on message passing-based inference for NARMAX system identification.
Jupyter Notebook
1
star
22

ExtendedVMP

Experiments for numerical approximations to VMP
Jupyter Notebook
1
star
23

TVAR_FFG

Time-varying autoregressive models in Forney-Style Factor Graphs
Jupyter Notebook
1
star
24

NARX

ForneyLab.jl factor node for a nonlinear autoregressive model with exogenous input.
Julia
1
star
25

IWAI2024-ambiguity

Expected free energy minimization with approximations to nonlinear observation functions
Jupyter Notebook
1
star
26

ReactiveInferencePendulum

A small demonstration of reactive Bayesian inference for pendulum dynamics
Jupyter Notebook
1
star
27

ACC2022-vmpNARMAX

Experiments and derivations for ACC2022 paper on variational message passing for online NARMAX identification.
Jupyter Notebook
1
star
28

SiPS2022-EfficientModelEvidenceComputation

Experiments and derivations for SiPS2022 paper "Efficient model evidence computation in tree-structured factor graph"
Jupyter Notebook
1
star
29

LAR

AR extension of ForneyLab.jl
Jupyter Notebook
1
star
30

PGM2022-SourceSeparationNAR

Experiments and code of the paper "Online Single-Microphone Source Separation using Non-Linear Autoregressive Models"
Jupyter Notebook
1
star
31

CVMP

Implementation of https://github.com/Nimrais/CCMPPaper
Julia
1
star
32

ThesisParallelMP

Master thesis project of Mattia Vicari about parallel computing in message passing-based Bayesian inference programs
Jupyter Notebook
1
star
33

CCTA2024-BIDconvection

Experiments for CCTA 2024 submission on fast Bayesian gray-box identification of convection in heat transfer dynamics.
Jupyter Notebook
1
star
34

Chengfeng_intent_inference

Jupyter Notebook
1
star
35

preds-not-commands

Experiment with sending predictions, not commands, to an actuator that reacts to minimize the prediction error.
Jupyter Notebook
1
star
36

OnlineMessagePassingDirichletProcess

Julia
1
star