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] Automatic wrapping of julia packages #118

Merged
merged 13 commits into from
Oct 20, 2019
Merged

Conversation

Non-Contradiction
Copy link
Collaborator

Implement the automatic wrapping functionality for julia functions and packages. Hope it is helpful for package developers using JuliaCall.

Description

Related Issue

Related to SciML/diffeqr#16

Example

The new code implements JuliaCall:::julia_function and JuliaCall:::julia_pkg_import, both unexported currently, which wrap functions and packages automatically. The usage is as follows:

JuliaCall::julia_library("DifferentialEquations")
JuliaCall::autowrap("DiffEqBase.AbstractODESolution", fields = c("t","u"))
f <- function(u,p,t) -u
u0 = 0.5
tspan = JuliaCall::julia_eval("(0., 1.)")
de <- JuliaCall:::julia_pkg_import("DifferentialEquations", c("ODEProblem", "solve"))
prob = de$ODEProblem(f, u0, tspan)
sol = de$solve(prob)

In progress.

@Non-Contradiction
Copy link
Collaborator Author

Push more commits into the branch with a more refined API.
Now the example should look like this:

## The above should be safe to go into the function level code.

de <- JuliaCall:::julia_pkg_import("DifferentialEquations",
                                   c("ODEProblem", "solve"))
JuliaCall:::julia_pkg_hook(de,
                           function(){
                               JuliaCall::autowrap("DiffEqBase.AbstractODESolution",
                                                   fields = c("t","u"))
                           })
time_range <- function(a, b) JuliaCall::julia_call("tuple",
                                                   a, b)

## the user code follows

f <- function(u,p,t) -u
u0 = 0.5
tspan = time_range(0, 1)
prob = de$ODEProblem(f, u0, tspan)
sol = de$solve(prob)

@ChrisRackauckas
Copy link
Member

Out of curiousity, does it the call on sol work for the continuous output, i.e. sol(0.4) there?

@Non-Contradiction
Copy link
Collaborator Author

Non-Contradiction commented Sep 23, 2019 via email

@ChrisRackauckas
Copy link
Member

Maybe it can be something like sol$.(0.4)? I'm fine with any reasonable syntax on this: that's fixable just by documenting it.

@Non-Contradiction
Copy link
Collaborator Author

With the new commits, sol$.(0.4) will give the result as sol(0.4) in julia.
In the commits, $juliaobject$.()` is the syntax to mimic callable objects in Julia, and one cavity is that it doesn't support keyword arguments currently.

@Non-Contradiction
Copy link
Collaborator Author

I will first merge this PR and get a new release with all the new functionalities and bug fixes. More work will be done in future PRs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants