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

Add parallel capable ps sweep #103

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
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
40 changes: 24 additions & 16 deletions backend/app/internal/flowsheet_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,19 @@

if sys.version_info < (3, 10):
from importlib_resources import files

importlib_old = True
else:
from importlib.resources import files

importlib_old = False
from importlib import metadata
from pathlib import Path
import time
from types import ModuleType
from typing import Optional, Dict, List, Union
import app
from multiprocessing import cpu_count

# third-party
from fastapi import HTTPException
Expand Down Expand Up @@ -78,7 +81,9 @@ def __init__(self, **kwargs):
self.startup_time = time.time()

# Add custom flowsheets path to the system path
self.custom_flowsheets_path = self.app_settings.data_basedir / "custom_flowsheets"
self.custom_flowsheets_path = (
self.app_settings.data_basedir / "custom_flowsheets"
)
sys.path.append(str(self.custom_flowsheets_path))

for package in self.app_settings.packages:
Expand Down Expand Up @@ -205,9 +210,7 @@ def get_diagram(self, id_: str) -> bytes:
# _log.info(f"inside get diagram:: info is - {info}")
if info.custom:
# do this
data_path = (
self.app_settings.custom_flowsheets_dir / f"{info.id_}.png"
)
data_path = self.app_settings.custom_flowsheets_dir / f"{info.id_}.png"
data = data_path.read_bytes()

else:
Expand Down Expand Up @@ -470,7 +473,7 @@ def add_custom_flowsheet(self, new_files, new_id):

query = tinydb.Query()
try:

custom_flowsheets_dict = self._histdb.search(
query.fragment({"custom_flowsheets_version": VERSION})
)
Expand Down Expand Up @@ -547,7 +550,7 @@ def remove_custom_flowsheet(self, id_):
_log.info(f"unable to delete {id_} from flowsheets list")

self.add_custom_flowsheets()

def remove_custom_flowsheet_files(self, flowsheet_files):
# remove each file
for flowsheet_file in flowsheet_files:
Expand Down Expand Up @@ -578,35 +581,40 @@ def add_custom_flowsheets(self):

def get_number_of_subprocesses(self):
# _log.info(f'getting number of subprocesses')
maxNumberOfSubprocesses = 8
maxNumberOfSubprocesses = (
int(cpu_count()) - 1
) # this will get max number of processors on system reserve 1 for UI

query = tinydb.Query()
item = self._histdb.search(query.fragment({"version": VERSION, "name": "numberOfSubprocesses"}))
# _log.info(f'item is : {item}')
item = self._histdb.search(
query.fragment({"version": VERSION, "name": "numberOfSubprocesses"})
)
_log.info(f"item MS is : {item}")
if len(item) == 0:
# _log.info(f'setting number of subprocesses to be 1')
currentNumberOfSubprocesses = 1
self._histdb.upsert(
{
"version": VERSION,
"name": "numberOfSubprocesses",
"value": currentNumberOfSubprocesses
"value": currentNumberOfSubprocesses,
},
(query.version == VERSION and query.name == "numberOfSubprocesses"),
)
else:
currentNumberOfSubprocesses = item[0]["value"]
# _log.info(f'number of subprocesses is: {currentNumberOfSubprocesses}')
# prevent user from overspecifying number of sub processes on accident and killing thier system

if currentNumberOfSubprocesses > maxNumberOfSubprocesses:
currentNumberOfSubprocesses = maxNumberOfSubprocesses
return currentNumberOfSubprocesses, maxNumberOfSubprocesses

def set_number_of_subprocesses(self, value):
# _log.info(f'setting number of subprocesses to {value}')
query = tinydb.Query()
self._histdb.upsert(
{
"version": VERSION,
"name": "numberOfSubprocesses",
"value": value
},
{"version": VERSION, "name": "numberOfSubprocesses", "value": value},
(query.version == VERSION and query.name == "numberOfSubprocesses"),
)
return value
Expand Down
Loading
Loading