Closes: #16 Add the ability to control the simulation from JS#24
Merged
Closes: #16 Add the ability to control the simulation from JS#24
Conversation
andeplane
reviewed
Feb 19, 2026
| } | ||
|
|
||
| const bool ok = LAMMPSWebAsync::invokeStepCallbackAndWait( | ||
| static_cast<std::int32_t>(update->ntimestep) |
Collaborator
There was a problem hiding this comment.
Maybe we should cast this as 64 bit int?
Collaborator
There was a problem hiding this comment.
Or maybe we don't have 64 bit ints in the compiled version, hmm...unlikely to be a problem regardless.
| } | ||
|
|
||
| void FixJsAsync::min_post_force(int) { | ||
| ++step_count; |
Collaborator
There was a problem hiding this comment.
Should this be reset after a successful minimization?
| namespace LAMMPSWebAsync { | ||
| namespace { | ||
| emscripten::val g_step_callback = emscripten::val::undefined(); | ||
| emscripten::val g_promise_waiter = emscripten::val::undefined(); |
Collaborator
There was a problem hiding this comment.
These are global so it means we can only have one LAMMPS instance at the same time (afaik)? Anything we could do here instead?
| (err) => { | ||
| module.HEAP32[errPtr >> 2] = 1; | ||
| module.HEAP32[donePtr >> 2] = 1; | ||
| module.__lammpsAsyncError = err; |
| } | ||
| nevery = utils::inumeric(FLERR, arg[3], false, lmp); | ||
| if (nevery <= 0) { | ||
| error->all(FLERR, 3, "Illegal fix js/async nevery value {}; must be > 0", nevery); |
andeplane
approved these changes
Feb 19, 2026
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.
Related Issue
Similarly to Atomify, I added fix js/async to hook LAMMPS end-of-step and minimization (MIN_POST_FORCE) and call back into JS via Asyncify, blocking the simulation until the Promise resolves. Still no LAMMPS
core patching, but now we also expose selected compute scalar values in callbacks (in addition to particles/bonds/box snapshots).
runScriptWithAsyncCallback now supports both run and minimize flows, injects fix js/async automatically when needed, and keeps managed fix state so frequency updates can be reused safely across runs. It also handles sync throw cleanup correctly (callback is always cleared).
Callback payload still returns simulation snapshots by default (particles/bonds/box), and now optionally includes computeScalars for requested compute IDs.
ThreeJS example
Tests / stability
Dist packaging