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

Refactor Frhodo to be a Python package #7

Open
wants to merge 3 commits into
base: master
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
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
5 changes: 3 additions & 2 deletions src/calculate/mech_fcns.py → frhodo/calculate/mech_fcns.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
import cantera as ct
from cantera import interrupts, cti2yaml#, ck2yaml, ctml2yaml
import numpy as np
from calculate import reactors, shock_fcns, integrate
import ck2yaml
from timeit import default_timer as timer

from . import reactors, shock_fcns, integrate
from .. import ck2yaml


class Chemical_Mechanism:
def __init__(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,14 @@
except:
#import pathlib
#sys.path.append(pathlib.Path(__file__).parent.absolute()) # add directory of **this** file to path
import calculate.optimize.CheKiPEUQ_local as CKPQ
import frhodo.calculate.optimize.CheKiPEUQ_local as CKPQ

try:
import CheKiPEUQ.UserInput as UserInput
except:
import calculate.optimize.CheKiPEUQ_local.UserInput as UserInput
from .CheKiPEUQ_local import UserInput

try:
import CiteSoft
except:
#import pathlib #The below lines are to allow CiteSoftLocal to be called regardless of user's working directory.
#sys.path.append(pathlib.Path(__file__).parent.absolute()) # add directory of **this** file to path
import CiteSoftLocal as CiteSoft
import frhodo.CiteSoftLocal as CiteSoft

#get things ready for CiteSoft entry...
software_name = "CheKiPEUQ Bayesian Parameter Estimation"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,13 @@
from collections.abc import Iterable
#import mumce_py.Project as mumce_pyProject #FIXME: Eric to fix plotting/graphing issue described in issue 9 -- https://github.com/AdityaSavara/ODE-KIN-BAYES-SG-EW/issues/9
#import mumce_py.solution mumce_pySolution
try:
import CiteSoft
except:
#import pathlib #The below lines are to allow CiteSoftLocal to be called regardless of user's working directory.
#sys.path.append(pathlib.Path(__file__).parent.absolute()) # add directory of **this** file to path
import CiteSoftLocal as CiteSoft

import frhodo.CiteSoftLocal as CiteSoft

try:
import UnitTesterSG.nestedObjectsFunctions as nestedObjectsFunctions
except:
import calculate.optimize.CheKiPEUQ_local.nestedObjectsFunctionsLocal as nestedObjectsFunctions
except ImportError:
import frhodo.calculate.optimize.CheKiPEUQ_local.nestedObjectsFunctionsLocal as nestedObjectsFunctions

class parameter_estimation:
#Inside this class, a UserInput namespace is provided. This has dictionaries of UserInput choices.
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@
from timeit import default_timer as timer
import itertools

from calculate.convert_units import OoM, Bisymlog
from calculate.optimize.misc_fcns import penalized_loss_fcn, set_arrhenius_bnds, min_pos_system_value, max_pos_system_value
from ..convert_units import OoM, Bisymlog
from ..optimize.misc_fcns import penalized_loss_fcn, set_arrhenius_bnds, min_pos_system_value, max_pos_system_value
import frhodo

Ru = ct.gas_constant
# Ru = 1.98720425864083
Expand Down Expand Up @@ -134,7 +135,7 @@ def ln_arrhenius_jac(T, *args):
return popt


path = {'main': pathlib.Path(sys.argv[0]).parents[0].resolve()}
path = {'main': pathlib.Path(frhodo.__file__).parents[0].resolve()} # TODO (wardlt) - Make a globally-accessible Path
OS_type = platform.system()
if OS_type == 'Windows':
path['bonmin'] = path['main'] / 'bonmin/bonmin-win64/bonmin.exe'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@
from timeit import default_timer as timer
import itertools

from calculate.convert_units import OoM
from calculate.optimize.misc_fcns import penalized_loss_fcn, set_arrhenius_bnds
import frhodo
from ..convert_units import OoM
from ..optimize.misc_fcns import penalized_loss_fcn, set_arrhenius_bnds

Ru = ct.gas_constant
# Ru = 1.98720425864083
Expand Down Expand Up @@ -50,7 +51,7 @@ def ln_arrhenius_k(T, Ea, ln_A, n): # LPL, HPL, Fcent
def fit_arrhenius(rates, T, x0=[], coefNames=default_arrhenius_coefNames, bnds=[], loss='linear'):
def fit_fcn_decorator(x0, alter_idx, jac=False):
def set_coeffs(*args):
coeffs = x0
coeffs = x0git
for n, idx in enumerate(alter_idx):
coeffs[idx] = args[n]
return coeffs
Expand Down Expand Up @@ -118,7 +119,7 @@ def ln_arrhenius_jac(T, *args):
return popt


path = {'main': pathlib.Path(sys.argv[0]).parents[0].resolve()}
path = {'main': pathlib.Path(frhodo.__file__).parents[0].resolve()} # TODO (wardlt) - Make a globally-accessible Path
OS_type = platform.system()
if OS_type == 'Windows':
path['bonmin'] = path['main'] / 'bonmin/bonmin-win64/bonmin.exe'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
from scipy import stats
from copy import deepcopy

from calculate.mech_fcns import Chemical_Mechanism
from calculate.convert_units import OoM, Bisymlog
from calculate.optimize.misc_fcns import weighted_quantile, outlier, penalized_loss_fcn
from calculate.optimize.fit_coeffs import fit_coeffs
from calculate.optimize.CheKiPEUQ_from_Frhodo import CheKiPEUQ_Frhodo_interface
from ..mech_fcns import Chemical_Mechanism
from ..convert_units import OoM, Bisymlog
from ..optimize.misc_fcns import weighted_quantile, outlier, penalized_loss_fcn
from ..optimize.fit_coeffs import fit_coeffs
from ..optimize.CheKiPEUQ_from_Frhodo import CheKiPEUQ_Frhodo_interface

mpMech = {}
def initialize_parallel_worker(mech_dict, species_dict, coeffs, coeffs_bnds, rate_bnds):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@

from scipy import stats

from calculate.optimize.optimize_worker import Worker
from calculate.optimize.fit_fcn import update_mech_coef_opt
from calculate.optimize.misc_fcns import rates, set_bnds
from calculate.optimize.fit_coeffs import fit_generic as Troe_fit
from ..optimize.optimize_worker import Worker
from ..optimize.fit_fcn import update_mech_coef_opt
from ..optimize.misc_fcns import rates, set_bnds
from ..optimize.fit_coeffs import fit_generic as Troe_fit

Ru = ct.gas_constant
default_arrhenius_coefNames = ['activation_energy', 'pre_exponential_factor', 'temperature_exponent']
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import cantera as ct
import pathlib, sys

import frhodo

Ru = ct.gas_constant

min_pos_system_value = (np.finfo(float).tiny*(1E20))**(1/2)
Expand All @@ -20,7 +22,7 @@


# interpolation function for Z from loss function
path = {'main': pathlib.Path(sys.argv[0]).parents[0].resolve()}
path = {'main': pathlib.Path(frhodo.__file__).parents[0].resolve()}
path['Z_tck_spline.dat'] = path['main'] / 'data/loss_partition_fcn_tck_spline.dat'

tck = []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@

from timeit import default_timer as timer

from calculate.optimize.fit_fcn import initialize_parallel_worker, Fit_Fun
from calculate.optimize.misc_fcns import rates
from ..optimize.fit_fcn import initialize_parallel_worker, Fit_Fun
from ..optimize.misc_fcns import rates
import frhodo


debug = True
Expand Down Expand Up @@ -210,7 +211,7 @@ class WorkerSignals(QObject):
'Optimization failed: Out of memory', 'Optimization failed: Roundoff errors limited progress',
'Optimization failed: Forced termination']

path = {'main': pathlib.Path(sys.argv[0]).parents[0].resolve()}
path = {'main': pathlib.Path(frhodo.__file__).parents[0].resolve()} # TODO (wardlt) - Make a globally-accessible Path
OS_type = platform.system()
if OS_type == 'Windows':
path['bonmin'] = path['main'] / 'bonmin/bonmin-win64/bonmin.exe'
Expand Down
4 changes: 2 additions & 2 deletions src/calculate/reactors.py → frhodo/calculate/reactors.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import cantera as ct
from cantera import interrupts, cti2yaml#, ck2yaml, ctml2yaml
import numpy as np
from calculate import shock_fcns, integrate
import ck2yaml
from . import shock_fcns, integrate
import frhodo.ck2yaml
from timeit import default_timer as timer


Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
45 changes: 29 additions & 16 deletions src/main.py → frhodo/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,20 @@
# and licensed under BSD-3-Clause. See License.txt in the top-level
# directory for license and copyright information.

version = '1.3.1'
import os, sys, platform, multiprocessing, pathlib, ctypes
# os.environ['QT_API'] = 'pyside2' # forces pyside2
from typing import Tuple

from qtpy.QtWidgets import QMainWindow, QApplication, QMessageBox
from qtpy import uic, QtCore, QtGui

import numpy as np
# from timeit import default_timer as timer

from plot.plot_main import All_Plots as plot
from misc_widget import MessageWindow
from calculate import mech_fcns, reactors, convert_units
import appdirs, options_panel_widgets, sim_explorer_widget
import settings, config_io, save_widget, error_window, help_menu
from .plot.plot_main import All_Plots as plot
from .misc_widget import MessageWindow
from .calculate import mech_fcns, reactors, convert_units
from .version import __version__
from . import appdirs, options_panel_widgets, sim_explorer_widget
from . import settings, config_io, save_widget, error_window, help_menu

if os.environ['QT_API'] == 'pyside2': # Silence warning: "Qt WebEngine seems to be initialized from a plugin."
QApplication.setAttribute(QtCore.Qt.AA_ShareOpenGLContexts)
Expand All @@ -31,7 +30,7 @@
QApplication.setAttribute(QtCore.Qt.AA_UseHighDpiPixmaps, True)

# set main folder
path = {'main': pathlib.Path(sys.argv[0]).parents[0].resolve()}
path = {'main': pathlib.Path(__file__).parents[0].resolve()}

# set appdata folder using AppDirs library (but just using the source code file)
dirs = appdirs.AppDirs(appname='Frhodo', roaming=True, appauthor=False)
Expand Down Expand Up @@ -86,7 +85,7 @@ def __init__(self, app, path):
self.initialize_settings() # ~ 4 sec

# Setup help menu
self.version = version
self.version = __version__
help_menu.HelpMenu(self)

def initialize_settings(self): # TODO: Solving for loaded shock twice
Expand Down Expand Up @@ -290,17 +289,31 @@ def run_single(self, event=None, t_save=None, rxn_changed=False):
# def raise_error(self):
# assert False


if __name__ == '__main__':

def launch_gui() -> Tuple[QApplication, Main]:
"""Launch the GUI

Returns:
- The QApplication instance
- Link to the main window
"""
if platform.system() == 'Windows': # this is required for pyinstaller on windows
multiprocessing.freeze_support()

if getattr(sys, 'frozen', False): # if frozen minimize console immediately
if getattr(sys, 'frozen', False): # if frozen minimize console immediately
ctypes.windll.user32.ShowWindow(ctypes.windll.kernel32.GetConsoleWindow(), 0)

app = QApplication(sys.argv)
sys.excepthook = error_window.excepthookDecorator(app, path, shut_down)

main = Main(app, path)
main_window = Main(app, path)
return app, main_window


def main():
"""Launch the GUI and then block until it finishes"""
# Launch the application
app, main_window = launch_gui()

# Pass the exit code forward
sys.exit(app.exec_())

8 changes: 4 additions & 4 deletions src/mech_widget.py → frhodo/mech_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
# and licensed under BSD-3-Clause. See License.txt in the top-level
# directory for license and copyright information.

from copy import deepcopy
import sys, ast, re
import misc_widget

import cantera as ct
import numpy as np
from copy import deepcopy
from functools import partial
from scipy.optimize import root_scalar
from qtpy.QtWidgets import *
from qtpy import QtWidgets, QtGui, QtCore

from timeit import default_timer as timer
from . import misc_widget


def silentSetValue(obj, value):
obj.blockSignals(True) # stop changing text from signaling
Expand Down
2 changes: 1 addition & 1 deletion src/misc_widget.py → frhodo/misc_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import numpy as np
from qtpy.QtWidgets import *
from qtpy import QtWidgets, QtGui, QtCore
from calculate.convert_units import OoM
from .calculate.convert_units import OoM

# Regular expression to find floats. Match groups are the whole string, the
# whole coefficient, the decimal part of the coefficient, and the exponent
Expand Down
15 changes: 9 additions & 6 deletions src/options_panel_widgets.py → frhodo/options_panel_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,20 @@
# directory for license and copyright information.

import pathlib, os, sys
from copy import deepcopy

import numpy as np
from scipy.optimize import minimize
import nlopt
import mech_widget, misc_widget, thermo_widget, series_viewer_widget, save_output
from calculate import shock_fcns
from calculate.optimize.mech_optimize import Multithread_Optimize
from calculate.convert_units import OoM
from settings import double_sigmoid
from qtpy.QtWidgets import *
from qtpy import QtWidgets, QtGui, QtCore
from copy import deepcopy

from . import mech_widget, misc_widget, thermo_widget, series_viewer_widget, save_output
from .calculate import shock_fcns
from .calculate.optimize.mech_optimize import Multithread_Optimize
from .calculate.convert_units import OoM
from .settings import double_sigmoid



class Initialize(QtCore.QObject):
Expand Down
Empty file added frhodo/plot/__init__.py
Empty file.
6 changes: 3 additions & 3 deletions src/plot/base_plot.py → frhodo/plot/base_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
#mpl.use("module://mplcairo.qt") # This implements mplcairo, faster/more accurate. Issues with other OSes?
import numpy as np

from calculate.convert_units import Bisymlog
from plot.custom_mplscale import *
from plot.custom_mpl_ticker_formatter import *
from ..calculate.convert_units import Bisymlog
from .custom_mplscale import *
from .custom_mpl_ticker_formatter import *
from timeit import default_timer as timer


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from matplotlib import scale as mplscale

import numpy as np
from calculate.convert_units import Bisymlog
from frhodo.calculate.convert_units import Bisymlog

class AbsoluteLogScale(mplscale.LogScale):
name = 'abslog'
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
# and licensed under BSD-3-Clause. See License.txt in the top-level
# directory for license and copyright information.

import colors
from frhodo import colors

import matplotlib as mpl
import numpy as np

from plot.base_plot import Base_Plot
from .base_plot import Base_Plot


colormap = colors.colormap(reorder_from=1, num_shift=4)
Expand Down
2 changes: 1 addition & 1 deletion src/plot/plot_main.py → frhodo/plot/plot_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# and licensed under BSD-3-Clause. See License.txt in the top-level
# directory for license and copyright information.

from plot import raw_signal_plot, signal_plot, sim_explorer_plot, optimization_plot, plot_widget
from . import raw_signal_plot, signal_plot, sim_explorer_plot, optimization_plot, plot_widget


class All_Plots: # container to hold all plots
Expand Down
2 changes: 1 addition & 1 deletion src/plot/plot_widget.py → frhodo/plot/plot_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from qtpy import QtWidgets, QtGui, QtCore
from copy import deepcopy

import misc_widget
from .. import misc_widget

class Observable_Widgets(QtCore.QObject):
def __init__(self, parent):
Expand Down
Loading