Skip to content

Commit acfc3df

Browse files
willtebbuttyebaimhauru
authored
Completely Refactor (#179)
* Rework test cases a bit * Add formatter config * Update gitignore to remove redundant items * Bump minor version because small breaking change * Tell users that various old types have been actually removed * Formatting of perf * Remove old code * Rework includes in package and runtests * More formatting * Add in copyable_task files * Clean up runtests * Update project deps etc * Drop 1.7 from CI * Initial transfer of code * Fix bug for function with no produce statements * Test for construction of new mutable struct * Fix more test cases * Add another test case * More test cases * More work * Formatting * Remove unhelpful docstring * Relax Test compat a bit * Lower minor version to make integration tests run * Handle code_coverage_effect * Some tweaks + docs * Fix copying * Formatting * Enable more tests * Implement dynamic scope * Test dynamic scope correctness * README and NEWS overhaul * Export get_dynamic_scope and set_dynamic_scope * Placeholder docstring for produce * Initial docs * Ignore build folder of docs * Update cache action * Formatting * Ignore all top-level manifest files * Add dependency on ScopedValues * Fix on LTS * Do not check for stale deps on 1.11 * Some docs * Docs action * Tidy up docs * Tidy up docs slightly * Refactor + basic nested produce handling * Fomatting * Dynamic nested calls and uses of return values of calls which might produce * Fix docs build * Update CI * Handle callable structs * Fix docs and add doctest * Test kwargs * More tests * Fix inference bug * Improve documentation * Performance enhancements * Caching and tweaks * Fix docs build * Docs and tidy up * Include specifics from Mooncake * Tidy up further * Tidy up further * Remove undefined export * Bump patch version * Test produce global performance * Remove more references to dynamic scope * Document type assertion * Fix benchmarks (#180) * Update benchmark.jl * Update benchmark.jl * Apply suggestions from code review Co-authored-by: Markus Hauru <[email protected]> * Fix loopinfo expression * Remove redundant extended help section * Note why __v exists * Sort out consume * Explain produce function * Document callable_ret_type * Update benchmark.jl * Docstring for build_callable * Tweaks to build_callable and docs * Document aliasing * Document bbcode usage * More docs * Formatting and remove unnecessary import * Remove redundant comment * Fix test wording * Remove redundant test cases * Fix typo * Formatting * Docstring * Fix docs bulid * Docstring for fresh_copy * More docs * Expand on refs and misty closure usage * Explain gotoifnot a bit more carefully * Link to GotoIfNot in Julia docs * Update Documentation.yml (#181) * Apply suggestions from code review Co-authored-by: Markus Hauru <[email protected]> * Update src/copyable_task.jl Co-authored-by: Markus Hauru <[email protected]> * Update src/copyable_task.jl Co-authored-by: Markus Hauru <[email protected]> --------- Co-authored-by: Hong Ge <[email protected]> Co-authored-by: Markus Hauru <[email protected]>
1 parent 560f993 commit acfc3df

28 files changed

+2488
-1336
lines changed

.JuliaFormatter.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
style = "blue"

.github/workflows/Documentation.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: Documentation
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
tags: '*'
8+
pull_request:
9+
10+
permissions:
11+
contents: write
12+
pull-requests: write
13+
14+
jobs:
15+
docs:
16+
runs-on: ubuntu-latest
17+
18+
steps:
19+
- name: Build and deploy Documenter.jl docs
20+
uses: TuringLang/actions/DocsDocumenter@main

.github/workflows/Testing.yaml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,9 @@ jobs:
1111
strategy:
1212
matrix:
1313
version:
14-
- '1.7'
1514
- '1.10'
1615
- '1'
17-
- 'nightly'
16+
- 'pre'
1817
os:
1918
- ubuntu-latest
2019
- windows-latest
@@ -26,12 +25,12 @@ jobs:
2625
- os: macOS-latest
2726
arch: x86
2827
steps:
29-
- uses: actions/checkout@v2
30-
- uses: julia-actions/setup-julia@v1
28+
- uses: actions/checkout@v4
29+
- uses: julia-actions/setup-julia@v2
3130
with:
3231
version: ${{ matrix.version }}
3332
arch: ${{ matrix.arch }}
34-
- uses: actions/cache@v1
33+
- uses: actions/cache@v4
3534
env:
3635
cache-name: cache-artifacts
3736
with:

.gitignore

Lines changed: 2 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,4 @@
1-
# Prerequisites
2-
*.d
3-
4-
# Object files
5-
*.o
6-
*.ko
7-
*.obj
8-
*.elf
9-
10-
# Linker output
11-
*.ilk
12-
*.map
13-
*.exp
14-
15-
# Precompiled Headers
16-
*.gch
17-
*.pch
18-
19-
# Libraries
20-
*.lib
21-
*.a
22-
*.la
23-
*.lo
24-
25-
# Shared objects (inc. Windows DLLs)
26-
*.dll
27-
*.so
28-
*.so.*
29-
*.dylib
30-
31-
# Executables
32-
*.exe
33-
*.out
34-
*.app
35-
*.i*86
36-
*.x86_64
37-
*.hex
38-
39-
# Debug files
40-
*.dSYM/
41-
*.su
42-
*.idb
43-
*.pdb
44-
45-
# Kernel Module Compile Results
46-
*.mod*
47-
*.cmd
48-
.tmp_versions/
49-
modules.order
50-
Module.symvers
51-
Mkfile.old
52-
dkms.conf
53-
541
# Projects files
55-
Manifest.toml
56-
deps/build.log
57-
deps/deps.jl
58-
deps/usr/
59-
deps/tmp-build.jl
2+
Manifest*
603
*.cov
4+
docs/build

NEWS.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
- From v0.6.0, Libtask is implemented by recording all the computing
2+
to a tape and copying that tape. Before that version, it is based on
3+
a tricky hack on the Julia internals. You can check the commit
4+
history of this repo to see the details.
5+
6+
- From version 0.9.0, the old `TArray` and `TRef` types are completely removed, where
7+
previously they were only deprecated. Additionally, the internals have been completely
8+
overhauled, and the public interface more precisely defined. See the docs for more info.

Project.toml

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,23 @@ uuid = "6f1fad26-d15e-5dc8-ae53-837a1d7b8c9f"
33
license = "MIT"
44
desc = "Tape based task copying in Turing"
55
repo = "https://github.com/TuringLang/Libtask.jl.git"
6-
version = "0.8.8"
6+
version = "0.9.0"
77

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

1412
[compat]
15-
FunctionWrappers = "1.1"
16-
LRUCache = "1.3"
17-
julia = "1.7"
13+
Aqua = "0.8.11"
14+
JuliaFormatter = "1.0.62"
15+
MistyClosures = "2.0.0"
16+
Test = "1"
17+
julia = "1.10.8"
1818

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

2324
[targets]
24-
test = ["Test", "BenchmarkTools"]
25+
test = ["Aqua", "JuliaFormatter", "Test"]

README.md

Lines changed: 3 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -2,98 +2,8 @@
22

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

5-
Tape based task copying in Turing
65

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

9-
Stack allocated objects are always deep copied:
10-
11-
```julia
12-
using Libtask
13-
14-
function f()
15-
t = 0
16-
for _ in 1:10
17-
produce(t)
18-
t = 1 + t
19-
end
20-
end
21-
22-
ttask = TapedTask(f)
23-
24-
@show consume(ttask) # 0
25-
@show consume(ttask) # 1
26-
27-
a = copy(ttask)
28-
@show consume(a) # 2
29-
@show consume(a) # 3
30-
31-
@show consume(ttask) # 2
32-
@show consume(ttask) # 3
33-
```
34-
35-
Heap-allocated Array and Ref objects are deep copied by default:
36-
37-
```julia
38-
using Libtask
39-
40-
function f()
41-
t = [0 1 2]
42-
for _ in 1:10
43-
produce(t[1])
44-
t[1] = 1 + t[1]
45-
end
46-
end
47-
48-
ttask = TapedTask(f)
49-
50-
@show consume(ttask) # 0
51-
@show consume(ttask) # 1
52-
53-
a = copy(ttask)
54-
@show consume(a) # 2
55-
@show consume(a) # 3
56-
57-
@show consume(ttask) # 2
58-
@show consume(ttask) # 3
59-
```
60-
61-
Other heap-allocated objects (e.g., `Dict`) are shallow copied, by default:
62-
63-
```julia
64-
using Libtask
65-
66-
function f()
67-
t = Dict(1=>10, 2=>20)
68-
while true
69-
produce(t[1])
70-
t[1] = 1 + t[1]
71-
end
72-
end
73-
74-
ttask = TapedTask(f)
75-
76-
@show consume(ttask) # 10
77-
@show consume(ttask) # 11
78-
79-
a = copy(ttask)
80-
@show consume(a) # 12
81-
@show consume(a) # 13
82-
83-
@show consume(ttask) # 14
84-
@show consume(ttask) # 15
85-
```
86-
87-
Notes:
88-
89-
- The [Turing](https://github.com/TuringLang/Turing.jl) probabilistic
90-
programming language uses this task copying feature in an efficient
91-
implementation of the [particle
92-
filtering](https://en.wikipedia.org/wiki/Particle_filter) sampling
93-
algorithm for arbitrary order [Markov
94-
processes](https://en.wikipedia.org/wiki/Markov_model#Hidden_Markov_model).
95-
96-
- From v0.6.0, Libtask is implemented by recording all the computing
97-
to a tape and copying that tape. Before that version, it is based on
98-
a tricky hack on the Julia internals. You can check the commit
99-
history of this repo to see the details.
9+
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/).

docs/Project.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[deps]
2+
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
3+
Libtask = "6f1fad26-d15e-5dc8-ae53-837a1d7b8c9f"

docs/make.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
using Documenter, Libtask
2+
3+
DocMeta.setdocmeta!(Libtask, :DocTestSetup, :(using Libtask); recursive=true)
4+
5+
makedocs(;
6+
sitename="Libtask", doctest=true, pages=["index.md", "internals.md"], modules=[Libtask]
7+
)
8+
9+
deploydocs(; repo="github.com/TuringLang/Libtask.jl.git", push_preview=true)

docs/src/index.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Libtask
2+
3+
Libtask is best explained by the docstring for [`TapedTask`](@ref):
4+
```@docs; canonical=true
5+
Libtask.TapedTask
6+
```
7+
8+
The functions discussed in the above docstring (in addition to [`TapedTask`](@ref) itself) form the
9+
public interface of Libtask.jl.
10+
They divide neatly into two kinds of functions: those which are used to manipulate
11+
[`TapedTask`](@ref)s, and those which are intended to be used _inside_ a
12+
[`TapedTask`](@ref).
13+
First, manipulation of [`TapedTask`](@ref)s:
14+
```@docs; canonical=true
15+
Libtask.consume
16+
Base.copy(::Libtask.TapedTask)
17+
Libtask.set_taped_globals!
18+
```
19+
20+
Functions for use inside a [`TapedTask`](@ref)s are:
21+
```@docs; canonical=true
22+
Libtask.produce
23+
Libtask.get_taped_globals
24+
```

0 commit comments

Comments
 (0)