Пример #1
0
    def __init__(self):
        super(CbcConfig, self).__init__()

        self.declare('executable', ConfigValue())
        self.declare('filename', ConfigValue(domain=str))
        self.declare('keepfiles', ConfigValue(domain=bool))
        self.declare('solver_output_logger', ConfigValue())
        self.declare('log_level', ConfigValue(domain=NonNegativeInt))

        self.executable = Executable('cbc')
        self.filename = None
        self.keepfiles = False
        self.solver_output_logger = logger
        self.log_level = logging.INFO
Пример #2
0
    def __init__(self,
                 description=None,
                 doc=None,
                 implicit=False,
                 implicit_domain=None,
                 visibility=0):
        super(IpoptConfig, self).__init__(description=description,
                                          doc=doc,
                                          implicit=implicit,
                                          implicit_domain=implicit_domain,
                                          visibility=visibility)

        self.declare('executable', ConfigValue())
        self.declare('filename', ConfigValue(domain=str))
        self.declare('keepfiles', ConfigValue(domain=bool))
        self.declare('solver_output_logger', ConfigValue())
        self.declare('log_level', ConfigValue(domain=NonNegativeInt))

        self.executable = Executable('ipopt')
        self.filename = None
        self.keepfiles = False
        self.solver_output_logger = logger
        self.log_level = logging.INFO
Пример #3
0
def runtests(options):

    from pyomo.common.fileutils import PYOMO_ROOT_DIR as basedir, Executable
    env = os.environ.copy()
    os.chdir(basedir)

    print("Running tests in directory %s" % (basedir, ))

    if sys.platform.startswith('win'):
        binDir = os.path.join(sys.exec_prefix, 'Scripts')
        nosetests = os.path.join(binDir, 'nosetests.exe')
    else:
        binDir = os.path.join(sys.exec_prefix, 'bin')
        nosetests = os.path.join(binDir, 'nosetests')

    if os.path.exists(nosetests):
        cmd = [nosetests]
    else:
        nose = Executable('nosetests')
        cmd = [sys.executable, nose.path()]

    if (sys.platform.startswith('win') and sys.version_info[0:2] >= (3, 8)):
        #######################################################
        # This option is required due to a (likely) bug within nosetests.
        # Nose is no longer maintained, but this workaround is based on a public forum suggestion:
        #   https://stackoverflow.com/questions/58556183/nose-unittest-discovery-broken-on-python-3-8
        #######################################################
        cmd.append('--traverse-namespace')

    if binDir not in env['PATH']:
        env['PATH'] = os.pathsep.join([binDir, env.get('PATH', '')])

    if options.verbose:
        cmd.append('-v')
    if options.stop:
        cmd.append('-x')
    if options.dryrun:
        cmd.append('--collect-only')

    if options.xunit:
        cmd.append('--with-xunit')
        cmd.append('--xunit-file=TEST-pyomo.xml')

    attr = []
    _with_performance = False
    _categories = []
    for x in options.cat:
        _categories.extend(TestCase.parse_categories(x))

    # If no one specified a category, default to "smoke" (and anything
    # not built on pyomo.common.unittest.TestCase)
    if not _categories:
        _categories = [(('smoke', 1), ), (('pyomo_unittest', 0), )]
    # process each category set (that is, each conjunction of categories)
    for _category_set in _categories:
        _attrs = []
        # "ALL" deletes the categories, and just runs everything.  Note
        # that "ALL" disables performance testing
        if ('all', 1) in _category_set:
            _categories = []
            _with_performance = False
            attr = []
            break
        # For each category set, unless the user explicitly says
        # something about fragile, assume that fragile should be
        # EXCLUDED.
        if ('fragile',1) not in _category_set \
           and ('fragile',0) not in _category_set:
            _category_set = _category_set + (('fragile', 0), )
        # Process each category in the conjection and add to the nose
        # "attrib" plugin arguments
        for _category, _value in _category_set:
            if not _category:
                continue
            if _value:
                _attrs.append(_category)
            else:
                _attrs.append("(not %s)" % (_category, ))
            if _category == 'performance' and _value == 1:
                _with_performance = True
        if _attrs:
            attr.append("--eval-attr=%s" % (' and '.join(_attrs), ))
    cmd.extend(attr)
    if attr:
        print(" ... for test categor%s: %s" %
              ('y' if len(attr) <= 2 else 'ies', ' '.join(attr[1::2])))

    if _with_performance:
        cmd.append('--with-testdata')
        env['NOSE_WITH_TESTDATA'] = '1'
        env['NOSE_WITH_FORCED_GC'] = '1'

    cmd.extend(options.targets)
    print(cmd)
    print("Running...\n    %s\n" % (' '.join(
        (x if ' ' not in x else '"' + x + '"') for x in cmd), ))
    sys.stdout.flush()
    result = subprocess.run(cmd, env=env)
    rc = result.returncode
    return rc
Пример #4
0
from pyomo.common.config import ConfigValue, In, Path, ListOf, Bool
from pyomo.common.tee import TeeStream
from pyomo.common.fileutils import Executable
from pyomo.common.tempfiles import TempfileManager

from idaes.surrogate.base.surrogate_base import SurrogateTrainer, SurrogateBase
from idaes.core.util.exceptions import ConfigurationError
import idaes.logger as idaeslog


# Set up logger
_log = idaeslog.getLogger(__name__)

# TODO: Adaptive sampling

alamo = Executable('alamo')

# Define mapping of Pyomo function names for expression evaluation
GLOBAL_FUNCS = {"sin": sin, "cos": cos, "log": log, "exp": exp}


# The values associated with these must match those expected in the .alm file
class Modelers(Enum):
    BIC = 1
    MallowsCp = 2
    AICc = 3
    HQC = 4
    MSE = 5
    SSEP = 6
    RIC = 7
    MADp = 8