Skip to content

feat: Support the use of expression builder objects in settings parameter. - #5546

Draft
prmukherj wants to merge 9 commits into
mainfrom
feat/expr_builder_objs_in_settings_parameter
Draft

prmukherj wants to merge 9 commits into
mainfrom
feat/expr_builder_objs_in_settings_parameter

Conversation

@prmukherj

Copy link
Copy Markdown
Collaborator

Context

What was the situation or problem before this change?

Change Summary

  1. Generic, Fluent-agnostic protocol in the settings layer:

    • Removed the Fluent-coupled machinery: EXPRESSION_DEFINITION_PATHS, _matches_expression_definition_path, _python_name_chain, and _try_render_expression (which keyed off fluent_expr and a hard-coded setup.named_expressions.definition path).
    • Added a domain-neutral protocol the settings layer talks to — settings_str (render), settings_kind (structural tag), settings_dimensions (physical dims) — plus helpers _is_settings_expression, _normalize_dimensions, _leaf_dimensions, _validate_expression_quantity, and _render_settings_expression. flobject no longer references fluent_expr or the offline.expressions package at all.
  2. expr usable wherever an expression string is permitted:

    • Textual.set_state (String/Filename) now accepts expression objects anywhere, not just one whitelisted path, since Fluent string settings broadly accept expressions.
    • RealNumerical.set_state (covers Real/RealList) now accepts expression objects to -->> LLM suggestion: "closing the biggest gap — previously an expr there raised UnhandledQuantity".
  3. Quantity-type checks before str conversion:

    • Expr base now implements settings_str (forwards to the internal fluent_expr), settings_kind, and settings_dimensions. Quantity derives dims from its units; Variable from its VariableDescriptor.dimension. fluent_expr stays as the package-internal renderer.

Rationale

Why was this approach taken?

Impact

What parts of the system or workflows are affected?

Note:
When running against a live session: the dimensional check depends on ansys.units being able to resolve the leaf's SI unit string and the expression's units; anything it can't resolve is treated as "unknown" and tolerated, so it will never spuriously block a valid assignment.

Also added two parametrized tests in test_flobject_expression_integration.py implementing the requested flow — start from an expression string → parse via the builder → read the built object's quantity type → compare with the target parameter's quantity type.

@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@prmukherj prmukherj linked an issue Oct 29, 2026 that may be closed by this pull request

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Dimension-key normalization rejects valid pressure expressions, vector variables bypass scalar-kind checks, and dimensionless, filename, and list settings retain validation gaps.

6 open issues
What changed in this PR

This PR broadens direct assignment of expression-builder objects to PyFluent settings, replacing path-specific integration with a generic settings-expression protocol.

Changes:

  • Adds rendering, structural-kind, and physical-dimension hooks to expression objects.
  • Extends textual and real-valued setters with expression handling and validation before rendering.
  • Updates examples, integration tests, and release notes.
File Description
tests/​expressions/​test_fluent_smoke.py Extends live named-expression assignment checks.
tests/​expressions/​test_flobject_expression_integration.py Tests protocol rendering, validation, and parsed-expression compatibility.
src/​ansys/​fluent/​core/​solver/​flobject.py Adds generic expression handling and quantity validation to settings setters.
src/​ansys/​fluent/​core/​offline/​expressions/​_ast.py Exposes expression rendering, kind, and dimension metadata.
src/​ansys/​fluent/​core/​offline/​expressions/​__init__.py Updates the example to assign expression objects directly.
doc/​changelog.d/​5546.added.md Announces expression-object support in settings parameters.

Review effort: Max

@prmukherj

Copy link
Copy Markdown
Collaborator Author

🟡 Changes recommended

Dimension-key normalization rejects valid pressure expressions, vector variables bypass scalar-kind checks, and dimensionless, filename, and list settings retain validation gaps.

6 open issues

What changed in this PR
This PR broadens direct assignment of expression-builder objects to PyFluent settings, replacing path-specific integration with a generic settings-expression protocol.

Changes:

  • Adds rendering, structural-kind, and physical-dimension hooks to expression objects.
  • Extends textual and real-valued setters with expression handling and validation before rendering.
  • Updates examples, integration tests, and release notes.

File Description
tests/​expressions/​test_fluent_smoke.py Extends live named-expression assignment checks.
tests/​expressions/​test_flobject_expression_integration.py Tests protocol rendering, validation, and parsed-expression compatibility.
src/​ansys/​fluent/​core/​solver/​flobject.py Adds generic expression handling and quantity validation to settings setters.
src/​ansys/​fluent/​core/​offline/​expressions/​_ast.py Exposes expression rendering, kind, and dimension metadata.
src/​ansys/​fluent/​core/​offline/​expressions/​__init__.py Updates the example to assign expression objects directly.
doc/​changelog.d/​5546.added.md Announces expression-object support in settings parameters.
Review effort: Max

All issues have been resolved as per suggestions.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Group updates and command arguments bypass protocol rendering and kind/dimension validation, leaving the new safeguards ineffective on these shared conversion paths.

2 open issues
2 previously missed issues

In code that hasn't changed since last review

Medium severity Preserve operand kind for unary expression validation

src/​ansys/​fluent/​core/​offline/​expressions/​_ast.py:87

builder.parse('-MakeVec(1, 2, 3)') produces a UnaryOp, which inherits Kind.SCALAR, so this hook reports "scalar" for a vector-valued expression. The new scalar Real setter consequently accepts and renders it, although it correctly rejects the unnegated vector. Please preserve the operand's settings kind for unary expressions so negation cannot bypass structural validation.

Medium severity Preserve empty mappings for dimensionless variables

src/​ansys/​fluent/​core/​offline/​expressions/​_ast.py:284

For a descriptor with an empty dimension mapping, this truthiness check returns None instead of {}, treating a known dimensionless variable as unknown. Such a variable can then be assigned to a pressure-valued leaf without the intended dimensional rejection. Check dimension is None so an empty mapping remains dimensionless.

6 resolved since last review

Review effort: Max

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Unresolved issues let dimensionless and negated-vector expressions bypass validation and cause protocol-based filename arguments to fail in pre-execution file hooks.

1 open issue
2 previously missed issues

In code that hasn't changed since last review

Medium severity Preserve operand settings kind when negating expressions

src/​ansys/​fluent/​core/​offline/​expressions/​_ast.py:87

Negating a vector changes its reported settings kind to scalar because UnaryOp inherits ScalarExpr, so a Real leaf accepts -MakeVec(...) even though it rejects MakeVec(...). Forward UnaryOp.__settings_kind__ to its operand and add a regression test for negated vector assignment.

Medium severity Treat empty dimension mappings as known dimensionless

src/​ansys/​fluent/​core/​offline/​expressions/​_ast.py:284

An empty descriptor dimension mapping is known dimensionless, not unknown. This truthiness check returns None for dimension={}, so a dimensionless variable bypasses validation against a pressure-valued leaf; the equivalent mapping {'LENGTH': 0.0} correctly normalizes to {} and is rejected. Check explicitly for None so empty mappings retain their dimensionless meaning.

2 resolved since last review

Review effort: Max

@prmukherj
prmukherj requested a max review from Copilot October 30, 2026 15:27

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

@prmukherj
prmukherj requested a balanced review from Copilot October 30, 2026 15:29

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Using expression builder objects in settings parameters

3 participants