|
40 | 40 | Pkg.add(["Statistics", "JLD2"])</code></pre><pre class="documenter-example-output"><code class="nohighlight hljs ansi"> Cloning git-repo `https://github.com/JuliaDynamics/DrWatson.jl.git`
|
41 | 41 | Resolving package versions...
|
42 | 42 | Updating `~/work/DrWatson.jl/DrWatson.jl/docs/build/DrWatsonExample/Project.toml`
|
43 |
| - [634d3b9d] ~ DrWatson v2.14.1 ⇒ v2.15.0 `~/.julia/dev/DrWatson` |
| 43 | + [634d3b9d] ~ DrWatson v2.15.0 ⇒ v2.15.0 `~/.julia/dev/DrWatson` |
44 | 44 | Updating `~/work/DrWatson.jl/DrWatson.jl/docs/build/DrWatsonExample/Manifest.toml`
|
45 |
| - [634d3b9d] ~ DrWatson v2.14.1 ⇒ v2.15.0 `~/.julia/dev/DrWatson` |
| 45 | + [634d3b9d] ~ DrWatson v2.15.0 ⇒ v2.15.0 `~/.julia/dev/DrWatson` |
46 | 46 | Resolving package versions...
|
47 | 47 | Updating `~/work/DrWatson.jl/DrWatson.jl/docs/build/DrWatsonExample/Project.toml`
|
48 | 48 | [033835bb] + JLD2 v0.4.46
|
|
70 | 70 | end</code></pre><pre class="documenter-example-output"><code class="nohighlight hljs ansi">fakesim (generic function with 2 methods)</code></pre><p>and we create some parameters in our scripts and run the simulation</p><pre><code class="language-julia hljs">a, b = 2, 3
|
71 | 71 | v = rand(5)
|
72 | 72 | method = "linear"
|
73 |
| -r, y = fakesim(a, b, v, method)</code></pre><pre class="documenter-example-output"><code class="nohighlight hljs ansi">([2.542145259253, 3.6518664510958336, 4.584802048524513, 3.1825562661089974, 2.743213595864532], 1.7320508075688772)</code></pre><p>Okay, that is fine, but it is typically the case that in scientific context some simulations are done for several different combinations of parameters. It is convenient to group all parameters in a dictionary, with the keys being the parameters. Depending on the package you will use to actually save the data, the key type should be either <code>String</code> or <code>Symbol</code>. Here we will be using JLD2.jl and therefore the key type will be <code>String</code>.</p><pre><code class="language-julia hljs">params = @strdict a b v method</code></pre><pre class="documenter-example-output"><code class="nohighlight hljs ansi">Dict{String, Any} with 4 entries: |
74 |
| - "v" => [0.180715, 0.550622, 0.861601, 0.394185, 0.247738] |
| 73 | +r, y = fakesim(a, b, v, method)</code></pre><pre class="documenter-example-output"><code class="nohighlight hljs ansi">([3.771290566566879, 2.0321773626552555, 4.345305891764846, 3.5269226668192335, 4.313644068705602], 1.7320508075688772)</code></pre><p>Okay, that is fine, but it is typically the case that in scientific context some simulations are done for several different combinations of parameters. It is convenient to group all parameters in a dictionary, with the keys being the parameters. Depending on the package you will use to actually save the data, the key type should be either <code>String</code> or <code>Symbol</code>. Here we will be using JLD2.jl and therefore the key type will be <code>String</code>.</p><pre><code class="language-julia hljs">params = @strdict a b v method</code></pre><pre class="documenter-example-output"><code class="nohighlight hljs ansi">Dict{String, Any} with 4 entries: |
| 74 | + "v" => [0.59043, 0.0107258, 0.781769, 0.508974, 0.771215] |
75 | 75 | "method" => "linear"
|
76 | 76 | "b" => 3
|
77 | 77 | "a" => 2</code></pre><p>Above we used the ultra-cool <a href="../name/#DrWatson.@strdict"><code>@strdict</code></a> macro, which creates a dictionary from existing variables!</p><p>Now, for every simulation we want to do, we would create such a container. We can use the <a href="../run&list/#DrWatson.dict_list"><code>dict_list</code></a> to ease up the process of preparing several of these parameter containers</p><pre><code class="language-julia hljs">allparams = Dict(
|
|
112 | 112 | wload(datadir("simulations", firstsim))</code></pre><pre class="documenter-example-output"><code class="nohighlight hljs ansi">Dict{String, Any} with 8 entries:
|
113 | 113 | "v" => [2, 1]
|
114 | 114 | "method" => "linear"
|
115 |
| - "gitcommit" => "ba90137550819a517057fef8cda2a16d7dea8422-dirty" |
| 115 | + "gitcommit" => "e1c87b1c2d02c50dc70245e8b64e10d01a7b4e97-dirty" |
116 | 116 | "script" => "docs/build/string#3"
|
117 | 117 | "b" => 3
|
118 | 118 | "r" => [7, 4]
|
|
122 | 122 |
|
123 | 123 | df = collect_results(datadir("simulations"))</code></pre><div><div style = "float: left;"><span>4×7 DataFrame</span></div><div style = "clear: both;"></div></div><div class = "data-frame" style = "overflow-x: scroll;"><table class = "data-frame" style = "margin-bottom: 6px;"><thead><tr class = "header"><th class = "rowNumber" style = "font-weight: bold; text-align: right;">Row</th><th style = "text-align: left;">v</th><th style = "text-align: left;">method</th><th style = "text-align: left;">b</th><th style = "text-align: left;">r</th><th style = "text-align: left;">a</th><th style = "text-align: left;">y</th><th style = "text-align: left;">path</th></tr><tr class = "subheader headerLastRow"><th class = "rowNumber" style = "font-weight: bold; text-align: right;"></th><th title = "Union{Missing, Vector{Int64}}" style = "text-align: left;">Array…?</th><th title = "Union{Missing, String}" style = "text-align: left;">String?</th><th title = "Union{Missing, Int64}" style = "text-align: left;">Int64?</th><th title = "Union{Missing, Vector{Int64}}" style = "text-align: left;">Array…?</th><th title = "Union{Missing, Int64}" style = "text-align: left;">Int64?</th><th title = "Union{Missing, Float64}" style = "text-align: left;">Float64?</th><th title = "Union{Missing, String}" style = "text-align: left;">String?</th></tr></thead><tbody><tr><td class = "rowNumber" style = "font-weight: bold; text-align: right;">1</td><td style = "text-align: left;">[2, 1]</td><td style = "text-align: left;">linear</td><td style = "text-align: right;">3</td><td style = "text-align: left;">[7, 4]</td><td style = "text-align: right;">1</td><td style = "text-align: right;">1.73205</td><td style = "text-align: left;">/home/runner/work/DrWatson.jl/DrWatson.jl/docs/build/DrWatsonExample/data/simulations/a=1_b=3_method=linear.jld2</td></tr><tr><td class = "rowNumber" style = "font-weight: bold; text-align: right;">2</td><td style = "text-align: left;">[2, 1]</td><td style = "text-align: left;">linear</td><td style = "text-align: right;">4</td><td style = "text-align: left;">[9, 5]</td><td style = "text-align: right;">1</td><td style = "text-align: right;">2.0</td><td style = "text-align: left;">/home/runner/work/DrWatson.jl/DrWatson.jl/docs/build/DrWatsonExample/data/simulations/a=1_b=4_method=linear.jld2</td></tr><tr><td class = "rowNumber" style = "font-weight: bold; text-align: right;">3</td><td style = "text-align: left;">[2, 1]</td><td style = "text-align: left;">linear</td><td style = "text-align: right;">3</td><td style = "text-align: left;">[8, 5]</td><td style = "text-align: right;">2</td><td style = "text-align: right;">1.73205</td><td style = "text-align: left;">/home/runner/work/DrWatson.jl/DrWatson.jl/docs/build/DrWatsonExample/data/simulations/a=2_b=3_method=linear.jld2</td></tr><tr><td class = "rowNumber" style = "font-weight: bold; text-align: right;">4</td><td style = "text-align: left;">[2, 1]</td><td style = "text-align: left;">linear</td><td style = "text-align: right;">4</td><td style = "text-align: left;">[10, 6]</td><td style = "text-align: right;">2</td><td style = "text-align: right;">2.0</td><td style = "text-align: left;">/home/runner/work/DrWatson.jl/DrWatson.jl/docs/build/DrWatsonExample/data/simulations/a=2_b=4_method=linear.jld2</td></tr></tbody></table></div><p>Some things to note:</p><ul><li>the returned object is a <code>DataFrame</code> for further analysis.</li><li>the input to <code>collect_result</code> is a folder, <strong>not</strong> a dataframe! The function does the loading and combining for you.</li><li>If you create new simulations, you can iteratively (or all from scratch) add them to this dataframe.</li><li>If you create new simulations that have <strong>new parameters</strong>, that don't exist in the simulations already saved, that's no problem. <code>collect_results</code> will appropriately and automatically add <code>missing</code> to all parameter values that don't exist in previous and/or current simulations. This is demonstrated explicitly in the <a href="../real_world/#Adapting-to-new-data/parameters">Adapting to new data/parameters</a> real world example, so it is not repeated here.</li><li>Similarly with e.g. <code>savename</code>, <code>collect_results</code> is a flexible function. It has several configuration options.</li></ul><p>Great! so now we are doing some analysis and we want to save some results... It is very often the case in science that the same analysis may be done again, and again, and some times even with the same parameters... And poor scientitists sometimes forget to change the name of the output file, and end up overwritting previous work! Devastating!</p><p>To avoid such scenarios, we can use the function <a href="../save/#DrWatson.safesave"><code>safesave</code></a>, e.g.</p><pre><code class="language-julia hljs">analysis = 42
|
124 | 124 |
|
125 |
| -safesave(datadir("ana", "linear.jld2"), @strdict analysis)</code></pre><p>If a file <code>linear.jld2</code> exists in that folder, it is not overwritten. Instead, it is renamed to <code>linear#1.jld2</code>, and a new <code>linear.jld2</code> file is made!</p><h2 id="6.-Share-your-project"><a class="docs-heading-anchor" href="#6.-Share-your-project">6. Share your project</a><a id="6.-Share-your-project-1"></a><a class="docs-heading-anchor-permalink" href="#6.-Share-your-project" title="Permalink"></a></h2><p>This is already discussed in the <a href="../project/#Reproducibility">Reproducibility</a> section of the docs so there is no reason to copy/paste everything here. What is demonstrated there is that it is truly trivial to share your project with a colleague, and this project is guaranteed to work for them!</p><hr/><p>And that's it! We hope that DrWatson will take some stress out of the absurdly stressfull scientific life!</p></article><nav class="docs-footer"><a class="docs-footer-prevpage" href="../">« Introduction</a><a class="docs-footer-nextpage" href="../project/">Project Setup »</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.3.0 on <span class="colophon-date" title="Wednesday 10 April 2024 17:10">Wednesday 10 April 2024</span>. Using Julia version 1.10.2.</p></section><footer class="modal-card-foot"></footer></div></div></div></body></html> |
| 125 | +safesave(datadir("ana", "linear.jld2"), @strdict analysis)</code></pre><p>If a file <code>linear.jld2</code> exists in that folder, it is not overwritten. Instead, it is renamed to <code>linear#1.jld2</code>, and a new <code>linear.jld2</code> file is made!</p><h2 id="6.-Share-your-project"><a class="docs-heading-anchor" href="#6.-Share-your-project">6. Share your project</a><a id="6.-Share-your-project-1"></a><a class="docs-heading-anchor-permalink" href="#6.-Share-your-project" title="Permalink"></a></h2><p>This is already discussed in the <a href="../project/#Reproducibility">Reproducibility</a> section of the docs so there is no reason to copy/paste everything here. What is demonstrated there is that it is truly trivial to share your project with a colleague, and this project is guaranteed to work for them!</p><hr/><p>And that's it! We hope that DrWatson will take some stress out of the absurdly stressfull scientific life!</p></article><nav class="docs-footer"><a class="docs-footer-prevpage" href="../">« Introduction</a><a class="docs-footer-nextpage" href="../project/">Project Setup »</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="Saturday 27 April 2024 08:34">Saturday 27 April 2024</span>. Using Julia version 1.10.2.</p></section><footer class="modal-card-foot"></footer></div></div></div></body></html> |
0 commit comments