Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 10, 2026

This PR does several things

  • adds a vector size function that is reused by both the python and javascript wrappers
  • adds a few apis to the musica state/micm classes which allows us to drop the wrappers in wasm
  • Exclusively uses embind (to the best of my ability) to marshal data between javascript/c++
  • Allows the javascript solver to use any number of grid cells, regardless of solver type, by abstracing getting/setting data onto the state
    • We may want to think about doing the same thing with Python, though that would mean we would be using the c-interface less. Unsure what tradeoff is best
  • refactors the javascript tests to reduce duplication and expand the number of options we test

Fixes #697

Copilot AI changed the title [WIP] Update vector length usage in JavaScript Fix JavaScript state indexing for vector-ordered matrices Jan 10, 2026
Copilot AI requested a review from K20shores January 10, 2026 14:16
@codecov-commenter
Copy link

codecov-commenter commented Jan 10, 2026

Codecov Report

❌ Patch coverage is 49.18919% with 94 lines in your changes missing coverage. Please review.
✅ Project coverage is 75.80%. Comparing base (24811ee) to head (4457d66).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/micm/state.cpp 0.00% 66 Missing ⚠️
javascript/micm/solver.js 73.91% 12 Missing ⚠️
javascript/micm/state.js 83.01% 9 Missing ⚠️
src/micm/micm_c_interface.cpp 0.00% 5 Missing ⚠️
src/micm/micm.cpp 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #729      +/-   ##
==========================================
- Coverage   76.63%   75.80%   -0.83%     
==========================================
  Files         108      108              
  Lines        7849     7974     +125     
==========================================
+ Hits         6015     6045      +30     
- Misses       1834     1929      +95     
Flag Coverage Δ
cpp_fortran 68.49% <7.59%> (-1.11%) ⬇️
javascript 92.21% <80.18%> (-1.80%) ⬇️
python 82.75% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes JavaScript state indexing for vector-ordered matrices by refactoring the WASM bindings to exclusively use embind for data marshaling between JavaScript and C++. The implementation adds new APIs to the musica state/micm classes, consolidates the vector size function for reuse across wrappers, and extends support for any number of grid cells regardless of solver type.

Changes:

  • Added GetMusicaVectorSize() function in C++ for consistent vector size retrieval across Python and JavaScript
  • Implemented new SetConcentrations(), GetConcentrations(), SetRateConstants(), and GetRateConstants() methods on State class that handle vector-ordered matrix indexing
  • Refactored JavaScript bindings to use embind exclusively, removing custom wrapper classes (StateWrapper, MICMWrapper)
  • Expanded JavaScript tests to cover multiple grid cells (1, 5, 10, 20) and all solver types

Reviewed changes

Copilot reviewed 21 out of 22 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
src/micm/state.cpp Added new methods for setting/getting concentrations and rate constants with proper vector-ordered indexing
src/micm/micm_c_interface.cpp Implemented GetMusicaVectorSize() function for determining vector size based on solver type
src/micm/micm.cpp Added convenience constructor accepting config path directly
python/bindings/micm/micm.cpp Updated to use shared GetMusicaVectorSize() function
javascript/src/musica_wasm.cpp Complete rewrite using embind exclusively, removed custom wrapper classes
javascript/src/micm/*.h/cpp Deleted wrapper files, replaced with direct embind bindings
javascript/micm/*.js Updated to use new WASM API with proper parameter naming (airDensities)
javascript/tests/**/*.test.js Refactored tests to reduce duplication and test multiple grid cells/solver types
javascript/CMakeLists.txt Removed wrapper source files from build
package.json Added -DMUSICA_ENABLE_TESTS=OFF to prevent building tests during WASM build
include/musica/micm/*.hpp Added new method declarations and forward declaration to break circular dependency

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@K20shores K20shores marked this pull request as ready for review January 12, 2026 19:54
@K20shores K20shores requested a review from boulderdaze January 12, 2026 19:54
Comment on lines 97 to 100

/// @brief Get the MUSICA vector size
/// @return The MUSICA vector size
std::size_t GetMusicaVectorSize(musica::MICMSolver);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function name could be just GetVectorSize() to be consistent with other functions such as?

size_t GetMaximumNumberOfGridCells(MICM *micm);

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

true

@K20shores K20shores merged commit 244b4de into main Jan 12, 2026
43 of 45 checks passed
@K20shores K20shores deleted the copilot/update-vector-length-usage-js branch January 12, 2026 21:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Update usage of vector length in javascript

4 participants