Skip to content

tighter test checks#4

Merged
aadityacs merged 1 commit into
mainfrom
lagrange_multipliers
Nov 13, 2025
Merged

tighter test checks#4
aadityacs merged 1 commit into
mainfrom
lagrange_multipliers

Conversation

@aadityacs

Copy link
Copy Markdown
Owner

No description provided.

@gemini-code-assist

Copy link
Copy Markdown

Summary of Changes

Hello @aadityacs, 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 focuses on enhancing the precision and reliability of the test suite by implementing tighter numerical checks. It systematically reduces the tolerance values in several key assertions within mmapy/mma_test.py, ensuring that the tested components adhere more closely to their expected mathematical properties and behaviors. This change aims to improve the overall quality and robustness of the codebase by catching more subtle deviations in calculations.

Highlights

  • Stricter Numerical Tolerances: Reduced acceptable error margins across various numerical assertion checks to improve test precision.
  • Constraint and Multiplier Checks: Tightened the tolerance for constraint activity from "0.1" to "0.05" and the minimum multiplier value from "0.1" to "0.01".
  • Stationarity Condition Checks: Significantly decreased the residual norm tolerance for stationarity at both lower and upper bounds from "0.5" to "0.01".
  • Scaling Relationship Accuracy: Improved the accuracy requirement for multiplier scaling with the objective and the constancy of "lambda * scale" by reducing relative error tolerances from "20-30%" to "1%".
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.

@aadityacs aadityacs merged commit bb1a03f into main Nov 13, 2025
0 of 2 checks passed

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

Copy link
Copy Markdown

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 tightens the tolerances in several tests, making them more precise, which is a great improvement. I've also suggested a couple of minor refactorings to use np.testing.assert_allclose for floating-point comparisons. This is more idiomatic when using NumPy and improves the readability and robustness of the tests.

Comment thread mmapy/mma_test.py
Comment on lines 1140 to 1146
relative_error = abs(actual_lambda - expected_lambda) / max(expected_lambda, 1e-6)

self.assertLess(
relative_error,
0.2, # 20% tolerance
0.01, # 1% tolerance
msg=f"Multiplier should scale with objective. "
f"Expected {expected_lambda:.4f}, got {actual_lambda:.4f}",
)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

While the manual calculation of relative error works, using np.testing.assert_allclose is more idiomatic and robust for comparing floating-point numbers in NumPy-based tests. It clearly expresses the intent of checking for approximate equality with a relative tolerance and handles edge cases around zero more gracefully.

Suggested change
relative_error = abs(actual_lambda - expected_lambda) / max(expected_lambda, 1e-6)
self.assertLess(
relative_error,
0.2, # 20% tolerance
0.01, # 1% tolerance
msg=f"Multiplier should scale with objective. "
f"Expected {expected_lambda:.4f}, got {actual_lambda:.4f}",
)
np.testing.assert_allclose(
actual_lambda,
expected_lambda,
rtol=0.01, # 1% tolerance
err_msg=(
"Multiplier should scale with objective. "
f"Expected {expected_lambda:.4f}, got {actual_lambda:.4f}"
),
)

Comment thread mmapy/mma_test.py
Comment on lines 1252 to 1257
relative_deviation = abs(prod - mean_product) / mean_product
self.assertLess(
relative_deviation,
0.3, # 30% tolerance
0.01, # 1% tolerance
msg="λ * scale should be approximately constant",
)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

For improved readability and to follow common testing patterns with NumPy, consider using np.testing.assert_allclose. This function is designed for comparing floating-point values and makes the intent of a relative tolerance check clearer than manually calculating the deviation.

Suggested change
relative_deviation = abs(prod - mean_product) / mean_product
self.assertLess(
relative_deviation,
0.3, # 30% tolerance
0.01, # 1% tolerance
msg="λ * scale should be approximately constant",
)
np.testing.assert_allclose(
prod,
mean_product,
rtol=0.01, # 1% tolerance
err_msg="λ * scale should be approximately constant",
)

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