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: Add an inprocess backend to pymapdl #3198

Merged
merged 8 commits into from
Jun 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions doc/changelog.d/3198.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
feat: Add an inprocess backend to pymapdl
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ omit = [
# ignore legacy interfaces
"ansys/mapdl/core/mapdl_console.py",
"ansys/mapdl/core/jupyter.py",
# ignore non exposed interfaces
"ansys/mapdl/core/mapdl_inprocess.py",
]

[tool.coverage.report]
Expand Down
65 changes: 65 additions & 0 deletions src/ansys/mapdl/core/mapdl_inprocess.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Copyright (C) 2024 ANSYS, Inc. and/or its affiliates.
# SPDX-License-Identifier: MIT
#
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

from typing import Optional, Protocol

Check warning on line 23 in src/ansys/mapdl/core/mapdl_inprocess.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/mapdl/core/mapdl_inprocess.py#L23

Added line #L23 was not covered by tests
Gryfenfer97 marked this conversation as resolved.
Show resolved Hide resolved

from ansys.mapdl.core.mapdl import MapdlBase

Check warning on line 25 in src/ansys/mapdl/core/mapdl_inprocess.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/mapdl/core/mapdl_inprocess.py#L25

Added line #L25 was not covered by tests


class _Backend(Protocol):
def run_command(self) -> str: ...

Check warning on line 29 in src/ansys/mapdl/core/mapdl_inprocess.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/mapdl/core/mapdl_inprocess.py#L28-L29

Added lines #L28 - L29 were not covered by tests
Gryfenfer97 marked this conversation as resolved.
Show resolved Hide resolved


class MapdlInProcess(MapdlBase):
def __init__(self, backend: _Backend):
super().__init__(

Check warning on line 34 in src/ansys/mapdl/core/mapdl_inprocess.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/mapdl/core/mapdl_inprocess.py#L32-L34

Added lines #L32 - L34 were not covered by tests
loglevel="WARNING", use_vtk=False, log_apdl=None, print_com=False
)
self._backend = backend
Gryfenfer97 marked this conversation as resolved.
Show resolved Hide resolved
self._cleanup: bool = True
self._name: str = "MapdlInProcess"
self._session_id: Optional[str] = None
Copy link
Collaborator

Choose a reason for hiding this comment

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

This line should be implemented in _MapdlCore. My fault.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It seems to be something specific to the grpc backend.
We can try to move it to mapdl_grpc instead and replace these lines by a _before_run() command implemented in the children.
@koubaa

self._mute: bool = False

Check warning on line 41 in src/ansys/mapdl/core/mapdl_inprocess.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/mapdl/core/mapdl_inprocess.py#L37-L41

Added lines #L37 - L41 were not covered by tests
Copy link
Collaborator

Choose a reason for hiding this comment

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

Probably this one could be also implemented in _MapdlCore.


def _run(self, command: str, verbose: bool = False, mute: bool = False) -> str:
if not command.strip():
raise ValueError("Empty commands not allowed")

Check warning on line 45 in src/ansys/mapdl/core/mapdl_inprocess.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/mapdl/core/mapdl_inprocess.py#L43-L45

Added lines #L43 - L45 were not covered by tests

if len(command) > 639:
raise ValueError("Maximum command length mut be less than 640 characters")

Check warning on line 48 in src/ansys/mapdl/core/mapdl_inprocess.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/mapdl/core/mapdl_inprocess.py#L47-L48

Added lines #L47 - L48 were not covered by tests

return self._backend.run_command(command, verbose, mute).strip()

Check warning on line 50 in src/ansys/mapdl/core/mapdl_inprocess.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/mapdl/core/mapdl_inprocess.py#L50

Added line #L50 was not covered by tests

@property
def name(self) -> str:
return self._name

Check warning on line 54 in src/ansys/mapdl/core/mapdl_inprocess.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/mapdl/core/mapdl_inprocess.py#L52-L54

Added lines #L52 - L54 were not covered by tests

@name.setter
def name(self, name) -> None:
self._name = name

Check warning on line 58 in src/ansys/mapdl/core/mapdl_inprocess.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/mapdl/core/mapdl_inprocess.py#L56-L58

Added lines #L56 - L58 were not covered by tests

def _check_session_id(self) -> None:
pass

Check warning on line 61 in src/ansys/mapdl/core/mapdl_inprocess.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/mapdl/core/mapdl_inprocess.py#L60-L61

Added lines #L60 - L61 were not covered by tests
Comment on lines +52 to +61
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should go to _MapdlCore.


def __repr__(self):
info = super().__repr__()
return info

Check warning on line 65 in src/ansys/mapdl/core/mapdl_inprocess.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/mapdl/core/mapdl_inprocess.py#L63-L65

Added lines #L63 - L65 were not covered by tests
Comment on lines +63 to +65
Copy link
Collaborator

Choose a reason for hiding this comment

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

We are not changing anything from super() I guess it should be implemented (again) in _MapdlCore class.

Loading