Skip to content

Commit 2aa334a

Browse files
committed
Add missing part of Python section
1 parent 88b0981 commit 2aa334a

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

lib/livebook/notebook/learn/intro_to_python.livemd

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,25 @@ result =
358358
end)
359359
```
360360

361+
Now, when using the **FLAME runner** smart cell, the runner is automatically initialized with Python environment matching the notebook's one. This means we can also evaluate Python code in the runner, without any other setup, it would look something like this:
362+
363+
<!-- livebook:{"force_markdown":true} -->
364+
365+
```elixir
366+
result =
367+
FLAME.call(:runner, fn ->
368+
~PY"""
369+
1 + 1
370+
"""
371+
end)
372+
```
373+
374+
> Note that the `~PY` sigil is a convenience for running Python code and it implicitly picks up any variable referenced in the code snipppet. You could also use the more explicit `Pythonx.eval/3` API.
375+
376+
The above call would return a remote Python object. A FLAME runner typically terminates if idle for a while, but since the Python object resides on that runner, the runner is kept around as long as we have a reference to the object!
377+
378+
This can be used to coordinate Python work across multiple machines, You can load a model onto a runner with a GPU and get a reference to the remote model object (keeping the model itself on the runner). You could subsequently use `FLAME.call/2` to run inference thorugh that model.
379+
361380
## Wrapping up
362381

363382
As you can see, there are many levels of interoperability between Elixir and Python. In your notebooks, you can mix and match code from both languages. In turn, you get access to the extensive ecosystem of Python packages for enhancing your data workflows, while still being able to orchestrate it with Elixir.

0 commit comments

Comments
 (0)