Skip to content

Commit

Permalink
Remove star imports in __init__.py
Browse files Browse the repository at this point in the history
  • Loading branch information
dhadka committed Sep 10, 2024
1 parent f801bf8 commit 15eb960
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 30 deletions.
63 changes: 44 additions & 19 deletions rhodium/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,48 @@
#
# You should have received a copy of the GNU General Public License
# along with Rhodium. If not, see <http://www.gnu.org/licenses/>.
__author__ = "David Hadka"
__copyright__ = "Copyright 2015-2024, David Hadka"
__license__ = "GPLv3"
__version__ = "1.4.0"
__maintainer__ = "David Hadka"
__email__ = "[email protected]"

from .config import *
from .model import *
from .plot import *
from .sa import *
from .classification import *
from .cache import *
from .optimization import *
from .sampling import *
from .robustness import *
from .brush import *
from .utils import *

from platypus.evaluator import *

# Note: The following submodules are not exported here to allow for optional
# dependencies:
# - rhodium.excel
# - rhodium.ffi
# - rhodium.openmdao
# - rhodium.rbridge

from .config import RhodiumConfig

from .model import RhodiumError, Parameter, Direction, Response, Constraint, \
Lever, RealLever, IntegerLever, CategoricalLever, PermutationLever, \
SubsetLever, Uncertainty, UniformUncertainty, TriangularUncertainty, \
PointUncertainty, NormalUncertainty, LogNormalUncertainty, \
IntegerUncertainty, CategoricalUncertainty, Model, DataSet, save, load, \
overwrite, update, populate_defaults

from .decorators import Real, Integer, Categorical, Permutation, Subset, \
Uniform, Normal, LogNormal, Minimize, Maximize, Info, Ignore, \
RhodiumModel, Parameters, Responses, Constraints, Levers, Uncertainties

from .plot import scatter2d, scatter3d, joint, pairs, kdeplot, hist, \
interact, contour2d, contour3d, animate3d, parallel_coordinates

from .sa import SAResult, sa, oat, regional_sa

from .classification import Cart

from .cache import setup_cache, cached, cache, clear_cache

from .optimization import evaluate, optimize, robust_optimize

from .sampling import sample_uniform, sample_lhs

from .robustness import evaluate_robustness

from .brush import Brush, BrushSet, apply_brush, brush_color_map, \
color_brush, color_indices

from .utils import promptToRun

from prim import Prim
from platypus import MapEvaluator, SubmitEvaluator, ApplyEvaluator, \
PoolEvaluator, MultiprocessingEvaluator, ProcessPoolEvaluator
1 change: 0 additions & 1 deletion rhodium/classification.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import sklearn
from sklearn import tree
from packaging.version import Version
from prim import Prim
from io import BytesIO, StringIO

class Cart:
Expand Down
1 change: 0 additions & 1 deletion rhodium/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ def __init__(self, *args, **kwargs):
def __new__(cls, *args, **kwargs):
return float.__new__(cls, kwargs.get("default_value", float("NaN")))


class Minimize(Response):

def __init__(self, name, **kwargs):
Expand Down
16 changes: 7 additions & 9 deletions rhodium/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,13 @@ def __getattr__(self, name):
else:
raise AttributeError()

# Set up the evaluation environment with all math function.
_eval_env = {}
module = __import__("math", fromlist=[''])
_module = __import__("math", fromlist=[''])

for name in dir(module):
for name in dir(_module):
if not name.startswith("_"):
_eval_env[name] = getattr(module, name)
_eval_env[name] = getattr(_module, name)

class Constraint:
"""Defines model constraints.
Expand Down Expand Up @@ -337,7 +338,6 @@ def levels(self, nlevels):
def ppf(self, x):
return self.min_value + x*(self.max_value - self.min_value)


class TriangularUncertainty(Uncertainty):
"""An uncertainty with a triangular distribution."""

Expand All @@ -363,7 +363,6 @@ def levels(self, nlevels):
def ppf(self, x):
return stats.triang.ppf(x, c=self.c, loc=self.min_value, scale=self.scale)


class PointUncertainty(Uncertainty):
"""An uncertainty distribution with all its probability mass at one point on the real line."""

Expand All @@ -377,7 +376,6 @@ def levels(self, nlevels):
def ppf(self, x):
return self.value


class NormalUncertainty(Uncertainty):
"""An uncertainty for real-valued parameters following a normal (Gaussian) distribution."""

Expand Down Expand Up @@ -437,7 +435,7 @@ def levels(self, nlevels):
def ppf(self, x):
return self.categories[int(math.floor(x*(len(self.categories)-0.0001)))]

class NamedObjectMap:
class NamedObjectMap(metaclass=ABCMeta):

def __init__(self, type):
self.type = type
Expand Down Expand Up @@ -798,7 +796,7 @@ def save(data, file, format=None, **kwargs):
else:
raise ValueError("unsupported file format '%s'" % str(format))

class _FileModel(Model):
class FileModel(Model):

def __init__(self, source):
super().__init__(self._evaluate)
Expand Down Expand Up @@ -840,7 +838,7 @@ def load(file, format=None, parameters=[], **kwargs):

data.append(entry)

model = _FileModel(file)
model = FileModel(file)
model.parameters = [Parameter(names[j] if isinstance(j, int) else j) for j in parameters]
model.responses = [Response(names[j]) for j in range(df.shape[1]) if j not in parameters and names[j] not in parameters]

Expand Down

0 comments on commit 15eb960

Please sign in to comment.