Skip to content

feat: add get and create methods and **kwargs support for create#4866

Open
Gobot1234 wants to merge 33 commits into
mainfrom
jhilton/create-and-find
Open

feat: add get and create methods and **kwargs support for create#4866
Gobot1234 wants to merge 33 commits into
mainfrom
jhilton/create-and-find

Conversation

@Gobot1234
Copy link
Copy Markdown
Collaborator

@Gobot1234 Gobot1234 commented Jan 27, 2026

The API surface now looks like which is fairly ORM like

AxisBoundary.get(solver, name='boundary')
AxisBoundary.all(solver)
AxisBoundary.create(solver, name='foo', other='parameters that', are='just values')

Context

Fixes #4863
And adds create and get methods as more clear methods for using name and new_instance_name to the object oriented API

Scope

This PR affects all of the object oriented API, and some of the settings API related code surrounding child creation

This is due to the following changes:

This needs settings api changes that I haven't figured out
Copilot AI review requested due to automatic review settings January 27, 2026 20:52
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

This PR adds get and create class methods to the object-oriented API for clearer alternatives to using name and new_instance_name parameters. The implementation refactors initialization logic into a shared mixin class and enables passing additional kwargs when creating objects.

Changes:

  • Refactored initialization logic into _SettingsInitializerMixin base class
  • Added get class method to _SingletonSetting for retrieving singleton instances
  • Added create class method to _CreatableNamedObjectSetting for creating new instances with optional attributes

Reviewed changes

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

File Description
src/ansys/fluent/core/solver/settings_builtin_bases.py Adds mixin class for shared initialization logic and implements get/create class methods
src/ansys/fluent/core/solver/flobject.py Updates _create_child_object and __getitem__ to accept and pass kwargs, enabling attribute setting during object creation

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

Comment thread src/ansys/fluent/core/solver/settings_builtin_bases.py Outdated
Comment thread src/ansys/fluent/core/solver/flobject.py
Comment thread src/ansys/fluent/core/solver/settings_builtin_bases.py Outdated
Comment thread src/ansys/fluent/core/solver/settings_builtin_bases.py Outdated
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings January 28, 2026 02:24
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

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.


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

Comment thread src/ansys/fluent/core/solver/settings_builtin_bases.py Outdated
Copilot AI review requested due to automatic review settings January 28, 2026 02:51
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

Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.


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

Comment thread src/ansys/fluent/core/solver/settings_builtin_bases.py Outdated
Comment thread src/ansys/fluent/core/solver/flobject.py
Comment thread src/ansys/fluent/core/solver/flobject.py Outdated
Comment thread tests/test_builtin_settings.py
Comment thread tests/test_builtin_settings.py Outdated
@seanpearsonuk
Copy link
Copy Markdown
Collaborator

@Gobot1234 Please can we define the scope of the current work. E.g.:

  • Adding create() and get() methods to the settings classes
  • Allowing creation there without need for a name to be specified?
  • Adding keyword arguments to the settings classes (at creation?)

If we know the scope, it makes it easier to understand the changes. Thanks.

@Gobot1234 Gobot1234 changed the title Add get and create methods to objects feat: get and create methods and **kwarg support for create Jan 28, 2026
@Gobot1234 Gobot1234 changed the title feat: get and create methods and **kwarg support for create feat: add get and create methods and **kwarg support for create Jan 28, 2026
Copilot AI review requested due to automatic review settings January 28, 2026 10:12
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.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings January 28, 2026 10:59
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

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


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

Comment thread src/ansys/fluent/core/solver/settings_builtin_bases.py Outdated
Comment thread src/ansys/fluent/core/solver/settings_builtin_bases.py
Comment thread src/ansys/fluent/core/solver/flobject.py
Copilot AI review requested due to automatic review settings January 28, 2026 12:43
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

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


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

Comment thread src/ansys/fluent/core/codegen/builtin_settingsgen.py Outdated
Comment thread src/ansys/fluent/core/codegen/builtin_settingsgen.py
Comment thread src/ansys/fluent/core/codegen/settingsgen.py
Comment thread src/ansys/fluent/core/solver/settings_builtin_bases.py Outdated
*,
name: str,
) -> Self:
"""Get and return the singleton instance of this object in Fluent.
Copy link

Copilot AI Jan 28, 2026

Choose a reason for hiding this comment

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

The docstring describes this method as returning a 'singleton instance', but this is misleading for a named object that can have multiple instances. Consider changing to 'Get and return the named instance of this object in Fluent.'

Copilot uses AI. Check for mistakes.
Comment thread src/ansys/fluent/core/codegen/builtin_settingsgen.py Outdated
@Gobot1234
Copy link
Copy Markdown
Collaborator Author

I've had some words with both core (cpython) and ty (the typechecker) devs and I've needed to change the codegen a bit more to change the current settings generator script to output pascal cased names in the pyi file so that things don't break (currently they would if you evaluated them at runtime) and so ty is now better supported.

Gobot1234 added 3 commits May 12, 2026 07:03
this api makes no sense to me, why late initialise something like this?
@github-actions github-actions Bot added the documentation Documentation related (improving, adding, etc) label May 12, 2026
Copilot AI review requested due to automatic review settings May 12, 2026 14:20
@Gobot1234 Gobot1234 review requested due to automatic review settings May 12, 2026 14:20
Copilot AI review requested due to automatic review settings May 13, 2026 09:31
Comment thread src/ansys/fluent/core/codegen/builtin_settingsgen.py Outdated
Copy link
Copy Markdown
Collaborator Author

@Gobot1234 Gobot1234 May 12, 2026

Choose a reason for hiding this comment

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

@seanpearsonuk please can I get some feedback on this, I'm not really sure why you'd choose to support late initialisation so I've remove it as it massively complicated the implementation.

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

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

Comments suppressed due to low confidence (2)

src/ansys/fluent/core/solver/settings_builtin_data.py:677

  • DATA is missing reciprocal (singular/plural) links for Pathlines/Pathline. The new get()/all() helpers rely on DATA[...][2]; leaving these as None will cause all() to fail for this named-object type. Add the appropriate reciprocal names so navigation works consistently.
    "Pathlines": (
        "Singleton",
        "results.graphics.pathline",
        None,
    ),
    "Pathline": (
        "NamedObject",
        "results.graphics.pathline",
        None,
    ),

src/ansys/fluent/core/solver/settings_builtin_data.py:764

  • Fluxes declares a reciprocal ("Flux") but the Flux entry leaves its reciprocal as None. This breaks the assumption in the new get()/all() helpers that the reciprocal name exists for named-object wrappers. Set Flux’s reciprocal to "Fluxes" (and ensure the pair is symmetric).
    "Fluxes": (
        "Singleton",
        "results.report.fluxes",
        "Flux",
    ),
    "Flux": (
        "NamedObject",
        "results.report.fluxes",
        None,
    ),

Comment on lines +27 to 31
from typing_extensions import Self

from ansys.fluent.core.generated.solver.settings_261 import root as Settings
from ansys.fluent.core.solver.flobject import (
InactiveObjectError,
Comment thread src/ansys/fluent/core/solver/settings_builtin_bases.py
Comment on lines 533 to 542
"IsoSurfaces": (
"Singleton",
"results.surfaces.iso_surface",
None,
),
"IsoSurface": (
"NamedObject",
"results.surfaces.iso_surface",
None,
),
Comment thread doc/source/user_guide/solver_settings/solver_settings_contents.rst Outdated
Comment on lines 214 to 217
The following examples access the list of allowed values for a particular state of
the viscous model. All string and string list objects have an ``allowed_values()``
method, which returns a list of allowed string values if such a constraint currently applies
for that object or returns ``None`` otherwise.
Comment thread doc/changelog.d/4866.added.md Outdated
Comment on lines +56 to +57
# Generate main .pyi file for the latest version processed
builtin_settingsgen.generate_main_pyi(version)
Copilot AI review requested due to automatic review settings May 13, 2026 09:42
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
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

Copilot reviewed 15 out of 15 changed files in this pull request and generated 6 comments.

Comments suppressed due to low confidence (3)

src/ansys/fluent/core/solver/settings_builtin_bases.py:33

  • Importing ansys.fluent.core.generated.solver.settings_261 in runtime code hard-codes a specific generated version and can raise ImportError in source checkouts / environments where generated modules are not present. Consider avoiding a runtime dependency on a specific generated version (e.g., move this import under TYPE_CHECKING, or type settings as SettingsBase / a Protocol instead of a concrete generated root).
from typing import Any, Protocol, cast, runtime_checkable

from typing_extensions import Self

from ansys.fluent.core.generated.solver.settings_261 import root as Settings
from ansys.fluent.core.solver.flobject import (
    InactiveObjectError,
    NamedObject,
    SettingsBase,

src/ansys/fluent/core/solver/settings_builtin_data.py:677

  • Pathlines / Pathline have None for the reciprocal field, but the new builtin .all() implementation expects the reciprocal name to exist. Consider setting Pathlines -> Pathline and Pathline -> Pathlines (or otherwise ensuring .all() doesn't depend on missing reciprocals) to prevent runtime errors.
    "Pathlines": (
        "Singleton",
        "results.graphics.pathline",
        None,
    ),
    "Pathline": (
        "NamedObject",
        "results.graphics.pathline",
        None,
    ),

src/ansys/fluent/core/solver/settings_builtin_data.py:764

  • Flux is missing its reciprocal (it is None), while Fluxes points at Flux. With the new .all() implementation depending on reciprocals, calling Flux(...).all() will fail. Consider setting Flux -> Fluxes (and verifying other NamedObject entries have reciprocals where .all() is expected to work).
    "Fluxes": (
        "Singleton",
        "results.report.fluxes",
        "Flux",
    ),
    "Flux": (
        "NamedObject",
        "results.report.fluxes",
        None,
    ),

Comment on lines +198 to +203
return cast(
list[Self],
list(
_get_settings_obj(
self.settings_source,
DATA[self._db_name][2],
Comment on lines +320 to 329
# Only pass name if it's not None to avoid sending name=None to Fluent

return cast(
Self,
_get_settings_obj(self.settings_source, self._db_name).create(
name, **kwargs
),
)


Comment thread src/ansys/fluent/core/solver/settings_builtin_data.py
Comment thread doc/source/user_guide/solver_settings/solver_settings_contents.rst
Comment thread doc/source/user_guide/solver_settings/solver_settings_contents.rst
Comment thread doc/changelog.d/4866.added.md Outdated
@Gobot1234 Gobot1234 changed the title feat: add get and create methods and **kwarg support for create feat: add get and create methods and **kwargs support for create May 14, 2026
Copilot AI review requested due to automatic review settings May 14, 2026 10:28
@Gobot1234 Gobot1234 review requested due to automatic review settings May 14, 2026 10:28
Copilot AI review requested due to automatic review settings May 14, 2026 10:46
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

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

Comments suppressed due to low confidence (1)

src/ansys/fluent/core/services/batch_ops_v1.py:1

  • src/ansys/fluent/core/services/batch_ops_v1.py is deleted in this PR, but src/ansys/fluent/core/services/__init__.py still has from ansys.fluent.core.services.batch_ops_v1 import BatchOpsService at line 28. Importing the package will fail with a ModuleNotFoundError at startup. Either restore the module or remove/replace the import (and any downstream usages of BatchOpsService). The deletion of this file (and the related rewrites to datamodel_se_v1.py) also appear to be unrelated to the stated scope of this PR (adding get/create/all and kwargs support); consider extracting them into a separate change.

Comment on lines 186 to +299
@@ -246,6 +241,12 @@ def update_dict(
"""RPC UpdateDict of DataModel service."""
return self._stub.UpdateDict(request, metadata=self._metadata)

def create_object(
self, request: DataModelProtoModule.CreateObjectRequest
) -> DataModelProtoModule.CreateObjectResponse:
"""RPC CreateObject of DataModel service."""
return self._stub.CreateObject(request, metadata=self._metadata)

def delete_object(
self, request: DataModelProtoModule.DeleteObjectRequest
) -> DataModelProtoModule.DeleteObjectResponse:
@@ -291,17 +292,11 @@ def delete_command_arguments(
"supported from Ansys 2023R2 onward."
) from None

def get_specs(
self, request: DataModelProtoModule.GetSpecsRequest
) -> DataModelProtoModule.GetSpecsResponse:
"""RPC GetSpecs of DataModel service."""
return self._stub.GetSpecs(request, metadata=self._metadata)

def get_static_info(
self, request: DataModelProtoModule.GetStaticInfoRequest
) -> DataModelProtoModule.GetStaticInfoResponse:
"""RPC GetStaticInfo of DataModel service."""
return self._stub.GetStaticInfo(request, metadata=self._metadata)
def get_schema(
self, request: DataModelProtoModule.GetSchemaRequest
) -> DataModelProtoModule.GetSchemaResponse:
"""RPC GetSchema of DataModel service."""
return self._stub.GetSchema(request, metadata=self._metadata)
Comment on lines +129 to +134
def __init__(
self,
settings_source: SettingsBase[object] | Solver | None = None,
/,
**kwargs: Any,
):
>>> velocity_request = VectorFieldDataRequest(
>>> field_name=VariableCatalog.VELOCITY,
>>> surfaces=VelocityInlets(settings_source=solver_session),
>>> surfaces=VelocityInlets(solver_session).get("inlet"),
Comment on lines 1805 to 1808
elif k in obj.argument_names:
newkwds[k] = v
else:
elif k not in obj.get_active_child_names():
unknown_keywords.add(k)
Comment on lines +166 to +182
db_name_to_use = DATA[self.__class__._db_name][2]
if db_name_to_use is not None:
self.__dict__["_db_name"] = db_name_to_use
settings_root = _get_settings_root(effective_source)
if self._should_materialize():
# Create extras dict with navigation params only (exclude wrapper params)
extras = {
k: v for k, v in self.__dict__.items() if k not in {"name", "kwargs"}
}
parent = _get_settings_obj(settings_root, self._db_name, extras=extras)
obj = self._init_settings_instance(parent)
_swap(self, settings_root, obj)
if db_name_to_use is not None:
self.__dict__["_db_name"] = db_name_to_use
else:
super().__setattr__(name, value)
# Container proxy: store session for get()/all().
self.__dict__["settings_source"] = settings_root
pyi_entries = [] # list of (decorator: str|None, class_def: str)
base_class_names = set() # PascalCase names to import from settings_{version}
for legacy_name, v in DATA.items():
kind, path, recip = v # reciprical name (singleton -> parent, parent -> singleton)
comps = path.split(".")
for comp in comps:
cls = cls._child_classes[comp]
# Check if the class has 'create' its command names (singletons) or its child classes (deprecated plural forms)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Documentation related (improving, adding, etc) new feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support for kwargs that pass through to the instance properties in .create() and the object oriented types

4 participants