Skip to content

External Model State Updates#924

Merged
mattldawson merged 10 commits into
mainfrom
develop-update-model-state
Feb 10, 2026
Merged

External Model State Updates#924
mattldawson merged 10 commits into
mainfrom
develop-update-model-state

Conversation

@mattldawson
Copy link
Copy Markdown
Collaborator

This PR adds the ability for users to access and update the portion of the solver state associated with an external model (e.g., aerosol or cloud models).

Adds square bracket operators to the State class that can be used to set elements of the State.variables_ matrix by variable index or unique name.

Copy link
Copy Markdown
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

Adds square-bracket (operator[]) access to micm::State variables to support convenient external-model state reads/updates by variable index, unique name, or Species.

Changes:

  • Introduced State::operator[] overloads returning proxy objects for scalar and multi-gridcell variable access/mutation.
  • Added unit tests covering proxy assignment, const access, and arithmetic operations.
  • Expanded aerosol-model integration tests to validate updating gas/external-model variables via the new operator[] API (including multi-cell cases).

Reviewed changes

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

File Description
include/micm/solver/state.hpp Declares operator[] overloads and proxy types for state variable access.
include/micm/solver/state.inl Implements proxy behavior (assignment, indexing, arithmetic, comparisons) and operator[] lookups.
test/unit/solver/test_state.cpp Adds unit tests for State::operator[] behavior in single- and multi-cell states.
test/integration/test_aerosol_model.cpp Adds integration tests demonstrating external-model state updates via operator[] and refactors system setup into a helper.

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

Comment thread test/unit/solver/test_state.cpp Outdated
Comment thread include/micm/solver/state.hpp Outdated
Comment thread test/integration/test_aerosol_model.cpp Outdated
Comment thread test/integration/test_aerosol_model.cpp Outdated
Comment thread test/integration/test_aerosol_model.cpp Outdated
Comment thread test/integration/test_aerosol_model.cpp Outdated
Comment thread test/integration/test_aerosol_model.cpp Outdated
mattldawson and others added 7 commits February 6, 2026 14:20
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Feb 6, 2026

Codecov Report

❌ Patch coverage is 80.76923% with 15 lines in your changes missing coverage. Please review.
✅ Project coverage is 94.29%. Comparing base (5816b12) to head (d29001d).
⚠️ Report is 4 commits behind head on main.

Files with missing lines Patch % Lines
include/micm/solver/state.inl 79.16% 15 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #924      +/-   ##
==========================================
- Coverage   94.63%   94.29%   -0.34%     
==========================================
  Files          68       68              
  Lines        3185     3263      +78     
==========================================
+ Hits         3014     3077      +63     
- Misses        171      186      +15     

☔ 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.

Copy link
Copy Markdown
Collaborator

@K20shores K20shores left a comment

Choose a reason for hiding this comment

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

I like it

Comment on lines +75 to +86
class VariableProxy
{
State& state_;
std::size_t index_;

public:
VariableProxy(State& state, std::size_t index)
: state_(state),
index_(index)
{
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

If this PR allows state to be manipulated by square bracket, it would effectively makes the usage of SetConcentration function obsolete. Is this a valid concern? Also I just noticed that State is struct but has public keywords. Should we consider converting State into a class and explicitly defining public/private members?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

We rely on SetConcentration in the wasm layer. Open to updating that if this is better though

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

what if we make SetConcentration deprecated, and then we can remove it as a separate issue at some point? I could also modify this PR to just overload the SetConcetration function, but this seemed a little cleaner to me.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Either way is fine with me

Copy link
Copy Markdown
Collaborator

@boulderdaze boulderdaze Feb 10, 2026

Choose a reason for hiding this comment

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

I like the first approach better, since it lets us evaluate the impact of removing this function on tests/tutorials, as well as on upstream including musica, atmospheric physics and cam-sima (assuming we still care about cam-sima)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

sounds good! I'll add a deprecated comment to the SetConcentration fundtions

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

updated! I like this approach too, it will let the other repos be gradually updated before removing the SetConcentration functions.

I left the SetConcentration() function that takes a map of species to concentrations in place. This wouldn't be covered by the square bracket functions.

Copy link
Copy Markdown
Collaborator

@boulderdaze boulderdaze left a comment

Choose a reason for hiding this comment

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

Thank you for addressing the comments!

@mattldawson mattldawson merged commit d91caef into main Feb 10, 2026
25 of 26 checks passed
@mattldawson mattldawson deleted the develop-update-model-state branch February 10, 2026 16:38
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.

5 participants