Add a web page solving instances with the WebAssembly module - #634
Merged
Merged
Conversation
fontanf
force-pushed
the
wasm-all-types-worker
branch
from
October 3, 2026 19:17
31eed86 to
81983ec
Compare
'wasm/web/' is a static page: the instance is entered in a form (every
problem type but irregular) or as a JSON file, solved in the Web Worker
with the chosen optimization mode and time limit (and a 'Stop' button),
and its solutions are drawn as they are found. The certificate and the
output can be downloaded.
- 'wasm/web/visualize/': JavaScript ports of the plotly visualizers of
'python/packingsolver/visualize/'. 'wasm/tests/visualize.test.mjs'
checks that they give the same figures as the Python ones, stored in
'wasm/tests/fixtures/visualize/' ('generate_visualize_fixtures.py').
- 'wasm/web/serve.py': development server, with the headers enabling
'SharedArrayBuffer'.
- The Web Worker gives the module the URL of its own script, which its
threads are started from: loaded with 'importScripts', it took the URL of
the worker.
- 'wasm/README.md' explains how to build, test and serve it.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #633, itself on #632. This PR's diff only shows the third step. GitHub retargets it as the base PRs are merged.
The page (
wasm/web/)A static page; the computation runs in the browser, in the Web Worker of #633.
SharedArrayBuffer, it explains it instead of failing.python3 wasm/web/serve.pyserves it with those headers.wasm/README.mdexplains how to build, test and serve it.Visualizers (
wasm/web/visualize/)JavaScript ports of the six plotly visualizers of
python/packingsolver/visualize/, with the same options. Each returns{data, layout}forPlotly.newPlot. plotly.js is loaded from jsDelivr, at version 4.1.1, the one plotly.py 7.1 uses.wasm/tests/visualize.test.mjschecks the JavaScript figures against the Python ones, stored as fixtures inwasm/tests/fixtures/visualize/(1.1 MB). That's 68 cases: the certificates of the Python visualizer tests, every option, and a few hand-made certificates for features the repository's certificates don't cover (defects, weights, arcs).generate_visualize_fixtures.pyregenerates the fixtures; it needs plotly.common.jsreproducesplotly.subplots.make_subplots. It's identical to plotly.py on every grid from 1x1 to 5x5, 2D and 3D, to the last bit.Worker fix
Loaded with
importScriptsin a Web Worker, the Emscripten module took the worker's URL as its own script's, and starts its threads from that URL. The worker now passesmainScriptUrlOrBlob.Testing
node --test wasm/tests/gives 99 tests, all passing: the 31 of WebAssembly module: all problem types, sessions and a Web Worker #633 and the 68 visualizer cases.crossOriginIsolatedis true;Notes on the Python visualizers
The ports reproduce them as they are, but these looked off while porting:
item, the othersitems.WEIGHTcolumn, but its percentages are divided by the sum of the item weights;COPIEScolumn: a bin used several times is drawn once. boxstacks only uses it withexpand_copies.columns=0, the grid computation divides by zero.