Skip to content

Commit

Permalink
build based on 8a42679
Browse files Browse the repository at this point in the history
  • Loading branch information
Documenter.jl committed Apr 30, 2024
1 parent 08221db commit 05f7b2c
Show file tree
Hide file tree
Showing 23 changed files with 2,125 additions and 3 deletions.
2 changes: 1 addition & 1 deletion stable
2 changes: 1 addition & 1 deletion v1
1 change: 1 addition & 0 deletions v1.16
1 change: 1 addition & 0 deletions v1.16.0/.documenter-siteinfo.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"documenter":{"julia_version":"1.10.2","generation_timestamp":"2024-04-30T12:04:03","documenter_version":"1.4.0"}}
30 changes: 30 additions & 0 deletions v1.16.0/Example_dsl/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<!DOCTYPE html>
<html lang="en"><head><meta charset="UTF-8"/><meta name="viewport" content="width=device-width, initial-scale=1.0"/><title>Example: Nice DiffEq Syntax Without A DSL · LabelledArrays.jl</title><meta name="title" content="Example: Nice DiffEq Syntax Without A DSL · LabelledArrays.jl"/><meta property="og:title" content="Example: Nice DiffEq Syntax Without A DSL · LabelledArrays.jl"/><meta property="twitter:title" content="Example: Nice DiffEq Syntax Without A DSL · LabelledArrays.jl"/><meta name="description" content="Documentation for LabelledArrays.jl."/><meta property="og:description" content="Documentation for LabelledArrays.jl."/><meta property="twitter:description" content="Documentation for LabelledArrays.jl."/><meta property="og:url" content="https://docs.sciml.ai/LabelledArrays/stable/Example_dsl/"/><meta property="twitter:url" content="https://docs.sciml.ai/LabelledArrays/stable/Example_dsl/"/><link rel="canonical" href="https://docs.sciml.ai/LabelledArrays/stable/Example_dsl/"/><script data-outdated-warner src="../assets/warner.js"></script><link href="https://cdnjs.cloudflare.com/ajax/libs/lato-font/3.0.0/css/lato-font.min.css" rel="stylesheet" type="text/css"/><link href="https://cdnjs.cloudflare.com/ajax/libs/juliamono/0.050/juliamono.min.css" rel="stylesheet" type="text/css"/><link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.2/css/fontawesome.min.css" rel="stylesheet" type="text/css"/><link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.2/css/solid.min.css" rel="stylesheet" type="text/css"/><link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.2/css/brands.min.css" rel="stylesheet" type="text/css"/><link href="https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.16.8/katex.min.css" rel="stylesheet" type="text/css"/><script>documenterBaseURL=".."</script><script src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.6/require.min.js" data-main="../assets/documenter.js"></script><script src="../search_index.js"></script><script src="../siteinfo.js"></script><script src="../../versions.js"></script><link class="docs-theme-link" rel="stylesheet" type="text/css" href="../assets/themes/documenter-dark.css" data-theme-name="documenter-dark" data-theme-primary-dark/><link class="docs-theme-link" rel="stylesheet" type="text/css" href="../assets/themes/documenter-light.css" data-theme-name="documenter-light" data-theme-primary/><script src="../assets/themeswap.js"></script><link href="../assets/favicon.ico" rel="icon" type="image/x-icon"/></head><body><div id="documenter"><nav class="docs-sidebar"><a class="docs-logo" href="../"><img src="../assets/logo.png" alt="LabelledArrays.jl logo"/></a><div class="docs-package-name"><span class="docs-autofit"><a href="../">LabelledArrays.jl</a></span></div><button class="docs-search-query input is-rounded is-small is-clickable my-2 mx-auto py-1 px-2" id="documenter-search-query">Search docs (Ctrl + /)</button><ul class="docs-menu"><li><a class="tocitem" href="../">Home</a></li><li class="is-active"><a class="tocitem" href>Example: Nice DiffEq Syntax Without A DSL</a></li><li><a class="tocitem" href="../SLArrays/">SLArrays</a></li><li><a class="tocitem" href="../LArrays/">LArrays</a></li><li><a class="tocitem" href="../NamedTuples_relation/">Relation to NamedTuples</a></li><li><a class="tocitem" href="../Note_labelled_slices/">Note: Labelled slices</a></li></ul><div class="docs-version-selector field has-addons"><div class="control"><span class="docs-label button is-static is-size-7">Version</span></div><div class="docs-selector control is-expanded"><div class="select is-fullwidth is-size-7"><select id="documenter-version-selector"></select></div></div></div></nav><div class="docs-main"><header class="docs-navbar"><a class="docs-sidebar-button docs-navbar-link fa-solid fa-bars is-hidden-desktop" id="documenter-sidebar-button" href="#"></a><nav class="breadcrumb"><ul class="is-hidden-mobile"><li class="is-active"><a href>Example: Nice DiffEq Syntax Without A DSL</a></li></ul><ul class="is-hidden-tablet"><li class="is-active"><a href>Example: Nice DiffEq Syntax Without A DSL</a></li></ul></nav><div class="docs-right"><a class="docs-navbar-link" href="https://github.com/SciML/LabelledArrays.jl" title="View the repository on GitHub"><span class="docs-icon fa-brands"></span><span class="docs-label is-hidden-touch">GitHub</span></a><a class="docs-navbar-link" href="https://github.com/SciML/LabelledArrays.jl/blob/master/docs/src/Example_dsl.md" title="Edit source on GitHub"><span class="docs-icon fa-solid"></span></a><a class="docs-settings-button docs-navbar-link fa-solid fa-gear" id="documenter-settings-button" href="#" title="Settings"></a><a class="docs-article-toggle-button fa-solid fa-chevron-up" id="documenter-article-toggle-button" href="javascript:;" title="Collapse all docstrings"></a></div></header><article class="content" id="documenter-page"><h1 id="Example:-Nice-DiffEq-Syntax-Without-A-DSL"><a class="docs-heading-anchor" href="#Example:-Nice-DiffEq-Syntax-Without-A-DSL">Example: Nice DiffEq Syntax Without A DSL</a><a id="Example:-Nice-DiffEq-Syntax-Without-A-DSL-1"></a><a class="docs-heading-anchor-permalink" href="#Example:-Nice-DiffEq-Syntax-Without-A-DSL" title="Permalink"></a></h1><p>Users of the SciML ecosystem are often solving large models with complicated states and hundreds or thousands of parameters. These models are implemented using arrays, and those arrays have traditionally been indexed by integers, such as <code>p[1]</code> or <code>p[1:5]</code>. Numerical indexing is wonderful for small models, but can quickly cause problems as models become bigger. It is easy to forget which index corresponds to which reaction rate or which diffusion coefficient. This confusion can lead to difficult to debug problems in a user&#39;s code. <code>LabelledArrays</code> can make an important difference here. It is much easier to build a model using parameter references such as <code>p.rate_nacl</code> or <code>p.probability_birth</code>, instead of <code>p[26]</code> or <code>p[1026]</code>. Labelled arrays make both the development and debugging of models much faster.</p><p>LabelledArrays.jl are a way to get DSL-like syntax without a macro. In this case, we can solve differential equations with labelled components by making use of labelled arrays, and always refer to the components by name instead of index.</p><p>One key caveat is that users do not need to sacrifice performance when using labelled arrays. Labelled arrays are as performant as traditional numerically indexed arrays.</p><p>Let&#39;s solve the Lorenz equation using an <code>LVector</code>s. <code>LVectors</code> are mutable. Hence, we can use the non-allocating form of the <code>OrdinaryDiffEq</code> API.</p><pre><code class="language-julia hljs">using LabelledArrays, OrdinaryDiffEq

function lorenz_f!(du, u, p, t)
du.x = p.σ * (u.y - u.x)
du.y = u.x * (p.ρ - u.z) - u.y
du.z = u.x * u.y - p.β * u.z
end

u0 = @LArray [1.0, 0.0, 0.0] (:x, :y, :z)
p = @LArray [10.0, 28.0, 8 / 3] (:σ, :ρ, :β)
tspan = (0.0, 10.0)
prob = ODEProblem(lorenz_f!, u0, tspan, p)
sol = solve(prob, Tsit5())
# Now the solution can be indexed as .x/y/z as well!
sol[10].x</code></pre><p>In the example above, we used an <code>LArray</code> to define the initial state <code>u0</code> as well as the parameter vector <code>p</code>. The remainder of the ODE solution steps are no different that the original <code>DifferentialEquations</code> <a href="https://docs.sciml.ai/DiffEqDocs/stable/tutorials/ode_example/#Example-2:-Solving-Systems-of-Equations">tutorials</a>.</p><p>Alternatively, we can use an immutable <code>SLVector</code> to implement the same equation. In this case, we need to use the allocating form of the <code>OrdinaryDiffEq</code> API when defining our model equation.</p><pre><code class="language-julia hljs">LorenzVector = @SLVector (:x, :y, :z)
LorenzParameterVector = @SLVector (:σ, :ρ, :β)

function f(u, p, t)
x = p.σ * (u.y - u.x)
y = u.x * (p.ρ - u.z) - u.y
z = u.x * u.y - p.β * u.z
LorenzVector(x, y, z)
end

u0 = LorenzVector(1.0, 0.0, 0.0)
p = LorenzParameterVector(10.0, 28.0, 8 / 3)
tspan = (0.0, 10.0)
prob = ODEProblem(f, u0, tspan, p)
sol = solve(prob, Tsit5())</code></pre></article><nav class="docs-footer"><a class="docs-footer-prevpage" href="../">« Home</a><a class="docs-footer-nextpage" href="../SLArrays/">SLArrays »</a><div class="flexbox-break"></div><p class="footer-message">Powered by <a href="https://github.com/JuliaDocs/Documenter.jl">Documenter.jl</a> and the <a href="https://julialang.org/">Julia Programming Language</a>.</p></nav></div><div class="modal" id="documenter-settings"><div class="modal-background"></div><div class="modal-card"><header class="modal-card-head"><p class="modal-card-title">Settings</p><button class="delete"></button></header><section class="modal-card-body"><p><label class="label">Theme</label><div class="select"><select id="documenter-themepicker"><option value="auto">Automatic (OS)</option><option value="documenter-light">documenter-light</option><option value="documenter-dark">documenter-dark</option></select></div></p><hr/><p>This document was generated with <a href="https://github.com/JuliaDocs/Documenter.jl">Documenter.jl</a> version 1.4.0 on <span class="colophon-date" title="Tuesday 30 April 2024 12:04">Tuesday 30 April 2024</span>. Using Julia version 1.10.2.</p></section><footer class="modal-card-foot"></footer></div></div></div></body></html>
Loading

0 comments on commit 05f7b2c

Please sign in to comment.