From b6e0d4897009a66b4fa8f7fde20f9b716f11c13d Mon Sep 17 00:00:00 2001 From: Mainak Kundu Date: Fri, 14 Oct 2022 20:00:55 +0530 Subject: [PATCH 1/4] Execute query in PyFluent --- codegen/settingsgen.py | 37 ++++++++++++++++++++++ src/ansys/fluent/core/services/settings.py | 21 ++++++++++++ src/ansys/fluent/core/solver/flobject.py | 8 +++++ 3 files changed, 66 insertions(+) diff --git a/codegen/settingsgen.py b/codegen/settingsgen.py index e06d12abb533..1d1c340e8076 100644 --- a/codegen/settingsgen.py +++ b/codegen/settingsgen.py @@ -76,6 +76,18 @@ def _populate_hash_dict(name, info, cls): else: commands_hash = None + queries = info.get("queries") + if queries: + queries_hash = [] + for qname, qinfo in queries.items(): + for query in getattr(cls, "query_names", None): + query_cls = getattr(cls, query) + if qname == query_cls.fluent_name: + queries_hash.append(_populate_hash_dict(qname, qinfo, query_cls)) + break + else: + queries_hash = None + arguments = info.get("arguments") if arguments: arguments_hash = [] @@ -106,6 +118,7 @@ def _populate_hash_dict(name, info, cls): info.get("help"), children_hash, commands_hash, + queries_hash, arguments_hash, object_hash, ) @@ -115,6 +128,7 @@ def _populate_hash_dict(name, info, cls): cls, children_hash, commands_hash, + queries_hash, arguments_hash, object_hash, ) @@ -131,6 +145,7 @@ def _populate_classes(parent_dir): cls, children_hash, commands_hash, + queries_hash, arguments_hash, object_hash, ) in hash_dict.items(): @@ -141,6 +156,7 @@ def _populate_classes(parent_dir): cls1, children_hash1, commands_hash1, + queries_hash1, arguments_hash1, object_hash1, ) in hash_dict.values(): @@ -171,6 +187,7 @@ def _populate_classes(parent_dir): cls, children_hash, commands_hash, + queries_hash, arguments_hash, object_hash, ) in hash_dict.items(): @@ -205,6 +222,11 @@ def _populate_classes(parent_dir): pchild_name = hash_dict.get(child)[0].__name__ f.write(f"from .{files_dict.get(child)} import {pchild_name}\n") + if queries_hash: + for child in queries_hash: + pchild_name = hash_dict.get(child)[0].__name__ + f.write(f"from .{files_dict.get(child)} import {pchild_name}\n") + if arguments_hash: for child in arguments_hash: pchild_name = hash_dict.get(child)[0].__name__ @@ -261,6 +283,21 @@ def _populate_classes(parent_dir): f.write(f"{istr1}{command} command of {cls_name}.") f.write(f'\n{istr1}"""\n') + # write query objects + query_names = getattr(cls, "query_names", None) + if query_names: + f.write(f"{istr1}query_names = \\\n") + strout = io.StringIO() + pprint.pprint(query_names, stream=strout, compact=True, width=70) + mn = ("\n" + istr2).join(strout.getvalue().strip().split("\n")) + f.write(f"{istr2}{mn}\n\n") + + for query in query_names: + f.write(f"{istr1}{query}: {query} = {query}\n") + f.write(f'{istr1}"""\n') + f.write(f"{istr1}{query} query of {cls_name}.") + f.write(f'\n{istr1}"""\n') + # write arguments arguments = getattr(cls, "argument_names", None) if arguments: diff --git a/src/ansys/fluent/core/services/settings.py b/src/ansys/fluent/core/services/settings.py index 932cb186ee53..4c26ac3faed1 100644 --- a/src/ansys/fluent/core/services/settings.py +++ b/src/ansys/fluent/core/services/settings.py @@ -61,6 +61,10 @@ def get_static_info(self, request): def execute_cmd(self, request): return self.__stub.ExecuteCommand(request, metadata=self.__metadata) + @catch_grpc_error + def execute_query(self, request): + return self.__stub.ExecuteQuery(request, metadata=self.__metadata) + @catch_grpc_error def get_attrs(self, request): return self.__stub.GetAttrs(request, metadata=self.__metadata) @@ -220,6 +224,11 @@ def _extract_static_info(self, info): child.name: self._extract_static_info(child.value) for child in info.commands } + if info.queries: + ret["queries"] = { + child.name: self._extract_static_info(child.value) + for child in info.queries + } if info.arguments: ret["arguments"] = { child.name: self._extract_static_info(child.value) @@ -273,6 +282,18 @@ def execute_cmd(self, path: str, command: str, **kwds) -> Any: response = self.__service_impl.execute_cmd(request) return self._get_state_from_value(response.reply) + @_trace + def execute_query(self, path: str, query: str, **kwds) -> Any: + """Execute a given query with the provided keyword arguments.""" + request = _get_request_instance_for_path( + SettingsModule.ExecuteQueryRequest, path + ) + request.query = query + self._set_state_from_value(request.args, kwds) + + response = self.__service_impl.execute_query(request) + return self._get_state_from_value(response.reply) + @_trace def _parse_attrs(self, response): ret = {} diff --git a/src/ansys/fluent/core/solver/flobject.py b/src/ansys/fluent/core/solver/flobject.py index 435353094a10..2aae07bf00b0 100644 --- a/src/ansys/fluent/core/solver/flobject.py +++ b/src/ansys/fluent/core/solver/flobject.py @@ -699,6 +699,14 @@ def __call__(self, **kwds): class Query(Base): """Query object.""" + def __init__(self, name: str = None, parent=None): + """__init__ of Command class.""" + super().__init__(name, parent) + if hasattr(self, "argument_names"): + for argument in self.argument_names: + cls = getattr(self.__class__, argument) + self._setattr(argument, cls(None, self)) + def __call__(self, **kwds): """Call a query with the specified keyword arguments.""" newkwds = _get_new_keywords(self, kwds) From 16cad200bfeb6c4bce5d0f033199f3ebbcd1adea Mon Sep 17 00:00:00 2001 From: Mainak Kundu Date: Mon, 17 Oct 2022 10:34:35 +0530 Subject: [PATCH 2/4] Execute query in PyFluent --- src/ansys/fluent/core/solver/flobject.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ansys/fluent/core/solver/flobject.py b/src/ansys/fluent/core/solver/flobject.py index 2aae07bf00b0..562bb98b6b38 100644 --- a/src/ansys/fluent/core/solver/flobject.py +++ b/src/ansys/fluent/core/solver/flobject.py @@ -700,7 +700,7 @@ class Query(Base): """Query object.""" def __init__(self, name: str = None, parent=None): - """__init__ of Command class.""" + """__init__ of Query class.""" super().__init__(name, parent) if hasattr(self, "argument_names"): for argument in self.argument_names: From 4b8a1d074461bbe6703e55135e21756614f60436 Mon Sep 17 00:00:00 2001 From: Mainak Kundu Date: Mon, 17 Oct 2022 11:02:39 +0530 Subject: [PATCH 3/4] Print Fluent version info in CI --- .github/workflows/ci.yml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f60b4514faaf..61e01d6bde04 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -302,6 +302,11 @@ jobs: PYFLUENT_LAUNCH_CONTAINER: 1 FLUENT_IMAGE_TAG: v22.2.0 + - name: Print 22.2 Fluent version info + run: | + cat src/ansys/fluent/core/fluent_version_222.py + python -c "from ansys.fluent.core.solver.settings_222 import SHASH; print(f'SETTINGS_HASH = {SHASH}')" + - name: Cache 23.1 API Code uses: actions/cache@v3 id: cache-231-api-code @@ -334,6 +339,11 @@ jobs: PYFLUENT_LAUNCH_CONTAINER: 1 FLUENT_IMAGE_TAG: v23.1.0 + - name: Print 23.1 Fluent version info + run: | + cat src/ansys/fluent/core/fluent_version_231.py + python -c "from ansys.fluent.core.solver.settings_231 import SHASH; print(f'SETTINGS_HASH = {SHASH}')" + - name: Install again after codegen run: | rm -rf dist From 178cb9982d216e4db60478369a3257bc450d57a5 Mon Sep 17 00:00:00 2001 From: Mainak Kundu Date: Mon, 17 Oct 2022 12:11:47 +0530 Subject: [PATCH 4/4] Fix for 22.2 --- src/ansys/fluent/core/services/settings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ansys/fluent/core/services/settings.py b/src/ansys/fluent/core/services/settings.py index 4c26ac3faed1..56f729fb1d31 100644 --- a/src/ansys/fluent/core/services/settings.py +++ b/src/ansys/fluent/core/services/settings.py @@ -224,7 +224,7 @@ def _extract_static_info(self, info): child.name: self._extract_static_info(child.value) for child in info.commands } - if info.queries: + if hasattr(info, "queries") and info.queries: ret["queries"] = { child.name: self._extract_static_info(child.value) for child in info.queries