Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: App utilities gRPC services #3552

Merged
merged 42 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
7fd3f4f
feat: App utilities
hpohekar Dec 5, 2024
d732e88
feat: App utilities
hpohekar Dec 9, 2024
7ab6420
feat: move to session.py
hpohekar Dec 9, 2024
3916437
feat: use service
hpohekar Dec 9, 2024
e1b995c
feat: use service 1
hpohekar Dec 9, 2024
c3588b1
feat: make private
hpohekar Dec 10, 2024
a045068
use match
hpohekar Dec 11, 2024
0bfad0e
version
hpohekar Dec 11, 2024
f779080
set black hook to 310
hpohekar Dec 11, 2024
c744f53
remove version
hpohekar Dec 11, 2024
79b85bf
version usage update
hpohekar Dec 11, 2024
4269c49
build info update 1
hpohekar Dec 11, 2024
ab5343b
error fix
hpohekar Dec 11, 2024
938ca31
api upgrade
hpohekar Dec 11, 2024
68cd7f7
feat: correct a typo
hpohekar Dec 12, 2024
a4dc09e
update handling
hpohekar Dec 16, 2024
1e13e19
update handling 1
hpohekar Dec 16, 2024
0ad99a8
working fine
hpohekar Dec 16, 2024
003eef7
api version 0.3.30
hpohekar Dec 16, 2024
bc6ec2d
Merge branch 'main' into feat/solver_utilities
hpohekar Dec 17, 2024
68929e1
use old and new
hpohekar Dec 17, 2024
9fc90ed
update 1
hpohekar Dec 17, 2024
18ae545
update interface
hpohekar Dec 17, 2024
4f8b5fb
update interface fix
hpohekar Dec 17, 2024
5a079a8
update interface fix 1
hpohekar Dec 17, 2024
d87ff63
update interface fix 2
hpohekar Dec 17, 2024
fd6c79e
update interface fix 3
hpohekar Dec 17, 2024
7bb53c4
Revert "update interface fix 3"
hpohekar Dec 17, 2024
8f75ec0
Merge branch 'main' into feat/solver_utilities
hpohekar Dec 18, 2024
81f0075
Merge branch 'main' into feat/solver_utilities
hpohekar Dec 18, 2024
a083f02
Merge branch 'main' into feat/solver_utilities
hpohekar Dec 19, 2024
5af91f0
update session.py
hpohekar Dec 19, 2024
eeaab40
Merge branch 'feat/solver_utilities' of https://github.com/ansys/pyfl…
hpohekar Dec 19, 2024
2e74007
pass callable
hpohekar Dec 19, 2024
88c766c
pass callable 1
hpohekar Dec 19, 2024
5366d5c
pass callable 1
hpohekar Dec 19, 2024
4ac6929
test fix 1
hpohekar Dec 19, 2024
6e5bded
test fix 3
hpohekar Dec 19, 2024
0c7687b
Merge branch 'main' into feat/solver_utilities
hpohekar Dec 19, 2024
698148e
test fix 4
hpohekar Dec 19, 2024
23edd91
test fix 4
hpohekar Dec 19, 2024
ce7158b
test fix 5
hpohekar Dec 19, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ repos:
hooks:
- id: black
args: [
--target-version=py39
--target-version=py310
hpohekar marked this conversation as resolved.
Show resolved Hide resolved
]

- repo: https://github.com/pycqa/isort
Expand Down
5 changes: 3 additions & 2 deletions codegen/allapigen.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
from time import time

from ansys.fluent.core import CODEGEN_OUTDIR, FluentMode, FluentVersion, launch_fluent
from ansys.fluent.core.codegen import StaticInfoType, allapigen, print_fluent_version
from ansys.fluent.core.codegen import StaticInfoType, allapigen
from ansys.fluent.core.codegen.print_fluent_version import print_fluent_version
from ansys.fluent.core.search import _generate_api_data
from ansys.fluent.core.utils.fluent_version import get_version_for_file_name

Expand Down Expand Up @@ -60,7 +61,7 @@
t1 = time()
print(f"Time to fetch static info: {t1 - t0:.2f} seconds")
CODEGEN_OUTDIR.mkdir(parents=True, exist_ok=True)
print_fluent_version.generate(version, solver.scheme_eval.scheme_eval)
print_fluent_version(solver._app_utilities)
hpohekar marked this conversation as resolved.
Show resolved Hide resolved
solver.exit()

allapigen.generate(version, static_infos)
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ packages = [

[tool.poetry.dependencies]
python = ">=3.10,<4.0"
ansys-api-fluent = "^0.3.28"
ansys-api-fluent = "^0.3.30"
ansys-platform-instancemanagement = "~=1.0"
ansys-tools-filetransfer = ">=0.1,<0.3"
ansys-units = "^0.3.3"
Expand Down
23 changes: 9 additions & 14 deletions src/ansys/fluent/core/codegen/print_fluent_version.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,21 @@
"""Module to write Fluent version information."""

from ansys.fluent.core import CODEGEN_OUTDIR, launch_fluent
from ansys.fluent.core.utils.fluent_version import get_version_for_file_name
from ansys.fluent.core import CODEGEN_OUTDIR, FluentVersion, launch_fluent


def print_fluent_version(version: str, scheme_eval):
def print_fluent_version(app_utilities):
"""Write Fluent version information to file."""
version = FluentVersion(app_utilities.get_product_version()).number
build_info = app_utilities.get_build_info()
version_file = (CODEGEN_OUTDIR / f"fluent_version_{version}.py").resolve()
with open(version_file, "w", encoding="utf8") as f:
f.write(f'FLUENT_VERSION = "{version}"\n')
f.write(f'FLUENT_BUILD_TIME = "{scheme_eval("(inquire-build-time)")}"\n')
f.write(f'FLUENT_BUILD_ID = "{scheme_eval("(inquire-build-id)")}"\n')
f.write(f'FLUENT_REVISION = "{scheme_eval("(inquire-src-vcs-id)")}"\n')
f.write(f'FLUENT_BRANCH = "{scheme_eval("(inquire-src-vcs-branch)")}"\n')


def generate(version: str, scheme_eval):
"""Write Fluent version information."""
print_fluent_version(version, scheme_eval)
f.write(f'FLUENT_BUILD_TIME = "{build_info["build_time"]}"\n')
f.write(f'FLUENT_BUILD_ID = "{build_info["build_id"]}"\n')
f.write(f'FLUENT_REVISION = "{build_info["vcs_revision"]}"\n')
f.write(f'FLUENT_BRANCH = "{build_info["vcs_branch"]}"\n')


if __name__ == "__main__":
solver = launch_fluent()
version = get_version_for_file_name(session=solver)
generate(version, solver.scheme_eval.scheme_eval)
print_fluent_version(solver._app_utilities)
48 changes: 26 additions & 22 deletions src/ansys/fluent/core/fluent_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@

import ansys.fluent.core as pyfluent
from ansys.fluent.core.services import service_creator
from ansys.fluent.core.services.app_utilities import (
AppUtilitiesOld,
AppUtilitiesService,
)
from ansys.fluent.core.services.scheme_eval import SchemeEvalService
from ansys.fluent.core.utils.execution import timeout_exec, timeout_loop
from ansys.fluent.core.utils.file_transfer_service import RemoteFileTransferStrategy
Expand Down Expand Up @@ -246,15 +250,24 @@ def __init__(self, create_grpc_service, error_state):
self.scheme_eval = service_creator("scheme_eval").create(
self._scheme_eval_service
)
if (
pyfluent.FluentVersion(self.scheme_eval.version)
< pyfluent.FluentVersion.v252
):
self._app_utilities = AppUtilitiesOld(self.scheme_eval)
else:
self._app_utilities_service = create_grpc_service(
AppUtilitiesService, error_state
)
self._app_utilities = service_creator("app_utilities").create(
self._app_utilities_service
)

@property
def product_build_info(self) -> str:
"""Get Fluent build information."""
build_time = self.scheme_eval.scheme_eval("(inquire-build-time)")
build_id = self.scheme_eval.scheme_eval("(inquire-build-id)")
rev = self.scheme_eval.scheme_eval("(inquire-src-vcs-id)")
branch = self.scheme_eval.scheme_eval("(inquire-src-vcs-branch)")
return f"Build Time: {build_time} Build Id: {build_id} Revision: {rev} Branch: {branch}"
build_info = self._app_utilities.get_build_info()
return f'Build Time: {build_info["build_time"]} Build Id: {build_info["build_id"]} Revision: {build_info["vcs_revision"]} Branch: {build_info["vcs_branch"]}'

def get_cortex_connection_properties(self):
"""Get connection properties of Fluent."""
Expand All @@ -263,10 +276,12 @@ def get_cortex_connection_properties(self):
try:
logger.info(self.product_build_info)
logger.debug("Obtaining Cortex connection properties...")
fluent_host_pid = self.scheme_eval.scheme_eval("(cx-client-id)")
cortex_host = self.scheme_eval.scheme_eval("(cx-cortex-host)")
cortex_pid = self.scheme_eval.scheme_eval("(cx-cortex-id)")
cortex_pwd = self.scheme_eval.scheme_eval("(cortex-pwd)")
cortex_info = self._app_utilities.get_controller_process_info()
solver_info = self._app_utilities.get_solver_process_info()
fluent_host_pid = solver_info["process_id"]
cortex_host = cortex_info["hostname"]
cortex_pid = cortex_info["process_id"]
cortex_pwd = cortex_info["working_directory"]
logger.debug("Cortex connection properties successfully obtained.")
except _InactiveRpcError:
logger.warning(
Expand All @@ -282,22 +297,11 @@ def get_cortex_connection_properties(self):

def get_mode(self):
"""Get the mode of a running fluent session."""
from ansys.fluent.core import FluentMode

if self.scheme_eval.scheme_eval("(cx-solver-mode?)"):
mode_str = self.scheme_eval.scheme_eval('(getenv "PRJAPP_APP")')
if mode_str == "flaero_server":
return FluentMode.SOLVER_AERO
elif mode_str == "flicing":
return FluentMode.SOLVER_ICING
else:
return FluentMode.SOLVER
else:
return FluentMode.MESHING
return self._app_utilities.get_app_mode()

def exit_server(self):
"""Exits the server."""
self.scheme_eval.exec(("(exit-server)",))
self._app_utilities.exit()


def _pid_exists(pid):
Expand Down
8 changes: 4 additions & 4 deletions src/ansys/fluent/core/journaling.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
class Journal:
"""Control the writing of Fluent Python journals."""

def __init__(self, scheme_eval):
def __init__(self, app_utilities):
"""__init__ method of Journal class."""
self.scheme_eval = scheme_eval
self._app_utilities = app_utilities

def start(self, file_name: str):
"""Start writing a Fluent Python journal at the specified file_name."""
self.scheme_eval.exec([f'(api-start-python-journal "{file_name}")'])
self._app_utilities.start_python_journal(journal_name=file_name)

def stop(self):
"""Stop writing the Fluent Python journal."""
self.scheme_eval.exec(["(api-stop-python-journal)"])
self._app_utilities.stop_python_journal()
2 changes: 2 additions & 0 deletions src/ansys/fluent/core/services/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Provides a module to create gRPC services."""

from ansys.fluent.core.services.app_utilities import AppUtilities
from ansys.fluent.core.services.batch_ops import BatchOpsService
from ansys.fluent.core.services.datamodel_se import (
DatamodelService as DatamodelService_SE,
Expand All @@ -22,6 +23,7 @@
from ansys.fluent.core.services.transcript import TranscriptService

_service_cls_by_name = {
"app_utilities": AppUtilities,
"health_check": HealthCheckService,
"datamodel": DatamodelService_SE,
"tui": DatamodelService_TUI,
Expand Down
20 changes: 11 additions & 9 deletions src/ansys/fluent/core/services/api_upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import os
from typing import TypeVar

from ansys.fluent.core.services.scheme_eval import SchemeEval
from ansys.fluent.core.services.app_utilities import AppUtilities
from ansys.fluent.core.utils.fluent_version import FluentVersion

_TApiUpgradeAdvisor = TypeVar("_TApiUpgradeAdvisor", bound="ApiUpgradeAdvisor")
Expand All @@ -12,11 +12,17 @@
class ApiUpgradeAdvisor:
"""API upgrade advisor."""

def __init__(self, scheme_eval: SchemeEval, version: str, mode: str) -> None:
def __init__(
self,
app_utilities: AppUtilities,
version: str,
mode: str,
) -> None:
"""Initialize ApiUpgradeAdvisor."""
self._scheme_eval = scheme_eval.scheme_eval
self._app_utilities = app_utilities
self._version = version
self._mode = mode
self._id = None

def _can_advise(self) -> bool:
return (
Expand All @@ -27,16 +33,12 @@ def _can_advise(self) -> bool:

def __enter__(self) -> _TApiUpgradeAdvisor:
if self._can_advise():
self._scheme_eval("(define pyfluent-journal-str-port (open-output-string))")
self._scheme_eval("(api-echo-python-port pyfluent-journal-str-port)")
self._id = self._app_utilities.start_python_journal()
return self

def __exit__(self, exc_type, exc_value, exc_tb) -> None:
if self._can_advise():
self._scheme_eval("(api-unecho-python-port pyfluent-journal-str-port)")
journal_str = self._scheme_eval(
"(close-output-port pyfluent-journal-str-port)"
).strip()
journal_str = (self._app_utilities.stop_python_journal(self._id)).strip()
if (
journal_str.startswith("solver.")
and not journal_str.startswith("solver.tui")
Expand Down
Loading
Loading