-
Notifications
You must be signed in to change notification settings - Fork 43
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/pypim #445
Merged
Merged
Feat/pypim #445
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -137,6 +137,7 @@ def __init__( | |
channel: grpc.Channel = None, | ||
cleanup_on_exit: bool = True, | ||
start_transcript: bool = True, | ||
remote_instance=None, | ||
): | ||
"""Instantiate a Session. | ||
|
||
|
@@ -165,14 +166,20 @@ def __init__( | |
The Fluent transcript is started in the client only when | ||
start_transcript is True. It can be started and stopped | ||
subsequently via method calls on the Session object. | ||
remote_instance : ansys.platform.instancemanagement.Instance | ||
The corresponding remote instance when Fluent is launched through | ||
PyPIM. This instance will be deleted when calling | ||
``Session.exit()``. | ||
""" | ||
self._channel_str = None | ||
if channel is not None: | ||
self._channel = channel | ||
else: | ||
if not ip: | ||
ip = os.getenv("PYFLUENT_FLUENT_IP", "127.0.0.1") | ||
if not port: | ||
port = os.getenv("PYFLUENT_FLUENT_PORT") | ||
self._channel_str = f"{ip}:{port}" | ||
if not port: | ||
raise ValueError( | ||
"The port to connect to Fluent session is not provided." | ||
|
@@ -229,6 +236,8 @@ def __init__( | |
if start_transcript: | ||
self.start_transcript() | ||
|
||
self._remote_instance = remote_instance | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a reason this is there 2x? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, this is a bad merge, resolving conflicts |
||
|
||
@classmethod | ||
def create_from_server_info_file( | ||
cls, | ||
|
@@ -320,6 +329,9 @@ def exit(self) -> None: | |
self._channel.close() | ||
self._channel = None | ||
|
||
if self._remote_instance: | ||
self._remote_instance.delete() | ||
|
||
def __enter__(self): | ||
"""Close the Fluent connection and exit Fluent.""" | ||
return self | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
"""Test the PyPIM integration.""" | ||
from unittest.mock import create_autospec | ||
|
||
import grpc | ||
from util.solver_workflow import new_solver_session # noqa: F401 | ||
|
||
from ansys.fluent.core.launcher import launcher | ||
import ansys.platform.instancemanagement as pypim | ||
|
||
|
||
def test_launch_remote_instance(monkeypatch, new_solver_session): | ||
fluent = new_solver_session | ||
# Create a mock pypim pretenting it is configured and returning a channel to an already running Fluent | ||
mock_instance = pypim.Instance( | ||
definition_name="definitions/fake-fluent", | ||
name="instances/fake-fluent", | ||
ready=True, | ||
status_message=None, | ||
services={"grpc": pypim.Service(uri=fluent._channel_str, headers={})}, | ||
) | ||
pim_channel = grpc.insecure_channel( | ||
fluent._channel_str, | ||
) | ||
mock_instance.wait_for_ready = create_autospec(mock_instance.wait_for_ready) | ||
mock_instance.build_grpc_channel = create_autospec( | ||
mock_instance.build_grpc_channel, return_value=pim_channel | ||
) | ||
mock_instance.delete = create_autospec(mock_instance.delete) | ||
|
||
mock_client = pypim.Client(channel=grpc.insecure_channel("localhost:12345")) | ||
mock_client.create_instance = create_autospec( | ||
mock_client.create_instance, return_value=mock_instance | ||
) | ||
|
||
mock_connect = create_autospec(pypim.connect, return_value=mock_client) | ||
mock_is_configured = create_autospec(pypim.is_configured, return_value=True) | ||
monkeypatch.setattr(pypim, "connect", mock_connect) | ||
monkeypatch.setattr(pypim, "is_configured", mock_is_configured) | ||
|
||
# Start fluent with launch_fluent | ||
# Note: This is mocking to start Fluent, but actually reusing the common one | ||
# Thus cleanup_on_exit is set to false | ||
fluent = launcher.launch_fluent(cleanup_on_exit=False) | ||
|
||
# Assert: PyFluent went through the pypim workflow | ||
assert mock_is_configured.called | ||
assert mock_connect.called | ||
mock_client.create_instance.assert_called_with( | ||
"fluent-3ddp", product_version=launcher.PIM_FLUENT_PRODUCT_VERSION | ||
) | ||
assert mock_instance.wait_for_ready.called | ||
mock_instance.build_grpc_channel.assert_called_with() | ||
|
||
# And it connected using the channel created by PyPIM | ||
assert fluent._channel == pim_channel | ||
|
||
# and it kept track of the instance to be able to delete it | ||
assert fluent._remote_instance == mock_instance |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it need to be public?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only reason was that it is accessed in the added test. So, it's a moot point perhaps.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah ok, I see it now. If it's on purpose that's fine.