Skip to content

Conversation

@henry2004y
Copy link
Owner

Updated the fit_gmm method in flekspy/amrex/particle_data.py to automatically detect a "weight" variable in the particle data. If present, the method now performs weighted resampling of the particles before fitting the Gaussian Mixture Model. This ensures that the GMM fit correctly reflects the weighted distribution of the particle population.

This change also implicitly updates extract_core_population to respect particle weights, as it relies on fit_gmm.

Added a regression test to verify the fix.

Updated the `fit_gmm` method in `flekspy/amrex/particle_data.py` to automatically detect a "weight" variable in the particle data. If present, the method now performs weighted resampling of the particles before fitting the Gaussian Mixture Model. This ensures that the GMM fit correctly reflects the weighted distribution of the particle population.

This change also implicitly updates `extract_core_population` to respect particle weights, as it relies on `fit_gmm`.

Added a regression test to verify the fix.
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @henry2004y, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the fit_gmm function to properly account for particle weights, which is critical for accurately modeling distributions where individual data points have varying importance. By introducing weighted resampling, the Gaussian Mixture Model fit will now be more representative of the true underlying data, directly improving the fidelity of downstream analyses that depend on this model.

Highlights

  • Weighted Resampling in GMM: The fit_gmm method in flekspy/amrex/particle_data.py now automatically detects a 'weight' variable in particle data and performs weighted resampling before fitting the Gaussian Mixture Model. This ensures the GMM accurately reflects the weighted distribution of particles.
  • Implicit Update to extract_core_population: Due to its reliance on fit_gmm, the extract_core_population method implicitly gains the ability to respect particle weights, leading to more accurate core population extraction.
  • New Regression Test: A new regression test (tests/test_weighted_gmm.py) has been added to verify the correct implementation and functionality of weighted GMM fitting.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@codecov
Copy link

codecov bot commented Jan 4, 2026

Codecov Report

❌ Patch coverage is 96.00000% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 78.79%. Comparing base (fc8fb30) to head (8372094).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
tests/test_weighted_gmm.py 95.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #181      +/-   ##
==========================================
+ Coverage   78.34%   78.79%   +0.45%     
==========================================
  Files          31       32       +1     
  Lines        4341     4391      +50     
==========================================
+ Hits         3401     3460      +59     
+ Misses        940      931       -9     

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

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request adds support for weighted particle resampling in fit_gmm, which is a great feature. The implementation is mostly correct, and the new regression test is well-designed.

I've identified a couple of areas for improvement:

  1. In flekspy/amrex/particle_data.py, the resampling logic can be made more robust by applying it directly to rdata before any transformations. This avoids potential bugs if a transform function alters the number of particles. I've also suggested adding a check for negative particle weights to prevent runtime errors.
  2. In tests/test_weighted_gmm.py, making the random data generation deterministic by using a fixed seed will make the test more reliable.

These changes should improve the robustness and reliability of the new functionality. Overall, this is a valuable addition.

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@henry2004y henry2004y merged commit 5aa7655 into main Jan 4, 2026
3 checks passed
@henry2004y henry2004y deleted the weighted-gmm-resampling-13496064438593411501 branch January 4, 2026 16:23
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.

1 participant