Skip to content

Commit

Permalink
deploy: 1cd27b3
Browse files Browse the repository at this point in the history
  • Loading branch information
martinjrobins committed Apr 1, 2024
1 parent b412ad1 commit a217ccf
Show file tree
Hide file tree
Showing 10 changed files with 1,392 additions and 426 deletions.
2 changes: 1 addition & 1 deletion 404.html
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@

<nav id="sidebar" class="sidebar" aria-label="Table of contents">
<div class="sidebar-scrollbox">
<ol class="chapter"><li class="chapter-item expanded "><a href="../../index.html"><strong aria-hidden="true">1.</strong> Introduction</a></li><li class="chapter-item expanded "><a href="language.html"><strong aria-hidden="true">2.</strong> DiffSL Language</a></li></ol>
<ol class="chapter"><li class="chapter-item expanded "><a href="introduction.html"><strong aria-hidden="true">1.</strong> DiffSL Language</a></li><li class="chapter-item expanded "><a href="tensors.html"><strong aria-hidden="true">2.</strong> Tensor Variables</a></li><li class="chapter-item expanded "><a href="operations.html"><strong aria-hidden="true">3.</strong> Tensor Operations</a></li><li class="chapter-item expanded "><a href="odes.html"><strong aria-hidden="true">4.</strong> Defining ODEs</a></li><li class="chapter-item expanded "><a href="inputs_outputs.html"><strong aria-hidden="true">5.</strong> Inputs and Outputs</a></li></ol>
</div>
<div id="sidebar-resize-handle" class="sidebar-resize-handle">
<div class="sidebar-resize-indicator"></div>
Expand Down
97 changes: 21 additions & 76 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<!-- Book generated using mdBook -->
<meta charset="UTF-8">
<title>Introduction - DiffSL</title>
<title>DiffSL Language - DiffSL</title>


<!-- Custom HTML head -->
Expand Down Expand Up @@ -90,7 +90,7 @@

<nav id="sidebar" class="sidebar" aria-label="Table of contents">
<div class="sidebar-scrollbox">
<ol class="chapter"><li class="chapter-item expanded "><a href="../../index.html" class="active"><strong aria-hidden="true">1.</strong> Introduction</a></li><li class="chapter-item expanded "><a href="language.html"><strong aria-hidden="true">2.</strong> DiffSL Language</a></li></ol>
<ol class="chapter"><li class="chapter-item expanded "><a href="introduction.html" class="active"><strong aria-hidden="true">1.</strong> DiffSL Language</a></li><li class="chapter-item expanded "><a href="tensors.html"><strong aria-hidden="true">2.</strong> Tensor Variables</a></li><li class="chapter-item expanded "><a href="operations.html"><strong aria-hidden="true">3.</strong> Tensor Operations</a></li><li class="chapter-item expanded "><a href="odes.html"><strong aria-hidden="true">4.</strong> Defining ODEs</a></li><li class="chapter-item expanded "><a href="inputs_outputs.html"><strong aria-hidden="true">5.</strong> Inputs and Outputs</a></li></ol>
</div>
<div id="sidebar-resize-handle" class="sidebar-resize-handle">
<div class="sidebar-resize-indicator"></div>
Expand Down Expand Up @@ -175,90 +175,35 @@ <h1 class="menu-title">DiffSL</h1>

<div id="content" class="content">
<main>
<h1 id="diffsl"><a class="header" href="#diffsl">DiffSL</a></h1>
<img src="https://github.com/martinjrobins/diffsl/actions/workflows/ci.yml/badge.svg" alt="CI build status badge">
<p>A compiler for a domain-specific language for ordinary differential equations (ODEs) of the following form:</p>
<p>DiffSL Language</p>
<p>The DSL is designed to be an easy and flexible language for specifying
DAE systems and is based on the idea that a DAE system can be specified by a set
of equations of the form:</p>
<p>$$
M(t) \frac{d\mathbf{u}}{dt} = F(\mathbf{u}, t)
$$</p>
<p>As an example, the following code defines a classic DAE testcase, the Robertson
(1966) problem, which models the kinetics of an autocatalytic reaction, given
by the following set of equations:</p>
<p>where \( \mathbf{u}$ \) is the vector of state variables and \( t \) is the time. The DSL
allows the user to specify the state vector \( \mathbf{u} \) and the RHS function \( F \).
Optionally, the user can also define the derivative of the state vector \( d\mathbf{u}/dt \)
and the mass matrix \( M \) as a function of \( d\mathbf{u}/dt \) (note that this function should be linear!).</p>
<p>The user is also free to define an an arbitrary number of intermediate
scalars and vectors of the users that are required to calculate \( F \) and \( M \).</p>
<h2 id="a-simple-example"><a class="header" href="#a-simple-example">A Simple Example</a></h2>
<p>To illustrate the language, consider the following simple example of a logistic growth model:</p>
<p>$$
\begin{align}
\frac{dx}{dt} &amp;= -0.04x + 10^4 y z \
\frac{dy}{dt} &amp;= 0.04x - 10^4 y z - 3 \cdot 10^7 y^2 \
0 &amp;= x + y + z - 1
\end{align}
\frac{dN}{dt} = r N (1 - N/K)
$$</p>
<p>The DiffSL code for this problem is as follows:</p>
<pre><code>in = [k1, k2, k3]
k1 { 0.04 }
k2 { 10000 }
k3 { 30000000 }
u_i {
x = 1,
y = 0,
z = 0,
}
dudt_i {
dxdt = 1,
dydt = 0,
dzdt = 0,
}
M_i {
dxdt,
dydt,
0,
}
F_i {
-k1 * x + k2 * y * z,
k1 * x - k2 * y * z - k3 * y * y,
1 - x - y - z,
}
out_i {
x,
y,
z,
}
</code></pre>
<h2 id="diffsl-language-features"><a class="header" href="#diffsl-language-features">DiffSL Language Features</a></h2>
<p>See the <a href="#diffsl-language">DiffSL Language</a> section for a full description.</p>
<ul>
<li>Tensor types:
<ul>
<li>Scalars (double precision floating point numbers)</li>
<li>Vectors (1D arrays of scalars)</li>
<li>N-dimensional tensor of scalars</li>
<li>Sparse/dense/diagonal tensors</li>
</ul>
</li>
<li>Tensor operations:
<ul>
<li>Elementwise operations</li>
<li>Broadcasting</li>
<li>Tensor contractions/matmul/translation etc via index notation</li>
</ul>
</li>
</ul>
<h2 id="dependencies"><a class="header" href="#dependencies">Dependencies</a></h2>
<p>You will need to install the <a href="https://llvm.org/">LLVM project</a>. The easiest way to
install this is to use the package manager for your operating system. For
example, on Ubuntu you can install these with the following command:</p>
<pre><code class="language-bash">sudo apt-get install llvm
</code></pre>
<h2 id="installing-diffsl"><a class="header" href="#installing-diffsl">Installing DiffSL</a></h2>
<p>You can install DiffSL using cargo. You will need to indicate the llvm version you have installed using a feature flag. For example, for llvm 14:</p>
<pre><code class="language-bash">cargo add diffsl --features llvm14-0
</code></pre>
<p>Other versions of llvm are also supported given by the features <code>llvm4-0</code>, <code>llvm5-0</code>, <code>llvm6-0</code>, <code>llvm7-0</code>, <code>llvm8-0</code>, <code>llvm9-0</code>, <code>llvm10-0</code>, <code>llvm11-0</code>, <code>llvm12-0</code>, <code>llvm13-0</code>, <code>llvm14-0</code>, <code>llvm15-0</code>, <code>llvm16-0</code>, <code>llvm17-0</code>.</p>
<p>where \( N \) is the population, \( r \) is the growth rate, and \( K \) is the carrying capacity.</p>
<p>To specify this model in DiffSL, we can write:</p>
<p><code>in = [r, k] u_i { N = 0.0 } F_i { r * N * (1 - N/k) } out_i { N }</code></p>
<p>Here, we define the input parameters for our model as a vector <code>in</code> with the growth rate <code>r</code> and the carrying capacity <code>k</code>. We then define the state vector <code>u_i</code> with the population <code>N</code> initialized to <code>0.0</code>. Next, we define the RHS function <code>F_i</code> as the logistic growth equation. Finally, we define the output vector <code>out_i</code> with the population <code>N</code>.</p>

</main>

<nav class="nav-wrapper" aria-label="Page navigation">
<!-- Mobile navigation buttons -->

<a rel="next prefetch" href="language.html" class="mobile-nav-chapters next" title="Next chapter" aria-label="Next chapter" aria-keyshortcuts="Right">
<a rel="next prefetch" href="tensors.html" class="mobile-nav-chapters next" title="Next chapter" aria-label="Next chapter" aria-keyshortcuts="Right">
<i class="fa fa-angle-right"></i>
</a>

Expand All @@ -269,7 +214,7 @@ <h2 id="installing-diffsl"><a class="header" href="#installing-diffsl">Installin

<nav class="nav-wide-wrapper" aria-label="Page navigation">

<a rel="next prefetch" href="language.html" class="nav-chapters next" title="Next chapter" aria-label="Next chapter" aria-keyshortcuts="Right">
<a rel="next prefetch" href="tensors.html" class="nav-chapters next" title="Next chapter" aria-label="Next chapter" aria-keyshortcuts="Right">
<i class="fa fa-angle-right"></i>
</a>
</nav>
Expand Down
Loading

0 comments on commit a217ccf

Please sign in to comment.