Skip to content

Commit

Permalink
Allow Input Templates to inherit from Message User (#1757)
Browse files Browse the repository at this point in the history
* Add warnings

* Remove lb & ub sub in DiscreteUniform LogNormal

* Allow InputTemplate to inherit from MessageUser
  • Loading branch information
dylanjm authored Jan 31, 2022
1 parent daae580 commit edbbe94
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 15 deletions.
3 changes: 2 additions & 1 deletion framework/CodeInterfaces/Prescient/PrescientCodeInterface.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@

import os
import re
import warnings
try:
import pkg_resources
prescient = pkg_resources.get_distribution("prescient")
prescientLocation = prescient.location
except Exception as inst:
print("Finding Prescient failed with",inst)
warnings.warn(f"Finding Prescient failed with {inst}")
prescientLocation = None

from CodeInterfaceBaseClass import CodeInterfaceBase
Expand Down
5 changes: 3 additions & 2 deletions framework/Decorators/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,20 @@
@author: alfoa
"""
import builtins
import warnings

# line_profiler decorator, @Decorators.timingProfile
## if using kernprof, use "profile" builtin; otherwise, passthrough.
try:
builtins.profile
timingProfile = builtins.profile
except (AttributeError, ImportError):
print('Unable to load "timingProfile" decorator; replacing with passthrough ...')
warnings.warn('Unable to load "timingProfile" decorator; replacing with passthrough ...', ImportWarning)
timingProfile = lambda f: f

# memory_profiler decorator, @Decorators.memoryProfile
try:
from memory_profiler import profile as memoryProfile
except (AttributeError, ImportError):
print('Unable to load "memoryProfile" decorator; replacing with passthrough ...')
warnings.warn('Unable to load "memoryProfile" decorator; replacing with passthrough ...', ImportWarning)
memoryProfile = lambda f: f
10 changes: 0 additions & 10 deletions framework/Distributions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1804,13 +1804,6 @@ def getInputSpecification(cls):
is returned to $N$). In case the ``with replacement'' strategy is used, the distribution samples
always from the complete set of specified $N$ values.
"""
lb = InputData.parameterInputFactory('lowerBound', contentType=InputTypes.FloatType, printPriority=109,
descr=r""" Lower bound of the set of allowed sample values. """)
specs.addSub(lb)

ub = InputData.parameterInputFactory('upperBound', contentType=InputTypes.FloatType, printPriority=109,
descr=r""" Upper bound of the set of allowed sample values. """)
specs.addSub(ub)

np = InputData.parameterInputFactory('nPoints', contentType=InputTypes.IntegerType, printPriority=109,
descr=r""" Number of points between lower and upper bound. """)
Expand Down Expand Up @@ -2864,9 +2857,6 @@ class cls.
inputSpecification = super(LogUniform, cls).getInputSpecification()

BaseInputType = InputTypes.makeEnumType("base", "baseType", ["natural","decimal"])

inputSpecification.addSub(InputData.parameterInputFactory("lowerBound", contentType=InputTypes.FloatType))
inputSpecification.addSub(InputData.parameterInputFactory("upperBound", contentType=InputTypes.FloatType))
inputSpecification.addSub(InputData.parameterInputFactory("base" , BaseInputType))

return inputSpecification
Expand Down
6 changes: 4 additions & 2 deletions framework/InputTemplates/TemplateBaseClass.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@
frameworkDir = os.path.normpath(os.path.join(os.path.dirname(__file__), '..'))
sys.path.append(frameworkDir)
from utils import xmlUtils
from BaseClasses import MessageUser


class Template(object):
class Template(MessageUser):
"""
Generic class for templating input files.
Intended to be used to read a template, be given instructions on how to fill it,
Expand Down Expand Up @@ -61,12 +62,13 @@ def addNamingTemplates(cls, templates):
###############
# API METHODS #
###############
def __init__(self):
def __init__(self, **kwargs):
"""
Constructor.
@ In, None
@ Out, None
"""
super().__init__()
self._template = None # XML element with the root Simulation node of a RAVEN input
# assure that the template path gives the location of the inheriting template, not the base class
self._templatePath = os.path.dirname(os.path.normpath(sys.modules[self.__class__.__module__].__file__))
Expand Down

0 comments on commit edbbe94

Please sign in to comment.