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

[WIP] A way to add kwarg support to #164 #165

Draft
wants to merge 7 commits into
base: subtape
Choose a base branch
from

Conversation

torfjelde
Copy link
Member

@torfjelde torfjelde commented Jun 22, 2023

I had a branch locally with some initial work on kwarg-support, and now, thanks to #164, it works!

julia> f(x; y=2) = (produce(2x + y); return 2x)
f (generic function with 1 method)

julia> g(x) = f(f(x))
g (generic function with 1 method)

julia> Libtask.is_primitive(::typeof(f), x) = false

julia> task = Libtask.TapedTask(g, 1)
TapedTask{typeof(g), Tuple{Int64}}(Task (runnable) @0x00007f9f16a160e0, TapedFunction:
* .func => g
* .ir   =>
------------------
CodeInfo(
1%1 = Main.f(x)::Int64%2 = Main.f(%1)::Int64
└──      return %2
)
------------------
, (1,), Channel{Any}(0), Channel{Int64}(0), Any[])

julia> consume(task)
4

julia> consume(task)
6

julia> consume(task)

A few very important drawbacks:

  • Currently only work on Julia 1.9, but it should be possible to make it work on previous versions by making use of Core.kwftype.
  • Will have name-clashes with cache and deepcopy_types that are used in Libtask.jl. This can be resolved by a) renaming those to something less common, e.g. __libtask__cache__ or something, and b) throwing an error if we hit it.

EDIT: I wanted to make this PR to your branch @willtebbutt but couldn't because that branch is on your fork.

@torfjelde torfjelde marked this pull request as draft June 22, 2023 10:48
@torfjelde
Copy link
Member Author

TBH I think I prefer this to making changes in DynamicPPL, as originally discussed. This way we keep all the complexity in Libtask, rather than shifting some of the complexity of Libtask into the design of DynamicPPL.jl

@yebai yebai changed the base branch from master to subtape August 2, 2023 17:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants