-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
{"documenter":{"julia_version":"1.10.2","generation_timestamp":"2024-03-15T18:31:09","documenter_version":"1.3.0"}} | ||
{"documenter":{"julia_version":"1.10.4","generation_timestamp":"2024-07-19T08:50:09","documenter_version":"1.5.0"}} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"><head><meta charset="UTF-8"/><meta name="viewport" content="width=device-width, initial-scale=1.0"/><title>TaxSystem · Agents.jl Example Zoo</title><meta name="title" content="TaxSystem · Agents.jl Example Zoo"/><meta property="og:title" content="TaxSystem · Agents.jl Example Zoo"/><meta property="twitter:title" content="TaxSystem · Agents.jl Example Zoo"/><meta name="description" content="Documentation for Agents.jl Example Zoo."/><meta property="og:description" content="Documentation for Agents.jl Example Zoo."/><meta property="twitter:description" content="Documentation for Agents.jl Example Zoo."/><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/catppuccin-mocha.css" data-theme-name="catppuccin-mocha"/><link class="docs-theme-link" rel="stylesheet" type="text/css" href="../../assets/themes/catppuccin-macchiato.css" data-theme-name="catppuccin-macchiato"/><link class="docs-theme-link" rel="stylesheet" type="text/css" href="../../assets/themes/catppuccin-frappe.css" data-theme-name="catppuccin-frappe"/><link class="docs-theme-link" rel="stylesheet" type="text/css" href="../../assets/themes/catppuccin-latte.css" data-theme-name="catppuccin-latte"/><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="https://fonts.googleapis.com/css?family=Montserrat|Source+Code+Pro&display=swap" rel="stylesheet" type="text/css"/></head><body><div id="documenter"><nav class="docs-sidebar"><a class="docs-logo" href="../../"><img src="../../assets/logo.png" alt="Agents.jl Example Zoo logo"/></a><div class="docs-package-name"><span class="docs-autofit"><a href="../../">Agents.jl Example Zoo</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="../../">Introduction</a></li><li><span class="tocitem">Examples</span><ul><li><a class="tocitem" href="../ants/">Ants</a></li><li><a class="tocitem" href="../battle/">Battle Royale</a></li><li><a class="tocitem" href="../social_distancing/">Continuous space social distancing</a></li><li><a class="tocitem" href="../game_of_life_2D_CA/">Conway's game of life</a></li><li><a class="tocitem" href="../growing_bacteria/">Bacterial Growth</a></li><li><a class="tocitem" href="../daisyworld/">Daisyworld</a></li><li><a class="tocitem" href="../forest_fire/">Forest fire</a></li><li><a class="tocitem" href="../fractal_growth/">Fractal Growth</a></li><li><a class="tocitem" href="../hk/">Hegselmann-Krause opinion dynamics</a></li><li><a class="tocitem" href="../maze/">Maze Solver</a></li><li><a class="tocitem" href="../runners/">Mountain Runners</a></li><li><a class="tocitem" href="../opinion_spread/">Opinion spread</a></li><li><a class="tocitem" href="../sugarscape/">Sugarscape</a></li><li class="is-active"><a class="tocitem" href>TaxSystem</a><ul class="internal"><li><a class="tocitem" href="#Overview-of-TaxSystem"><span>Overview of TaxSystem</span></a></li></ul></li><li><a class="tocitem" href="../wealth_distribution/">Wealth distribution model</a></li><li><a class="tocitem" href="../wright-fisher/">Wright-Fisher model of evolution</a></li></ul></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><a class="is-disabled">Examples</a></li><li class="is-active"><a href>TaxSystem</a></li></ul><ul class="is-hidden-tablet"><li class="is-active"><a href>TaxSystem</a></li></ul></nav><div class="docs-right"><a class="docs-navbar-link" href="https://github.com/JuliaDynamics/AgentsExampleZoo.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/JuliaDynamics/AgentsExampleZoo.jl/blob/main/docs/examples/taxsystem.jl" 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"><div class="admonition is-info"><header class="admonition-header">This model is predefined and can be accessed with `AgentsExampleZoo.taxsystem()`</header><div class="admonition-body"></div></div><h1 id="TaxSystem"><a class="docs-heading-anchor" href="#TaxSystem">TaxSystem</a><a id="TaxSystem-1"></a><a class="docs-heading-anchor-permalink" href="#TaxSystem" title="Permalink"></a></h1><p>Study this example to learn about</p><ul><li>Parallelizing a model where agents are simulated independently</li></ul><h2 id="Overview-of-TaxSystem"><a class="docs-heading-anchor" href="#Overview-of-TaxSystem">Overview of TaxSystem</a><a id="Overview-of-TaxSystem-1"></a><a class="docs-heading-anchor-permalink" href="#Overview-of-TaxSystem" title="Permalink"></a></h2><p>This model is a toy tax system simulation with the main purpose to explain how parallelization of the agent step can be achieved when agents don't interact with each other, but only evolve following a set of rules. A tax system is a good candidate to show that because taxes can have heterogeneous effects on the wealth of the agents depending on some of their characteristics, and at the same time there is no need for any interaction between agents to simulate such a system.</p><pre><code class="language-julia hljs">using Agents, Random</code></pre><p>the Payer agent contains the necessary characteristics to simulate its taxation in this toy model. In a real application, the properties can be much more than these</p><pre><code class="language-julia hljs">@agent struct Payer(NoSpaceAgent) | ||
alive::Bool | ||
age::Int | ||
wage::Float64 | ||
wealth::Float64 | ||
end</code></pre><p>Here we create the model, which contains a certain number of agents with a random age and a random wage each. The accumulated wealth at the start of the simulation is zero.</p><pre><code class="language-julia hljs">function taxsystem(; nagents = 100000) | ||
model = StandardABM(Payer; model_step!, container = Vector, rng = Xoshiro(42)) | ||
for _ in 1:nagents | ||
add_agent!(model, true, rand(abmrng(model), 20:30), rand(abmrng(model), 500:5000), 0) | ||
end | ||
return model | ||
end</code></pre><pre class="documenter-example-output"><code class="nohighlight hljs ansi">taxsystem (generic function with 1 method)</code></pre><p>To parallelize the stepping function we use a model step because it allows the loop updating the agents. Since the <code>tax_agent!</code> function evolves each agent without updating any other agent inside the function, it is thread-safe and so the simulation can be easily parallelized with <code>Threads.@threads</code></p><pre><code class="language-julia hljs">function model_step!(model) | ||
Threads.@threads for agent in allagents(model) | ||
tax_agent!(agent) | ||
end | ||
end</code></pre><pre class="documenter-example-output"><code class="nohighlight hljs ansi">model_step! (generic function with 1 method)</code></pre><p>In the simulation agents only get older (eventually dying) and accumulate their residual wage after paying taxes</p><pre><code class="language-julia hljs">function tax_agent!(agent) | ||
!agent.alive && return | ||
agent.age += 1 | ||
agent.wealth += agent.wage - (agent.wage < 1000 ? 0.0 : agent.wage * 0.2) | ||
agent.alive = rand(abmrng(model)) < 0.02 ? false : true | ||
end</code></pre><pre class="documenter-example-output"><code class="nohighlight hljs ansi">tax_agent! (generic function with 1 method)</code></pre><pre><code class="language-julia hljs">model = taxsystem()</code></pre><pre class="documenter-example-output"><code class="nohighlight hljs ansi">StandardABM with 100000 agents of type Payer | ||
agents container: Vector | ||
space: nothing (no spatial structure) | ||
scheduler: fastest</code></pre><p>Run the example with a different number of threads to see the speed-up, on the tested machine the model with 6 threads was 3.4 times faster than with 1 thread</p><pre><code class="language-julia hljs">@time step!(model, 100);</code></pre><pre class="documenter-example-output"><code class="nohighlight hljs ansi"> 2.105507 seconds (4.39 M allocations: 69.448 MiB, 3.60% compilation time)</code></pre></article><nav class="docs-footer"><a class="docs-footer-prevpage" href="../sugarscape/">« Sugarscape</a><a class="docs-footer-nextpage" href="../wealth_distribution/">Wealth distribution model »</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><option value="catppuccin-latte">catppuccin-latte</option><option value="catppuccin-frappe">catppuccin-frappe</option><option value="catppuccin-macchiato">catppuccin-macchiato</option><option value="catppuccin-mocha">catppuccin-mocha</option></select></div></p><hr/><p>This document was generated with <a href="https://github.com/JuliaDocs/Documenter.jl">Documenter.jl</a> version 1.5.0 on <span class="colophon-date" title="Friday 19 July 2024 08:50">Friday 19 July 2024</span>. Using Julia version 1.10.4.</p></section><footer class="modal-card-foot"></footer></div></div></div></body></html> |