diff options
Diffstat (limited to 'docs/articles/web_only/compiled_models.html')
-rw-r--r-- | docs/articles/web_only/compiled_models.html | 64 |
1 files changed, 32 insertions, 32 deletions
diff --git a/docs/articles/web_only/compiled_models.html b/docs/articles/web_only/compiled_models.html index c2964762..e45655b6 100644 --- a/docs/articles/web_only/compiled_models.html +++ b/docs/articles/web_only/compiled_models.html @@ -31,7 +31,7 @@ </button> <span class="navbar-brand"> <a class="navbar-link" href="../../index.html">mkin</a> - <span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">0.9.50.3</span> + <span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">1.0.0</span> </span> </div> @@ -80,7 +80,7 @@ <ul class="nav navbar-nav navbar-right"> <li> <a href="https://github.com/jranke/mkin/"> - <span class="fab fa fab fa-github fa-lg"></span> + <span class="fab fa-github fa-lg"></span> </a> </li> @@ -100,7 +100,7 @@ <h1 data-toc-skip>Performance benefit by using compiled model definitions in mkin</h1> <h4 class="author">Johannes Ranke</h4> - <h4 class="date">2020-10-15</h4> + <h4 class="date">2021-02-03</h4> <small class="dont-index">Source: <a href="https://github.com/jranke/mkin/blob/master/vignettes/web_only/compiled_models.rmd"><code>vignettes/web_only/compiled_models.rmd</code></a></small> <div class="hidden name"><code>compiled_models.rmd</code></div> @@ -113,33 +113,33 @@ <h2 class="hasAnchor"> <a href="#how-to-benefit-from-compiled-models" class="anchor"></a>How to benefit from compiled models</h2> <p>When using an mkin version equal to or greater than 0.9-36 and a C compiler is available, you will see a message that the model is being compiled from autogenerated C code when defining a model using mkinmod. Starting from version 0.9.49.9, the <code><a href="../../reference/mkinmod.html">mkinmod()</a></code> function checks for presence of a compiler using</p> -<div class="sourceCode" id="cb1"><pre class="downlit"> -<span class="fu">pkgbuild</span><span class="fu">::</span><span class="fu"><a href="https://rdrr.io/pkg/pkgbuild/man/has_compiler.html">has_compiler</a></span><span class="op">(</span><span class="op">)</span></pre></div> +<div class="sourceCode" id="cb1"><pre class="downlit sourceCode r"> +<code class="sourceCode R"><span class="fu">pkgbuild</span><span class="fu">::</span><span class="fu"><a href="https://rdrr.io/pkg/pkgbuild/man/has_compiler.html">has_compiler</a></span><span class="op">(</span><span class="op">)</span></code></pre></div> <p>In previous versions, it used <code><a href="https://rdrr.io/r/base/Sys.which.html">Sys.which("gcc")</a></code> for this check.</p> <p>On Linux, you need to have the essential build tools like make and gcc or clang installed. On Debian based linux distributions, these will be pulled in by installing the build-essential package.</p> <p>On MacOS, which I do not use personally, I have had reports that a compiler is available by default.</p> <p>On Windows, you need to install Rtools and have the path to its bin directory in your PATH variable. You do not need to modify the PATH variable when installing Rtools. Instead, I would recommend to put the line</p> -<div class="sourceCode" id="cb2"><pre class="downlit"> -<span class="fu"><a href="https://rdrr.io/r/base/Sys.setenv.html">Sys.setenv</a></span><span class="op">(</span>PATH <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/r/base/paste.html">paste</a></span><span class="op">(</span><span class="st">"C:/Rtools/bin"</span>, <span class="fu"><a href="https://rdrr.io/r/base/Sys.getenv.html">Sys.getenv</a></span><span class="op">(</span><span class="st">"PATH"</span><span class="op">)</span>, sep<span class="op">=</span><span class="st">";"</span><span class="op">)</span><span class="op">)</span></pre></div> +<div class="sourceCode" id="cb2"><pre class="downlit sourceCode r"> +<code class="sourceCode R"><span class="fu"><a href="https://rdrr.io/r/base/Sys.setenv.html">Sys.setenv</a></span><span class="op">(</span>PATH <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/r/base/paste.html">paste</a></span><span class="op">(</span><span class="st">"C:/Rtools/bin"</span>, <span class="fu"><a href="https://rdrr.io/r/base/Sys.getenv.html">Sys.getenv</a></span><span class="op">(</span><span class="st">"PATH"</span><span class="op">)</span>, sep<span class="op">=</span><span class="st">";"</span><span class="op">)</span><span class="op">)</span></code></pre></div> <p>into your .Rprofile startup file. This is just a text file with some R code that is executed when your R session starts. It has to be named .Rprofile and has to be located in your home directory, which will generally be your Documents folder. You can check the location of the home directory used by R by issuing</p> -<div class="sourceCode" id="cb3"><pre class="downlit"> -<span class="fu"><a href="https://rdrr.io/r/base/Sys.getenv.html">Sys.getenv</a></span><span class="op">(</span><span class="st">"HOME"</span><span class="op">)</span></pre></div> +<div class="sourceCode" id="cb3"><pre class="downlit sourceCode r"> +<code class="sourceCode R"><span class="fu"><a href="https://rdrr.io/r/base/Sys.getenv.html">Sys.getenv</a></span><span class="op">(</span><span class="st">"HOME"</span><span class="op">)</span></code></pre></div> </div> <div id="comparison-with-other-solution-methods" class="section level2"> <h2 class="hasAnchor"> <a href="#comparison-with-other-solution-methods" class="anchor"></a>Comparison with other solution methods</h2> <p>First, we build a simple degradation model for a parent compound with one metabolite, and we remove zero values from the dataset.</p> -<div class="sourceCode" id="cb4"><pre class="downlit"> -<span class="kw"><a href="https://rdrr.io/r/base/library.html">library</a></span><span class="op">(</span><span class="st"><a href="https://pkgdown.jrwb.de/mkin/">"mkin"</a></span>, quietly <span class="op">=</span> <span class="cn">TRUE</span><span class="op">)</span> +<div class="sourceCode" id="cb4"><pre class="downlit sourceCode r"> +<code class="sourceCode R"><span class="kw"><a href="https://rdrr.io/r/base/library.html">library</a></span><span class="op">(</span><span class="st"><a href="https://pkgdown.jrwb.de/mkin/">"mkin"</a></span>, quietly <span class="op">=</span> <span class="cn">TRUE</span><span class="op">)</span> <span class="va">SFO_SFO</span> <span class="op"><-</span> <span class="fu"><a href="../../reference/mkinmod.html">mkinmod</a></span><span class="op">(</span> - parent <span class="op">=</span> <span class="fu"><a href="../../reference/mkinsub.html">mkinsub</a></span><span class="op">(</span><span class="st">"SFO"</span>, <span class="st">"m1"</span><span class="op">)</span>, - m1 <span class="op">=</span> <span class="fu"><a href="../../reference/mkinsub.html">mkinsub</a></span><span class="op">(</span><span class="st">"SFO"</span><span class="op">)</span><span class="op">)</span></pre></div> -<pre><code>## Successfully compiled differential equation model from auto-generated C code.</code></pre> -<div class="sourceCode" id="cb6"><pre class="downlit"> -<span class="va">FOCUS_D</span> <span class="op"><-</span> <span class="fu"><a href="https://rdrr.io/r/base/subset.html">subset</a></span><span class="op">(</span><span class="va">FOCUS_2006_D</span>, <span class="va">value</span> <span class="op">!=</span> <span class="fl">0</span><span class="op">)</span></pre></div> + parent <span class="op">=</span> <span class="fu"><a href="../../reference/mkinmod.html">mkinsub</a></span><span class="op">(</span><span class="st">"SFO"</span>, <span class="st">"m1"</span><span class="op">)</span>, + m1 <span class="op">=</span> <span class="fu"><a href="../../reference/mkinmod.html">mkinsub</a></span><span class="op">(</span><span class="st">"SFO"</span><span class="op">)</span><span class="op">)</span></code></pre></div> +<pre><code>## Temporary DLL for differentials generated and loaded</code></pre> +<div class="sourceCode" id="cb6"><pre class="downlit sourceCode r"> +<code class="sourceCode R"><span class="va">FOCUS_D</span> <span class="op"><-</span> <span class="fu"><a href="https://rdrr.io/r/base/subset.html">subset</a></span><span class="op">(</span><span class="va">FOCUS_2006_D</span>, <span class="va">value</span> <span class="op">!=</span> <span class="fl">0</span><span class="op">)</span></code></pre></div> <p>We can compare the performance of the Eigenvalue based solution against the compiled version and the R implementation of the differential equations using the benchmark package. In the output of below code, the warnings about zero being removed from the FOCUS D dataset are suppressed. Since mkin version 0.9.49.11, an analytical solution is also implemented, which is included in the tests below.</p> -<div class="sourceCode" id="cb7"><pre class="downlit"> -<span class="kw">if</span> <span class="op">(</span><span class="kw"><a href="https://rdrr.io/r/base/library.html">require</a></span><span class="op">(</span><span class="va"><a href="http://rbenchmark.googlecode.com">rbenchmark</a></span><span class="op">)</span><span class="op">)</span> <span class="op">{</span> +<div class="sourceCode" id="cb7"><pre class="downlit sourceCode r"> +<code class="sourceCode R"><span class="kw">if</span> <span class="op">(</span><span class="kw"><a href="https://rdrr.io/r/base/library.html">require</a></span><span class="op">(</span><span class="va"><a href="http://rbenchmark.googlecode.com">rbenchmark</a></span><span class="op">)</span><span class="op">)</span> <span class="op">{</span> <span class="va">b.1</span> <span class="op"><-</span> <span class="fu"><a href="https://rdrr.io/pkg/rbenchmark/man/benchmark.html">benchmark</a></span><span class="op">(</span> <span class="st">"deSolve, not compiled"</span> <span class="op">=</span> <span class="fu"><a href="../../reference/mkinfit.html">mkinfit</a></span><span class="op">(</span><span class="va">SFO_SFO</span>, <span class="va">FOCUS_D</span>, solution_type <span class="op">=</span> <span class="st">"deSolve"</span>, @@ -156,23 +156,23 @@ <span class="fu"><a href="https://rdrr.io/r/base/print.html">print</a></span><span class="op">(</span><span class="va">b.1</span><span class="op">)</span> <span class="op">}</span> <span class="kw">else</span> <span class="op">{</span> <span class="fu"><a href="https://rdrr.io/r/base/print.html">print</a></span><span class="op">(</span><span class="st">"R package rbenchmark is not available"</span><span class="op">)</span> -<span class="op">}</span></pre></div> +<span class="op">}</span></code></pre></div> <pre><code>## test replications relative elapsed -## 4 analytical 1 1.000 0.200 -## 3 deSolve, compiled 1 1.745 0.349 -## 2 Eigenvalue based 1 2.040 0.408 -## 1 deSolve, not compiled 1 42.235 8.447</code></pre> +## 4 analytical 1 1.000 0.181 +## 3 deSolve, compiled 1 1.818 0.329 +## 2 Eigenvalue based 1 2.061 0.373 +## 1 deSolve, not compiled 1 43.923 7.950</code></pre> <p>We see that using the compiled model is by more than a factor of 10 faster than using deSolve without compiled code.</p> </div> <div id="model-without-analytical-solution" class="section level2"> <h2 class="hasAnchor"> <a href="#model-without-analytical-solution" class="anchor"></a>Model without analytical solution</h2> <p>This evaluation is also taken from the example section of mkinfit. No analytical solution is available for this system, and now Eigenvalue based solution is possible, so only deSolve using with or without compiled code is available.</p> -<div class="sourceCode" id="cb9"><pre class="downlit"> -<span class="kw">if</span> <span class="op">(</span><span class="kw"><a href="https://rdrr.io/r/base/library.html">require</a></span><span class="op">(</span><span class="va"><a href="http://rbenchmark.googlecode.com">rbenchmark</a></span><span class="op">)</span><span class="op">)</span> <span class="op">{</span> +<div class="sourceCode" id="cb9"><pre class="downlit sourceCode r"> +<code class="sourceCode R"><span class="kw">if</span> <span class="op">(</span><span class="kw"><a href="https://rdrr.io/r/base/library.html">require</a></span><span class="op">(</span><span class="va"><a href="http://rbenchmark.googlecode.com">rbenchmark</a></span><span class="op">)</span><span class="op">)</span> <span class="op">{</span> <span class="va">FOMC_SFO</span> <span class="op"><-</span> <span class="fu"><a href="../../reference/mkinmod.html">mkinmod</a></span><span class="op">(</span> - parent <span class="op">=</span> <span class="fu"><a href="../../reference/mkinsub.html">mkinsub</a></span><span class="op">(</span><span class="st">"FOMC"</span>, <span class="st">"m1"</span><span class="op">)</span>, - m1 <span class="op">=</span> <span class="fu"><a href="../../reference/mkinsub.html">mkinsub</a></span><span class="op">(</span> <span class="st">"SFO"</span><span class="op">)</span><span class="op">)</span> + parent <span class="op">=</span> <span class="fu"><a href="../../reference/mkinmod.html">mkinsub</a></span><span class="op">(</span><span class="st">"FOMC"</span>, <span class="st">"m1"</span><span class="op">)</span>, + m1 <span class="op">=</span> <span class="fu"><a href="../../reference/mkinmod.html">mkinsub</a></span><span class="op">(</span> <span class="st">"SFO"</span><span class="op">)</span><span class="op">)</span> <span class="va">b.2</span> <span class="op"><-</span> <span class="fu"><a href="https://rdrr.io/pkg/rbenchmark/man/benchmark.html">benchmark</a></span><span class="op">(</span> <span class="st">"deSolve, not compiled"</span> <span class="op">=</span> <span class="fu"><a href="../../reference/mkinfit.html">mkinfit</a></span><span class="op">(</span><span class="va">FOMC_SFO</span>, <span class="va">FOCUS_D</span>, @@ -185,13 +185,13 @@ <span class="op">}</span> <span class="kw">else</span> <span class="op">{</span> <span class="va">factor_FOMC_SFO</span> <span class="op"><-</span> <span class="cn">NA</span> <span class="fu"><a href="https://rdrr.io/r/base/print.html">print</a></span><span class="op">(</span><span class="st">"R package benchmark is not available"</span><span class="op">)</span> -<span class="op">}</span></pre></div> -<pre><code>## Successfully compiled differential equation model from auto-generated C code.</code></pre> +<span class="op">}</span></code></pre></div> +<pre><code>## Temporary DLL for differentials generated and loaded</code></pre> <pre><code>## test replications relative elapsed -## 2 deSolve, compiled 1 1.000 0.483 -## 1 deSolve, not compiled 1 30.451 14.708</code></pre> +## 2 deSolve, compiled 1 1.000 0.474 +## 1 deSolve, not compiled 1 30.179 14.305</code></pre> <p>Here we get a performance benefit of a factor of 30 using the version of the differential equation model compiled from C code!</p> -<p>This vignette was built with mkin 0.9.50.3 on</p> +<p>This vignette was built with mkin 1.0.0 on</p> <pre><code>## R version 4.0.3 (2020-10-10) ## Platform: x86_64-pc-linux-gnu (64-bit) ## Running under: Debian GNU/Linux 10 (buster)</code></pre> |