Skip to content

Commit cfe7718

Browse files
committed
Add Python integration
1 parent 902c584 commit cfe7718

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

Diff for: Project.toml

+3
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,15 @@ Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
3232
GraphViz = "f526b714-d49f-11e8-06ff-31ed36ee7ee0"
3333
JSON3 = "0f8b85d8-7281-11e9-16c2-39a750bddbf1"
3434
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
35+
PythonCall = "6099a3de-0909-46bc-b1f4-468b9a2dfc0d"
3536

3637
[extensions]
3738
DistributionsExt = "Distributions"
3839
GraphVizExt = "GraphViz"
3940
GraphVizSimpleExt = "Colors"
4041
JSON3Ext = "JSON3"
4142
PlotsExt = ["DataFrames", "Plots"]
43+
PythonExt = "PythonCall"
4244

4345
[compat]
4446
Adapt = "4.0.4"
@@ -69,3 +71,4 @@ Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
6971
GraphViz = "f526b714-d49f-11e8-06ff-31ed36ee7ee0"
7072
JSON3 = "0f8b85d8-7281-11e9-16c2-39a750bddbf1"
7173
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
74+
PythonCall = "6099a3de-0909-46bc-b1f4-468b9a2dfc0d"

Diff for: ext/PythonExt.jl

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
module PythonExt
2+
3+
if isdefined(Base, :get_extension)
4+
using PythonCall
5+
else
6+
using ..PythonCall
7+
end
8+
9+
import Dagger
10+
import Dagger: Processor, OSProc, ThreadProc, Chunk
11+
import Distributed: myid
12+
13+
const CPUProc = Union{OSProc, ThreadProc}
14+
15+
struct PythonProcessor <: Processor
16+
owner::Int
17+
end
18+
19+
Dagger.root_worker_id(proc::PythonProcessor) = proc.owner
20+
Dagger.get_parent(proc::PythonProcessor) = OSProc(proc.owner)
21+
Dagger.default_enabled(::PythonProcessor) = true
22+
23+
Dagger.iscompatible_func(::ThreadProc, opts, ::Type{Py}) = false
24+
Dagger.iscompatible_func(::PythonProcessor, opts, ::Type{Py}) = true
25+
Dagger.iscompatible_arg(::PythonProcessor, opts, ::Type{Py}) = true
26+
Dagger.iscompatible_arg(::PythonProcessor, opts, ::Type{<:PyArray}) = true
27+
28+
Dagger.move(from_proc::CPUProc, to_proc::PythonProcessor, x::Chunk) =
29+
Dagger.move(from_proc, to_proc, Dagger.move(from_proc, Dagger.get_parent(to_proc), x))
30+
Dagger.move(::CPUProc, ::PythonProcessor, x) = Py(x)
31+
Dagger.move(::CPUProc, ::PythonProcessor, x::Py) = x
32+
Dagger.move(::CPUProc, ::PythonProcessor, x::PyArray) = x
33+
# FIXME: Conversion from Python to Julia
34+
35+
function Dagger.execute!(::PythonProcessor, f, args...; kwargs...)
36+
@assert f isa Py "Function must be a Python object"
37+
@show f args kwargs
38+
return f(args...; kwargs...)
39+
end
40+
41+
function __init__()
42+
Dagger.add_processor_callback!(:pythonproc) do
43+
return PythonProcessor(myid())
44+
end
45+
end
46+
47+
end # module PythonExt

0 commit comments

Comments
 (0)