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

Foqus cloud #1242

Merged
merged 34 commits into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
608b5e4
Replace time.process_time() with time.time()
boverhof Jan 19, 2023
9af78d4
Merge remote-tracking branch 'upstream/master' into foqus_cloud
boverhof Feb 14, 2023
3e0082c
Merge remote-tracking branch 'upstream/master' into foqus_cloud
boverhof Mar 7, 2023
4096db3
Exception handling
boverhof Mar 7, 2023
7c02310
Backend updates for user plugins
boverhof Mar 10, 2023
9382917
If setttings bad throw runtime error
boverhof Mar 10, 2023
9d76185
Merge pull request #1 from boverhof/boverhof.user_plugins_backend.202…
boverhof Mar 10, 2023
176aa5d
code improvements
boverhof Mar 11, 2023
14c33e7
Ran Black
boverhof Mar 13, 2023
786f1e4
Merge remote-tracking branch 'upstream/master' into foqus_cloud
boverhof Jun 7, 2023
c953148
Merge remote-tracking branch 'upstream/master' into foqus_cloud
boverhof May 30, 2024
70fdb66
Log to CloudWatch using watchtower /user/{username}/ec2/{instance_id}
boverhof May 30, 2024
830a6c2
Log out to CloudWatch using watchtower
boverhof May 30, 2024
8bb96d1
Add Watchtower to installs
boverhof May 30, 2024
b158460
logging file for cloudwatch aws
boverhof May 30, 2024
f135a19
Merge branch 'foqus_cloud' of https://github.com/boverhof/FOQUS into …
boverhof Jun 1, 2024
970d82d
Use core for simsinter and turbineLite home paths
boverhof Jun 26, 2024
270396a
add import
boverhof Jun 26, 2024
843d202
add core
boverhof Jun 26, 2024
1b6495a
change isfile to isdir for install path
boverhof Jun 27, 2024
7ec236d
less logging messages
boverhof Jun 27, 2024
ef445bf
update logging
boverhof Jun 27, 2024
c59a84c
clean code
boverhof Jun 27, 2024
1e6f013
Merge remote-tracking branch 'upstream/master' into foqus_cloud
boverhof Sep 24, 2024
1142414
format with black
boverhof Sep 24, 2024
ed05b38
comment out this override code so tests will pass
boverhof Oct 4, 2024
7102ef6
Merge remote-tracking branch 'upstream/master' into foqus_cloud
boverhof Oct 4, 2024
30b94d3
run black
boverhof Oct 4, 2024
76fdaeb
pylint fixes
boverhof Oct 4, 2024
407d9cb
move functools in front of boto3
boverhof Oct 4, 2024
6863a43
replace header
boverhof Oct 7, 2024
ee9980f
turbine client is required and installed during setup
boverhof Oct 7, 2024
855f93a
remove sphinx deprecation
boverhof Oct 9, 2024
06110ec
fix conflict
boverhof Oct 9, 2024
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
38 changes: 38 additions & 0 deletions cloud/aws/logging.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Default AWS Config
version: 1
disable_existing_loggers: False
formatters:
simple_formatter:
format: "%(levelname)-8s - %(asctime)12s - %(message)s"
handlers:
console:
class: logging.StreamHandler
level: DEBUG
stream: ext://sys.stdout
formatter: simple_formatter
logfile:
class: logging.handlers.RotatingFileHandler
level: DEBUG
filename: watchtower.log
maxBytes: 1000000
backupCount: 3
formatter: simple_formatter
watchtower:
#class: watchtower.CloudWatchLogHandler
class: foqus_lib.service.flowsheet.FoqusCloudWatchLogHandler
level: DEBUG
log_group_name: foqus-cloud-service
#log_stream_name: "{machine_name}-{strftime:%y-%m-%d}"
log_stream_name: "{machine_name}"
send_interval: 10
create_log_group: True
formatter: simple_formatter
root:
level: DEBUG
propagate: True
handlers: [console, logfile, watchtower]
loggers:
botocore:
level: WARN
urllib3:
level: WARN
210 changes: 210 additions & 0 deletions foqus_lib/core.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,210 @@
#################################################################################
# FOQUS Copyright (c) 2012 - 2024, by the software owners: Oak Ridge Institute
# for Science and Education (ORISE), TRIAD National Security, LLC., Lawrence
# Livermore National Security, LLC., The Regents of the University of
# California, through Lawrence Berkeley National Laboratory, Battelle Memorial
# Institute, Pacific Northwest Division through Pacific Northwest National
# Laboratory, Carnegie Mellon University, West Virginia University, Boston
# University, the Trustees of Princeton University, The University of Texas at
# Austin, URS Energy & Construction, Inc., et al. All rights reserved.
#
# Please see the file LICENSE.md for full copyright and license information,
# respectively. This file is also available online at the URL
# "https://github.com/CCSI-Toolset/FOQUS".
#################################################################################
"""
Joshua Boverhof, Lawrence Berkeley National Labs, 2024
"""
import os, shutil, logging

# from foqus_lib.framework.session.session import generalSettings as FoqusSettings


class DependencyTracker:
@classmethod
def available(cls):
"""Returns set of available packages"""
raise NotImplementedError()

Check warning on line 27 in foqus_lib/core.py

View check run for this annotation

Codecov / codecov/patch

foqus_lib/core.py#L27

Added line #L27 was not covered by tests

@classmethod
def unavailable(cls):
"""Returns set of unavailable packages"""
raise NotImplementedError()

Check warning on line 32 in foqus_lib/core.py

View check run for this annotation

Codecov / codecov/patch

foqus_lib/core.py#L32

Added line #L32 was not covered by tests


class ModuleDependencyTracker:
"""tracks imported python modules"""

python_modules_available = {}
python_modules_unavailable = {}
python_module_name = None

@classmethod
def available(cls):
return tuple(cls.python_modules_available.values())

Check warning on line 44 in foqus_lib/core.py

View check run for this annotation

Codecov / codecov/patch

foqus_lib/core.py#L44

Added line #L44 was not covered by tests

@classmethod
def unavailable(cls):
return tuple(cls.python_modules_unavailable.values())

Check warning on line 48 in foqus_lib/core.py

View check run for this annotation

Codecov / codecov/patch

foqus_lib/core.py#L48

Added line #L48 was not covered by tests

@classmethod
def load(cls):
instance = cls.python_modules_available.get(cls.python_module_name)

Check warning on line 52 in foqus_lib/core.py

View check run for this annotation

Codecov / codecov/patch

foqus_lib/core.py#L52

Added line #L52 was not covered by tests
if instance is not None:
return instance
instance = cls()
try:
exec("import %s" % (instance.python_module_name))
except ModuleNotFoundError:
cls.python_modules_unavailable[instance.python_module_name] = instance
raise
instance._module = eval(instance.python_module_name)
cls.python_modules_available[instance.python_module_name] = instance
return instance

Check warning on line 63 in foqus_lib/core.py

View check run for this annotation

Codecov / codecov/patch

foqus_lib/core.py#L54-L63

Added lines #L54 - L63 were not covered by tests

@classmethod
def load_capture_error(cls):
instance = None
try:
instance = cls.load()
except ModuleNotFoundError:
pass
return instance

Check warning on line 72 in foqus_lib/core.py

View check run for this annotation

Codecov / codecov/patch

foqus_lib/core.py#L67-L72

Added lines #L67 - L72 were not covered by tests

def __init__(self):
self._module = None

Check warning on line 75 in foqus_lib/core.py

View check run for this annotation

Codecov / codecov/patch

foqus_lib/core.py#L75

Added line #L75 was not covered by tests

@property
def module(self):
return self._module

Check warning on line 79 in foqus_lib/core.py

View check run for this annotation

Codecov / codecov/patch

foqus_lib/core.py#L79

Added line #L79 was not covered by tests


class ExecutableDependencyTracker(DependencyTracker):
"""tracks optional executables"""

executables_available = dict()
executables_unavailable = dict()
executable_name = None
default_path = None
required = False

@classmethod
def available(cls):
return cls.executables_available.values()

Check warning on line 93 in foqus_lib/core.py

View check run for this annotation

Codecov / codecov/patch

foqus_lib/core.py#L93

Added line #L93 was not covered by tests

@classmethod
def unavailable(cls):
return cls.executables_unavailable.values()

Check warning on line 97 in foqus_lib/core.py

View check run for this annotation

Codecov / codecov/patch

foqus_lib/core.py#L97

Added line #L97 was not covered by tests

@classmethod
def path(cls):
raise NotImplementedError()

Check warning on line 101 in foqus_lib/core.py

View check run for this annotation

Codecov / codecov/patch

foqus_lib/core.py#L101

Added line #L101 was not covered by tests

@classmethod
def load(cls):
assert cls.executable_name is not None
instance = cls.executables_available.get(cls.executable_name)

Check warning on line 106 in foqus_lib/core.py

View check run for this annotation

Codecov / codecov/patch

foqus_lib/core.py#L105-L106

Added lines #L105 - L106 were not covered by tests
if instance is not None:
return instance
instance = cls()

Check warning on line 109 in foqus_lib/core.py

View check run for this annotation

Codecov / codecov/patch

foqus_lib/core.py#L108-L109

Added lines #L108 - L109 were not covered by tests
if not os.path.isfile(instance.path()):
raise RuntimeError("%r: Failed to Load Dependency" % (instance))

Check warning on line 111 in foqus_lib/core.py

View check run for this annotation

Codecov / codecov/patch

foqus_lib/core.py#L111

Added line #L111 was not covered by tests
if not os.access(instance.path(), os.X_OK):
raise RuntimeError(

Check warning on line 113 in foqus_lib/core.py

View check run for this annotation

Codecov / codecov/patch

foqus_lib/core.py#L113

Added line #L113 was not covered by tests
"%r: Dependency Path is not Executable: %s" % (instance.path())
)
cls.executables_available[instance.executable_name] = instance

Check warning on line 116 in foqus_lib/core.py

View check run for this annotation

Codecov / codecov/patch

foqus_lib/core.py#L116

Added line #L116 was not covered by tests


class PsuadeDependencyTracker(ExecutableDependencyTracker):
"""
plugin = PsuadeDependencyTracker.load()
if plugin == None: print("unavailable")
elif plugin.nomad is False: print("nomand unavailable")
"""

required = False
executable_name = "psuade"
default_path = "C:/Program Files (x86)/psuade_project 1.7.5/bin/psuade.exe"

def path(self):
return shutil.which("psuade") or self.default_path

Check warning on line 131 in foqus_lib/core.py

View check run for this annotation

Codecov / codecov/patch

foqus_lib/core.py#L131

Added line #L131 was not covered by tests


class RScriptDependencyTracker(ExecutableDependencyTracker):
required = False
executable_name = "Rscript.exe"
default_path = "C:\\Program Files\\R\\R-3.1.2\\bin\\x64\\Rscript.exe"

@classmethod
def path(cls):
return shutil.which(cls.executable_name) or cls.default_path

Check warning on line 141 in foqus_lib/core.py

View check run for this annotation

Codecov / codecov/patch

foqus_lib/core.py#L141

Added line #L141 was not covered by tests


class WindowsPackageDependencyTracker(DependencyTracker):
"""tracks installed Windows Packages"""

windows_packages_available = {}
windows_packages_unavailable = {}
package_name = None
install_path = None
required = False

@classmethod
def available(cls):
return cls.windows_packages_available.values()

Check warning on line 155 in foqus_lib/core.py

View check run for this annotation

Codecov / codecov/patch

foqus_lib/core.py#L155

Added line #L155 was not covered by tests

@classmethod
def unavailable(cls):
return cls.windows_packages_unavailable.values()

Check warning on line 159 in foqus_lib/core.py

View check run for this annotation

Codecov / codecov/patch

foqus_lib/core.py#L159

Added line #L159 was not covered by tests

@classmethod
def load(cls):
instance = cls.windows_packages_available.get(cls.package_name)
instance = instance or cls()
if not os.path.isdir(instance.path):
if cls.required:
raise RuntimeError("Install Path Does Not Exist: %s" % (instance.path))

Check warning on line 167 in foqus_lib/core.py

View check run for this annotation

Codecov / codecov/patch

foqus_lib/core.py#L167

Added line #L167 was not covered by tests
if instance.package_name not in cls.windows_packages_unavailable:
cls.windows_packages_unavailable[instance.package_name] = (
cls.windows_packages_unavailable
)
logging.getLogger().warning(
"Install Path Does Not Exist: %s" % (instance.path)
)
cls.windows_packages_available[instance.package_name] = instance
return instance

@classmethod
def path(cls):
raise NotImplementedError()

Check warning on line 180 in foqus_lib/core.py

View check run for this annotation

Codecov / codecov/patch

foqus_lib/core.py#L180

Added line #L180 was not covered by tests


class SimSinterDependencyTracker(WindowsPackageDependencyTracker):
"""
plugin = PsuadeDependencyTracker.load()
if plugin == None: print("unavailable")
elif plugin.nomad is False: print("nomand unavailable")
"""

package_name = "SimSinter"
install_path = "C:/Program Files/CCSI/SimSinter"

@property
def path(self):
return self.install_path


class TurbineLiteDependencyTracker(WindowsPackageDependencyTracker):
"""
plugin = PsuadeDependencyTracker.load()
if plugin == None: print("unavailable")
elif plugin.nomad is False: print("nomand unavailable")
"""

package_name = "TurbineLite"
install_path = "C:/Program Files/Turbine/Lite"

@property
def path(self):
return self.install_path
7 changes: 3 additions & 4 deletions foqus_lib/foqus.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
import sys
import time
import uuid
import traceback
import turbine

# FOQUS imports
import foqus_lib.version.version as ver # foqus version and other info
Expand Down Expand Up @@ -254,10 +256,7 @@ def main(args_to_parse=None):
logging.getLogger("foqus").setLevel(logging.DEBUG)
logging.getLogger("turbine").setLevel(logging.DEBUG)
sys.excepthook = logException # for unhandled exception logging
try:
turbine.commands._setup_logging.done = True
except:
_logger.exception("Cannot find turbine module")
turbine.commands._setup_logging.done = True
app = None # Qt application if I need to display message boxes.
## Setup the command line arguments
parser = argparse.ArgumentParser()
Expand Down
9 changes: 5 additions & 4 deletions foqus_lib/framework/session/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@
import sys
import uuid

from foqus_lib import core
import foqus_lib.framework.optimizer.problem as oprob
from foqus_lib.framework.graph.graph import *
from foqus_lib.framework.graph.graph import Graph, GraphEx
from foqus_lib.framework.graph.node import nodeModelTypes
from foqus_lib.framework.ml_ai_models import mlaiSearch
from foqus_lib.framework.optimizer import problem
Expand All @@ -40,7 +41,7 @@
from foqus_lib.framework.plugins import pluginSearch
from foqus_lib.framework.pymodel import pymodel
from foqus_lib.framework.sampleResults.results import Results
from foqus_lib.framework.sim.turbineConfiguration import *
from foqus_lib.framework.sim.turbineConfiguration import TurbineConfiguration
from foqus_lib.framework.surrogate import surrogate
from foqus_lib.framework.surrogate.surrogate import surrogate as junk2
from foqus_lib.framework.uq.LocalExecutionModule import *
Expand Down Expand Up @@ -770,7 +771,7 @@ def __init__(self):
self.working_dir_override = False
self.working_dir = ""
self.new_working_dir = ""
self.simsinter_path = "C:/Program Files (x86)/CCSI/SimSinter"
self.simsinter_path = core.SimSinterDependencyTracker.load().path
self.psuade_path = (
shutil.which("psuade")
or "C:/Program Files (x86)/psuade_project 1.7.5/bin/psuade.exe"
Expand All @@ -791,7 +792,7 @@ def __init__(self):
self.turbineRemoteReSub = 0 # number of times to resubmit failed
# jobs to Turbine when running remote
self.aspenVersion = 2 # 0 = none, 1 = 7.3, 2 = 7.3.2 or higher
self.turbLiteHome = "C:\\Program Files (x86)\\Turbine\\Lite"
self.turbLiteHome = core.TurbineLiteDependencyTracker.load().path
self.rScriptPath = "C:\\Program Files\\R\\R-3.1.2\\bin\\x64\\Rscript.exe"
self.logFormat = "%(asctime)s - %(levelname)s - %(name)s - %(message)s"
self.logRotate = False
Expand Down
4 changes: 3 additions & 1 deletion foqus_lib/framework/sim/turbineConfiguration.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
read_configuration,
)

from foqus_lib import core
import foqus_lib.framework.sim.process_management as _pm
from foqus_lib.framework.foqusException.foqusException import *

Expand Down Expand Up @@ -238,7 +239,7 @@
self.user = ""
self.pwd = ""
self.turbVer = "Lite" # Lite, Remote or ....
self.turbineLiteHome = "C:\\Program Files (x86)\\Turbine\\Lite"
self.turbineLiteHome = core.TurbineLiteDependencyTracker.load().path
self.consumers = {}
self.consumerCountDict = {}
self.reloadTurbine()
Expand Down Expand Up @@ -368,6 +369,7 @@

sinter_process_log = open("%s_sinter_log.txt" % app, "a")
sinter_process_log.write("starting consumer\n")
_log.info("executing process: %s", f)

Check warning on line 372 in foqus_lib/framework/sim/turbineConfiguration.py

View check run for this annotation

Codecov / codecov/patch

foqus_lib/framework/sim/turbineConfiguration.py#L372

Added line #L372 was not covered by tests
proc = subprocess.Popen(
[f],
stdout=sinter_process_log,
Expand Down
8 changes: 5 additions & 3 deletions foqus_lib/framework/sim/turbineLiteDB.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@
John Eslick, Carnegie Mellon University, 2014
"""
import os
import os.path
import threading
import time
import uuid

import adodbapi
import adodbapi.apibase
from foqus_lib import core

adodbapi.adodbapi.defaultCursorLocation = 2 # adodbapi.adUseServer

Expand Down Expand Up @@ -57,9 +59,9 @@
def __init__(self, close_after=True):
self.conn = None
self.close_after = close_after
self.dbFile = (
"C:\\Program Files (x86)"
"\\Turbine\\Lite\\Data\\TurbineCompactDatabase.sdf"
self.dbFile = os.path.join(

Check warning on line 62 in foqus_lib/framework/sim/turbineLiteDB.py

View check run for this annotation

Codecov / codecov/patch

foqus_lib/framework/sim/turbineLiteDB.py#L62

Added line #L62 was not covered by tests
core.TurbineLiteDependencyTracker.load().path,
"/Data/TurbineCompactDatabase.sdf",
)

def __del__(self):
Expand Down
Loading
Loading