How SWIM works (Scala)

SWIM's Scala3 code (>25k lines) now compiles to three outputs:
Scala.js (/wasm) web version
Runs as js in web-app, creating SVG (scalable vector graphics). Open in a browser, it 'just works'.
Accessible, good for exploring and demonstrating system interconnections, dynamics.
Test relative sensitivity to policy options and scientific uncertainties.
Response time to parameter adjustments: ~ 0.5-5s
Can also run as wasm (new - see below ...)
JVM desktop version
Runs as java, reusing old "swing" GUI from JCM.
Faster => better for systematic analysis.
Simpler debugging for code in development
Response time to to parameter adjustments: ~ 0.1-1s.
Scala native version (New Sum25!)
Runs from command line (headless).
Fastest for systematic analyses and testing.
Could run scripts, e.g. probabilistic analysis of thousands of variants.
Could link / pipe to other models in other languages.

Snapshot of JVM desktop app

No GUI - pic is just Zed editor, running SWIM as scala native
Yet all versions share the same science code, calculate the same curves.
Scala3 - strongly typed, multi-paradigm, yet with readable syntax (minimal braces), is both reliable and flexible.
SWIM shows how scala(3).js succeeds to run a complex model in a browser, fast, flexibly, robustly.
So it's "scalable" in several senses: As well as zooming in space /time, there is scope to increase complexity and resolution. Scala code could also move from client to server for more complex / data-intensive science modules.

Note: Scalajs recently ( v17 +) added WASM (webassembly) export
This works well - you can try by adding ?wasm to SWIM url
Wasm is new - it may be necessary to set your browser to support wasm:
  • In Firefox (recent) it just works.
  • In Chrome go to (address bar) chrome://flags/#enable-experimental-webassembly-features.
  • In Vivaldi go to vivaldi://flags and enable "experimental webassembly".
  • In Safari it depends on the version (re-broken spring25, but maybe ok in most recent / tech/preview?) (although for plain js safari is still fastest).
Use the developer console to check the code really is mostly wasm - which even makes the svg plots!
Using wasm SWIM may recalculate a little faster, although the code has not yet been modified to optimise this, for example gui and console update calls likely slow-down the model loop.
Later wasm may also help connect with other models / tools written in other languages.

Links: More about Scala-JS and Scala 3 and Scala Native. Also using Libraries and Mill from LiHaoyi
Next: Model Doc + Code
(Overview)