Skip to content

Commit

Permalink
Merge branch 'main' into sweep-chart-list
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelPesce authored Jul 11, 2024
2 parents a723c89 + 0d9c1ae commit bce82cd
Show file tree
Hide file tree
Showing 21 changed files with 5,288 additions and 274 deletions.
34 changes: 19 additions & 15 deletions .github/workflows/electron-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: App build
on:
push:
branches:
- "0.12.0rc0"
- "new-charts"

defaults:
run:
Expand All @@ -26,7 +26,7 @@ jobs:
- uses: actions/checkout@v4
- uses: conda-incubator/setup-miniconda@v3
with:
environment-file: environment.yml
environment-file: environment-build.yml
activate-environment: watertap-ui-env

- name: Install Azure Signtool
Expand All @@ -52,9 +52,13 @@ jobs:
# working-directory: ../
# run: git clone https://github.com/watertap-org/watertap.git && cd watertap && pip install --progress-bar off .

- name: Install Watertap locally
# - name: Install Watertap locally
# working-directory: ../
# run: git clone https://github.com/watertap-org/watertap.git && cd watertap && git fetch --all --tags && git checkout 0.12.0 && pip install --progress-bar off .

- name: Install adudchenko/generic treatment train Watertap
working-directory: ../
run: git clone https://github.com/watertap-org/watertap.git && cd watertap && git fetch --all --tags && git checkout 0.12.0 && pip install --progress-bar off .
run: git clone https://github.com/avdudchenko/watertap.git && cd watertap && git fetch --all --tags && git checkout generic_treatment_train && pip install --progress-bar off .

- name: Transfer Entry points
run: |
Expand All @@ -66,17 +70,17 @@ jobs:
# install slightly older versions of numpy, pandas, and scipy.
# having issues when freezing the latest packages of each (numpy 1.26, pandas 2.1, scipy 1.11)
- name: Install numpy 1.24.3
run: |
pip uninstall -y numpy && pip install numpy==1.24.3
# - name: Install numpy 1.24.3
# run: |
# pip uninstall -y numpy && pip install numpy==1.24.3

- name: Install pandas 2.0.3
run: |
pip uninstall -y pandas && pip install pandas==2.0.3
# - name: Install pandas 2.0.3
# run: |
# pip uninstall -y pandas && pip install pandas==2.0.3

- name: Install scipy 1.9.1
run: |
pip uninstall -y scipy && pip install scipy==1.9.1
# - name: Install scipy 1.9.1
# run: |
# pip uninstall -y scipy && pip install scipy==1.9.1

- name: Build Backend
run: npm --prefix electron run build-backend
Expand All @@ -89,7 +93,7 @@ jobs:

- name: Sign Windows Distribution
run: |
AzureSignTool sign -kvu "${{ secrets.AZURE_KEY_VAULT_URI }}" -kvi "${{ secrets.AZURE_CLIENT_ID }}" -kvt "${{ secrets.AZURE_TENANT_ID }}" -kvs "${{ secrets.AZURE_CLIENT_SECRET }}" -kvc ${{ secrets.AZURE_CERT_NAME }} -tr http://timestamp.digicert.com -v electron/dist/WaterTAP-UI_24.03.29_win64.exe
AzureSignTool sign -kvu "${{ secrets.AZURE_KEY_VAULT_URI }}" -kvi "${{ secrets.AZURE_CLIENT_ID }}" -kvt "${{ secrets.AZURE_TENANT_ID }}" -kvs "${{ secrets.AZURE_CLIENT_SECRET }}" -kvc ${{ secrets.AZURE_CERT_NAME }} -tr http://timestamp.digicert.com -v electron/dist/WaterTAP-UI_24.05.17_win64.exe
- name: Upload artifact for windows build
Expand All @@ -98,7 +102,7 @@ jobs:
with:
name: windows-dist
path: |
electron/dist/WaterTAP-UI_24.03.29_win64.exe
electron/dist/WaterTAP-UI_24.05.17_win64.exe
# linux-build:
Expand Down
34 changes: 24 additions & 10 deletions backend/app/internal/parameter_sweep.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
from pathlib import Path
from fastapi import HTTPException
import numpy as np
from watertap.tools.parameter_sweep import LinearSample, ParameterSweep, parameter_sweep
import watertap.examples.flowsheets.case_studies.wastewater_resource_recovery.amo_1575_magprex.magprex as magprex
from parameter_sweep import LinearSample, ParameterSweep, parameter_sweep
from importlib import import_module
import idaes.logger as idaeslog
from pyomo.environ import (
ConcreteModel,
value,
Var,
units as pyunits,
)

_log = idaeslog.getLogger(__name__)

Expand All @@ -25,6 +30,15 @@ def set_up_sensitivity(m, solve, output_params):
return outputs, optimize_kwargs, opt_function


def get_conversion_unit(flowsheet, key):
obj = flowsheet.fs_exp.exports[key].obj
ui_units = flowsheet.fs_exp.exports[key].ui_units
temp = Var(initialize=1, units=obj.get_units())
temp.construct()
crv = value(pyunits.convert(temp, to_units=ui_units))
return crv


def run_analysis(
m,
flowsheet,
Expand Down Expand Up @@ -97,10 +111,7 @@ def run_parameter_sweep(flowsheet, info):
results_table["headers"].append(
flowsheet.fs_exp.exports[key].name
)
conversion_factor = (
flowsheet.fs_exp.exports[key].ub
/ flowsheet.fs_exp.exports[key].obj.ub
)
conversion_factor = get_conversion_unit(flowsheet, key)
try:
parameters.append(
{
Expand Down Expand Up @@ -130,16 +141,19 @@ def run_parameter_sweep(flowsheet, info):
for key in flowsheet.fs_exp.exports:
if (
flowsheet.fs_exp.exports[key].is_output
or (
not flowsheet.fs_exp.exports[key].is_output
and flowsheet.fs_exp.exports[key].is_input
and not flowsheet.fs_exp.exports[key].fixed
)
# and not flowsheet.fs_exp.exports[key].is_input
):
results_table["headers"].append(
flowsheet.fs_exp.exports[key].name
)

try:
conversion_factor = (
flowsheet.fs_exp.exports[key].value
/ flowsheet.fs_exp.exports[key].obj.value
)
conversion_factor = get_conversion_unit(flowsheet, key)
except Exception as e:
conversion_factor = 1
conversion_factors.append(conversion_factor)
Expand Down
154 changes: 116 additions & 38 deletions backend/app/main-hooks/hook-watertap.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,34 @@
from uuid import uuid4
import sys

from pathlib import Path


imports = set()
datas = []

# add all modules to watertap modules hidden imports
for package in ["watertap"]:

for package in ["watertap", "pyomo"]:
pkg = importlib.import_module(package)
try:
# base_folder = Path(pkg.__path__[0])
pkg_path = Path(pkg.__file__).parent
base_folder = pkg_path.parent
print("------------------importing", package, base_folder, pkg_path)
except TypeError: # missing __init__.py perhaps
print(
f"Cannot find package '{package}' directory, possibly "
f"---------------Cannot find package '{package}' directory, possibly "
f"missing an '__init__.py' file"
)
if not pkg_path.is_dir():
print(
f"Cannot load from package '{package}': "
f"--------------------Cannot load from package '{package}': "
f"path '{pkg_path}' not a directory"
)

skip_expr = re.compile(r"_test|test_|__")
print('beginning python files')
print("beginning python files")
for python_file in pkg_path.glob("**/*.py"):
if skip_expr.search(str(python_file)):
continue
Expand All @@ -46,76 +53,147 @@
continue

# ensure all parent modules are imported (a lot of repeats here but it works)
relative_path=relative_path.parent
while relative_path != Path('.'):
relative_path = relative_path.parent
while relative_path != Path("."):
dotted_name = relative_path.as_posix().replace("/", ".")
module_name = package + "." + dotted_name
try:
module = importlib.import_module(module_name)
imports.add(module_name)
relative_path=relative_path.parent
relative_path = relative_path.parent
except:
relative_path=relative_path.parent
print('error on my part')
relative_path = relative_path.parent
print("error on my part")
continue

# add all png files to pyinstaller data
for png_file in pkg_path.glob("**/*.png"):
file_name = '/' + png_file.as_posix().split('/')[-1]
file_name = "/" + png_file.as_posix().split("/")[-1]
# print(file_name)
if skip_expr.search(str(png_file)):
continue
relative_path = png_file.relative_to(pkg_path)
dotted_name = relative_path.as_posix()
src_name = "../../../watertap/" + package + "/" + dotted_name
dst_name = package + "/" + dotted_name.replace(file_name,'')
src_name = f"{base_folder}/" + package + "/" + dotted_name
dst_name = package + "/" + dotted_name.replace(file_name, "")
try:
datas.append((src_name,dst_name))
datas.append((src_name, dst_name))
except Exception as err: # assume the import could do bad things
print(f"Import of file '{png_file}' failed: {err}")
continue

# add all yaml files to pyinstaller data
for yaml_file in pkg_path.glob("**/*.yaml"):
file_name = '/' + yaml_file.as_posix().split('/')[-1]
file_name = "/" + yaml_file.as_posix().split("/")[-1]
# print(file_name)
if skip_expr.search(str(yaml_file)):
continue
relative_path = yaml_file.relative_to(pkg_path)
dotted_name = relative_path.as_posix()
src_name = "../../../watertap/" + package + "/" + dotted_name
dst_name = package + "/" + dotted_name.replace(file_name,'')
src_name = f"{base_folder}/" + package + "/" + dotted_name
dst_name = package + "/" + dotted_name.replace(file_name, "")
try:
datas.append((src_name,dst_name))
datas.append((src_name, dst_name))
except Exception as err: # assume the import could do bad things
print(f"Import of file '{yaml_file}' failed: {err}")
continue

hiddenimports = list(imports)
# print("hiddenimports")
# print(hiddenimports)
# manually add all pyomo hidden imports
# # manually add all pyomo hidden imports
pyomo_imports = [
'networkx', 'pyomo.contrib.ampl_function_demo.plugins', 'pyomo.contrib.appsi.plugins',
'pyomo.contrib.community_detection.plugins', 'pyomo.contrib.example.plugins', 'pyomo.contrib.fme.plugins',
'pyomo.contrib.gdp_bounds.plugins', 'pyomo.contrib.gdpopt.plugins', 'pyomo.contrib.gjh.plugins',
'pyomo.contrib.mcpp.plugins', 'pyomo.contrib.mindtpy.plugins', 'pyomo.contrib.multistart.plugins',
'pyomo.contrib.preprocessing.plugins', 'pyomo.contrib.pynumero.plugins', 'pyomo.contrib.trustregion.plugins',
'pyomo.repn.util', 'pyomo.contrib.gdpbb', 'pyomo.contrib.gdpbb.plugins', 'pint', 'numbers',
'pyutilib', 'pyomo', 'pyomo.environ', 'pyomo.core', 'pyomo.core.plugins', 'pyomo.dae', 'pyomo.dae.plugins',
'pyomo.gdp', 'pyomo.gdp.plugins', 'pyomo.neos', 'pyomo.neos.plugins', 'pyomo.opt', 'pyomo.opt.plugins',
'pyomo.pysp', 'pyomo.pysp.plugins', 'pyomo.solvers.plugins', 'pyomo.solvers', 'pyomo.contrib',
'pyomo.dataportal', 'pyomo.dataportal.plugins', 'pyomo.duality', 'pyomo.contrib.solver.plugins',
'pyomo.duality.plugins', 'pyomo.kernel', 'pyomo.mpec', 'pyomo.mpec.plugins', 'pyomo.contrib.solver',
'pyomo.network', 'pyomo.network.plugins', 'pyomo.repn', 'pyomo.repn.plugins', 'pyomo.scripting',
'pyomo.scripting.plugins', 'pyomo.util', 'pyomo.common', 'pyomo.common.plugins',
'sys', 'logging', 're', 'sys', 'pyomo.core.expr.numvalue', 'pyomo.core.expr.numvalue',
'pyomo.solvers.plugins.solvers.direct_solver', 'pyomo.solvers.plugins.solvers.direct_or_persistent_solver',
'pyomo.core.kernel.component_set', 'pyomo.core.kernel.component_map', 'pyomo.opt.results.results_',
'pyomo.opt.results.solution', 'pyomo.opt.results.solver', 'pyomo.opt.base', 'pyomo.core.base.suffix',
'pyomo.core.base.var', 'pyomo.core.base.PyomoModel', 'pyomo.solvers.plugins.solvers.persistent_solver',
'pyomo.opt.base.problem', 'pyomo.opt.base.convert', 'pyomo.opt.base.formats', 'pyomo.opt.base.results',
'pyomo.core.base.block', 'pyomo.core.kernel.block', 'pyomo.core.kernel.suffix','pyomo.contrib.cp.plugins',
"networkx",
"pint",
"numbers",
"pyutilib",
"sys",
"logging",
"re",
"sys",
"pyomo.contrib.ampl_function_demo.plugins",
"pyomo.contrib.appsi.plugins",
"pyomo.contrib.community_detection.plugins",
"pyomo.contrib.example.plugins",
"pyomo.contrib.fme.plugins",
"pyomo.contrib.gdp_bounds.plugins",
"pyomo.contrib.gdpopt.plugins",
"pyomo.contrib.gjh.plugins",
"pyomo.contrib.mcpp.plugins",
"pyomo.contrib.mindtpy.plugins",
"pyomo.contrib.multistart.plugins",
"pyomo.contrib.preprocessing.plugins",
"pyomo.contrib.pynumero.plugins",
"pyomo.contrib.trustregion.plugins",
"pyomo.repn.util",
"pyomo.contrib.gdpbb",
"pyomo.contrib.gdpbb.plugins",
"pyomo",
"pyomo.environ",
"pyomo.age",
"pyomo.bilevel",
"pyomo.bilevel.plugins",
"pyomo.core",
"pyomo.core.plugins",
"pyomo.dae",
"pyomo.dae.plugins",
"pyomo.gdp",
"pyomo.gdp.plugins",
"pyomo.neos",
"pyomo.neos.plugins",
"pyomo.opt",
"pyomo.opt.plugins",
"pyomo.pysp",
"pyomo.pysp.plugins",
"pyomo.solvers.plugins",
"pyomo.solvers",
"pyomo.checker",
"pyomo.checker.plugins",
"pyomo.contrib",
"pyomo.contrib.plugins",
"pyomo.contrib.solver",
"pyomo.contrib.solver.plugins",
"pyomo.dataportal",
"pyomo.dataportal.plugins",
"pyomo.duality",
"pyomo.duality.plugins",
"pyomo.kernel",
"pyomo.kernel.plugins",
"pyomo.mpec",
"pyomo.mpec.plugins",
"pyomo.network",
"pyomo.network.plugins",
"pyomo.repn",
"pyomo.repn.plugins",
"pyomo.scripting",
"pyomo.scripting.plugins",
"pyomo.util",
"pyomo.util.plugins",
"pyomo.common",
"pyomo.common.plugins",
"pyomo.common.dependencies",
"pyomo.core.expr.numvalue",
"pyomo.core.expr.numvalue",
"pyomo.solvers.plugins.solvers.direct_solver",
"pyomo.solvers.plugins.solvers.direct_or_persistent_solver",
"pyomo.core.kernel.component_set",
"pyomo.core.kernel.component_map",
"pyomo.opt.results.results_",
"pyomo.opt.results.solution",
"pyomo.opt.results.solver",
"pyomo.opt.base",
"pyomo.core.base.suffix",
"pyomo.core.base.var",
"pyomo.core.base.PyomoModel",
"pyomo.solvers.plugins.solvers.persistent_solver",
"pyomo.opt.base.problem",
"pyomo.opt.base.convert",
"pyomo.opt.base.formats",
"pyomo.opt.base.results",
"pyomo.core.base.block",
"pyomo.core.kernel.block",
"pyomo.core.kernel.suffix",
"pyomo.contrib.cp.plugins",
]

hiddenimports.extend(pyomo_imports)
9 changes: 8 additions & 1 deletion backend/app/main.spec
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
# -*- mode: python ; coding: utf-8 -*-
import sys
import watertap
from pathlib import Path
import os

# get actual water path path incase its dev
pkg_path = Path(watertap.__file__).parent

sys.setrecursionlimit(5000)

block_cipher = None

# this file is not actually needed there, but we need the core directory
# to be present in the python executable to avoid errors being thrown
added_files = [
('../../../watertap/watertap/data/techno_economic/metab.yaml', 'watertap/core')
(os.path.join(pkg_path,"data/techno_economic/metab.yaml"), os.path.join("pkg_path","core"))
]

a = Analysis(
Expand Down
Loading

0 comments on commit bce82cd

Please sign in to comment.