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

Fix left column performance #40

Merged
merged 4 commits into from
Feb 20, 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
5 changes: 4 additions & 1 deletion examples/toolkit/pyaedt_toolkit/backend/run_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
from ansys.aedt.toolkits.common.backend.rest_api import app
from ansys.aedt.toolkits.common.backend.rest_api import jsonify
from ansys.aedt.toolkits.common.backend.rest_api import logger
from ansys.aedt.toolkits.common.backend.rest_api import toolkit_api

from api import ToolkitBackend

toolkit_api = ToolkitBackend()


@app.route("/create_geometry", methods=["POST"])
Expand Down
6 changes: 4 additions & 2 deletions examples/toolkit/pyaedt_toolkit/ui/run_frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ def __init__(self):
logger.error(msg)
self.settings_menu.signal_flag = False
self.settings_menu.aedt_version.addItem("Backend OFF")
self.settings_menu.aedt_session.addItem("Backend OFF")
Samuelopez-ansys marked this conversation as resolved.
Show resolved Hide resolved
else:
# Get default properties
be_properties = self.get_properties()
Expand Down Expand Up @@ -115,8 +116,9 @@ def geometry_menu_clicked(self):
# is_left_visible = self.ui.is_left_column_visible()
# current_page = self.ui.load_pages.pages.currentIndex()
self.ui.set_page(self.geometry_menu.geometry_menu_widget)

self.ui.toggle_left_column()
is_left_visible = self.ui.is_left_column_visible()
if not is_left_visible:
self.ui.toggle_left_column()

self.ui.set_left_column_menu(
menu=self.ui.left_column.menus.menu_home,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ def __init__(self, app, selected_project, selected_design, geometry, multiplier)

def run(self):
self.app.ui.progress.progress = 50
import time

time.sleep(1)
success = self.app.create_geometry_toolkit(
self.selected_project, self.selected_design, self.geometry, self.multiplier
)
Expand Down Expand Up @@ -141,8 +139,8 @@ def geometry_button_clicked(self):
self.ui.logger.log(msg)
return False

if self.app.backend_busy():
msg = "toolkit running"
if self.geometry_thread and self.geometry_thread.isRunning() or self.app.backend_busy():
msg = "Toolkit running"
self.ui.logger.log(msg)
self.app.logger.debug(msg)
return False
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ tests = [
"flask",
]
doc = [
"pyaedt[all]",
"ansys-sphinx-theme==0.14.0",
"numpydoc==1.6.0",
"recommonmark==0.7.1",
Expand Down
44 changes: 38 additions & 6 deletions src/ansys/aedt/toolkits/common/backend/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,10 +218,20 @@ def installed_aedt_version() -> List:

# Detect existing AEDT installation
installed_versions = []

for ver in list_installed_ansysem():
installed_versions.append(
"20{}.{}".format(ver.replace("ANSYSEM_ROOT", "")[:2], ver.replace("ANSYSEM_ROOT", "")[-1])
)
if "ANSYSEMSV_ROOT" in ver:
# Handle the special case
installed_versions.append(
"20{}.{} STUDENT".format(
ver.replace("ANSYSEMSV_ROOT", "")[:2], ver.replace("ANSYSEMSV_ROOT", "")[-1]
)
)
else:
installed_versions.append(
"20{}.{}".format(ver.replace("ANSYSEM_ROOT", "")[:2], ver.replace("ANSYSEM_ROOT", "")[-1])
)

logger.debug(str(installed_versions))
return installed_versions

Expand Down Expand Up @@ -356,9 +366,13 @@ def launch_aedt(self) -> bool:
logger.debug("Launching AEDT.")
pyaedt.settings.use_grpc_api = self.properties.use_grpc
pyaedt.settings.enable_logger = self.properties.debug

version, is_student = self.__get_aedt_version()

desktop_args = {
"specified_version": self.properties.aedt_version,
"specified_version": version,
"non_graphical": self.properties.non_graphical,
"student_version": is_student,
}

# AEDT with COM
Expand Down Expand Up @@ -428,9 +442,12 @@ def connect_aedt(self) -> bool:
pyaedt.settings.enable_logger = self.properties.debug
logger.debug("Connecting AEDT.")

version, is_student = self.__get_aedt_version()

desktop_args = {
"specified_version": self.properties.aedt_version,
"specified_version": version,
"non_graphical": self.properties.non_graphical,
"student_version": is_student,
"new_desktop_session": False,
}
if self.properties.use_grpc:
Expand Down Expand Up @@ -524,13 +541,17 @@ def connect_design(self, app_name: Optional[str] = None):
active_design = design_name

if not self.aedtapp and aedt_app:

version, is_student = self.__get_aedt_version()

aedt_app_args = {
"specified_version": self.properties.aedt_version,
"specified_version": version,
"port": self.properties.selected_process,
"non_graphical": self.properties.non_graphical,
"new_desktop_session": False,
"projectname": project_name,
"designname": active_design,
"student_version": is_student,
}
if self.properties.use_grpc:
aedt_app_args["port"] = self.properties.selected_process
Expand Down Expand Up @@ -734,6 +755,17 @@ def get_design_names(self) -> List[str]:

return design_list

def __get_aedt_version(self):
"""Get AEDT version and if student version is used."""
if "STUDENT" in self.properties.aedt_version:
version_text = self.properties.aedt_version.split(" ")
version = version_text[0]
is_student = True
else:
version = self.properties.aedt_version
is_student = False
return version, is_student

def __save_project_info(self):
"""Save project and design info."""
# Save project and design info
Expand Down
17 changes: 12 additions & 5 deletions src/ansys/aedt/toolkits/common/backend/rest_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,11 @@
# SOFTWARE.

from enum import Enum
import json

from flask import Flask
from flask import jsonify
from flask import request

from ansys.aedt.toolkits.common.backend.api import AEDTCommon
from ansys.aedt.toolkits.common.backend.api import ToolkitThreadStatus
from ansys.aedt.toolkits.common.backend.logger_handler import logger

Expand All @@ -39,7 +37,16 @@ class BodyErrorMessage(str, Enum):
INCORRECT_CONTENT = "Body content is not correct."


toolkit_api = AEDTCommon()
try:
from api import ToolkitBackend

toolkit_api = ToolkitBackend()

except ImportError:
from ansys.aedt.toolkits.common.backend.api import AEDTCommon

toolkit_api = AEDTCommon()

app = Flask(__name__)


Expand Down Expand Up @@ -133,8 +140,8 @@ def open_project():
logger.error(msg)
return jsonify(msg), 500

data = body.decode("utf-8")
project_path = json.loads(data)
project_path = body.decode("utf-8")
# project_path = json.loads(data)
response = toolkit_api.open_project(project_path)

if response:
Expand Down
14 changes: 9 additions & 5 deletions src/ansys/aedt/toolkits/common/ui/actions_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,16 @@ def __init__(self):
# Load toolkit icon
self.images_path = os.path.join(os.path.dirname(__file__), "images")

def poll_url(self, url: str, timeout: int = 10):
"""Perform GET requests on an URL.
@staticmethod
def poll_url(url: str, timeout: int = 10):
"""Perform GET requests on URL.

Continuously perform GET requests to the specified URL until a valid response is received.

Parameters
----------
url : str
URL to poll.
timeout : int, optional
Time out in seconds. The default is 10 seconds.

Expand All @@ -71,7 +74,7 @@ def poll_url(self, url: str, timeout: int = 10):
response_content = None
response_success = False
try:
while not response_success and count < 10:
while not response_success and count < timeout:
time.sleep(1)
response = requests.get(url)
response_success = response.ok
Expand Down Expand Up @@ -141,10 +144,11 @@ def set_properties(self, data):
msg = "Set properties failed"
self.log_and_update_progress(msg, log_level="error")

def find_process_ids(self, version):
def find_process_ids(self, version, non_graphical):
try:
be_properties = self.get_properties()
be_properties["aedt_version"] = version
be_properties["non_graphical"] = non_graphical
self.set_properties(be_properties)
response = requests.get(self.url + "/aedt_sessions")
sessions = []
Expand Down Expand Up @@ -206,7 +210,7 @@ def open_project(self, selected_project):
elif res_idle:
self.ui.progress.progress = 0
response = requests.get(self.url + "/health")
if response.ok and response.json() == "toolkit not connected to AEDT":
if response.ok and response.json() == "toolkit is not connected to AEDT.":
response = requests.post(self.url + "/open_project", data=selected_project)
if response.status_code == 200:
msg = "Project opened"
Expand Down
10 changes: 4 additions & 6 deletions src/ansys/aedt/toolkits/common/ui/common_windows/main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,10 @@ def main_clicked(self):
is_progress_visible = self._app.ui.is_progress_visible()

self._app.ui.left_menu.select_only_one(selected_menu.objectName())

if selected_menu.objectName() == "home_menu":
self._app.ui.set_page(self._app.ui.load_pages.home_page)
if selected_menu.objectName() == "home_menu" and not is_left_visible:
self._app.ui.toggle_left_column()
if not is_left_visible:
self._app.ui.toggle_left_column()
self._app.ui.set_left_column_menu(
menu=self._app.ui.left_column.menus.menu_home,
title="Home",
Expand All @@ -107,13 +107,11 @@ def main_clicked(self):
self._app.ui.set_right_column_menu(title="Settings")

elif selected_menu.objectName() == "progress_menu":
if is_left_visible:
self._app.ui.toggle_left_column()
if is_progress_visible:
selected_menu.set_active(False)
self._app.ui.toggle_progress()

elif is_left_visible or selected_menu.objectName() == "close_left_column" or is_right_visible:
elif selected_menu.objectName() == "close_left_column" or is_right_visible:
if self._app.ui.is_left_column_visible():
selected_menu.set_active(False)
self._app.ui.toggle_left_column()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,10 @@ def process_id(self):
if self.signal_flag:
self.aedt_session.clear()
self.aedt_session.addItem("New Session")
non_graphical_pos = self.graphical_mode.position
non_graphical = non_graphical_pos == 24.0
if self.aedt_version.currentText() and self.aedt_version.currentText() != "AEDT not installed":
sessions = self.app.find_process_ids(self.aedt_version.currentText())
sessions = self.app.find_process_ids(self.aedt_version.currentText(), non_graphical)
for pid in sessions:
if sessions[pid] == -1:
self.aedt_session.addItem("Process {}".format(pid))
Expand Down
3 changes: 2 additions & 1 deletion tests/backend/tests_rest_api/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
# Update AEDT settings
setup_aedt_settings(config)


@pytest.fixture(scope="session")
def client(logger, common_temp_dir):
"""Create a test client."""
Expand All @@ -73,7 +74,7 @@ def client(logger, common_temp_dir):
timeout = 60
response = client.get("/wait_thread", json=timeout)
aedt_file = os.path.join(common_temp_dir, "input_data", f"{PROJECT_NAME}.aedt")
client.post("/open_project", json=aedt_file)
client.post("/open_project", data=aedt_file)
assert response.status_code == 200

yield client
Expand Down
Loading