emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* emacs-jupyter does not send result form babel block
@ 2021-09-04 20:20 Rafael
  2021-09-08 13:54 ` John Kitchin
  0 siblings, 1 reply; 3+ messages in thread
From: Rafael @ 2021-09-04 20:20 UTC (permalink / raw)
  To: emacs-orgmode


I am using emacs-jupyter (https://github.com/nnicandro/emacs-jupyter),
and I have just noticed that results from a block are not sent to
another block. I think it has to do with this issue
https://github.com/nnicandro/emacs-jupyter/issues/222. Can somebody
suggest a workaround? (I actually want to use the output from a kernel
different from python, but since the problem happens also with the python
kernel I'm using it as an example).

  #+name: atest
  #+begin_src jupyter-python :session test
1+1
  #+end_src

  #+RESULTS: graphst
  : 2
  
  #+begin_src python :var adjs=atest
adjs
  #+end_src

  #+RESULTS
  : nil


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: emacs-jupyter does not send result form babel block
  2021-09-04 20:20 emacs-jupyter does not send result form babel block Rafael
@ 2021-09-08 13:54 ` John Kitchin
  2021-11-11 20:55   ` Rafael
  0 siblings, 1 reply; 3+ messages in thread
From: John Kitchin @ 2021-09-08 13:54 UTC (permalink / raw)
  To: Rafael; +Cc: org-mode-email

[-- Attachment #1: Type: text/plain, Size: 2400 bytes --]

I think this is a bug in jupyter-org-client.el in this function:

(defun jupyter-org--add-result (req result)
  (cond
   ((jupyter-org-request-silent-p req)
    (unless (equal (jupyter-org-request-silent-p req) "none")
      (message "%s" (org-element-interpret-data result))))
   ((jupyter-org-request-async-p req)
    (jupyter-org--clear-request-id req)
    (jupyter-org--do-insert-result req result))
   (t
    (push result (jupyter-org-request-results req)))))

The problem is that when the jupyter block is executed to define the
variable in the python header, it is run with a "silent" results param. The
function above is responsible for adding the results to the
jupyter-org-request struct, and here when it sees the results are silent,
it does not do that, so the results are nil, which is why you see what you
see.

I don't think that behavior is correct. It isn't quite right to just remove
the first block though, at least in this case. The result in this function
is already structured as a fixed-width results element intended to be
interpreted as a results string, and not the numeric value returned. So the
fix is probably upstream from this.

I am not sure what the fix is for this. The code path from C-cC-c to
executing the code, handling the request to the kernel, getting results and
to the output is very hard to follow for me. I would post an issue at
https://github.com/nnicandro/emacs-jupyter/issues.

John

-----------------------------------
Professor John Kitchin (he/him/his)
Doherty Hall A207F
Department of Chemical Engineering
Carnegie Mellon University
Pittsburgh, PA 15213
412-268-7803
@johnkitchin
http://kitchingroup.cheme.cmu.edu



On Sat, Sep 4, 2021 at 4:22 PM Rafael <rvf0068@gmail.com> wrote:

>
> I am using emacs-jupyter (https://github.com/nnicandro/emacs-jupyter),
> and I have just noticed that results from a block are not sent to
> another block. I think it has to do with this issue
> https://github.com/nnicandro/emacs-jupyter/issues/222. Can somebody
> suggest a workaround? (I actually want to use the output from a kernel
> different from python, but since the problem happens also with the python
> kernel I'm using it as an example).
>
>   #+name: atest
>   #+begin_src jupyter-python :session test
> 1+1
>   #+end_src
>
>   #+RESULTS: graphst
>   : 2
>
>   #+begin_src python :var adjs=atest
> adjs
>   #+end_src
>
>   #+RESULTS
>   : nil
>
>

[-- Attachment #2: Type: text/html, Size: 3504 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: emacs-jupyter does not send result form babel block
  2021-09-08 13:54 ` John Kitchin
@ 2021-11-11 20:55   ` Rafael
  0 siblings, 0 replies; 3+ messages in thread
From: Rafael @ 2021-11-11 20:55 UTC (permalink / raw)
  To: emacs-orgmode

John Kitchin <jkitchin@andrew.cmu.edu> writes:

>> On Sat, Sep 4, 2021 at 4:22 PM Rafael <rvf0068@gmail.com> wrote:
>>
>>>
>>> I am using emacs-jupyter (https://github.com/nnicandro/emacs-jupyter),
>>> and I have just noticed that results from a block are not sent to
>>> another block. I think it has to do with this issue
>>> https://github.com/nnicandro/emacs-jupyter/issues/222. Can somebody
>>> suggest a workaround? (I actually want to use the output from a kernel
>>> different from python, but since the problem happens also with the python
>>> kernel I'm using it as an example).
>>>
>>>   #+name: atest
>>>   #+begin_src jupyter-python :session test
>>> 1+1
>>>   #+end_src
>>>
>>>   #+RESULTS: graphst
>>>   : 2
>>>
>>>   #+begin_src python :var adjs=atest
>>> adjs
>>>   #+end_src
>>>
>>>   #+RESULTS
>>   : nil
>>
>>
>
> I think this is a bug in jupyter-org-client.el in this function:
>
> (defun jupyter-org--add-result (req result)
>   (cond
>    ((jupyter-org-request-silent-p req)
>     (unless (equal (jupyter-org-request-silent-p req) "none")
>       (message "%s" (org-element-interpret-data result))))
>    ((jupyter-org-request-async-p req)
>     (jupyter-org--clear-request-id req)
>     (jupyter-org--do-insert-result req result))
>    (t
>     (push result (jupyter-org-request-results req)))))
>
> The problem is that when the jupyter block is executed to define the
> variable in the python header, it is run with a "silent" results param. The
> function above is responsible for adding the results to the
> jupyter-org-request struct, and here when it sees the results are silent,
> it does not do that, so the results are nil, which is why you see what you
> see.
>
> I don't think that behavior is correct. It isn't quite right to just remove
> the first block though, at least in this case. The result in this function
> is already structured as a fixed-width results element intended to be
> interpreted as a results string, and not the numeric value returned. So the
> fix is probably upstream from this.
>
> I am not sure what the fix is for this. The code path from C-cC-c to
> executing the code, handling the request to the kernel, getting results and
> to the output is very hard to follow for me. I would post an issue at
> https://github.com/nnicandro/emacs-jupyter/issues.

Thanks for your answer and sorry for not following up. There is already
an issue about this which has been open since March 2020, see
https://github.com/nnicandro/emacs-jupyter/issues/222.


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-11-11 20:56 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-09-04 20:20 emacs-jupyter does not send result form babel block Rafael
2021-09-08 13:54 ` John Kitchin
2021-11-11 20:55   ` Rafael

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).