• Stars
    star
    158
  • Rank 237,192 (Top 5 %)
  • Language
    Julia
  • License
    Other
  • Created about 7 years ago
  • Updated about 2 months ago

Reviews

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

Repository Details

C# style generators a.k.a. semi-coroutines for Julia.

ResumableFunctions

C# has a convenient way to create iterators using the yield return statement. The package ResumableFunctions provides the same functionality for the Julia language by introducing the @resumable and the @yield macros. These macros can be used to replace the Task switching functions produce and consume which were deprecated in Julia v0.6. Channels are the preferred way for inter-task communication in julia v0.6+, but their performance is subpar for iterator applications. See the benchmarks section below.

Build Status & Coverage

Build Status codecov.io

Installation

ResumableFunctions is a registered package and can be installed by running:

using Pkg
Pkg.add("ResumableFunctions")

Documentation

using ResumableFunctions

@resumable function fibonacci(n::Int) :: Int
  a = 0
  b = 1
  for i in 1:n
    @yield a
    a, b = b, a+b
  end
end

for fib in fibonacci(10)
  println(fib)
end

Benchmarks

The following block is the result of running julia --project=. benchmark/benchmarks.jl on a Macbook Pro with following processor: Intel Core i9 2,4 GHz 8-Core. Julia version 1.5.3 was used.

Fibonacci with Int values:

Direct: 
  27.184 ns (0 allocations: 0 bytes)
ResumableFunctions: 
  27.503 ns (0 allocations: 0 bytes)
Channels csize=0: 
  2.438 ms (101 allocations: 3.08 KiB)
Channels csize=1: 
  2.546 ms (23 allocations: 1.88 KiB)
Channels csize=20: 
  138.681 μs (26 allocations: 2.36 KiB)
Channels csize=100: 
  35.071 μs (28 allocations: 3.95 KiB)
Task scheduling
  17.726 μs (86 allocations: 3.31 KiB)
Closure: 
  1.948 μs (82 allocations: 1.28 KiB)
Closure optimised: 
  25.910 ns (0 allocations: 0 bytes)
Closure statemachine: 
  28.048 ns (0 allocations: 0 bytes)
Iteration protocol: 
  41.143 ns (0 allocations: 0 bytes)

Fibonacci with BigInt values:

Direct: 
  5.747 μs (188 allocations: 4.39 KiB)
ResumableFunctions: 
  5.984 μs (191 allocations: 4.50 KiB)
Channels csize=0: 
  2.508 ms (306 allocations: 7.75 KiB)
Channels csize=1: 
  2.629 ms (306 allocations: 7.77 KiB)
Channels csize=20: 
  150.274 μs (309 allocations: 8.25 KiB)
Channels csize=100: 
  44.592 μs (311 allocations: 9.84 KiB)
Task scheduling
  24.802 μs (198 allocations: 6.61 KiB)
Closure: 
  7.064 μs (192 allocations: 4.47 KiB)
Closure optimised: 
  5.809 μs (190 allocations: 4.44 KiB)
Closure statemachine: 
  5.826 μs (190 allocations: 4.44 KiB)
Iteration protocol: 
  5.822 μs (190 allocations: 4.44 KiB)

Licence & References

License status DOI

Authors

Contributing

  • To discuss problems or feature requests, file an issue. For bugs, please include as much information as possible, including operating system, julia version, and version of MacroTools.
  • To contribute, make a pull request. Contributions should include tests for any new features/bug fixes.

Release notes

  • 2023: v0.6.2

    • Julia v1.10 compatibility fix
    • resumable functions can now dispatch on types
  • 2021: v0.6.1

    • continu in loop works
  • 2021: v0.6.0

    • introduction of @nosave to keep a variable out of the saved structure.
    • optimized for loop.
  • 2020: v0.5.2 is Julia v1.6 compatible.

  • 2019: v0.5.1

    • inference problem solved: force iterator next value to be of type Union of Tuple and Nothing.
  • 2019: v0.5.0 is Julia v1.2 compatible.

  • 2018: v0.4.2 prepare for Julia v1.1

    • better inference caused a problem;).
    • iterator with a specified rtype is fixed.
  • 2018: v0.4.0 is Julia v1.0 compatible.

  • 2018: v0.3.1 uses the new iteration protocol.

    • the new iteration protocol is used for a @resumable function based iterator.
    • the for loop transformation implements also the new iteration protocol.
  • 2018: v0.3 is Julia v0.7 compatible.

    • introduction of let block to allow variables not te be persisted between @resumable function calls (EXPERIMENTAL).
    • the eltype of a @resumable function based iterator is its return type if specified, otherwise Any.
  • 2018: v0.2 the iterator now behaves as a Python generator: only values that are explicitely yielded are generated; the return value is ignored and a warning is generated.

  • 2017: v0.1 initial release that is Julia v0.6 compatible:

    • Introduction of the @resumable and the @yield macros.
    • A @resumable function generates a type that implements the iterator interface.
    • Parametric @resumable functions are supported.

Caveats

  • In a try block only top level @yield statements are allowed.
  • In a finally block a @yield statement is not allowed.
  • An anonymous function can not contain a @yield statement.

More Repositories

1

Agents.jl

Agent-based modeling framework in Julia
Julia
757
star
2

DrWatson.jl

The perfect sidekick to your scientific inquiries
Julia
749
star
3

DynamicalSystems.jl

Award winning software library for nonlinear dynamics and nonlinear timeseries analysis
Julia
743
star
4

GoodScientificCodeWorkshop

A workshop on writing good scientific code.
Julia
183
star
5

ChaosTools.jl

Tools for the exploration of chaos and nonlinear dynamics
Julia
183
star
6

ConcurrentSim.jl

A discrete event process oriented simulation framework written in Julia. Formerly named SimJulia!
Julia
176
star
7

NonlinearDynamicsTextbook

Nonlinear Dynamics: A concise introduction interlaced with code
Julia
167
star
8

InteractiveDynamics.jl

Fast, general-purpose interactive applications for complex systems
Julia
167
star
9

NetworkDynamics.jl

Julia package for simulating Dynamics on Networks
Julia
128
star
10

CausalityTools.jl

Algorithms for detecting associations, dynamical influences and causal inference from data.
Julia
124
star
11

TimeseriesPrediction.jl

Prediction of timeseries using methods of nonlinear dynamics and timeseries analysis
Julia
101
star
12

DynamicalBilliards.jl

An easy-to-use, modular, extendable and absurdly fast Julia package for dynamical billiards in two dimensions.
Julia
98
star
13

JuliaDynamics

Website for JuliaDynamics and various resources, like notebooks, videos, etc.
Jupyter Notebook
61
star
14

DiscreteEvents.jl

Discrete event generation and simulation in Julia
Julia
56
star
15

DynamicalSystemsBase.jl

Definition of dynamical systems and integrators for DynamicalSystems.jl
Julia
51
star
16

ARFIMA.jl

Simulate stochastic timeseries that follow ARFIMA, ARMA, ARIMA, AR, etc. processes
Julia
47
star
17

TimeseriesSurrogates.jl

A Julia package for generating timeseries surrogates
Julia
43
star
18

RecurrenceAnalysis.jl

Recurrence Quantification Analysis in Julia
Julia
43
star
19

ComplexityMeasures.jl

Estimators for probabilities, entropies, and other complexity measures derived from observations in the context of nonlinear dynamics and complex systems
Julia
39
star
20

SignalDecomposition.jl

Decompose a signal/timeseries into structure and noise or seasonal and residual components
Julia
33
star
21

DynamicSumTypes.jl

Easy-to-use sum types in Julia
Julia
27
star
22

CriticalTransitions.jl

A Julia package for critical transitions in dynamical systems with time-dependent forcing
Julia
26
star
23

NonlinearDynamicsComplexSystemsCourse

Material for a full course on applied nonlinear dynamics, nonlinear timeseries analysis, and complex systems, in Julia
Jupyter Notebook
24
star
24

DelayEmbeddings.jl

Delay coordinates embeddings and optimizing them
Julia
23
star
25

StreamSampling.jl

Sampling methods for data streams
Julia
20
star
26

ChaosThroughBilliards

Code repository for an educational video on deterministic chaos
Julia
19
star
27

Attractors.jl

Find attractors of dynamical systems, their basins, and continue them across parameters. Also tipping points for analytic systems.
Julia
19
star
28

RigorousInvariantMeasures.jl

Package for the Rigorous Computation of Invariant Measures
Julia
11
star
29

TransferEntropy.jl

Transfer entropy (conditional mutual information) estimators for the Julia language
Julia
10
star
30

HardSphereDynamics.jl

Dynamics of elastic hard balls in arbitrary number of dimensions in Julia
Julia
9
star
31

PredefinedDynamicalSystems.jl

Collection of predefined dynamical systems for DynamicalSystems.jl
Julia
9
star
32

AgentsExampleZoo.jl

Examples written with Agents.jl
Julia
8
star
33

FractalDimensions.jl

Estimating the fractal dimension of timeseries or multidimensional datasets
Julia
7
star
34

ABM_Framework_Comparisons

Benchmarks and comparisons of leading ABM frameworks with Agents.jl
NetLogo
6
star
35

TransitionsInTimeseries.jl

Transition Indicators / Early Warning Signals / Regime Shifts / Change Point Detection
Julia
6
star
36

SpatioTemporalSystems.jl

Simulations of spatio temporal dynamical systems
Julia
5
star
37

AgentsPlots.jl

Plotting functionality for Agents.jl - Agent-Based Modelling in Julia
Julia
5
star
38

LagrangianDescriptors.jl

Painting the phase portrait of random and deterministic systems
Julia
5
star
39

ExercisesRepo

wip
Julia
4
star
40

PerronFrobenius.jl

Estimating the transfer operator (Perron Frobenius operator) and invariant measures from time series.
Julia
4
star
41

CaosDB.jl

CaosDB interface for Julia
Julia
4
star
42

doctheme

Documentation theme for the packages of JuliaDynamics
SCSS
3
star
43

StateSpaceReconstruction.jl

State space reconstruction (SSR) for the study of dynamical system from time series.
Julia
3
star
44

CausalityToolsBase.jl

Base functionality used throughout the CausalityTools ecosystem
Julia
2
star
45

CrossMappings.jl

A Julia package for computing cross mapping causality measures between time series.
Julia
2
star
46

StateSpaceSets.jl

The `StateSpaceSet` interface for packages of JuliaDynamics
Julia
2
star
47

chaospp

Metropolis-Hastings for sampling rare states of chaotic systems
C++
1
star
48

Simplices.jl

Compute exact simplex intersections in N dimensions.
Julia
1
star
49

TreeEmbedding.jl

This project implements the MCDTS algorithm outlined in the paper Nonlinear Dynamics volume 108, pages 1525–1545 (2022).
Julia
1
star