Skip to content

Completely Refactor #179

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

Open
wants to merge 70 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
55dcca5
Rework test cases a bit
willtebbutt Feb 27, 2025
8f9c3ce
Add formatter config
willtebbutt Feb 27, 2025
9f0ad12
Update gitignore to remove redundant items
willtebbutt Feb 27, 2025
ffd86e2
Bump minor version because small breaking change
willtebbutt Feb 27, 2025
2d06346
Tell users that various old types have been actually removed
willtebbutt Feb 27, 2025
0c545bb
Formatting of perf
willtebbutt Feb 27, 2025
dc5ab50
Remove old code
willtebbutt Feb 27, 2025
5228dc2
Rework includes in package and runtests
willtebbutt Feb 27, 2025
fc01732
More formatting
willtebbutt Feb 27, 2025
5ddfb60
Add in copyable_task files
willtebbutt Feb 27, 2025
159fe13
Clean up runtests
willtebbutt Feb 27, 2025
61594e4
Update project deps etc
willtebbutt Feb 27, 2025
ae6d000
Drop 1.7 from CI
willtebbutt Feb 27, 2025
dc4a0be
Initial transfer of code
willtebbutt Feb 27, 2025
7e9ba1e
Fix bug for function with no produce statements
willtebbutt Feb 27, 2025
8e6f1b6
Test for construction of new mutable struct
willtebbutt Feb 27, 2025
71e6444
Fix more test cases
willtebbutt Feb 27, 2025
4d18d47
Add another test case
willtebbutt Feb 27, 2025
f1b247d
More test cases
willtebbutt Feb 27, 2025
85ec6a2
More work
willtebbutt Feb 27, 2025
04544ca
Formatting
willtebbutt Feb 27, 2025
ecbf41c
Remove unhelpful docstring
willtebbutt Feb 27, 2025
22f6f67
Relax Test compat a bit
willtebbutt Feb 27, 2025
04e4dcd
Lower minor version to make integration tests run
willtebbutt Feb 27, 2025
b25d2f4
Handle code_coverage_effect
willtebbutt Feb 27, 2025
94aed2f
Some tweaks + docs
willtebbutt Feb 28, 2025
1579bff
Fix copying
willtebbutt Feb 28, 2025
5114d64
Formatting
willtebbutt Feb 28, 2025
b803f58
Enable more tests
willtebbutt Feb 28, 2025
6aeaac3
Implement dynamic scope
willtebbutt Mar 7, 2025
b546f21
Test dynamic scope correctness
willtebbutt Mar 7, 2025
8f4e4b5
README and NEWS overhaul
willtebbutt Mar 7, 2025
4d0b423
Export get_dynamic_scope and set_dynamic_scope
willtebbutt Mar 7, 2025
bde142f
Placeholder docstring for produce
willtebbutt Mar 7, 2025
4e58e11
Initial docs
willtebbutt Mar 7, 2025
21816ee
Ignore build folder of docs
willtebbutt Mar 7, 2025
3205273
Update cache action
willtebbutt Mar 7, 2025
06c168f
Formatting
willtebbutt Mar 7, 2025
258a4cd
Ignore all top-level manifest files
willtebbutt Mar 7, 2025
a3c2162
Add dependency on ScopedValues
willtebbutt Mar 7, 2025
4bb0dfa
Fix on LTS
willtebbutt Mar 7, 2025
a63660e
Do not check for stale deps on 1.11
willtebbutt Mar 7, 2025
4e1e5df
Some docs
willtebbutt Mar 7, 2025
54c745c
Docs action
willtebbutt Mar 7, 2025
0102653
Tidy up docs
willtebbutt Mar 7, 2025
e751db3
Tidy up docs slightly
willtebbutt Mar 7, 2025
6a221c2
Refactor + basic nested produce handling
willtebbutt Mar 11, 2025
f94ea17
Fomatting
willtebbutt Mar 11, 2025
57b808c
Dynamic nested calls and uses of return values of calls which might p…
willtebbutt Mar 13, 2025
bf1893c
Fix docs build
willtebbutt Mar 13, 2025
2c82159
Update CI
willtebbutt Mar 13, 2025
b393c54
Handle callable structs
willtebbutt Mar 13, 2025
906cb66
Fix docs and add doctest
willtebbutt Mar 20, 2025
4f80127
Test kwargs
willtebbutt Apr 8, 2025
065fb19
More tests
willtebbutt Apr 8, 2025
1ba2dfe
Fix inference bug
willtebbutt Apr 8, 2025
999f5bc
Improve documentation
willtebbutt Apr 8, 2025
ec9edb7
Performance enhancements
willtebbutt Apr 15, 2025
5135c4a
Caching and tweaks
willtebbutt Apr 15, 2025
b42227e
Fix docs build
willtebbutt Apr 15, 2025
aa86594
Docs and tidy up
willtebbutt Apr 15, 2025
5b07ec1
Include specifics from Mooncake
willtebbutt Apr 15, 2025
bc480c2
Tidy up further
willtebbutt Apr 15, 2025
35e9b7a
Tidy up further
willtebbutt Apr 15, 2025
42096b3
Merge branch 'main' into wct/refactor
willtebbutt Apr 15, 2025
c54dc5c
Remove undefined export
willtebbutt Apr 15, 2025
b2e65b8
Bump patch version
willtebbutt Apr 15, 2025
01a0b34
Test produce global performance
willtebbutt Apr 15, 2025
ebe8f91
Remove more references to dynamic scope
willtebbutt Apr 15, 2025
2907f03
Document type assertion
willtebbutt Apr 15, 2025
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
1 change: 1 addition & 0 deletions .JuliaFormatter.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
style = "blue"
32 changes: 32 additions & 0 deletions .github/workflows/Documentation.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Documentation

on:
push:
branches:
- main
tags: '*'
pull_request:

jobs:
build:
permissions:
contents: write
pull-requests: read
statuses: write
actions: write
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: julia-actions/setup-julia@v2
with:
version: '1'
arch: x64
include-all-prereleases: false
- name: Install dependencies
run: julia --project=docs/ -e 'using Pkg; Pkg.develop(PackageSpec(path=pwd())); Pkg.update(); Pkg.instantiate()'
- name: Build and deploy
env:
GKSwstype: nul # turn off GR's interactive plotting for notebooks
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # If authenticating with GitHub Actions token
DOCUMENTER_KEY: ${{ secrets.DOCUMENTER_KEY }} # For authentication with SSH deploy key
run: julia --project=docs/ docs/make.jl
7 changes: 3 additions & 4 deletions .github/workflows/Testing.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ jobs:
strategy:
matrix:
version:
- '1.7'
- '1.10'
- '1'
- 'nightly'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- 'nightly'
- 'pre'

We've switched to pre over nightly in other TuringLang repos.

Expand All @@ -26,12 +25,12 @@ jobs:
- os: macOS-latest
arch: x86
steps:
- uses: actions/checkout@v2
- uses: julia-actions/setup-julia@v1
- uses: actions/checkout@v4
- uses: julia-actions/setup-julia@v2
with:
version: ${{ matrix.version }}
arch: ${{ matrix.arch }}
- uses: actions/cache@v1
- uses: actions/cache@v4
env:
cache-name: cache-artifacts
with:
Expand Down
60 changes: 2 additions & 58 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,60 +1,4 @@
# Prerequisites
*.d

# Object files
*.o
*.ko
*.obj
*.elf

# Linker output
*.ilk
*.map
*.exp

# Precompiled Headers
*.gch
*.pch

# Libraries
*.lib
*.a
*.la
*.lo

# Shared objects (inc. Windows DLLs)
*.dll
*.so
*.so.*
*.dylib

# Executables
*.exe
*.out
*.app
*.i*86
*.x86_64
*.hex

# Debug files
*.dSYM/
*.su
*.idb
*.pdb

# Kernel Module Compile Results
*.mod*
*.cmd
.tmp_versions/
modules.order
Module.symvers
Mkfile.old
dkms.conf

# Projects files
Manifest.toml
deps/build.log
deps/deps.jl
deps/usr/
deps/tmp-build.jl
Manifest*
*.cov
docs/build
8 changes: 8 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
- From v0.6.0, Libtask is implemented by recording all the computing
to a tape and copying that tape. Before that version, it is based on
a tricky hack on the Julia internals. You can check the commit
history of this repo to see the details.

- From version 0.9.0, the old `TArray` and `TRef` types are completely removed, where
previously they were only deprecated. Additionally, the internals have been completely
overhauled, and the public interface more precisely defined. See the docs for more info.
21 changes: 11 additions & 10 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,23 @@ uuid = "6f1fad26-d15e-5dc8-ae53-837a1d7b8c9f"
license = "MIT"
desc = "Tape based task copying in Turing"
repo = "https://github.com/TuringLang/Libtask.jl.git"
version = "0.8.8"
version = "0.9.0"

[deps]
FunctionWrappers = "069b7b12-0de2-55c6-9aab-29f3d0a68a2e"
LRUCache = "8ac3fa9e-de4c-5943-b1dc-09c6b5f20637"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
MistyClosures = "dbe65cb8-6be2-42dd-bbc5-4196aaced4f4"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is Test meant to be a strong dep of the package and not just of tests?


[compat]
FunctionWrappers = "1.1"
LRUCache = "1.3"
julia = "1.7"
Aqua = "0.8.11"
JuliaFormatter = "1.0.62"
MistyClosures = "2.0.0"
Test = "1"
julia = "1.10.8"

[extras]
BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf"
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
JuliaFormatter = "98e50ef6-434e-11e9-1051-2b60c6c9e899"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Test", "BenchmarkTools"]
test = ["Aqua", "JuliaFormatter", "Test"]
96 changes: 3 additions & 93 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,98 +2,8 @@

[![Libtask Testing](https://github.com/TuringLang/Libtask.jl/workflows/Libtask%20Testing/badge.svg)](https://github.com/TuringLang/Libtask.jl/actions?branch=main)

Tape based task copying in Turing

## Getting Started
Resumable and copyable functions in Julia, with optional function-specific globals.
See the docs for example usage.

Stack allocated objects are always deep copied:

```julia
using Libtask

function f()
t = 0
for _ in 1:10
produce(t)
t = 1 + t
end
end

ttask = TapedTask(f)

@show consume(ttask) # 0
@show consume(ttask) # 1

a = copy(ttask)
@show consume(a) # 2
@show consume(a) # 3

@show consume(ttask) # 2
@show consume(ttask) # 3
```

Heap-allocated Array and Ref objects are deep copied by default:

```julia
using Libtask

function f()
t = [0 1 2]
for _ in 1:10
produce(t[1])
t[1] = 1 + t[1]
end
end

ttask = TapedTask(f)

@show consume(ttask) # 0
@show consume(ttask) # 1

a = copy(ttask)
@show consume(a) # 2
@show consume(a) # 3

@show consume(ttask) # 2
@show consume(ttask) # 3
```

Other heap-allocated objects (e.g., `Dict`) are shallow copied, by default:

```julia
using Libtask

function f()
t = Dict(1=>10, 2=>20)
while true
produce(t[1])
t[1] = 1 + t[1]
end
end

ttask = TapedTask(f)

@show consume(ttask) # 10
@show consume(ttask) # 11

a = copy(ttask)
@show consume(a) # 12
@show consume(a) # 13

@show consume(ttask) # 14
@show consume(ttask) # 15
```

Notes:

- The [Turing](https://github.com/TuringLang/Turing.jl) probabilistic
programming language uses this task copying feature in an efficient
implementation of the [particle
filtering](https://en.wikipedia.org/wiki/Particle_filter) sampling
algorithm for arbitrary order [Markov
processes](https://en.wikipedia.org/wiki/Markov_model#Hidden_Markov_model).

- From v0.6.0, Libtask is implemented by recording all the computing
to a tape and copying that tape. Before that version, it is based on
a tricky hack on the Julia internals. You can check the commit
history of this repo to see the details.
Used in the [Turing](https://github.com/TuringLang/Turing.jl) probabilistic programming language to implement various particle-based inference methods, for example those in [AdvancedPS.jl](https://github.com/TuringLang/AdvancedPS.jl/).
3 changes: 3 additions & 0 deletions docs/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[deps]
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
Libtask = "6f1fad26-d15e-5dc8-ae53-837a1d7b8c9f"
9 changes: 9 additions & 0 deletions docs/make.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using Documenter, Libtask

DocMeta.setdocmeta!(Libtask, :DocTestSetup, :(using Libtask); recursive=true)

makedocs(;
sitename="Libtask", doctest=true, pages=["index.md", "internals.md"], modules=[Libtask]
)

deploydocs(; repo="github.com/TuringLang/Libtask.jl.git", push_preview=true)
24 changes: 24 additions & 0 deletions docs/src/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Libtask

Libtask is best explained by the docstring for [`TapedTask`](@ref):
```@docs; canonical=true
Libtask.TapedTask
```

The functions discussed the above docstring (in addition to [`TapedTask`](@ref) itself) form the
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The functions discussed the above docstring (in addition to [`TapedTask`](@ref) itself) form the
The functions discussed in the above docstring (in addition to [`TapedTask`](@ref) itself) form the

public interface of Libtask.jl.
They divide neatly into two kinds of functions: those which are used to manipulate
[`TapedTask`](@ref)s, and those which are intended to be used _inside_ a
[`TapedTask`](@ref).
First, manipulation of [`TapedTask`](@ref)s:
```@docs; canonical=true
Libtask.consume
Base.copy(::Libtask.TapedTask)
Libtask.set_taped_globals!
```

Functions for use inside a [`TapedTask`](@ref)s are:
```@docs; canonical=true
Libtask.produce
Libtask.get_taped_globals
```
17 changes: 17 additions & 0 deletions docs/src/internals.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Internals

```@docs; canonical=true
Libtask.produce_value
Libtask.is_produce_stmt
Libtask.might_produce
Libtask.stmt_might_produce
Libtask.LazyCallable
Libtask.inc_args
Libtask.get_type
Libtask._typeof
Libtask.replace_captures
Libtask.BasicBlockCode
Libtask.opaque_closure
Libtask.misty_closure
Libtask.optimise_ir!
```
2 changes: 1 addition & 1 deletion perf/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Turing = "fce5fe82-541a-59a6-adf8-730c64b5f9a0"

[compat]
julia = "1.3"
julia = "1.10.8"

[targets]
test = ["Test", "BenchmarkTools"]
Loading
Loading