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

Allow Input Templates to inherit from Message User #1757

Merged
merged 3 commits into from
Jan 31, 2022
Merged
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
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,
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@joshua-cogliati-inl I think instead of removing these lines of code, I could use that removeSubWithName() method you mentioned in chat. Let me know your thoughts.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm curious about why we can remove the upper and lower bounds for these distributions; is it because it's defined in the base class?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@PaulTalbot-INL Yes, I believe that's why we're getting those INPUT SPEC ERROR when running HERON before. When I removed the upper and lower bound for these distributions the errors went away.

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