* Get =#+RESULTS= without re-evaluating source code block? @ 2021-01-27 22:14 doltes 2021-01-27 22:38 ` tomas 0 siblings, 1 reply; 7+ messages in thread From: doltes @ 2021-01-27 22:14 UTC (permalink / raw) To: emacs-orgmode Get =#+RESULTS= without re-evaluating source code block? Let's suppose I have a code block which requires a long time to finish #+NAME: big-computation #+begin_src bash sleep 5 # Some computation which requires a long time to complete. echo a #+end_src #+RESULTS: big-computation #+begin_example a #+end_example I want to use the results of that code block in other code blocks so I use a =noweb= reference (see below.) #+begin_src bash :noweb yes printf "%s\n" <<big-computation()>> #+end_src #+RESULTS: #+begin_example a #+end_example However, doing this (i.e. using a =noweb= reference) would make the command to be evaluated whenever getting its results. I don't want this, I want the =:noweb= reference to actually use the already computed results. So, my question is: Is it possible to use the actual =#+RESULTS= code block instead of always evaluating it when referencing the results through a =:noweb= reference? -- Greetings, doltes. ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Get =#+RESULTS= without re-evaluating source code block? 2021-01-27 22:14 Get =#+RESULTS= without re-evaluating source code block? doltes @ 2021-01-27 22:38 ` tomas 2021-01-27 23:31 ` John Kitchin 2021-01-27 23:33 ` doltes 0 siblings, 2 replies; 7+ messages in thread From: tomas @ 2021-01-27 22:38 UTC (permalink / raw) To: emacs-orgmode [-- Attachment #1: Type: text/plain, Size: 1348 bytes --] On Wed, Jan 27, 2021 at 05:14:43PM -0500, doltes wrote: > Get =#+RESULTS= without re-evaluating source code block? > > Let's suppose I have a code block which requires a long time to finish > > #+NAME: big-computation > #+begin_src bash > sleep 5 # Some computation which requires a long time to complete. > echo a > #+end_src > > #+RESULTS: big-computation > #+begin_example > a > #+end_example > > I want to use the results of that code block in other code blocks so I > use a =noweb= reference (see below.) > > #+begin_src bash :noweb yes > printf "%s\n" <<big-computation()>> > #+end_src > > #+RESULTS: > #+begin_example > a > > #+end_example > > However, doing this (i.e. using a =noweb= reference) would make the > command to be evaluated whenever getting its results. I don't want > this, I want the =:noweb= reference to actually use the already > computed results. > > So, my question is: Is it possible to use the actual =#+RESULTS= code > block instead of always evaluating it when referencing the results > through a =:noweb= reference? Perhaps "Cache results of evaluation" (15.5 Evaluating Code Blocks, in the Interwebs here [1] is for you. In short, add a header argument :cache yes to your code block. Cheers [1] https://orgmode.org/org.html#Evaluating-Code-Blocks - t [-- Attachment #2: Digital signature --] [-- Type: application/pgp-signature, Size: 198 bytes --] ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Get =#+RESULTS= without re-evaluating source code block? 2021-01-27 22:38 ` tomas @ 2021-01-27 23:31 ` John Kitchin 2021-01-28 3:26 ` Greg Minshall 2021-01-27 23:33 ` doltes 1 sibling, 1 reply; 7+ messages in thread From: John Kitchin @ 2021-01-27 23:31 UTC (permalink / raw) To: tomas; +Cc: emacs-orgmode [-- Attachment #1: Type: text/plain, Size: 1717 bytes --] I tried this but it did not work for me. On Wed, Jan 27, 2021 at 5:38 PM <tomas@tuxteam.de> wrote: > On Wed, Jan 27, 2021 at 05:14:43PM -0500, doltes wrote: > > Get =#+RESULTS= without re-evaluating source code block? > > > > Let's suppose I have a code block which requires a long time to finish > > > > #+NAME: big-computation > > #+begin_src bash > > sleep 5 # Some computation which requires a long time to complete. > > echo a > > #+end_src > > > > #+RESULTS: big-computation > > #+begin_example > > a > > #+end_example > > > > I want to use the results of that code block in other code blocks so I > > use a =noweb= reference (see below.) > > > > #+begin_src bash :noweb yes > > printf "%s\n" <<big-computation()>> > > #+end_src > > > > #+RESULTS: > > #+begin_example > > a > > > > #+end_example > > > > However, doing this (i.e. using a =noweb= reference) would make the > > command to be evaluated whenever getting its results. I don't want > > this, I want the =:noweb= reference to actually use the already > > computed results. > > > > So, my question is: Is it possible to use the actual =#+RESULTS= code > > block instead of always evaluating it when referencing the results > > through a =:noweb= reference? > > Perhaps "Cache results of evaluation" (15.5 Evaluating Code Blocks, > in the Interwebs here [1] is for you. > > In short, add a header argument :cache yes to your code block. > > Cheers > > [1] https://orgmode.org/org.html#Evaluating-Code-Blocks > > - t > -- John ----------------------------------- Professor John Kitchin Doherty Hall A207F Department of Chemical Engineering Carnegie Mellon University Pittsburgh, PA 15213 412-268-7803 @johnkitchin http://kitchingroup.cheme.cmu.edu [-- Attachment #2: Type: text/html, Size: 2769 bytes --] ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Get =#+RESULTS= without re-evaluating source code block? 2021-01-27 23:31 ` John Kitchin @ 2021-01-28 3:26 ` Greg Minshall 2021-02-02 2:10 ` John Kitchin 0 siblings, 1 reply; 7+ messages in thread From: Greg Minshall @ 2021-01-28 3:26 UTC (permalink / raw) To: John Kitchin; +Cc: tomas, emacs-orgmode John, > I tried this but it did not work for me. to be clear, caching means that the *first* time you execute, your reference will have to wait for the long-running computation to complete, but not during subsequent executions (unless the source block that performs the execution changes, in which case the reference will again have to wait). also, caching means that, after the first execution (ditto caveat) the source block *will no longer run*. so, if there were any (other) side effects of running that source block, they will not happen. (you could possibly split the side effect-producing code out of that block.) i'm not sure if this explains what did not work for you. cheers, Greg > > > On Wed, Jan 27, 2021 at 5:38 PM <tomas@tuxteam.de> wrote: > > > On Wed, Jan 27, 2021 at 05:14:43PM -0500, doltes wrote: > > > Get =#+RESULTS= without re-evaluating source code block? > > > > > > Let's suppose I have a code block which requires a long time to finish > > > > > > #+NAME: big-computation > > > #+begin_src bash > > > sleep 5 # Some computation which requires a long time to complete. > > > echo a > > > #+end_src > > > > > > #+RESULTS: big-computation > > > #+begin_example > > > a > > > #+end_example > > > > > > I want to use the results of that code block in other code blocks so I > > > use a =noweb= reference (see below.) > > > > > > #+begin_src bash :noweb yes > > > printf "%s\n" <<big-computation()>> > > > #+end_src > > > > > > #+RESULTS: > > > #+begin_example > > > a > > > > > > #+end_example > > > > > > However, doing this (i.e. using a =noweb= reference) would make the > > > command to be evaluated whenever getting its results. I don't want > > > this, I want the =:noweb= reference to actually use the already > > > computed results. > > > > > > So, my question is: Is it possible to use the actual =#+RESULTS= code > > > block instead of always evaluating it when referencing the results > > > through a =:noweb= reference? > > > > Perhaps "Cache results of evaluation" (15.5 Evaluating Code Blocks, > > in the Interwebs here [1] is for you. > > > > In short, add a header argument :cache yes to your code block. > > > > Cheers > > > > [1] https://orgmode.org/org.html#Evaluating-Code-Blocks > > > > - t > > > -- > John > > ----------------------------------- > Professor John Kitchin > Doherty Hall A207F > Department of Chemical Engineering > Carnegie Mellon University > Pittsburgh, PA 15213 > 412-268-7803 > @johnkitchin > http://kitchingroup.cheme.cmu.edu ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Get =#+RESULTS= without re-evaluating source code block? 2021-01-28 3:26 ` Greg Minshall @ 2021-02-02 2:10 ` John Kitchin 2021-02-02 20:02 ` Nick Dokos 0 siblings, 1 reply; 7+ messages in thread From: John Kitchin @ 2021-02-02 2:10 UTC (permalink / raw) To: Greg Minshall; +Cc: tomas, emacs-orgmode I discovered that it matters a lot which block you cache. You have to cache the long running block. I had put cache on the block with noweb expansion, and then the long running block still runs every time. That was a surprise to me, since nothing was changing in that block, so I thought it would just use the cached result. Greg Minshall <minshall@umich.edu> writes: > John, > >> I tried this but it did not work for me. > > to be clear, caching means that the *first* time you execute, your > reference will have to wait for the long-running computation to > complete, but not during subsequent executions (unless the source block > that performs the execution changes, in which case the reference will > again have to wait). > > also, caching means that, after the first execution (ditto caveat) the > source block *will no longer run*. so, if there were any (other) side > effects of running that source block, they will not happen. (you could > possibly split the side effect-producing code out of that block.) > > i'm not sure if this explains what did not work for you. > > cheers, Greg > >> >> >> On Wed, Jan 27, 2021 at 5:38 PM <tomas@tuxteam.de> wrote: >> >> > On Wed, Jan 27, 2021 at 05:14:43PM -0500, doltes wrote: >> > > Get =#+RESULTS= without re-evaluating source code block? >> > > >> > > Let's suppose I have a code block which requires a long time to finish >> > > >> > > #+NAME: big-computation >> > > #+begin_src bash >> > > sleep 5 # Some computation which requires a long time to complete. >> > > echo a >> > > #+end_src >> > > >> > > #+RESULTS: big-computation >> > > #+begin_example >> > > a >> > > #+end_example >> > > >> > > I want to use the results of that code block in other code blocks so I >> > > use a =noweb= reference (see below.) >> > > >> > > #+begin_src bash :noweb yes >> > > printf "%s\n" <<big-computation()>> >> > > #+end_src >> > > >> > > #+RESULTS: >> > > #+begin_example >> > > a >> > > >> > > #+end_example >> > > >> > > However, doing this (i.e. using a =noweb= reference) would make the >> > > command to be evaluated whenever getting its results. I don't want >> > > this, I want the =:noweb= reference to actually use the already >> > > computed results. >> > > >> > > So, my question is: Is it possible to use the actual =#+RESULTS= code >> > > block instead of always evaluating it when referencing the results >> > > through a =:noweb= reference? >> > >> > Perhaps "Cache results of evaluation" (15.5 Evaluating Code Blocks, >> > in the Interwebs here [1] is for you. >> > >> > In short, add a header argument :cache yes to your code block. >> > >> > Cheers >> > >> > [1] https://orgmode.org/org.html#Evaluating-Code-Blocks >> > >> > - t >> > >> -- >> John >> >> ----------------------------------- >> Professor John Kitchin >> Doherty Hall A207F >> Department of Chemical Engineering >> Carnegie Mellon University >> Pittsburgh, PA 15213 >> 412-268-7803 >> @johnkitchin >> http://kitchingroup.cheme.cmu.edu -- Professor John Kitchin Doherty Hall A207F Department of Chemical Engineering Carnegie Mellon University Pittsburgh, PA 15213 412-268-7803 @johnkitchin http://kitchingroup.cheme.cmu.edu ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Get =#+RESULTS= without re-evaluating source code block? 2021-02-02 2:10 ` John Kitchin @ 2021-02-02 20:02 ` Nick Dokos 0 siblings, 0 replies; 7+ messages in thread From: Nick Dokos @ 2021-02-02 20:02 UTC (permalink / raw) To: emacs-orgmode John Kitchin <jkitchin@andrew.cmu.edu> writes: > I discovered that it matters a lot which block you cache. You have to > cache the long running block. I had put cache on the block with noweb > expansion, and then the long running block still runs every time. That > was a surprise to me, since nothing was changing in that block, so I > thought it would just use the cached result. > Just to elaborate a bit: Org mode checks whether to reevaluate a cached block by checksumming it and seeing if the sum is different from before. That's why you have to mark the actual block for caching, not its callers. -- Nick "There are only two hard problems in computer science: cache invalidation, naming things, and off-by-one errors." -Martin Fowler ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Get =#+RESULTS= without re-evaluating source code block? 2021-01-27 22:38 ` tomas 2021-01-27 23:31 ` John Kitchin @ 2021-01-27 23:33 ` doltes 1 sibling, 0 replies; 7+ messages in thread From: doltes @ 2021-01-27 23:33 UTC (permalink / raw) To: tomas; +Cc: emacs-orgmode Yes, it worked like a charm! Thanks! tomas@tuxteam.de writes: > On Wed, Jan 27, 2021 at 05:14:43PM -0500, doltes wrote: >> Get =#+RESULTS= without re-evaluating source code block? >> >> Let's suppose I have a code block which requires a long time to finish >> >> #+NAME: big-computation >> #+begin_src bash >> sleep 5 # Some computation which requires a long time to complete. >> echo a >> #+end_src >> >> #+RESULTS: big-computation >> #+begin_example >> a >> #+end_example >> >> I want to use the results of that code block in other code blocks so I >> use a =noweb= reference (see below.) >> >> #+begin_src bash :noweb yes >> printf "%s\n" <<big-computation()>> >> #+end_src >> >> #+RESULTS: >> #+begin_example >> a >> >> #+end_example >> >> However, doing this (i.e. using a =noweb= reference) would make the >> command to be evaluated whenever getting its results. I don't want >> this, I want the =:noweb= reference to actually use the already >> computed results. >> >> So, my question is: Is it possible to use the actual =#+RESULTS= code >> block instead of always evaluating it when referencing the results >> through a =:noweb= reference? > > Perhaps "Cache results of evaluation" (15.5 Evaluating Code Blocks, > in the Interwebs here [1] is for you. > > In short, add a header argument :cache yes to your code block. > > Cheers > > [1] https://orgmode.org/org.html#Evaluating-Code-Blocks > > - t -- Greetings, doltes. ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2021-02-02 20:03 UTC | newest] Thread overview: 7+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2021-01-27 22:14 Get =#+RESULTS= without re-evaluating source code block? doltes 2021-01-27 22:38 ` tomas 2021-01-27 23:31 ` John Kitchin 2021-01-28 3:26 ` Greg Minshall 2021-02-02 2:10 ` John Kitchin 2021-02-02 20:02 ` Nick Dokos 2021-01-27 23:33 ` doltes
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).