
Show HN: Power system simulation on GNU Octave in WASM - rwlincoln
https://matpower.app
======
7thaccount
This is pretty neat, but can the creator show what it would look like on a
realistic system with Ex: 20k+ buses. This is not uncommon in the industry.

I'm also curious about why a web GUI is being used here? Power Systems
information varies by country, but is generally not something that will ever
be publically available, so desktop applications have done well here.

After more thinking, I guess it's a free way for researchers to upload and run
public models using free software?

~~~
rwlincoln
There are some test cases included in MATPOWER that are around that size and
may be imported. I only embedded small test cases in the application to keep
the download size down.

I imagine this app being quite useful to lecturers teaching Power Engineering
at Universities. Being able to just send students a link and not requiring
them to install complex libraries, deal with licenses or restricted trial
versions and them not having to use a particular OS or CPU architecture should
help get them started quickly.

[https://github.com/MATPOWER/matpower/tree/master/data](https://github.com/MATPOWER/matpower/tree/master/data)

~~~
7thaccount
Btw...checked out your open source apps. Nice work. I just wish industry was
bigger into building their own tools (like was common in the 80s when everyone
wrote their own loadflow tools) instead of being reliant upon vendors for
everything. There are advantages though to both.

~~~
rwlincoln
My view is that the open source projects for power system simulation available
now are approaching a stage where they can perform all of the main functions
of commercial tools. In some cases, they even offer functionality that
expensive proprietary applications do not have. However, they are typically
provided as libraries or with text-based interfaces.

WebAssembly creates an exciting opportunity to combine these libraries with
convenient, reactive user interfaces that help to manage the their complexity.
The web development community is so large and the frameworks and tools
available are of such high quality that an individual, or small team of
developers, can quickly create complex applications that would have previously
taken much longer. Ultimately, this should accelerate the process of bringing
the latest research to industry.

~~~
7thaccount
I've been making a similar argument for awhile. With the libraries now
available and high level tools (Python, SQL, Numpy...etc) we can build tiny
applications (just a few pages of code) that are easy to maintain and do
exactly what we need. So replacing the majority of PSSE isn't very hard. An
entire EMS system is another game entirely. It's not just the algorithms, but
the full integration with SCADA and other things that most companies don't
want to get involved with (too much risk).

On a different note, how are you approaching sparse matrices in Octave? Also,
I assumed Octave's performance would be a non-starter here for large models.
Is it performant enough for you?

~~~
rwlincoln
Octave includes support for sparse matrices and MATPOWER makes use of them by
default. It doesn't require any additional effort from me. In general, Octave
can quite match MATLAB for performance, but it is typically not far off.
Running it as WebAssembly also comes with a small performance penalty. I
haven't run any benchmarks yet, but this can be expected to improve as browser
vendors optimize their runtimes.

Octave is using UMFPACK to solve sparse systems of linear equations. There may
be some performance to be gained by using KLU with AMD preordering.

I am interested to know how best to compile BLAS and LAPACK to WebAssembly.
Traditionally, implementations optimized for a particular machine architecture
are used to extract maximum performance. However, WebAssembly targets a stack-
based conceptual machine. At present, I use LAPACK v3.4.2 and convert it to C
with f2c before compiling to WebAssembly. It would be interesting to perform
some benchmark tests against other implementations and compare across
browsers.

~~~
7thaccount
Neat and thanks for the explanations! When you say running it as Webassembly,
is the entire thing compiled that way, or is that just in the front end with
Octave running on the server?

~~~
rwlincoln
The whole application runs on the client (in the browser). The server just
serves up static resources. These are cached by the browser so the application
will still work if you are offline. The result is much like the desktop
applications you mentioned, but without anything needing to be installed.

The JavaScript application presents the UI and controls editing of a JSON
representation of the MATPOWER case structure. This data can be seen using the
JSON option on the Export page. The WebAssembly program contains GNU Octave
and its dependencies. It is run in a WebWorker (background thread) and the
JSON data is passed to and fro. The program that converts the JSON into Octave
data structures and back again is available here:

[https://github.com/rwl/octpower](https://github.com/rwl/octpower)

