tskit-dev / msprime

Simulate genealogical trees and genomic sequence data using population genetic models
GNU General Public License v3.0
176 stars 87 forks source link

Add pyodide package #2053

Closed benjeffery closed 2 years ago

benjeffery commented 2 years ago

To enable usage in-browser.

benjeffery commented 2 years ago

https://github.com/pyodide/pyodide/pull/2548

grahamgower commented 2 years ago

I'm curious, do you have use cases in mind for this?

jeromekelleher commented 2 years ago

Education mainly. Ultimately we hope to run msprime/tskit workshops directly from the browser, without any need for JupyterHub etc. Performance is totally good enough for this.

grahamgower commented 2 years ago

Ah, ok. I thought maybe you were going to take advantage of future msprime docs viewers to crowd source some simulation results. :P

benjeffery commented 2 years ago

I'm curious, do you have use cases in mind for this?

This lets any javascript browser app use msprime as a library, so for example you could have a web app where you had a box that had a demes model in, and as you edit the model a load of plots/analysis update in real-time. Would give people a great way to get a handle on how the demographic model influences different metrics.

molpopgen commented 2 years ago

It'd be great to display the SVG trees/tree sequences using this.

jeromekelleher commented 2 years ago

That should already be possible (although loading up a tree sequence from a URL is a bit of a faff and we need a nice recipe for it).

molpopgen commented 2 years ago

That should already be possible (although loading up a tree sequence from a URL is a bit of a faff and we need a nice recipe for it).

Yeah, I've tried and given up. But my JS skills are weak.

molpopgen commented 2 years ago

In the past, I experimented with flask. I didn't get very far.

benjeffery commented 2 years ago

Merged at pyodide.

molpopgen commented 2 years ago

Exciting!

benjeffery commented 2 years ago

Yikes, this is mad: ts = msprime.sim_ancestry(1_000_000); Browser: 17.7s Native: 13.2s

Only ~30% slower.

jeromekelleher commented 2 years ago

That's pretty nuts - msprime in the browser is probably faster than any other simulator for most things then.

molpopgen commented 2 years ago

This is fantastic timing. I'm redoing most/all of my lecture slides with Remark.js for the upcoming year.

grahamgower commented 2 years ago

How's the memory use compare?

benjeffery commented 2 years ago

Browser (memory footprint of the tab in chrome dev tools) - after import msprime: 269M, after simulation: 1,667M Native - after import msprime: 28M, after simulation: 1,000M.