xp1632 / VPE_IP

0 stars 0 forks source link

Reflection_multi-language kernel switching_path_conflicts with VP project #59

Open xp1632 opened 5 months ago

xp1632 commented 5 months ago

Q: If I have A jupyter notebook that has multiple cells, the first cell is code written in python, the second cell is code written in java. I first run this notebook with IPython kernel for execution of the first cell, and I would like to use its result, changing the kernel to IJava Kernel and run the second cell of Java. Is it possible? would the data be lost while I changing the jupyter kernel?


A:

Unfortunately, Jupyter notebooks do not support running different cells with different kernels within the same notebook. When you change the kernel in a Jupyter notebook, it restarts the computational environment, which means that all variables and imported modules from the previous kernel are lost.

If you need to use both Python and Java in the same project, there are a few workarounds:

xp1632 commented 5 months ago

However, while BeakerX also supports "polyglot magics" which allow you to run code from different languages within the same notebook. You can use the %%python magic to run Python code in a cell of a Java notebook, or the %%java magic to run Java code in a cell of a Python notebook.

Here's an example:

image

Please note that while this allows you to run code from different languages in the same notebook, it does not allow you to share variables or data directly between the languages. You would still need to use some form of inter-process communication (like writing to a file or a database, or sending messages over a network) to pass data between the languages.

xp1632 commented 5 months ago

To summarize, in order to exchange data between different languages,

xp1632 commented 5 months ago

My impression of the related paper is that, they either has another external environment that contains these cells inside the same scope to achieve data exchange, Or they store all the outputs into another database and call it when needed

xp1632 commented 5 months ago

So now we try the wrapper way of JPype and PyImageJ

xp1632 commented 5 months ago

Final thoughts of changing path:

Reason 1 : data losing when changing kernel

Reason 2 : not partial execution in VP