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

Open
wants to merge 21 commits into
base: main
Choose a base branch
from
Open

Conversation

hpohekar
Copy link
Collaborator

@hpohekar hpohekar commented Dec 5, 2024

closes #3553

>>> solver._app_utilities.get_product_version() 
'25.2.0'
>>> solver._app_utilities.get_build_info()      
'Build Time: Dec 10 2024 14:19:50 EST Build ID: 39 Revision: 14070d11dc Branch: hpohekar/t1178910/solver_utilities_grpc_service'
>>> solver._app_utilities.get_controller_process_info() 
{'hostname': 'AAPQ13pUvWxQtxN', 'process_id': 69100, 'working_directory': 'D:\\pyfluent'}
>>> solver._app_utilities.get_solver_process_info()     
{'hostname': 'AAPQ13pUvWxQtxN.win.ansys.com', 'process_id': 85668, 'working_directory': 'D:/pyfluent'}
>>> solver._app_utilities.get_app_mode()            
<FluentMode.SOLVER: 'solver'>
>>> solver._app_utilities.start_python_journal("test_pyfluent_journal.py") 

>>> "hi"

> "bye"


>>> solver._app_utilities.stop_python_journal()
>>>
>>> solver._app_utilities.is_beta_enabled()     
False
>>> solver._app_utilities.is_wildcard("hello") 
False
>>> solver._app_utilities.is_wildcard("hello*") 
True
>>>
>>> solver._app_utilities.is_solution_data_available() 
False
>>> > Fast-loading "D:\ANSYSDev\vNNN\fluent\fluent25.2\\addons\afd\lib\hdfio.bin"
Done.
Multicore SMT processors detected. Processor affinity set!

Reading from AAPQ13pUvWxQtxN:"D:/mixing_elbow.msh.h5" in NODE0 mode ...
  Reading mesh ...
       17822 cells,     1 cell zone  ...
          17822 mixed cells,  zone id: 87
       91581 faces,     7 face zones ...
           2168 polygonal wall faces,  zone id: 34
            268 polygonal wall faces,  zone id: 33
            155 polygonal pressure-outlet faces,  zone id: 32
            152 polygonal velocity-inlet faces,  zone id: 31
             55 polygonal velocity-inlet faces,  zone id: 30
           2001 polygonal symmetry faces,  zone id: 29
          86782 mixed interior faces,  zone id: 89
       66417 nodes,     3 node zones ...

Building...
     mesh
     materials,
     interface,
     domains,
     zones,
        Skipping thread 20 of domain 1 (not referenced by grid).
        Skipping thread 21 of domain 1 (not referenced by grid).
        Skipping thread 22 of domain 1 (not referenced by grid).
        Skipping thread 23 of domain 1 (not referenced by grid).
        Skipping thread 24 of domain 1 (not referenced by grid).
        Skipping thread 25 of domain 1 (not referenced by grid).
        Skipping thread 26 of domain 1 (not referenced by grid).
        Skipping thread 27 of domain 1 (not referenced by grid).
        Skipping thread 28 of domain 1 (not referenced by grid).
        wall-elbow
        wall-inlet
        outlet
        cold-inlet
        hot-inlet
        symmetry-xyplane
        interior--elbow-fluid
        elbow-fluid
     parallel,
Done.
Mesh is now scaled to meters.
adjoint/                parallel/               server/
define/                 parametric-study/       solve/
display/                plot/                   surface/
exit                    preferences/            turbo-workflow/
file/                   print-license-usage     views/
mesh/                   report/

> 
Initialize using the hybrid initialization method.

Checking case topology...
-This case has both inlets & outlets
-Pressure information is not available at the boundaries.
 Case will be initialized with constant pressure

        iter            scalar-0

        1               0.000000e+00
        2               0.000000e+00
        3               0.000000e+00
        4               0.000000e+00
        5               0.000000e+00
        6               0.000000e+00
        7               0.000000e+00
        8               0.000000e+00
        9               0.000000e+00
        10              0.000000e+00

Hybrid initialization is done.

Note: Settings to improve the robustness of pathline and
      particle tracking have been automatically enabled.

adjoint/                parallel/               server/
define/                 parametric-study/       solve/
display/                plot/                   surface/
exit                    preferences/            turbo-workflow/
file/                   print-license-usage     views/
mesh/                   report/


>>> solver._app_utilities.is_solution_data_available()
True
>>>
>>> from ansys.fluent.core.streaming_services.events_streaming import SolverEvent
>>> solver._app_utilities.register_pause_on_solution_events(SolverEvent.TIMESTEP_ENDED)
'1'
>>> solver._app_utilities.unregister_pause_on_solution_events('1')                      

>>>

@hpohekar hpohekar changed the title feat: App utilities feat: App utilities gRPC services Dec 5, 2024
@hpohekar hpohekar marked this pull request as draft December 5, 2024 14:13
@hpohekar hpohekar marked this pull request as ready for review December 11, 2024 04:20
@hpohekar hpohekar marked this pull request as draft December 11, 2024 05:47
@hpohekar hpohekar marked this pull request as ready for review December 11, 2024 08:05
codegen/allapigen.py Outdated Show resolved Hide resolved
@seanpearsonuk
Copy link
Collaborator

seanpearsonuk commented Dec 11, 2024

@hpohekar Is the AppUtilities interface implemented differently for older (pre 252) versions of Fluent?

@hpohekar
Copy link
Collaborator Author

@hpohekar Is the AppUtilities interface implemented differently for older (pre 252) versions of Fluent?

@seanpearsonuk No. We don't have such cases for app utilities.

@seanpearsonuk
Copy link
Collaborator

@hpohekar Is the AppUtilities interface implemented differently for older (pre 252) versions of Fluent?

@seanpearsonuk No. We don't have such cases for app utilities.
@hpohekar I need some help to understand the design. How are we still supporting the older Fluent versions with these changes? Aren't we switching code that depended on scheme_eval etc to now depend on app_utilities?

@hpohekar
Copy link
Collaborator Author

@hpohekar Is the AppUtilities interface implemented differently for older (pre 252) versions of Fluent?

@seanpearsonuk No. We don't have such cases for app utilities.
@hpohekar I need some help to understand the design. How are we still supporting the older Fluent versions with these changes? Aren't we switching code that depended on scheme_eval etc to now depend on app_utilities?

@seanpearsonuk The changes we have made in this PR are independent of Fluent versions.

@mkundu1
Copy link
Contributor

mkundu1 commented Dec 12, 2024

@hpohekar Is the AppUtilities interface implemented differently for older (pre 252) versions of Fluent?

Good point, eventually we'll need another implementation of AppUtilities using scheme-eval to get it working with Fluent version < 25.2. We'll keep the usage code of AppUtilities unchanged, abstracting the version-dependenent implementation inside the services module.

@hpohekar

@hpohekar
Copy link
Collaborator Author

hpohekar commented Dec 12, 2024

@hpohekar Is the AppUtilities interface implemented differently for older (pre 252) versions of Fluent?

Good point, eventually we'll need another implementation of AppUtilities using scheme-eval to get it working with Fluent version < 25.2. We'll keep the usage code of AppUtilities unchanged, abstracting the version-dependenent implementation inside the services module.

@hpohekar

@seanpearsonuk @mkundu1

Yes, got it now. app_utilities.proto will be available in the 25R2 only not in the prior versions. Yes, I agree with both of you. I considered ansys-api-fluent only, for the availability of the app_utilities.proto but it is present in Fluent as well.

return self._stub.Exit(request, metadata=self._metadata)


class AppUtilities:
Copy link
Collaborator

Choose a reason for hiding this comment

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

@hpohekar

  • Methods in this class are generally annotated as returning Any but there is a fixed, concrete return type in each case.

if with_patch:
return f"{response.major}.{response.minor}.{response.patch}"
else:
return f"{response.major}{response.minor}"
Copy link
Collaborator

@seanpearsonuk seanpearsonuk Dec 17, 2024

Choose a reason for hiding this comment

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

@hpohekar The formatting seems to be wrong here. Returning a FluentVersion object would help to avoid such issues.

"""__init__ method of AppUtilities class."""
self.service = service

def get_product_version(self, with_patch: bool = True) -> Any:
Copy link
Collaborator

@seanpearsonuk seanpearsonuk Dec 17, 2024

Choose a reason for hiding this comment

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

@hpohekar with_patch obfuscates this interface. Why not simply return a FluentVersion object and allow the caller to take the information they want?

Comment on lines +190 to +201
def start_python_journal(self, journal_name: str | None = None) -> Any:
"""Start python journal."""
request = AppUtilitiesProtoModule.StartPythonJournalRequest()
request.journal_name = journal_name
response = self.service.start_python_journal(request)
return response

def stop_python_journal(self) -> Any:
"""Stop python journal."""
request = AppUtilitiesProtoModule.StopPythonJournalRequest()
response = self.service.stop_python_journal(request)
return response
Copy link
Collaborator

@seanpearsonuk seanpearsonuk Dec 17, 2024

Choose a reason for hiding this comment

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

@hpohekar These two methods return gRPC responses, which should not be the case. This has added importance when you consider that we will need to substitute different AppUtilities implementations to support older Fluent versions.

Comment on lines +234 to +252
def resume_on_solution_event(self, registration_id: str) -> Any:
"""Resume on solution event."""
request = AppUtilitiesProtoModule.ResumeOnSolutionEventRequest()
request.registration_id = registration_id
response = self.service.resume_on_solution_event(request)
return response

def unregister_pause_on_solution_events(self, registration_id: str) -> Any:
"""Unregister pause on solution events."""
request = AppUtilitiesProtoModule.UnregisterPauseOnSolutionEventsRequest()
request.registration_id = registration_id
response = self.service.unregister_pause_on_solution_events(request)
return response

def exit(self) -> Any:
"""Exit."""
request = AppUtilitiesProtoModule.ExitRequest()
response = self.service.exit(request)
return response
Copy link
Collaborator

Choose a reason for hiding this comment

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

@hpohekar These three methods return gRPC responses.

Comment on lines +374 to +380
if FluentVersion(self.scheme_eval.version) < FluentVersion.v252:
has_wildcard = self._scheme_eval.scheme_eval(
f'(has-fnmatch-wild-card? "{name}")'
)
else:
has_wildcard = self._app_utilities.is_wildcard(name)
return self._scheme_eval.is_defined("has-fnmatch-wild-card?") and has_wildcard
Copy link
Collaborator

Choose a reason for hiding this comment

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

@hpohekar It looks like it shouldn't be too difficult to encapsulate this in the AppUtilities object.

@seanpearsonuk
Copy link
Collaborator

seanpearsonuk commented Dec 17, 2024

@hpohekar Is the AppUtilities interface implemented differently for older (pre 252) versions of Fluent?

Good point, eventually we'll need another implementation of AppUtilities using scheme-eval to get it working with Fluent version < 25.2. We'll keep the usage code of AppUtilities unchanged, abstracting the version-dependenent implementation inside the services module.
@hpohekar

@seanpearsonuk @mkundu1

Yes, got it now. app_utilities.proto will be available in the 25R2 only not in the prior versions. Yes, I agree with both of you. I considered ansys-api-fluent only, for the availability of the app_utilities.proto but it is present in Fluent as well.

Finally, to answer my own question, the following (a commit from today) is the kind of change we are putting in all the calling code. This was my assumption, but I don't think that this question is being addressed anywhere.

image

Two issues here:

  • We have not been clear about the approach.
  • I am not convinced that this approach is more efficient than simply implementing a flexible AppUtilities class from the outset.

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.

Implement app utilities gRPC services
3 participants