<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: cosmosoneness</title>
    <description>The latest articles on DEV Community by cosmosoneness (@cosmosoneness).</description>
    <link>https://dev.to/cosmosoneness</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3933488%2F5d6d958a-79f6-4028-b641-b173ad3e96b8.jpg</url>
      <title>DEV Community: cosmosoneness</title>
      <link>https://dev.to/cosmosoneness</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/cosmosoneness"/>
    <language>en</language>
    <item>
      <title>I Simulated an Entire Human Body in Python: From Ion Channels to Sepsis</title>
      <dc:creator>cosmosoneness</dc:creator>
      <pubDate>Tue, 02 Jun 2026 15:03:58 +0000</pubDate>
      <link>https://dev.to/cosmosoneness/i-simulated-an-entire-human-body-in-python-from-ion-channels-to-sepsis-3nii</link>
      <guid>https://dev.to/cosmosoneness/i-simulated-an-entire-human-body-in-python-from-ion-channels-to-sepsis-3nii</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fj8fjt6ohou8ysuen2o0a.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fj8fjt6ohou8ysuen2o0a.png" alt="humanbody — whole-body physiology simulator" width="799" height="398"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;What if you could create a human being inside your computer — not a 3D avatar, but a &lt;em&gt;physiological&lt;/em&gt; one? A body with a beating heart whose blood pressure responds to blood loss, lungs that desaturate at altitude, a pancreas that releases insulin after a meal, and an immune system that can tip into sepsis?&lt;/p&gt;

&lt;p&gt;That's &lt;code&gt;humanbody&lt;/code&gt;: a single Python object you step forward in time.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;humanbody&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;HumanBody&lt;/span&gt;

&lt;span class="n"&gt;body&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;HumanBody&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;_&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="nf"&gt;range&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;60&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;          &lt;span class="c1"&gt;# 60 seconds of life
&lt;/span&gt;    &lt;span class="n"&gt;body&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;step&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;dt&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mf"&gt;1.0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;body&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;state_summary&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
&lt;span class="c1"&gt;# HR=72, MAP=93, PaO2=97, SaO2=0.98, glucose=94, cortisol=15, pH=7.40 ...
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Every number that comes out of &lt;code&gt;state_summary()&lt;/code&gt; is the emergent result of dozens of coupled differential equations — not a lookup table. Change one thing (bleed the patient, feed them, send them up a mountain) and the whole body responds the way a real body would.&lt;/p&gt;

&lt;p&gt;It's &lt;strong&gt;255 tests&lt;/strong&gt; of mathematical physiology, and it's open source.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;🔗 &lt;strong&gt;Code:&lt;/strong&gt; &lt;a href="https://github.com/cosmosoneness/Cosmos" rel="noopener noreferrer"&gt;github.com/cosmosoneness/Cosmos&lt;/a&gt; (under &lt;code&gt;Emulation/Human_Body/&lt;/code&gt;)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Why build this?
&lt;/h2&gt;

&lt;p&gt;Textbooks teach physiology one system at a time: here's the cardiac cycle, here's the nephron, here's the HPA axis. But the body isn't a list of chapters — it's a giant feedback network. When you exercise, your muscles demand oxygen, which raises your heart rate, which the baroreflex modulates, which shifts your blood pressure, which changes kidney filtration, which adjusts your fluid balance… all at once.&lt;/p&gt;

&lt;p&gt;I wanted to &lt;em&gt;feel&lt;/em&gt; those couplings, not just read about them. The only way to really understand a control system is to build one and watch it misbehave.&lt;/p&gt;

&lt;p&gt;So I built the whole thing — fourteen phases, from molecules up to clinical scenarios.&lt;/p&gt;

&lt;h2&gt;
  
  
  The architecture: thinking in scales
&lt;/h2&gt;

&lt;p&gt;The model is organized by biological scale, and the dependency arrow always points up:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;molecular   →  enzyme kinetics, Hill dissociation, ATP/PCr/lactate
cellular    →  Hodgkin–Huxley ion channels, membrane potential
tissue      →  Krogh-cylinder oxygen diffusion
systems/    →  9 organ systems (the meat)
integration →  HumanBody aggregator + homeostasis
scenarios   →  clinical challenges you can run
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The nine organ systems each implement well-known models from the literature:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;System&lt;/th&gt;
&lt;th&gt;Model&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Cardiovascular&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Suga–Sagawa time-varying elastance + Ursino Windkessel + baroreflex&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Respiratory&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Otis–Rohrer mechanics + alveolar gas equation + Hill O₂ dissociation&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Nervous&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Wilson–Cowan cortical mass + brainstem rhythm generator + autonomic tone&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Endocrine&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;HPA / HPT / HPG axes + Dalla Man glucose–insulin + ADH/RAAS&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Digestive&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;5-compartment GI transit + liver glycogen + microbiome SCFA&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Renal&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;glomerulus + tubular handling + countercurrent multiplier + acid–base&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Musculoskeletal&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Hill-type muscle + PCr/lactate buffering + Lemaire bone remodeling&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Integumentary&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Gagge two-node thermal model&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Immune&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;innate + adaptive + Perelson pathogen dynamics + SIRS criteria&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;They talk to each other through a shared &lt;strong&gt;signal bus&lt;/strong&gt; — a dictionary of cross-system variables like mean arterial pressure, arterial oxygen, glucose, and cortisol — plus an event bus for discrete events like "a meal was eaten."&lt;/p&gt;

&lt;h2&gt;
  
  
  The hard part: time
&lt;/h2&gt;

&lt;p&gt;Here's the thing nobody tells you about whole-body simulation — &lt;strong&gt;different systems live on wildly different timescales.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The heart beats on the order of milliseconds. A cardiac action potential, valve dynamics, the pressure pulse — all of it is &lt;em&gt;stiff&lt;/em&gt;. Meanwhile, your cortisol rhythm plays out over hours, and bone remodeling takes weeks.&lt;/p&gt;

&lt;p&gt;My first integration attempt used a naive forward-Euler step at &lt;code&gt;dt = 1 second&lt;/code&gt; for everything. The result? Mean arterial pressure exploded to &lt;strong&gt;5 × 10⁴⁹ mmHg&lt;/strong&gt;. The cardiac ODE was catastrophically unstable at that step size.&lt;/p&gt;

&lt;p&gt;The fix was &lt;strong&gt;per-system substepping&lt;/strong&gt;: inside one &lt;code&gt;body.step(dt=1.0)&lt;/code&gt;, the engine runs the heart and circulation at &lt;strong&gt;1 ms&lt;/strong&gt; substeps (1000 iterations), the respiratory pump at &lt;strong&gt;50 ms&lt;/strong&gt; substeps, and everything slower at the full &lt;code&gt;dt&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;step&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;dt&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mf"&gt;1.0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="n"&gt;perturbations&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="c1"&gt;# Cardiac dynamics are stiff — substep finely
&lt;/span&gt;    &lt;span class="n"&gt;n_cardio&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;max&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;int&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;dt&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mf"&gt;1e-3&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;_&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="nf"&gt;range&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;n_cardio&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;cardio&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;step&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mf"&gt;1e-3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;signal&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;signal&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="c1"&gt;# Respiratory — medium substep
&lt;/span&gt;    &lt;span class="n"&gt;n_resp&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;max&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;int&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;dt&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mf"&gt;0.05&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;_&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="nf"&gt;range&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;n_resp&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;respiratory&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;step&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mf"&gt;0.05&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;signal&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;signal&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="c1"&gt;# Slow systems — one macro step
&lt;/span&gt;    &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;endocrine&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;step&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;dt&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;signal&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;signal&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;renal&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;step&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;dt&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;signal&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;signal&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;bus&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;publish&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;TickEvent&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;source&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;body&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;dt&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;dt&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is the same idea as multi-rate integration in circuit simulators. It's not glamorous, but it's the difference between a model and a number that overflows a float.&lt;/p&gt;

&lt;h2&gt;
  
  
  Watching it come alive: clinical scenarios
&lt;/h2&gt;

&lt;p&gt;The payoff is the scenario framework. Seven clinical challenges ship built-in:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;humanbody.scenarios&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;HemorrhageScenario&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;run_scenario&lt;/span&gt;

&lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;run_scenario&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;HemorrhageScenario&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;volume_mL&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;1000&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="n"&gt;dt&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mf"&gt;1.0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;alerts&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;# ['Shock: MAP &amp;lt; 65 mmHg']
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Run the &lt;strong&gt;hemorrhage&lt;/strong&gt; scenario and you watch the baroreflex fight to maintain pressure as a liter of blood drains away — heart rate climbs, then pressure finally collapses into shock and the homeostasis monitor raises an alert.&lt;/p&gt;

&lt;p&gt;Run &lt;strong&gt;sepsis&lt;/strong&gt; and IL-6 rises, drives a fever and tachycardia, and the system checks itself against the actual SIRS criteria.&lt;/p&gt;

&lt;p&gt;Run &lt;strong&gt;high-altitude&lt;/strong&gt; and the barometric pressure drop propagates through the alveolar gas equation into the Hill oxygen-dissociation curve — SaO₂ falls, the chemoreflex kicks in, and ventilation rises.&lt;/p&gt;

&lt;p&gt;Run &lt;strong&gt;diabetic ketoacidosis&lt;/strong&gt; and glucose stays sky-high while bicarbonate falls and the pH drops below 7.3.&lt;/p&gt;

&lt;p&gt;Each scenario is just a small class — and writing your own takes about a dozen lines:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;humanbody.scenarios.clinical&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Scenario&lt;/span&gt;

&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;CaffeineDose&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Scenario&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="sh"&gt;"""&lt;/span&gt;&lt;span class="s"&gt;200 mg caffeine -&amp;gt; tachycardia + higher cortisol.&lt;/span&gt;&lt;span class="sh"&gt;"""&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;__init__&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="nf"&gt;super&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;__init__&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Caffeine&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                         &lt;span class="n"&gt;description&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;200 mg single dose&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                         &lt;span class="n"&gt;duration&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mf"&gt;3600.0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;applied&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="bp"&gt;False&lt;/span&gt;

    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;step_perturbation&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;body&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;applied&lt;/span&gt; &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="n"&gt;t&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="mi"&gt;60&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="n"&gt;body&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;endocrine&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;hpa&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;stress_input&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="mf"&gt;0.2&lt;/span&gt;
            &lt;span class="n"&gt;body&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;cardio&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;baroreflex&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;set_point&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;
            &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;applied&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="bp"&gt;True&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  What it can — and can't — do
&lt;/h2&gt;

&lt;p&gt;Let me be honest about the boundaries, because that matters more than the demo.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;It's good for:&lt;/strong&gt; teaching integrated physiology, prototyping clinical scenarios, "what-if" experiments, and as a scaffold you can subclass into something research-grade. You learn an enormous amount just by breaking it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;It's not:&lt;/strong&gt; a medical device, a source of patient-specific predictions, or publication-grade quantitative biology. Every ODE is forward-Euler with substepping — accurate enough to be &lt;em&gt;qualitatively&lt;/em&gt; right, not quantitatively certified. &lt;strong&gt;Do not use it for medical decisions.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;There's also a fun gotcha I left in the docs: ask for blood pressure at the wrong instant and you might see "MAP = 8.9 mmHg." That's not a bug — it's the &lt;em&gt;instantaneous&lt;/em&gt; pressure sampled at diastole. The cardiac ODE is genuinely pulsatile at 1 ms resolution, so you have to average over a cycle to get a textbook number. The model is more honest than the summary statistic.&lt;/p&gt;

&lt;h2&gt;
  
  
  The bigger project
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;humanbody&lt;/code&gt; is actually one chapter of a larger repo I'm calling the &lt;strong&gt;Cosmos Research Institute&lt;/strong&gt; — an umbrella for end-to-end "emulators" of real systems, from a cellular artificial-life world to connectome-level whole-brain emulation. The ambition is to keep building computational models of the world we live in until the name stops being a joke.&lt;/p&gt;

&lt;p&gt;But you have to start somewhere, and the body is a beautiful place to start: it's the most sophisticated control system any of us will ever own, and now there's a version of it you can &lt;code&gt;pip install&lt;/code&gt; and break to your heart's content.&lt;/p&gt;

&lt;h2&gt;
  
  
  Try it
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git clone https://github.com/cosmosoneness/Cosmos.git
&lt;span class="nb"&gt;cd &lt;/span&gt;Cosmos/Emulation/Human_Body
pip &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;-e&lt;/span&gt; &lt;span class="s2"&gt;".[dev]"&lt;/span&gt;
pytest tests/ &lt;span class="nt"&gt;-q&lt;/span&gt;          &lt;span class="c"&gt;# 255 passed&lt;/span&gt;

humanbody run exercise &lt;span class="nt"&gt;--duration&lt;/span&gt; 600
humanbody serve &lt;span class="nt"&gt;--port&lt;/span&gt; 8000   &lt;span class="c"&gt;# REST API&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;🔗 &lt;strong&gt;Source:&lt;/strong&gt; &lt;a href="https://github.com/cosmosoneness/Cosmos" rel="noopener noreferrer"&gt;github.com/cosmosoneness/Cosmos&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;📖 &lt;strong&gt;Tutorial:&lt;/strong&gt; the &lt;code&gt;TUTORIAL.md&lt;/code&gt; in the repo has seven hands-on walkthroughs&lt;/li&gt;
&lt;li&gt;⭐ If it teaches you something, a star helps others find it&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;em&gt;Built in Python with the help of Claude Code. The individual modules credit the papers they implement — Suga &amp;amp; Sagawa, Ursino, Dalla Man, Wilson &amp;amp; Cowan, Lemaire, Gagge, Perelson, and many others whose mathematical physiology made this possible.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>python</category>
      <category>science</category>
      <category>programming</category>
      <category>opensource</category>
    </item>
    <item>
      <title>I Built an Artificial Life Simulation Where Cells Carry Tiny Neural Networks — and Started Measuring Their Φ</title>
      <dc:creator>cosmosoneness</dc:creator>
      <pubDate>Tue, 19 May 2026 14:56:48 +0000</pubDate>
      <link>https://dev.to/cosmosoneness/i-built-an-artificial-life-simulation-where-cells-carry-tiny-neural-networks-and-started-18a6</link>
      <guid>https://dev.to/cosmosoneness/i-built-an-artificial-life-simulation-where-cells-carry-tiny-neural-networks-and-started-18a6</guid>
      <description>&lt;p&gt;&lt;em&gt;A six-phase journey from Conway's Game of Life to Integrated Information, all in one TypeScript file tree.&lt;/em&gt;&lt;/p&gt;




&lt;p&gt;There's a particular flavor of programming that feels less like writing software and more like building a small universe — set the rules, press play, and watch what happens. Conway's Game of Life is the canonical example, but the modern Cambrian explosion of compute has made it almost trivial to go much, much further: real ecosystems with energy and nutrients, evolving genomes, chemical communication, multi-cell organisms, embedded neural networks for decision-making, and — at the top of the stack — measurements borrowed from consciousness research.&lt;/p&gt;

&lt;p&gt;I spent a few sessions building exactly that. It's a TypeScript + Vite project called &lt;strong&gt;Life&lt;/strong&gt;, the first subproject of an open-source umbrella I'm calling &lt;a href="https://github.com/cosmosoneness/Cosmos" rel="noopener noreferrer"&gt;Cosmos Research Institute&lt;/a&gt;. The whole thing runs deterministically from a seed, ticks at about 10 Hz in a browser tab, and ships with &lt;strong&gt;75 passing tests&lt;/strong&gt; that pin every layer in place.&lt;/p&gt;

&lt;p&gt;This post is a tour through the six phases that turn a 128×128 grid of dead pixels into something I can no longer fully predict.&lt;/p&gt;

&lt;h2&gt;
  
  
  Phase 0 — The foundation
&lt;/h2&gt;

&lt;p&gt;The architecture is the boring-on-purpose part: TypeScript in strict mode, Vite for the dev server, Vitest for tests, and HTML5 Canvas as the only rendering surface. No frameworks, no DOM-per-cell, no WebGL. The simulation core (&lt;code&gt;src/core/&lt;/code&gt;) is pure: every tick takes a &lt;code&gt;WorldState&lt;/code&gt; and returns a new &lt;code&gt;WorldState&lt;/code&gt;. The renderer (&lt;code&gt;src/render/&lt;/code&gt;) is the only place side effects happen.&lt;/p&gt;

&lt;p&gt;Two foundational utilities make everything else possible:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// xoshiro256** PRNG — deterministic, fast, good statistical properties&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;rng&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;createRNG&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;42&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;rng&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;next&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;      &lt;span class="c1"&gt;// 0..1&lt;/span&gt;
&lt;span class="nx"&gt;rng&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;nextInt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;rng&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;nextBool&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mf"&gt;0.3&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// Toroidal grid — coordinates wrap, so the world has no edges&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;grid&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;createGrid&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Cell&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;128&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;128&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;createEmptyCell&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;
&lt;span class="nx"&gt;grid&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// same cell as grid.get(127, 0)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Determinism matters. Same seed → identical universe, every time. That's what lets me run regression tests on a simulation whose emergent behavior I can't predict.&lt;/p&gt;

&lt;h2&gt;
  
  
  Phase 1 — Conway's Game of Life, the right way
&lt;/h2&gt;

&lt;p&gt;Conway is famous because it's the smallest interesting cellular automaton. B3/S23: a dead cell with exactly three live neighbors becomes alive; a live cell with two or three live neighbors survives. From two rules you get gliders, oscillators, glider guns, even Turing-complete computation.&lt;/p&gt;

&lt;p&gt;The implementation is a pure-function tick:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;tickWorld&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;WorldState&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="nx"&gt;WorldState&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;next&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;grid&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;clone&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="k"&gt;for &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;y&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;y&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;grid&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;height&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;y&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;for &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;grid&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;width&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;cell&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;grid&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;y&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
      &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;n&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;countNeighbors&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;grid&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;y&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;c&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;alive&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
      &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;cell&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;alive&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="nx"&gt;next&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;y&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;n&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="nx"&gt;n&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="nx"&gt;cell&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;dead&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;
      &lt;span class="k"&gt;else&lt;/span&gt;             &lt;span class="nx"&gt;next&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;y&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;n&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="nf"&gt;born&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;dead&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;grid&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;next&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;tick&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;tick&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Two tests pin it down: a blinker oscillates with period 2, a block is a still life. If either ever breaks, I know an upstream change leaked into the rules.&lt;/p&gt;

&lt;h2&gt;
  
  
  Phase 2 — Energy, nutrients, and the end of binary life
&lt;/h2&gt;

&lt;p&gt;Conway's "alive" is binary. Real cells aren't — they need fuel, they starve, they overpopulate. So Phase 2 adds two grid layers underneath the cell grid:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Energy&lt;/strong&gt; — added by sunlight (with a top-down gradient and a sinusoidal day/night cycle), absorbed by living cells, returned to the environment when they die ("decay").&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Nutrients&lt;/strong&gt; — regenerate slowly in empty tiles, get consumed by living cells, diffuse via discrete Laplacian to spread.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now there's a &lt;em&gt;carrying capacity&lt;/em&gt;. Dense regions starve themselves. The population oscillates around a stable equilibrium, with boom-bust dynamics that emerge entirely from local rules — no global tuning required.&lt;/p&gt;

&lt;h2&gt;
  
  
  Phase 3 — Genomes, mutation, speciation
&lt;/h2&gt;

&lt;p&gt;This is where it stops feeling like cellular automata and starts feeling like evolution.&lt;/p&gt;

&lt;p&gt;Every living cell carries a 64-bit genome stored as &lt;code&gt;Uint8Array(8)&lt;/code&gt;. The bits map to traits:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Bits&lt;/th&gt;
&lt;th&gt;Trait&lt;/th&gt;
&lt;th&gt;Effect&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;0–3&lt;/td&gt;
&lt;td&gt;birth threshold&lt;/td&gt;
&lt;td&gt;how many neighbors trigger birth&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;4–7&lt;/td&gt;
&lt;td&gt;survive threshold&lt;/td&gt;
&lt;td&gt;how many neighbors are needed to survive&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;8–11&lt;/td&gt;
&lt;td&gt;metabolic efficiency&lt;/td&gt;
&lt;td&gt;scales energy consumption&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;12–15&lt;/td&gt;
&lt;td&gt;reproduction cost&lt;/td&gt;
&lt;td&gt;energy required to spawn a child&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;16–19&lt;/td&gt;
&lt;td&gt;aggression&lt;/td&gt;
&lt;td&gt;probability of attacking neighbors&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;20–23&lt;/td&gt;
&lt;td&gt;cooperation&lt;/td&gt;
&lt;td&gt;probability of sharing energy&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;24–31&lt;/td&gt;
&lt;td&gt;color hue&lt;/td&gt;
&lt;td&gt;phenotype color (this is what you see)&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Reproduction copies the parent's genome and applies per-bit mutation at a small rate. Adjacent compatible cells (Hamming distance &amp;lt; threshold) can also reproduce sexually via single-point crossover. Over generations, a greedy clustering algorithm groups similar genomes into &lt;strong&gt;species&lt;/strong&gt; — and because color hue is part of the genome, related cells naturally cluster &lt;em&gt;visually&lt;/em&gt; into colored bands.&lt;/p&gt;

&lt;p&gt;Within minutes of starting from a uniform random soup, the simulation reliably evolves dozens of co-existing species. None of this is hard-coded. It's just selection acting on local rules.&lt;/p&gt;

&lt;h2&gt;
  
  
  Phase 4 — Organisms, signals, terrain
&lt;/h2&gt;

&lt;p&gt;Cells alone get boring. Multi-cell &lt;strong&gt;organisms&lt;/strong&gt; are where the interesting structure lives. Every tick, a flood-fill connected-component algorithm finds clusters of cells whose genomes are mutually similar (Hamming distance &amp;lt; 8). Each cluster gets an organism record with size, centroid, total energy, and a partition into &lt;strong&gt;boundary cells&lt;/strong&gt; (touching at least one non-member) and &lt;strong&gt;interior cells&lt;/strong&gt;. Interior cells share energy with boundary cells (amplified by the cooperation gene). Organisms larger than 20 cells split at their thinnest point.&lt;/p&gt;

&lt;p&gt;On top of this sits a &lt;strong&gt;chemical signaling&lt;/strong&gt; layer — three diffusing scalar fields:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Food signal&lt;/strong&gt; — emitted by cells with surplus energy. Other cells preferentially reproduce &lt;em&gt;toward&lt;/em&gt; the gradient (chemotaxis).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Danger signal&lt;/strong&gt; — emitted by cells under attack. Other cells preferentially reproduce &lt;em&gt;away&lt;/em&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Attract signal&lt;/strong&gt; — emitted during reproduction readiness. Adjusts mating direction.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I never coded flocking, herding, or predator avoidance directly. They show up anyway, as side effects of local emission + diffusion + gradient sensing.&lt;/p&gt;

&lt;p&gt;Finally there's &lt;strong&gt;terrain&lt;/strong&gt;: multi-octave value noise generates an elevation map, water occupies low areas (cells can't live there), latitude + elevation set per-tile temperature, and a seasonal cycle modulates everything globally. Meteors, plagues, and ice ages strike at random and stress the population from outside.&lt;/p&gt;

&lt;h2&gt;
  
  
  Phase 5 — Genomes that &lt;em&gt;think&lt;/em&gt;
&lt;/h2&gt;

&lt;p&gt;Phase 5 doubles the genome from 64 to 128 bits and uses the new bits to encode a small feed-forward neural network: 4 inputs, 2 hidden, 3 outputs. Fourteen weights, each a 4-bit signed integer.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Inputs:  [normalized energy, neighbor count, food signal, danger signal]
Hidden:  2 nodes with tanh activation
Outputs: [action, direction bias, signal emission]
         action ∈ {STAY, MOVE, REPRODUCE} via thresholded output
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Each tick, every cell runs its own neural network and acts on the output. Mutation and crossover operate on raw genome bits, so &lt;strong&gt;the neural weights evolve through natural selection&lt;/strong&gt; — cells with brains that lead to better survival out-reproduce cells with worse brains.&lt;/p&gt;

&lt;p&gt;Click any cell in the running simulation and a live inspector pops up: phenotype values, current neural inputs, current output, and a diagram of the network with green/red connections sized by weight magnitude. It's hypnotic to watch the same brain fire across hundreds of related cells in a clade.&lt;/p&gt;

&lt;h2&gt;
  
  
  Phase 6 — Measuring something like consciousness
&lt;/h2&gt;

&lt;p&gt;Here's where I went off the deep end, in a fun way.&lt;/p&gt;

&lt;p&gt;If organisms are forming via natural selection, and they're integrating information across their member cells, then maybe — just &lt;em&gt;maybe&lt;/em&gt; — they should register on the metrics consciousness researchers have proposed. Integrated Information Theory (IIT) defines a quantity called &lt;strong&gt;Φ&lt;/strong&gt; (phi) that measures how much information a system generates beyond the sum of its parts. Exact Φ is computationally intractable, but there's a useful approximation called &lt;strong&gt;Φ*&lt;/strong&gt;:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;For each organism, sample 24 random bipartitions of its cells.&lt;/li&gt;
&lt;li&gt;For each bipartition, compute the normalized mutual information across the cut, using a discrete state token per cell (energy bucket + age bucket + aggression + neighborhood signature).&lt;/li&gt;
&lt;li&gt;Report the &lt;em&gt;minimum&lt;/em&gt; NMI as Φ* — the bottleneck partition.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;High Φ* means the organism's information is integrated: you can't cleanly decompose it into independent parts without losing structure. Low Φ* means it's just a pile of cells that happen to be next to each other.&lt;/p&gt;

&lt;p&gt;The Phase 6 dashboard surfaces this alongside a few other complexity metrics:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Shannon entropy&lt;/strong&gt; of the cell-state distribution (bits/cell)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Compression complexity&lt;/strong&gt; — the more compressible the grid, the more ordered it is&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Spatial mutual information&lt;/strong&gt; between distant regions — long-range order detection&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Lyapunov exponent estimate&lt;/strong&gt; from population history — chaotic vs stable dynamics&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;There's also a &lt;strong&gt;hypothesis log&lt;/strong&gt;: whenever an organism's Φ* crosses a configurable threshold, the simulation records the tick, the organism's size, its centroid, and a hex hash of its founder's genome.&lt;/p&gt;

&lt;p&gt;In a test run on a 64×64 grid with seed 42, one organism reached Φ* = &lt;strong&gt;1.0&lt;/strong&gt;. That doesn't mean it's conscious. It means the integrated-information measure detected something — and that something arose from local rules with zero global supervision.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I take away from this
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Determinism is non-negotiable for emergence research.&lt;/strong&gt; Without seed reproducibility, every weird thing you observe is unfalsifiable. The xoshiro256** + immutable-state-per-tick discipline pays off constantly.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;You can't reason your way to good rule sets — you have to run them.&lt;/strong&gt; I spent more time on the &lt;em&gt;thresholds&lt;/em&gt; (mutation rate, reproduction cost, signal decay) than on the &lt;em&gt;algorithms&lt;/em&gt;. Good rules are a search problem.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;The neural network layer changes the regime.&lt;/strong&gt; Before Phase 5, behaviors were essentially hand-coded. After Phase 5, behaviors are &lt;em&gt;selected for&lt;/em&gt;. You can almost feel the moment when chemotaxis starts emerging from random networks under selection pressure.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Φ* is suggestive, not conclusive.&lt;/strong&gt; I make no claim that any organism here is conscious. But the metric does flag exactly the structures that &lt;em&gt;look&lt;/em&gt; coherent — and that's already useful as an instrument.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Try it
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git clone https://github.com/cosmosoneness/Cosmos.git
&lt;span class="nb"&gt;cd &lt;/span&gt;Cosmos/Emulation/Life
npm &lt;span class="nb"&gt;install
&lt;/span&gt;npm run dev
&lt;span class="c"&gt;# open http://localhost:5173&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Key&lt;/th&gt;
&lt;th&gt;Action&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;Space&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;pause / resume&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;.&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;single-step&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;V&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;cycle view (genome / life / energy / nutrients / signals / terrain / phi)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;D&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;toggle emergence dashboard&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;Click&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;inspect a cell (phenotype + neural network)&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The whole project is MIT-licensed. It's also part of the &lt;a href="https://github.com/cosmosoneness/Cosmos" rel="noopener noreferrer"&gt;Cosmos Research Institute&lt;/a&gt; — an umbrella for "computational emulations" that try to run scientific systems end-to-end on a laptop. Alongside Life are two siblings: &lt;strong&gt;HumanBody&lt;/strong&gt; (a 13-organ multi-scale physiology simulator) and &lt;strong&gt;WholeBrainEmulation&lt;/strong&gt; (connectome-level neural simulation with consciousness metrics). The plan is to keep building until the institute earns its name.&lt;/p&gt;

&lt;p&gt;If you build something on top of it, or just want to argue about Φ*, I'd love to hear from you.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Built with the help of Claude Code. All bugs are mine.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>showdev</category>
      <category>typescript</category>
      <category>ai</category>
      <category>programming</category>
    </item>
  </channel>
</rss>
