FIX: Handle zero-valued expression variables properly.#6376
Merged
Conversation
I noticed the Hfss.evaluate_expression() method was incorrectly
returning the symbolic value of an expression, instead of the float
value, when the expression evaluated to zero.
For example, this code would print the string 'test - test' instead of
0.0 as expected:
app = Hfss("ZeroVariableTest")
app['x'] = '10 mm'
app["test"] = 'x / 1mm'
print(f'{app.evaluate_expression('test - test')=}') # should be 0.0
I tracked it down to the Variable class constructor, where `si_value'
was being directly used as a truth value:
if si_value:
self._value = si_value
else:
self._value = self._calculated_value
Unfortunately, float(0.0) is a Falsy value in Python (`bool(0.0) ==
False`), so the above incorrectly treats a 0.0 float the same as
None. The correct condition for None-ness is `if si_value is not None`
instead of `if si_value`.
(cherry picked from commit 2e0c753)
Contributor
|
Thanks for opening a Pull Request. If you want to perform a review write a comment saying: @ansys-reviewer-bot review |
7 tasks
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #6376 +/- ##
==========================================
- Coverage 85.36% 85.35% -0.02%
==========================================
Files 175 175
Lines 65989 65989
==========================================
- Hits 56333 56326 -7
- Misses 9656 9663 +7 🚀 New features to boost your workflow:
|
SMoraisAnsys
approved these changes
Jul 10, 2025
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.
I noticed the Hfss.evaluate_expression() method was incorrectly returning the symbolic value of an expression, instead of the float value, when the expression evaluated to zero.
For example, this code would print the string 'test - test' instead of 0.0 as expected:
I tracked it down to the Variable class constructor, where `si_value' was being directly used as a truth value:
Unfortunately, float(0.0) is a Falsy value in Python (
bool(0.0) == False), so the above incorrectly treats a 0.0 float the same as None. The correct condition for None-ness isif si_value is not Noneinstead ofif si_value.(cherry picked from commit 2e0c753)
Description
Please provide a brief description of the changes made in this pull request.
Issue linked
Please mention the issue number or describe the problem this pull request addresses.
Checklist