<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
    <title>Passing Curiosity: Posts tagged simulation</title>
    <link href="https://passingcuriosity.com/tags/simulation/simulation.xml" rel="self" />
    <link href="https://passingcuriosity.com" />
    <id>https://passingcuriosity.com/tags/simulation/simulation.xml</id>
    <author>
        <name>Thomas Sutton</name>
        
        <email>me@thomas-sutton.id.au</email>
        
    </author>
    <updated>2013-08-28T00:00:00Z</updated>
    <entry>
    <title>FP-Syd, August 2013</title>
    <link href="https://passingcuriosity.com/2013/fp-syd-august/" />
    <id>https://passingcuriosity.com/2013/fp-syd-august/</id>
    <published>2013-08-28T00:00:00Z</published>
    <updated>2013-08-28T00:00:00Z</updated>
    <summary type="html"><![CDATA[<p>Here are some nodes from the August 2013 meeting of the <a href="http://fp-syd.ouroborus.net/">FP-Syd</a>
functional programming group.</p>
<h2 id="julian-gamble-on-simulation-testing-in-datomic">Julian Gamble on Simulation Testing in Datomic</h2>
<p><a href="http://juliangamble.com">Julian Gamble</a> ([<span class="citation" data-cites="juliansgamble">@juliansgamble</span>][] on Twitter) gave
his first FP-Syd talk with an introduction to simulation testing using [Datomic][].</p>
<p><span class="citation" data-cites="juliansgamble">[@juliansgamble]</span>: http://twitter.com/juliansgamble
[Datomic]: http://www.datomic.com</p>
<blockquote>
<p>Plug: He’s writing a book called <a href="http://clojurerecipes.net/">Clojure Recipes</a> which is due out in January 2014.</p>
</blockquote>
<p><a href="https://github.com/Datomic/simulant">Simulant</a> – the subject of the talk – is a framework for Datomic database.
It’s for <em>simulation testing</em>.</p>
<p>Many types of testing (in something resembling order of popularity):</p>
<ul>
<li>Unit testing</li>
<li>User acceptance testing</li>
<li>Performance testing</li>
<li>Simulation testing</li>
</ul>
<p>Simulation testing uses modeling and simulation to “test” systems which are too
complex for linear models like unit testing. Generations of simulations:</p>
<ul>
<li><p>High school solving maths problems</p></li>
<li><p>Stock analysts modelling and analysing companies</p></li>
<li><p>Analytics driven audits simulating systems for comparison.</p></li>
<li><p>Business scenarios predicting responses to, e.g., market crashes.</p></li>
</ul>
<p>Most of these can be done on a piece of paper or on a single machine, but
systems which aren’t amenable to such approaches are becoming more common.</p>
<p><a href="http://www.amazon.com/Purely-Functional-Structures-Chris-Okasaki/dp/0521663504">Chris Okasaki’s book Purely Functional Data Structures</a> popularised the
use of purely functional approaches to data structures through sharing.</p>
<p>Datomic is “a database as a value”. Or, put another way, a database as a
persistent data structure. This makes state management easier for, e.g.,
reproducing problems for bug fixing.</p>
<p>Built on pluggable storage system. Uses a Java-native store locally, can use
Amazon Dynamo DB. Writing is done through a single transactor process with
querying done directly from the data store.</p>
<p>Simulant is a framework which uses Datomic to help to distribute and scale
simulation testing. Assumes that you’ll be modelling <em>agents</em> and <em>actions</em> –
which are stored in the Simulant schema – and additonal model details stored
in your own schema. Uses git too, to keep track of version of the simulation
changing over time.</p>
<h3 id="process">Process</h3>
<ol type="1">
<li><p>Develop a Datomic schema for your model. This will be used to record the
generic details of the simulation – the actions performed by the agents – and
the domain specific details.</p></li>
<li><p>Set the model parameters (stocks/prices, etc. or ants/food/world size)</p></li>
<li><p>Make statistical assertions about the system. These will be verified against
the data recorded during the simulation.</p></li>
</ol>
<p>There are more details to this, but they flew past and I couldn’t get them down.</p>
<h3 id="why-datomic">Why Datomic?</h3>
<p>Being persistent (in the “persistent data structures” sense), Datomic makes it
far easier to review old data from older simulations, add additional
statistical assertions, etc. without having to jump through the many and varied
hoops you’d need for, e.g., a relational database.</p>
<p>I’m not sure how true a comparison this is, given that Datomic forces all
writes to the database through the single transactor. A similar architecture
with a relational database could quite easily use a single transactor to
enforce timestamp consistency on data being recorded. I must be missing
something.</p>
<h3 id="applicability">Applicability</h3>
<ul>
<li><p>Non-trivial system with multiple agents.</p></li>
<li><p>Datomic’s database as value, thing.</p></li>
<li><p>Where you have statistical assertions to be evaluated.</p></li>
</ul>
<h2 id="shane-stephens-on-web-animations">Shane Stephens on Web Animations</h2>
<p>Works on the <a href="http://w3.org/TR/web-animations/">web animations specification</a> for the W3C. Unifies SVG and
CSS animations on the web.</p>
<p>The web animations specification defines a Javascript API which looks something
like this:</p>
<div class="sourceCode" id="cb1"><pre class="sourceCode javascript"><code class="sourceCode javascript"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a><span class="kw">new</span> <span class="fu">Animation</span>(</span>
<span id="cb1-2"><a href="#cb1-2" aria-hidden="true" tabindex="-1"></a>	<span class="bu">document</span><span class="op">.</span><span class="fu">getElementById</span>(<span class="st">'hello'</span>)<span class="op">,</span></span>
<span id="cb1-3"><a href="#cb1-3" aria-hidden="true" tabindex="-1"></a>	[ {<span class="st">&quot;left&quot;</span> <span class="op">:</span> <span class="st">&quot;200px&quot;</span>}<span class="op">,</span></span>
<span id="cb1-4"><a href="#cb1-4" aria-hidden="true" tabindex="-1"></a>	  {<span class="st">&quot;left&quot;</span> <span class="op">:</span> <span class="st">&quot;400px&quot;</span><span class="op">,</span> <span class="st">&quot;height&quot;</span> <span class="op">:</span> <span class="st">&quot;100px&quot;</span>}]<span class="op">,</span></span>
<span id="cb1-5"><a href="#cb1-5" aria-hidden="true" tabindex="-1"></a>	<span class="dv">1</span></span>
<span id="cb1-6"><a href="#cb1-6" aria-hidden="true" tabindex="-1"></a>)<span class="op">;</span></span></code></pre></div>
<p>This talk isn’t about “generating a functional API for web animations” but he
thought it was two weeks ago. He tried to generate bindings, but failed.
Instead, it’s a discussion about the attempt and the result.</p>
<p>I think there might be animations of yak shaving involved.</p>
<h3 id="haskell-to-js-compilers">Haskell to JS compilers</h3>
<p>There are quite a few functional languages which target Javascript and they
all, in Shane’s opinion, hate the web.</p>
<h4 id="utrecht-haskell-compiler-javascript-backend">Utrecht Haskell Compiler JavaScript backend</h4>
<p>The <a href="https://github.com/UU-ComputerScience/uhc">UHC</a> Javascript backend has little documentation, claims to “compile
most of Hackage” and provides an FFI to interact with “native” Javascript code.</p>
<p>The barrier between Haskell and Javascript is the problem. Everything on the
web “platform” is exposed with APIs in Javascript. Having a UHC-JS generate a
blob of HTML and CSS and Javascript stuff is pretty hard to compose with other
web-ish things.</p>
<p>There’s a big impedance mismatch between Haskell and Javascript.</p>
<h4 id="elm">Elm</h4>
<p><a href="http://elm-lang.org/">Elm</a> is a functional reactive programming language which compiles to
Javascript. Lots of documentation, an online editor, and it already has
animations.</p>
<p>But Elm is another “replace the world” abstraction.</p>
<h4 id="roy">Roy</h4>
<p><a href="http://roy.brianmckenna.org/">Roy</a> has a much saner approach, largely just syntactice sugar around
Javascript:</p>
<ul>
<li>Javascript functions are available</li>
<li>Roy types are almost Javascript “types”</li>
</ul>
<p>But no ADTs, etc. Because JS is pretty shitty with no recursion, etc.</p>
<h4 id="krazy">krazy</h4>
<p>So with no “good” existing languages he started his own language called krazy.</p>
<ul>
<li><p>The current implementation is a PEG parser and interpreter in Javascript.</p></li>
<li><p>Functional types are Javascript types (lists, for example, really are Javascript arrays).</p></li>
<li><p>Supports ADTs, HOFs, pattern matching, etc.</p></li>
<li><p>JS interop “constrained” by type assertions.</p></li>
<li><p>Will probably add record with optional, structural typing.</p></li>
</ul>
<h3 id="animations">Animations</h3>
<p>Back to the web animations API.</p>
<p>The web animations specification has side-effect free constructors for
animations, effects, timing groups, etc.</p>
<p>This could be exposed to library authors and used as an interface or to
generate an interface automatically? I’m not sure.</p>
<h2 id="thomas-sewellts-on-learnings-about-sat">[Thomas Sewell][ts] on learnings about SAT</h2>
<p><a href="http://ssrg.nicta.com.au/people/?cn=Thomas+Sewell">Thomas Sewell</a></p>
<blockquote>
<p>Survey: who can name an NP-complete problem?</p>
</blockquote>
<p>NP-complete problems can be solved by a non-deterministic machine but the
solutions can be checked by a deterministic machine. In essence, they are very
hard to solve but easy to check.</p>
<p>Circuit satisfiability can be encoded in SAT.</p>
<p>The SAT problem attempts to assign values to logical variables in a formula in
conjunctive normal form and produces either a set of assignments (if the
formula is satisfiable) or “no” (if there is no assignment).</p>
<p>The DPLL algorithm is pretty naive and does lots of backtracking.</p>
<p>The CDCL algorithm – discovered in the 90s – increased the size of viable
problems to millions of variables. Instead of having to “re-learn” the same
pieces of information repeatedly when backtracking, the Conflict Driven Clause
Learning algorithm tracks the “cause” of a clause you learn and, when a
contradiction is derived, it learns the inverse of it’s parent.</p>
<p>E.g.</p>
<blockquote>
<p>If we reach contratiction, and the parents are <span class="math inline">\(x_{1}\)</span>, <span class="math inline">\(\neg x_{2}\)</span>, <span class="math inline">\(x_{12}\)</span>.
Then we need to learn <span class="math inline">\(\neg x_{1} \vee x_{2} \vee \neg x_{12}\)</span> as at least one
of the assumptions are false, so the negation of their disjunction must hold.</p>
</blockquote>
<h3 id="learnings">Learnings</h3>
<ul>
<li><p>Competitions - progress</p></li>
<li><p>Fast propagation - a modern SAT solver needs a very efficient implementation
of the propagation algorithm.</p></li>
<li><p>Locality - solvers make decisions “near” previous decisions. Need a heuristic
to find “nearby” variables for choice.</p></li>
<li><p>Phases - alternate between phases focussed on SAT and un-SAT phases.</p></li>
<li><p>Pruning - prune the database of clauses periodically to speed propagation.</p></li>
<li><p>Glue - Not sure what this means?</p></li>
<li><p>Rewriting - preprocessing the problem into an equisatisfiable problem. Make
the problem “better”, works well as a first step. Useful on problems like
CPUs problems.</p></li>
</ul>
<p>Lots of problems have nice and/or useful SAT encodings.</p>
<p>NP-complete problems were, in the not too distant past, primarily useful as a
polite “no” for managers. (You can’t have your cake and eat it too.)</p>
<h3 id="sat-with-proofs">SAT with Proofs</h3>
<p>Some solvers produce a resolution proof.</p>
<p>Reverse Unit Propagation of a proof is a services of clauses that can be
learned by unit propagation only. The conflict clauses of a CDCL solver in the
order they are learned form a RUP proof.</p>
<p>DRUP adds clause deletion, to speed up unit propagation.</p>
<p>Having useful proofs with rewriting is complex. Checking that a SAT proof for a
rewritten problem is tricky; dealing with the rewriting (incorporating it into
the proof and validating the rewriting is often as complex as the SAT problem
itself, etc.)</p>
<h3 id="motivations">Motivations</h3>
<p>Have some SMT proofs and would love to check them in HOL4 or Isabelle/HOL.
Satisfiability Modulo Theories (SMT) incorporates SAT as part of it. HOL4 and
Isabelle/HOL are highly trusted but very slow. Using SMT/SAT to solve a problem
quickly and Isabelle/HOL to replay and verify the result should result in a
fast, trusted proof.</p>
<p>There are SAT replay tools that do this sort of thing, but they were all pretty
or extremely slow. Turns out millions of variables are hard in more traditional
tools.</p>]]></summary>
</entry>

</feed>
