Loading Data, Constants, Lookups from .csv files in WebAssembly
Posted: Wed Oct 14, 2020 11:20 pm
Hello Ventana Team,
We at Energy Innovation are extremely interested in the new Vensim 8.1 feature that can convert a model to WebAssembly, to run in a browser. As you may recall, for the Energy Policy Simulator (EPS), we currently use a Linux multi-context version of Vensim running on a server to perform model runs when they are requested by a user. This means the user must send the parameters to the server, the server runs the model, and it sends the results data back to the user's browser. This is a slow process, due to network latency and also the time required for the server to perform a Vensim model run.
The possibility of converting the model to WebAssembly so that it is running locally in a user's web browser has the potential to dramatically speed up model performance, by eliminating latency and because modern browsers execute WebAssembly code very quickly (much more quickly than the server can complete a Vensim run). This means that interacting with a Vensim model online could be a much faster and more pleasant experience for users, while also allowing us to simplify our backend server architecture, which could save us money every month in Amazon Web Services hosting fees.
The EPS is a large model. It loads in constants, data, and lookups from hundreds of different .csv files, and it uses a wide variety of the various functions available in Vensim's programming language. I noticed in Vensim's documentation of the new WebAssembly converter feature that "All data and constants must be contained within the model. At present, Vensim WASM models cannot load external data or constants." That particular limitation would prevent the EPS from being converted to WebAssembly.
Emscripten provides a virtual file system that simulates the local file system, so that "code that uses traditional file APIs can then be compiled and run with little or no change." Emscripten documentation discusses their file system implementation here and explains how to package the files that populate the virtual file system here. It sounds like this might be a good solution that allows support for reading in external data files by the WebAssembly code running inside a browser sandbox.
Do you have any plans or timeframe to support the use of external data files in models converted to WebAssembly?
We would be happy to help debug the WebAssembly converter feature by trying to use it to convert the EPS to WebAssembly, and reporting to you on any errors or issues we encounter. If you can get your WebAssembly converter to successfully convert the EPS, it will probably work on almost all Vensim models, so the EPS would make a good test case for this new Vensim feature.
Jeff
We at Energy Innovation are extremely interested in the new Vensim 8.1 feature that can convert a model to WebAssembly, to run in a browser. As you may recall, for the Energy Policy Simulator (EPS), we currently use a Linux multi-context version of Vensim running on a server to perform model runs when they are requested by a user. This means the user must send the parameters to the server, the server runs the model, and it sends the results data back to the user's browser. This is a slow process, due to network latency and also the time required for the server to perform a Vensim model run.
The possibility of converting the model to WebAssembly so that it is running locally in a user's web browser has the potential to dramatically speed up model performance, by eliminating latency and because modern browsers execute WebAssembly code very quickly (much more quickly than the server can complete a Vensim run). This means that interacting with a Vensim model online could be a much faster and more pleasant experience for users, while also allowing us to simplify our backend server architecture, which could save us money every month in Amazon Web Services hosting fees.
The EPS is a large model. It loads in constants, data, and lookups from hundreds of different .csv files, and it uses a wide variety of the various functions available in Vensim's programming language. I noticed in Vensim's documentation of the new WebAssembly converter feature that "All data and constants must be contained within the model. At present, Vensim WASM models cannot load external data or constants." That particular limitation would prevent the EPS from being converted to WebAssembly.
Emscripten provides a virtual file system that simulates the local file system, so that "code that uses traditional file APIs can then be compiled and run with little or no change." Emscripten documentation discusses their file system implementation here and explains how to package the files that populate the virtual file system here. It sounds like this might be a good solution that allows support for reading in external data files by the WebAssembly code running inside a browser sandbox.
Do you have any plans or timeframe to support the use of external data files in models converted to WebAssembly?
We would be happy to help debug the WebAssembly converter feature by trying to use it to convert the EPS to WebAssembly, and reporting to you on any errors or issues we encounter. If you can get your WebAssembly converter to successfully convert the EPS, it will probably work on almost all Vensim models, so the EPS would make a good test case for this new Vensim feature.
Jeff