Ejemplo n.º 1
0
 def __init__(self, *args, **kwargs):
     super(TestClientResponseParam, self).__init__(*args, **kwargs)
     self.driver = 'ClientResponseDriver'
     self.args = None
     self.attr_list += ['comm', 'msg_id', 'response_address']
     self.comm_name = tools.get_default_comm()
     self.server_comm = tools.get_default_comm()
     self.icomm_name = self.server_comm
     self.ocomm_name = self.comm_name
Ejemplo n.º 2
0
 def __init__(self, *args, **kwargs):
     super(TestClientParam, self).__init__(*args, **kwargs)
     self.driver = 'ClientDriver'
     self.args = None
     self.attr_list += [
         'comm', 'response_drivers', 'request_name', 'request_address'
     ]
     # Increased to allow forwarding between IPC comms on MacOS
     # self.timeout = 5.0
     self.route_timeout = 2 * self.timeout
     # self.debug_flag = True
     self.comm_name = tools.get_default_comm()
     self.server_comm = tools.get_default_comm()
     self.icomm_name = self.comm_name
     self.ocomm_name = self.server_comm
Ejemplo n.º 3
0
 def __init__(self, *args, **kwargs):
     super(TestServerParam, self).__init__(*args, **kwargs)
     self.driver = 'ServerDriver'
     self.args = None
     self.attr_list += ['comm', 'response_drivers', 'nclients',
                        'request_name']
     # Increased to allow forwarding between IPC comms on MacOS
     self.timeout = 5.0
     self.route_timeout = 2 * self.timeout
     # if tools.get_default_comm() == "IPCComm":
     #     self.route_timeout = 120.0
     # self.debug_flag = True
     # self.sleeptime = 0.5
     # self.timeout = 10.0
     self.comm_name = tools.get_default_comm()
     self.client_comm = tools.get_default_comm()
     self.icomm_name = self.client_comm
     self.ocomm_name = self.comm_name
Ejemplo n.º 4
0
    def _get_alias(cls, overwrite=False):
        r"""Initialize the default comm class as the alias.

        Args:
            overwrite (bool, optional): If True, the existing aliased class will
                be replaced. Defaults to False

        Returns:
            class: The actual default comm class that this class represents.

        """
        if (getattr(cls, '_alias', None) is None) or overwrite:
            from yggdrasil.tools import get_default_comm
            cls._alias = import_component('comm', get_default_comm())
        return cls._alias
Ejemplo n.º 5
0
def get_comm_class(comm=None):
    r"""Return a communication class given it's name.

    Args:
        comm (str, optional): Name of communicator class. Defaults to
            tools.get_default_comm() if not provided.

    Returns:
        class: Communicator class.

    """
    if (comm is None) or (comm == 'DefaultComm'):
        comm = tools.get_default_comm()
    mod = importlib.import_module('yggdrasil.communication.%s' % comm)
    comm_cls = getattr(mod, comm)
    return comm_cls
Ejemplo n.º 6
0
    def get_internal_suffix(cls, commtype=None):
        r"""Determine the suffix that should be used for internal libraries.

        Args:
            commtype (str, optional): If provided, this is the communication
                type that should be used for the model. If None, the
                default comm is used.

        Returns:
            str: Suffix that should be added to internal libraries to
                differentiate between different dependencies.

        """
        out = super(FortranModelDriver,
                    cls).get_internal_suffix(commtype=commtype)
        if commtype is None:
            commtype = tools.get_default_comm()
        out += '_%s' % commtype[:3].lower()
        return out
Ejemplo n.º 7
0
import unittest
from yggdrasil import tools, platform
from yggdrasil.tests import MagicTestError, assert_raises
from yggdrasil.schema import get_schema
from yggdrasil.components import import_component
from yggdrasil.drivers.tests import test_Driver as parent
from yggdrasil.drivers.ConnectionDriver import ConnectionDriver
from yggdrasil.communication import (
    new_comm, ZMQComm, IPCComm, RMQComm)


_default_comm = tools.get_default_comm()
_zmq_installed = ZMQComm.ZMQComm.is_installed(language='python')
_ipc_installed = IPCComm.IPCComm.is_installed(language='python')
_rmq_installed = RMQComm.RMQComm.is_installed(language='python')


@unittest.skipIf(platform._is_win, ("Temp skip connection tests on windows for "
                                    "time's sake."))
class TestConnectionParam(parent.TestParam):
    r"""Test parameters for the ConnectionDriver class."""

    comm_name = _default_comm
    icomm_name = _default_comm
    ocomm_name = _default_comm
    testing_option_kws = {}
    driver = 'ConnectionDriver'
    
    def __init__(self, *args, **kwargs):
        super(TestConnectionParam, self).__init__(*args, **kwargs)
        self.attr_list += ['icomm_kws', 'ocomm_kws', 'icomm', 'ocomm',
Ejemplo n.º 8
0
def ygginfo():
    r"""Print information about yggdrasil installation."""
    from yggdrasil import __version__, tools, config, platform
    from yggdrasil.components import import_component
    lang_list = tools.get_installed_lang()
    prefix = '    '
    curr_prefix = ''
    vardict = [
        ('Location', os.path.dirname(__file__)), ('Version', __version__),
        ('Languages', ', '.join(lang_list)),
        ('Communication Mechanisms', ', '.join(tools.get_installed_comm())),
        ('Default Comm Mechanism', tools.get_default_comm()),
        ('Config File', config.usr_config_file)
    ]
    parser = argparse.ArgumentParser(
        description=
        'Display information about the current yggdrasil installation.')
    parser.add_argument(
        '--no-languages',
        action='store_true',
        dest='no_languages',
        help='Don\'t print information about individual languages.')
    parser.add_argument(
        '--verbose',
        action='store_true',
        help='Increase the verbosity of the printed information.')
    args = parser.parse_args()
    try:
        # Add language information
        if not args.no_languages:
            # Install languages
            vardict.append(('Installed Languages:', ''))
            curr_prefix += prefix
            for lang in sorted(lang_list):
                drv = import_component('model', lang)
                vardict.append((curr_prefix + '%s:' % lang.upper(), ''))
                curr_prefix += prefix
                if lang == 'executable':
                    vardict.append((curr_prefix + 'Location', ''))
                else:
                    exec_name = drv.language_executable()
                    if not os.path.isabs(exec_name):
                        exec_name = tools.which(exec_name)
                    vardict.append((curr_prefix + 'Location', exec_name))
                vardict.append(
                    (curr_prefix + 'Version', drv.language_version()))
                curr_prefix = curr_prefix.rsplit(prefix, 1)[0]
            curr_prefix = curr_prefix.rsplit(prefix, 1)[0]
            # Not installed languages
            vardict.append(("Languages Not Installed:", ''))
            curr_prefix += prefix
            for lang in tools.get_supported_lang():
                if lang in lang_list:
                    continue
                drv = import_component('model', lang)
                vardict.append((curr_prefix + '%s:' % lang.upper(), ''))
                curr_prefix += prefix
                vardict.append((curr_prefix + "Language Installed",
                                drv.is_language_installed()))
                vardict.append((curr_prefix + "Base Languages Installed",
                                drv.are_base_languages_installed()))
                if not drv.are_base_languages_installed():
                    vardict.append(
                        (curr_prefix + "Base Languages Not Installed", [
                            b for b in drv.base_languages if
                            (not import_component('model', b).is_installed())
                        ]))
                vardict.append((curr_prefix + "Dependencies Installed",
                                drv.are_dependencies_installed()))
                vardict.append((curr_prefix + "Interface Installed",
                                drv.is_interface_installed()))
                vardict.append(
                    (curr_prefix + "Comm Installed", drv.is_comm_installed()))
                vardict.append(
                    (curr_prefix + "Configured", drv.is_configured()))
                vardict.append((curr_prefix + "Disabled", drv.is_disabled()))
                curr_prefix = curr_prefix.rsplit(prefix, 1)[0]
            curr_prefix = curr_prefix.rsplit(prefix, 1)[0]
        # Add verbose information
        if args.verbose:
            # Conda info
            if os.environ.get('CONDA_PREFIX', ''):
                out = tools.bytes2str(
                    subprocess.check_output(['conda', 'info'])).strip()
                curr_prefix += prefix
                vardict.append((curr_prefix + 'Conda Info:',
                                "\n%s%s" % (curr_prefix + prefix,
                                            ("\n" + curr_prefix + prefix).join(
                                                out.splitlines(False)))))
                curr_prefix = curr_prefix.rsplit(prefix, 1)[0]
            # R and reticulate info
            Rdrv = import_component("model", "R")
            if Rdrv.is_installed():
                env_reticulate = copy.deepcopy(os.environ)
                env_reticulate['RETICULATE_PYTHON'] = sys.executable
                # Stack size
                out = Rdrv.run_executable(["-e", "Cstack_info()"]).strip()
                vardict.append((curr_prefix + "R Cstack_info:",
                                "\n%s%s" % (curr_prefix + prefix,
                                            ("\n" + curr_prefix + prefix).join(
                                                out.splitlines(False)))))
                # Compilation tools
                interp = 'R'.join(Rdrv.get_interpreter().rsplit('Rscript', 1))
                vardict.append((curr_prefix + "R C Compiler:", ""))
                curr_prefix += prefix
                for x in ['CC', 'CFLAGS', 'CXX', 'CXXFLAGS']:
                    out = tools.bytes2str(
                        subprocess.check_output([interp, 'CMD', 'config',
                                                 x])).strip()
                    vardict.append((curr_prefix + x,
                                    "%s" % ("\n" + curr_prefix + prefix).join(
                                        out.splitlines(False))))
                curr_prefix = curr_prefix.rsplit(prefix, 1)[0]
                # Session info
                out = Rdrv.run_executable(["-e", "sessionInfo()"]).strip()
                vardict.append((curr_prefix + "R sessionInfo:",
                                "\n%s%s" % (curr_prefix + prefix,
                                            ("\n" + curr_prefix + prefix).join(
                                                out.splitlines(False)))))
                # Reticulate conda_list
                if os.environ.get('CONDA_PREFIX', ''):
                    out = Rdrv.run_executable([
                        "-e",
                        ("library(reticulate); "
                         "reticulate::conda_list()")
                    ],
                                              env=env_reticulate).strip()
                    vardict.append(
                        (curr_prefix + "R reticulate::conda_list():",
                         "\n%s%s" % (curr_prefix + prefix,
                                     ("\n" + curr_prefix + prefix).join(
                                         out.splitlines(False)))))
                # Windows python versions
                if platform._is_win:  # pragma: windows
                    out = Rdrv.run_executable([
                        "-e",
                        ("library(reticulate); "
                         "reticulate::py_versions_windows()")
                    ],
                                              env=env_reticulate).strip()
                    vardict.append(
                        (curr_prefix + "R reticulate::py_versions_windows():",
                         "\n%s%s" % (curr_prefix + prefix,
                                     ("\n" + curr_prefix + prefix).join(
                                         out.splitlines(False)))))
                # conda_binary
                if platform._is_win:  # pragma: windows
                    out = Rdrv.run_executable([
                        "-e",
                        ("library(reticulate); "
                         "conda <- reticulate:::conda_binary(\"auto\"); "
                         "system(paste(conda, \"info --json\"))")
                    ],
                                              env=env_reticulate).strip()
                    vardict.append(
                        (curr_prefix + "R reticulate::py_versions_windows():",
                         "\n%s%s" % (curr_prefix + prefix,
                                     ("\n" + curr_prefix + prefix).join(
                                         out.splitlines(False)))))
                # Reticulate py_config
                out = Rdrv.run_executable([
                    "-e", ("library(reticulate); "
                           "reticulate::py_config()")
                ],
                                          env=env_reticulate).strip()
                vardict.append((curr_prefix + "R reticulate::py_config():",
                                "\n%s%s" % (curr_prefix + prefix,
                                            ("\n" + curr_prefix + prefix).join(
                                                out.splitlines(False)))))
    finally:
        # Print things
        max_len = max(len(x[0]) for x in vardict)
        lines = []
        line_format = '%-' + str(max_len) + 's' + prefix + '%s'
        for k, v in vardict:
            lines.append(line_format % (k, v))
        logger.info("yggdrasil info:\n%s" % '\n'.join(lines))
Ejemplo n.º 9
0
 def cleanup_comm_classes(self):
     r"""list: Comm classes that should be cleaned up following the test."""
     return [tools.get_default_comm()]
Ejemplo n.º 10
0
def get_flags(for_cmake=False, for_api=False, cpp=False):
    r"""Get the necessary flags for compiling & linking with Ygg libraries.

    Args:
        for_cmake (bool, optional): If True, the returned flags will match the
            format required by cmake. Defaults to False.
        for_api (bool, optional): If True, the returned flags will match those
            required for compiling the API static library. Defaults to False.
        cpp (bool, optional): If True, flags for compiling a C++ model are
            returned. Otherwise, flags for compiling a C model are returned.
            Defaults to False.

    Returns:
        tuple(list, list): compile and linker flags.

    """
    if cpp:
        _compile_flags = os.environ.get('CXXFLAGS', '').split()
    else:
        _compile_flags = os.environ.get('CFLAGS', '').split()
    _linker_flags = os.environ.get('LDFLAGS', '').split()
    if not _c_installed:  # pragma: windows
        logging.warning("No library installed for models written in C")
        return _compile_flags, _linker_flags
    if platform._is_win:  # pragma: windows
        _compile_flags += ["/nologo", "-D_CRT_SECURE_NO_WARNINGS"]
        _compile_flags += ['-I' + _top_dir]
        _compile_flags += ['-I' + _incl_interface]
        if not for_cmake:
            _regex_win32 = os.path.split(_regex_win32_lib)
            _compile_flags += ['-I' + _regex_win32[0]]
    if tools.is_comm_installed('ZMQComm', language='c'):
        zmq_flags = get_zmq_flags(for_cmake=for_cmake, for_api=for_api)
        _compile_flags += zmq_flags[0]
        _linker_flags += zmq_flags[1]
    if tools.is_comm_installed('IPCComm', language='c'):
        ipc_flags = get_ipc_flags(for_cmake=for_cmake, for_api=for_api)
        _compile_flags += ipc_flags[0]
        _linker_flags += ipc_flags[1]
    # Include dir
    for x in [
            _incl_interface, _incl_io, _incl_comm, _incl_seri, _incl_regex,
            _incl_dtype
    ]:
        _compile_flags += ["-I" + x]
    # Interface library
    if not for_api:
        if cpp:
            plib = _api_static_cpp
        else:
            plib = _api_static_c
        plib_d, plib_f = os.path.split(plib)
        if for_cmake:
            _linker_flags.append(plib)
            # _linker_flags += [_api_static_c, _api_static_cpp]
        elif platform._is_win:  # pragma: windows
            _linker_flags += ['/LIBPATH:%s' % plib_d, plib_f]
        else:
            _linker_flags += ["-L" + plib_d]
            _linker_flags += [
                "-l" + os.path.splitext(plib_f)[0].split(_prefix)[-1]
            ]
    if tools.get_default_comm() == 'IPCComm':
        _compile_flags += ["-DIPCDEF"]
    return _compile_flags, _linker_flags