Skip to content

Conversation

@Gobot1234
Copy link
Collaborator

Context

Duplicate of #4500 but on the ansys remote. Looking at this code more, I realise I've ran pyupgrade on this so don't merge this till I get the rest of the ruff stuff set up. I'm also realising there are 3 issues tied up in this, apologies for that.
Fixes #4489 and fixes #4490
Helps with #4543

Change Summary

Added a bunch of initial types for the public facing library part of #4738

Comment on lines +187 to +200
UnexpectedKeywordArgument
If an unexpected keyword argument is provided.
Notes
-----
In job scheduler environments (e.g., SLURM, LSF, PBS), resources and compute nodes are allocated,
and core counts are queried from these environments before being passed to Fluent.
"""
insecure_mode_env = os.getenv("PYFLUENT_CONTAINER_INSECURE_MODE") == "1"
if certificates_folder is None and not insecure_mode and not insecure_mode_env:
raise ValueError(
"To launch Fluent in secure gRPC mode, set `certificates_folder`."
)
if certificates_folder is not None and insecure_mode:
raise ValueError(
"`certificates_folder` and `insecure_mode` cannot be set at the same time."
)

locals_ = locals().copy()
argvals = {
arg: locals_.get(arg)
for arg in inspect.getargvalues(inspect.currentframe()).args
}
self.argvals, self.new_session = _get_argvals_and_session(argvals)
if self.argvals["start_timeout"] is None:
self.argvals, self.new_session = _get_argvals_and_session(
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This was changed as sadly there's no way to type transform a typedict to have optional keys (python isn't typescript, sad)

Comment on lines 131 to 229

@property
def tui(self):
def tui(self) -> "main_menu":
"""Instance of ``main_menu`` on which Fluent's SolverTUI methods can be
executed."""
return self._base_meshing.tui
return cast("main_menu", self._base_meshing.tui)

@property
def meshing(self):
def meshing(self) -> "meshing_root":
"""Datamodel root of meshing."""
return self._base_meshing.meshing
return cast("meshing_root", self._base_meshing.meshing)

@property
def meshing_utilities(self):
def meshing_utilities(self) -> "meshing_utilities_root | None":
"""Datamodel root of meshing_utilities."""
return self._base_meshing.meshing_utilities
if self.get_fluent_version() >= FluentVersion.v242:
return cast("meshing_utilities_root", self._base_meshing.meshing_utilities)
return None

@property
def workflow(self):
def workflow(self) -> "workflow_root":
"""Datamodel root of workflow."""
return self._base_meshing.workflow
return cast("workflow_root", self._base_meshing.workflow)

@property
def meshing_workflow(self):
"""Full API to meshing and meshing_workflow."""
return self._base_meshing.meshing_workflow
return cast("meshing_workflow_root", self._base_meshing.meshing_workflow)

def watertight(self):
"""Get a new watertight workflow."""
return self._base_meshing.watertight_workflow()

def fault_tolerant(self):
"""Get a new fault-tolerant workflow."""
return self._base_meshing.fault_tolerant_workflow()

def two_dimensional_meshing(self):
"""Get a new 2D meshing workflow."""
return self._base_meshing.two_dimensional_meshing_workflow()

def load_workflow(self, file_path: PathType):
"""Load a saved workflow."""
return self._base_meshing.load_workflow(file_path=os.fspath(file_path))

def create_workflow(self):
"""Create a meshing workflow."""
return self._base_meshing.create_workflow()

@property
def current_workflow(self):
"""Current meshing workflow."""
return self._base_meshing.current_workflow

def topology_based(self):
"""Get a new topology-based meshing workflow.
Raises
------
AttributeError
If beta features are not enabled in Fluent.
"""
if not self._is_beta_enabled:
raise BetaFeaturesNotEnabled("Topology-based meshing")
return self._base_meshing.topology_based_meshing_workflow()

@property
def PartManagement(self):
def PartManagement(self) -> "partmanagement_root":
"""Datamodel root of PartManagement."""
return self._base_meshing.PartManagement
return cast("partmanagement_root", self._base_meshing.PartManagement)

@property
def PMFileManagement(self):
def PMFileManagement(self) -> "pmfilemanagement_root":
"""Datamodel root of PMFileManagement."""
return self._base_meshing.PMFileManagement
return cast("pmfilemanagement_root", self._base_meshing.PMFileManagement)

@property
def preferences(self):
def preferences(self) -> "preferences_root":
"""Datamodel root of preferences."""
return self._base_meshing.preferences
return cast("preferences_root", self._base_meshing.preferences)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

These need to be reconsidered cause they currently will not work as they are trying to use modules as types which isn't supported. @mkundu1 is there a class version of these (in pyi form) that we could use instead to make type checkers happy?

def __call__(self):
return self.get_state()

def __getattribute__(self, item: str):
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This needs better typing desperately as it will allow you use basically anything at type time currently

@Gobot1234
Copy link
Collaborator Author

I'll try and get to the conflicts soonish, probably more useful to get the ruff changes in first

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.

Avoid having default None where a more informative default can be provided Make launch/connect_to_fluent and kwarg only

2 participants