yggdrasil.drivers package¶
Submodules¶
yggdrasil.drivers.BuildModelDriver module¶
- class yggdrasil.drivers.BuildModelDriver.BuildModelDriver(*args, **kwargs)[source]¶
Bases:
CompiledModelDriver
Class for running build file compiled drivers.
- Parameters:
name (str) – Driver name.
args (str, list) – Executable that should be created (make target) and any arguments for the executable.
target (str, optional) – Make target that should be built to create the model executable. Defaults to None.
target_language (str, optional) – Language that the target is written in. Defaults to None and will be set based on the source files provided.
target_compiler (str, optional) – Compilation tool that should be used to compile the target language. Defaults to None and will be set based on the selected language driver.
target_linker (str, optional) – Compilation tool that should be used to link the target language. Defaults to None and will be set based on the selected language driver.
target_compiler_flags (list, optional) – Compilation flags that should be passed to the target language compiler. Defaults to [].
target_linker_flags (list, optional) – Linking flags that should be passed to the target language linker. Defaults to [].
env_compiler (str, optional) – Environment variable where the compiler executable should be stored for use within the Makefile. If not provided, this will be determined by the target language driver.
env_compiler_flags (str, optional) – Environment variable where the compiler flags should be stored (including those required to compile against the yggdrasil interface). If not provided, this will be determined by the target language driver.
env_linker (str, optional) – Environment variable where the linker executable should be stored for use within the Makefile. If not provided, this will be determined by the target language driver.
env_linker_flags (str, optional) – Environment variable where the linker flags should be stored (including those required to link against the yggdrasil interface). If not provided, this will be determined by the target language driver.
**kwargs – Additional keyword arguments are passed to parent class.
- compiledir¶
Path to directory where compilation call should be made from. Defaults to working_dir.
- Type:
- target_language_driver¶
Language driver for the target language.
- Type:
- target_compiler_flags¶
Compilation flags that should be passed to the target language compiler.
- Type:
- Class Attributes:
- built_where_called (bool): If True, it is assumed that compilation
output will be saved in the same directory from which the compilation command is issued.
- Raises:
RuntimeError – If neither the IPC or ZMQ C libraries are available.
- static after_registration(cls, **kwargs)[source]¶
Operations that should be performed to modify class attributes after registration. For compiled languages this includes selecting the default compiler. The order of precedence is the config file ‘compiler’ option for the language, followed by the environment variable set by _compiler_env, followed by the existing class attribute.
- allow_parallel_build = False¶
- base_languages = ['c']¶
- buildfile_base = None¶
- built_where_called = False¶
- classmethod call_compiler(src, **kwargs)[source]¶
Compile a source file into an executable or linkable object file, checking for errors.
- compile_dependencies_instance(*args, **kwargs)[source]¶
Compile dependencies specifically for this instance.
- compile_model(**kwargs)[source]¶
Compile model executable(s).
- Parameters:
**kwargs – Keyword arguments are passed on to the parent class’s method.
- executable_type = 'build'¶
- full_language = False¶
- classmethod get_buildfile_lock(**kwargs)[source]¶
Get a lock for a buildfile to prevent simultaneous access, creating one as necessary.
- classmethod get_language_for_buildfile(buildfile, target=None)[source]¶
Determine the target language based on the contents of a build file.
- classmethod get_language_for_source(fname=None, buildfile=None, languages=None, early_exit=False, call_base=False, **kwargs)[source]¶
Determine the language that can be used with the provided source file(s). If more than one language applies to a set of multiple files, the language that applies to the most files is returned.
- Parameters:
fname (str, list) – The full path to one or more files. If more than one is provided, they are iterated over.
buildfile (str, optional) – Full path to the build configuration file. Defaults to None and will be searched for.
languages (list, optional) – The list of languages that are acceptable. Defaults to None and any language will be acceptable.
early_exit (bool, optional) – If True, the first language identified will be returned if fname is a list of files. Defaults to False.
source_dir (str, optional) – Full path to the directory containing the source files. Defaults to None and is determiend from fname.
buildfile – Full path to the build configuration file. Defaults to None and will be searched for.
target (str, optional) – The build target. Defaults to None.
call_base (bool, optional) – If True, the base class’s method is called directly. Defaults to False.
**kwargs – Additional keyword arguments are passed to the parent class’s method.
- Returns:
The language that can operate on the specified file.
- Return type:
- classmethod get_target_language_info(target_language_driver=None, target_language='c', target_compiler=None, target_compiler_flags=None, target_linker=None, target_linker_flags=None, logging_level=None, without_wrapper=False, compiler_flag_kwargs=None, linker_flag_kwargs=None, **kwargs)[source]¶
Get a dictionary of information about language compilation tools.
- Parameters:
target_language_driver (ModelDriver, optional) – Driver associated with the target language. If not provided, one will be created based on ‘target_language’.
target_language (str, optional) – Language to get info for. Defaults to ‘c’.
target_compiler (str, optional) – Compilation tool that should be used to compile the target language. Defaults to None and will be set based on the selected language driver.
target_linker (str, optional) – Compilation tool that should be used to link the target language. Defaults to None and will be set based on the selected language driver.
target_compiler_flags (list, optional) – Compilation flags that should be passed to the target language compiler. Defaults to [].
target_linker_flags (list, optional) – Linking flags that should be passed to the target language linker. Defaults to [].
logging_level (int, optional) – The numeric logging level that should be passed as a definition. Defaults to None and is ignored.
without_wrapper (bool, optional) – If True, the returned info will be updated for compilation when a build wrapper was not created. Defaults to False.
compiler_flag_kwargs (dict, optional) – Keyword arguments to pass to the get_compiler_flags method. Defaults to None.
linker_flag_kwargs (dict, optional) – Keyword arguments to pass to the get_linker_flags method. Defaults to None.
**kwargs – Additional keyword arguments are added to the output dictionary.
- Returns:
Information about language compilers and linkers.
- Return type:
- is_build_tool = True¶
- classmethod is_source_file(fname)[source]¶
Determine if the provided file name points to a source files for the associated programming language by checking the extension.
- parse_arguments(args, **kwargs)[source]¶
Sort arguments based on their syntax to determine if an argument is a source file, compilation flag, or runtime option/flag that should be passed to the model executable.
- Parameters:
args (list) – List of arguments provided.
**kwargs – Additional keyword arguments are passed to the parent class’s method.
- set_env(**kwargs)[source]¶
Get environment variables that should be set for the model process.
- Parameters:
**kwargs – Additional keyword arguments are passed to the parent class’s method.
- Returns:
Environment variables for the model process.
- Return type:
- classmethod set_env_compiler(language_info=None, **kwargs)[source]¶
Get environment variables that should be set for the compilation process.
- set_target_language()[source]¶
Set the language of the target being compiled (usually the same as the language associated with this driver.
- Returns:
Name of language.
- Return type:
- sourcedir_as_sourcefile = False¶
- class yggdrasil.drivers.BuildModelDriver.BuildToolBase(**kwargs)[source]¶
Bases:
CompilerBase
Base class for build tools.
- static before_registration(cls)[source]¶
Operations that should be performed to modify class attributes prior to registration including things like platform dependent properties and checking environment variables for default settings.
- build_language = None¶
- classmethod get_flags(**kwargs)[source]¶
Get compilation flags, replacing outfile with target.
- Parameters:
**kwargs – Additional keyword arguments are passed to the parent class’s method.
- Returns:
Compiler flags.
- Return type:
- classmethod get_tool_suffix()[source]¶
Get the string that should be added to tool products based on the tool used.
- Returns:
- Suffix that should be added to tool products to indicate the
tool used.
- Return type:
- is_build_tool = True¶
yggdrasil.drivers.CMakeModelDriver module¶
- class yggdrasil.drivers.CMakeModelDriver.CMakeBuilder(**kwargs)[source]¶
Bases:
LinkerBase
CMake build tool.
- default_executable = 'cmake'¶
- default_flags = []¶
- executable_ext = ''¶
- classmethod extract_kwargs(kwargs, **kwargs_ex)[source]¶
Extract linker kwargs, leaving behind just compiler kwargs.
- Parameters:
kwargs (dict) – Keyword arguments passed to the compiler that should be sorted into kwargs used by either the compiler or linker or both. Keywords that are not used by the compiler will be removed from this dictionary.
**kwargs_ex – Additional keyword arguments are passed to the parent class’s method.
- Returns:
Keyword arguments that should be passed to the linker.
- Return type:
- flag_options = {'builddir': {'key': '--build', 'position': 0}, 'configuration': '--config', 'target': '--target'}¶
- classmethod get_executable_command(args, **kwargs)[source]¶
Determine the command required to run the tool using the specified arguments and options.
- Parameters:
args (list) – The arguments that should be passed to the tool. If skip_flags is False, these are treated as input files that will be used by the tool.
**kwargs – Additional keyword arguments are passed to the parent class’s method.
- Returns:
Output to stdout from the command execution.
- Return type:
- classmethod get_flags(target=None, builddir=None, **kwargs)[source]¶
Get a list of build flags for building a project using cmake.
- Parameters:
target (str, optional) – Target that should be built. Defaults to to None and is ignored.
builddir (str, optional) – Directory containing the build tree. Defaults to None and is set based on outfile is provided or cls.default_builddir if not. Defaults to ‘.’ (which will be the current working directory).
**kwargs – Additional keyword arguments are ignored.
- Returns:
Linker flags.
- Return type:
- classmethod get_output_file(obj, target=None, builddir=None, **kwargs)[source]¶
Determine the appropriate output file that will result when bulding a given directory.
- Parameters:
obj (str) – Directory being built or a file in the directory being built.
target (str, optional) – Target that will be used to create the output file. Defaults to None. Target is required in order to determine the name of the file that will be created.
builddir (str, optional) – Directory where build tree should be created. Defaults to None and obj will used (if its a directory) or the directory containing obj will be used (if its a file).
**kwargs – Additional keyword arguments are passed to the parent class’s method.
- Returns:
Full path to file that will be produced.
- Return type:
- Raises:
RuntimeError – If target is None.
- is_gnu = False¶
- languages = ['cmake']¶
- library_ext = '.so'¶
- output_key = None¶
- tool_suffix_format = ''¶
- toolname = 'cmake'¶
- class yggdrasil.drivers.CMakeModelDriver.CMakeConfigure(**kwargs)[source]¶
Bases:
BuildToolBase
CMake configuration tool.
- add_libraries = False¶
- classmethod append_product(products, src, new, **kwargs)[source]¶
Append a product to the specified list along with additional values indicated by cls.product_exts.
- Parameters:
products (list) – List of of existing products that new product should be appended to.
src (list) – Input arguments to compilation call that was used to generate the output file (usually one or more source files).
new (str) – New product that should be appended to the list.
**kwargs – Additional keyword arguments are passed to the parent class’s method.
- static before_registration(cls)[source]¶
Operations that should be performed to modify class attributes prior to registration including things like platform dependent properties and checking environment variables for default settings.
- build_language = 'cmake'¶
- classmethod call(args, **kwargs)[source]¶
Call the tool with the provided arguments. If the first argument resembles the name of the tool executable, the executable will not be added.
- Parameters:
args (list) – The arguments that should be passed to the tool.
**kwargs – Additional keyword arguments are passed to the parent class’s method and the associated linker/archiver’s call method if dont_link is False.
- Returns:
- Output to stdout from the command execution if skip_flags is
True, produced file otherwise.
- Return type:
- combine_with_linker = False¶
- compile_only_flag = None¶
- classmethod create_include(fname, target, driver=None, compiler=None, compiler_flags=None, linker=None, linker_flags=None, library_flags=None, internal_library_flags=None, configuration='Release', verbose=False, **kwargs)[source]¶
Create CMakeList include file with necessary includes, definitions, and linker flags.
- Parameters:
fname (str) – File where the include file should be saved.
target (str) – Target that links should be added to.
driver (CompiledModelDriver) – Driver for the language being compiled.
compiler (CompilerBase) – Compiler that should be used to generate the list of compilation flags.
compile_flags (list, optional) – Additional compile flags that should be set. Defaults to [].
linker (LinkerBase) – Linker that should be used to generate the list of compilation flags.
linker_flags (list, optional) – Additional linker flags that should be set. Defaults to [].
library_flags (list, optional) – List of library flags to add. Defaults to [].
internal_library_flags (list, optional) – List of library flags associated with yggdrasil libraries. Defaults to [].
configuration (str, optional) – Build type/configuration that should be built. Defaults to ‘Release’. Only used on Windows to determine the standard library.
verbose (bool, optional) – If True, the contents of the created file are displayed. Defaults to False.
**kwargs – Additional keyword arguments are ignored.
- Returns:
- Lines that should be added before the executable is
defined in the CMakeLists.txt (e.g. LINK_DIRECTORIES commands).
- Return type:
- Raises:
ValueError – If a linker or compiler flag cannot be interpreted.
- default_archiver = False¶
- default_builddir = '.'¶
- default_executable = 'cmake'¶
- default_flags = []¶
- classmethod fix_path(x, is_gnu=False)[source]¶
Fix paths so that they conform to the format expected by the OS and/or build tool.
- flag_options = {'builddir': '-B%s', 'configuration': '-DCMAKE_BUILD_TYPE=%s', 'definitions': '-D%s', 'generator': '-G%s', 'platform': '-A%s', 'sourcedir': '', 'toolset': '-T%s'}¶
- classmethod generator(return_default=False, default=None, **kwargs)[source]¶
Determine the generator that should be used.
- Parameters:
return_default (bool, optional) – If True, the default generator will be returned even if the environment variable is set. Defaults to False.
default (str, optional) – Value that should be returned if a generator cannot be located. Defaults to None.
**kwargs – Keyword arguments are passed to cls.call.
- Returns:
Name of the generator.
- Return type:
- classmethod generator2toolset(generator)[source]¶
Determine the toolset string option that corresponds to the provided generator name.
- Parameters:
generator (str) – Name of the generator.
- Returns:
Name of the toolset.
- Return type:
- Raises:
NotImplementedError – If the platform is not windows.
ValueError – If the generator is not a flavor of Visual Studio.
ValueError – If a tool set cannot be located for the specified generator.
- classmethod get_executable_command(args, **kwargs)[source]¶
Determine the command required to run the tool using the specified arguments and options.
- Parameters:
args (list) – The arguments that should be passed to the tool. If skip_flags is False, these are treated as input files that will be used by the tool.
**kwargs – Additional keyword arguments are passed to the parent class’s method.
- Returns:
Output to stdout from the command execution.
- Return type:
- classmethod get_flags(sourcedir='.', builddir=None, target_compiler=None, target_linker=None, **kwargs)[source]¶
Get a list of configuration/generation flags.
- Parameters:
sourcedir (str, optional) – Directory containing the source files to be compiled and the target CMakeLists.txt file. Defaults to ‘.’ (the current working directory).
builddir (str, optional) – Directory that will contain the build tree. Defaults to ‘.’ (this current working directory).
target_compiler (str, optional) – Compiler that should be used by cmake. Defaults to None and the default for the target language will be used.
target_linker (str, optional) – Linker that should be used by cmake. Defaults to None and the default for the target language will be used.
**kwargs – Additional keyword arguments are passed to the parent class’s method.
- Returns:
Compiler flags.
- Return type:
- Raises:
RuntimeError – If dont_link is True and the provide outfile and builddir keyword arguments point to conflicting paths.
ValueError – If ‘include_dirs’ is set (‘sourcedir’ should be used for cmake to specify the location of the source).
- classmethod get_output_file(src, dont_link=False, dont_build=None, sourcedir=None, builddir=None, working_dir=None, **kwargs)[source]¶
Determine the appropriate output file or directory that will result when configuring/building a given source directory.
- Parameters:
src (str) – Directory containing source files being compiled.
dont_link (bool, optional) – If True, the result assumes that the source is just compiled and not linked. If False, the result will be the final result after linking.
dont_build (bool, optional) – Alias for dont_link. If not None, this keyword overrides the value of dont_link. Defaults to None.
sourcedir (str, optional) – Directory where sources files are located. Defaults to None. If None, src will be used to determine the value.
builddir (str, optional) – Directory where build tree should be created. Defaults to None. If None, sourcedir will be used.
working_dir (str, optional) – Working directory where output file should be located. Defaults to None and is ignored.
**kwargs – Additional keyword arguments are ignored unless dont_link is False; then they are passed to get_linker_output_file
- Returns:
Full path to file that will be produced.
- Return type:
- is_gnu = False¶
- is_linker = False¶
- languages = ['cmake']¶
- output_key = None¶
- product_files = ['Makefile', 'CMakeCache.txt', 'cmake_install.cmake', 'CMakeFiles']¶
- remove_product_exts = ['CMakeFiles']¶
- toolname = 'cmake'¶
- class yggdrasil.drivers.CMakeModelDriver.CMakeModelDriver(*args, **kwargs)[source]¶
Bases:
BuildModelDriver
Class for running cmake compiled drivers. Before running the cmake command, the cmake commands for setting the necessary compiler & linker flags for the interface’s C/C++ library are written to a file called ‘ygg_cmake.txt’ that should be included in the CMakeLists.txt file (after the target executable has been added).
- Parameters:
name (str) – Driver name.
args (str, list) – Executable that should be created (cmake target) and any arguments for the executable.
sourcedir (str, optional) – Source directory to call cmake on. If not provided it is set to working_dir. This should be the directory containing the CMakeLists.txt file. It can be relative to working_dir or absolute.
builddir (str, optional) – Directory where the build should be saved. Defaults to <sourcedir>/build. It can be relative to working_dir or absolute.
configuration (str, optional) – Build type/configuration that should be built. Defaults to ‘Release’.
**kwargs – Additional keyword arguments are passed to parent class.
- add_libraries¶
If True, interface libraries and dependency libraries are added using CMake’s ADD_LIBRARY directive. If False, interface libraries are found using FIND_LIBRARY.
- Type:
- configuration¶
Build type/configuration that should be built. This is only used on Windows.
- Type:
- Raises:
RuntimeError – If neither the IPC or ZMQ C libraries are available.
- add_libraries = False¶
- buildfile_base = 'CMakeLists.txt'¶
- property buildfile_orig¶
Full path to where the original CMakeLists.txt file will be stored during compilation of the modified file.
- Type:
- property buildfile_ygg¶
Full path to the verison of the CMakeLists.txt that has been updated w/ yggdrasil compilation flags.
- Type:
- cfg = <yggdrasil.config.YggConfigParser object>¶
- compile_model(target=None, **kwargs)[source]¶
Compile model executable(s) and appends any products produced by the compilation that should be removed after the run is complete.
- Parameters:
target (str, optional) – Target to build.
**kwargs – Keyword arguments are passed on to the call_compiler method.
- default_archiver = None¶
- default_archiver_flags = None¶
- default_compiler = 'cmake'¶
- default_compiler_flags = None¶
- default_linker = 'cmake'¶
- default_linker_flags = None¶
- classmethod get_language_for_buildfile(buildfile, target=None)[source]¶
Determine the target language based on the contents of a build file.
- classmethod get_target_language_info(target_compiler_flags=None, target_linker_flags=None, compiler_flag_kwargs=None, linker_flag_kwargs=None, without_wrapper=False, **kwargs)[source]¶
Get a dictionary of information about language compilation tools.
- Parameters:
target_compiler_flags (list, optional) – Compilation flags that should be passed to the target language compiler. Defaults to [].
target_linker_flags (list, optional) – Linking flags that should be passed to the target language linker. Defaults to [].
compiler_flag_kwargs (dict, optional) – Keyword arguments to pass to the get_compiler_flags method. Defaults to None.
linker_flag_kwargs (dict, optional) – Keyword arguments to pass to the get_linker_flags method. Defaults to None.
**kwargs – Keyword arguments are passed to the parent class’s method.
- Returns:
Information about language compilers and linkers.
- Return type:
- inverse_type_map = None¶
- language = 'cmake'¶
- parse_arguments(args, **kwargs)[source]¶
Sort arguments based on their syntax to determine if an argument is a source file, compilation flag, or runtime option/flag that should be passed to the model executable.
- Parameters:
args (list) – List of arguments provided.
**kwargs – Additional keyword arguments are passed to the parent class’s method.
- classmethod prune_sh_gcc(path, gcc)[source]¶
Remove instances of sh.exe from the path that are not associated with the selected gcc compiler. This can happen on windows when rtools or git install a version of sh.exe that is added to the path before the compiler.
- sourcedir_as_sourcefile = True¶
- classmethod update_compiler_kwargs(**kwargs)[source]¶
Update keyword arguments supplied to the compiler get_flags method for various options.
- Parameters:
**kwargs – Additional keyword arguments are passed to the parent class’s method.
- Returns:
- Keyword arguments for a get_flags method providing compiler
flags.
- Return type:
- use_env_vars = False¶
yggdrasil.drivers.CModelDriver module¶
- class yggdrasil.drivers.CModelDriver.ARArchiver(**kwargs)[source]¶
Bases:
ArchiverBase
Archiver class for ar tool.
- asan_flags = []¶
- compatible_toolsets = ['gnu', 'llvm']¶
- default_executable = 'ar'¶
- default_executable_env = 'AR'¶
- default_flags = []¶
- default_flags_env = None¶
- is_gnu = True¶
- languages = ['c', 'c++', 'fortran']¶
- library_ext = '.a'¶
- output_first_library = True¶
- output_key = ''¶
- search_path_envvar = ['LIBRARY_PATH']¶
- static_library_flag = 'rcs'¶
- toolname = 'ar'¶
- toolset = 'gnu'¶
- class yggdrasil.drivers.CModelDriver.CCompilerBase(**kwargs)[source]¶
Bases:
CompilerBase
Base class for C compilers.
- classmethod call(args, **kwargs)[source]¶
Call the compiler with the provided arguments. For yggdrasil C models will always be linked using the C++ linker since some parts of the interface library are written in C++.
- default_executable_env = 'CC'¶
- default_flags = ['-g', '-Wall']¶
- default_flags_env = 'CFLAGS'¶
- classmethod get_search_path(*args, **kwargs)[source]¶
Determine the paths searched by the tool for external library files.
- Parameters:
*args – Additional arguments are passed to the parent class’s method.
**kwargs – Additional keyword arguments are passed to the parent class’s method.
- Returns:
List of paths that the tools will search.
- Return type:
- languages = ['c']¶
- linker_attributes = {'default_executable_env': 'LD', 'default_flags_env': 'LDFLAGS', 'search_path_envvar': ['LIBRARY_PATH', 'LD_LIBRARY_PATH']}¶
- search_path_envvar = ['C_INCLUDE_PATH']¶
- search_path_flags = ['-E', '-v', '-xc', '/dev/null']¶
- search_regex = ['(?:#include <...> search starts here:)|(?: ([^\\n]+?)(?: \\(framework directory\\))?)\\n']¶
- search_regex_begin = '#include "..." search starts here:'¶
- search_regex_end = 'End of search list.'¶
- classmethod set_env(*args, **kwargs)[source]¶
Set environment variables required for compilation.
- Parameters:
*args – Arguments are passed to the parent class’s method.
**kwargs – Keyword arguments are passed to the parent class’s method.
- Returns:
Environment variables for the model process.
- Return type:
- class yggdrasil.drivers.CModelDriver.CModelDriver(*args, **kwargs)[source]¶
Bases:
CompiledModelDriver
Class for running C models.
- static after_registration(cls, **kwargs)[source]¶
Operations that should be performed to modify class attributes after registration.
- classmethod allows_realloc(var)[source]¶
Determine if a variable allows the receive call to perform realloc.
- brackets = ('{', '}')¶
- classmethod call_linker(obj, language=None, **kwargs)[source]¶
Link several object files to create an executable or library (shared or static), checking for errors.
- Parameters:
- Returns:
Full path to compiled source.
- Return type:
- cfg = <yggdrasil.config.YggConfigParser object>¶
- classmethod configure(cfg, macos_sdkroot=None, vcpkg_dir=None, **kwargs)[source]¶
Add configuration options for this language. This includes locating any required external libraries and setting option defaults.
- Parameters:
cfg (YggConfigParser) – Config class that options should be set for.
macos_sdkroot (str, optional) – Full path to the root directory for the MacOS SDK that should be used. Defaults to None and is ignored.
vcpkg_dir (str, optional) – Full path to the root directory containing a vcpkg installation. This should be the directory that contains the vcpkg executable and any packages installed by vcpkg (in subdirectories). Defaults to None and is ignored.
**kwargs – Additional keyword arguments are passed to the parent class’s method.
- Returns:
- Section, option, description tuples for options that could not
be set.
- Return type:
- default_archiver = 'ar'¶
- default_archiver_flags = None¶
- default_compiler = 'gcc'¶
- default_compiler_flags = None¶
- default_linker = 'gcc'¶
- default_linker_flags = None¶
- external_libraries = {'czmq': {'include': 'czmq.h', 'language': 'c', 'libtype': 'shared', 'shared': '/lib/x86_64-linux-gnu/libczmq.so'}, 'numpy': {'for_python_api': True, 'include': '/opt/hostedtoolcache/Python/3.8.17/x64/lib/python3.8/site-packages/numpy/core/include/numpy/arrayobject.h', 'language': 'c', 'libtype': 'header_only'}, 'python': {'for_python_api': True, 'include': '/opt/hostedtoolcache/Python/3.8.17/x64/include/python3.8/Python.h', 'language': 'c', 'libtype': 'shared', 'shared': '/opt/hostedtoolcache/Python/3.8.17/x64/lib/libpython3.8.so', 'standard': True}, 'rapidjson': {'include': '/opt/hostedtoolcache/Python/3.8.17/x64/lib/python3.8/site-packages/yggdrasil/rapidjson/include/rapidjson/rapidjson.h', 'language': 'c', 'libtype': 'header_only'}, 'zmq': {'include': 'zmq.h', 'language': 'c', 'libtype': 'shared', 'shared': '/lib/x86_64-linux-gnu/libzmq.so'}}¶
- classmethod finalize_function_io(direction, x)[source]¶
Finalize info for an input/output channel following function parsing.
- classmethod format_function_param(key, default=None, **kwargs)[source]¶
Return the formatted version of the specified key.
- Parameters:
- Returns:
Formatted string.
- Return type:
- Raises:
NotImplementedError – If key is not in cls.function_param and default is not set.
- function_param = {'and': '&&', 'assign': '{name} = {value};', 'assign_copy': 'memcpy({name}, {value}, {N}*sizeof({native_type}));', 'block_end': '}', 'break': 'break;', 'comment': '//', 'copy_any': 'copy_generic_into(&{name}, {value});', 'copy_array': 'copy_generic_into(&{name}, {value});', 'copy_class': '{name} = copy_python({value});', 'copy_function': '{name} = copy_python({value});', 'copy_instance': 'copy_generic_into(&{name}, {value});', 'copy_obj': '{name} = copy_obj({value});', 'copy_object': 'copy_generic_into(&{name}, {value});', 'copy_ply': '{name} = copy_ply({value});', 'copy_schema': 'copy_generic_into(&{name}, {value});', 'declare': '{type_name} {variable};', 'error': 'printf("{error_msg}\\n"); return -1;', 'exec_begin': 'int main() {', 'exec_end': ' return 0;\n}', 'exec_prefix': '#include <stdbool.h>', 'false': 'false', 'false_flag': '0', 'flag_cond': '{flag_var} >= 0', 'for_begin': 'for ({iter_var} = {iter_begin}; {iter_var} < {iter_end}; {iter_var}++) {{', 'fprintf': 'printf("{message}\\n", {variables});', 'free': 'if ({variable} != NULL) {{ free({variable}); {variable} = NULL; }}', 'free_any': 'free_generic({variable});', 'free_array': 'free_json_array({variable});', 'free_class': 'destroy_python({variable});', 'free_function': 'destroy_python({variable});', 'free_instance': 'free_generic({variable});', 'free_obj': 'free_obj({variable});', 'free_object': 'free_json_object({variable});', 'free_ply': 'free_ply({variable});', 'free_schema': 'free_schema({variable});', 'function_def_begin': '{output_type} {function_name}({input_var}) {{', 'function_def_regex': '(?P<flag_type>.+?)\\s*{function_name}\\s*\\((?P<inputs>(?:[^{{])*?)\\)\\s*\\{{(?P<body>(?:.*?\\n?)*?)(?:(?:return *(?P<flag_var>.+?)?;(?:.*?\\n?)*?\\}})|(?:\\}}))', 'if_begin': 'if ({cond}) {{', 'if_elif': '}} else if ({cond}) {{', 'if_else': '}} else {{', 'import': '#include "{filename}"', 'indent': ' ', 'index': '{variable}[{index}]', 'init_any': 'init_generic()', 'init_array': 'init_json_array()', 'init_class': 'init_python()', 'init_function': 'init_python()', 'init_instance': 'init_generic()', 'init_obj': 'init_obj()', 'init_object': 'init_json_object()', 'init_ply': 'init_ply()', 'init_schema': 'init_schema()', 'init_type_1darray': 'create_dtype_1darray("{subtype}", {precision}, {length}, "{units}", {use_generic})', 'init_type_array': 'create_dtype_json_array({nitems}, {items}, {use_generic})', 'init_type_default': 'create_dtype_default("{type}", {use_generic})', 'init_type_empty': 'create_dtype_empty({use_generic})', 'init_type_from_schema': 'create_dtype_from_schema("{schema}", {use_generic})', 'init_type_ndarray': 'create_dtype_ndarray("{subtype}", {precision}, {ndim}, {shape}, "{units}", {use_generic})', 'init_type_ndarray_arr': 'create_dtype_ndarray_arr("{subtype}", {precision}, {ndim}, {shape}, "{units}", {use_generic})', 'init_type_obj': 'create_dtype_obj({use_generic})', 'init_type_object': 'create_dtype_json_object({nitems}, {keys}, {values}, {use_generic})', 'init_type_ply': 'create_dtype_ply({use_generic})', 'init_type_pyobj': 'create_dtype_pyobj("{type}", {use_generic})', 'init_type_scalar': 'create_dtype_scalar("{subtype}", {precision}, "{units}", {use_generic})', 'init_type_schema': 'create_dtype_schema({use_generic})', 'input': '{channel} = yggInputType("{channel_name}", {channel_type});', 'inputs_def_regex': '\\s*(?P<native_type>(?:[^\\s\\*])+(\\s+)?(?P<ptr>\\*+)?)(?(ptr)(?(1)(?:\\s*)|(?:\\s+)))(\\((?P<name_ptr>\\*+)?)?(?P<name>.+?)(?(4)(?:\\)))(?P<shape>(?:\\[.+?\\])+)?\\s*(?:,|$)(?:\\n)?', 'interface': '#include "{interface_library}"', 'line_end': ';', 'not': '!', 'not_flag_cond': '{flag_var} < 0', 'null': 'NULL', 'output': '{channel} = yggOutputType("{channel_name}", {channel_type});', 'outputs_def_regex': '\\s*(?P<native_type>(?:[^\\s\\*])+(\\s+)?(?P<ptr>\\*+)?)(?(ptr)(?(1)(?:\\s*)|(?:\\s+)))(?P<name>.+?)(?P<shape>(?:\\[.+?\\])+)?\\s*(?:,|$)(?:\\n)?', 'print': 'printf("{message}\\n");', 'print_any': 'display_generic({object});', 'print_array': 'display_json_array({object});', 'print_bytes': 'printf("%s\\n", {object});', 'print_class': 'display_python({object});', 'print_complex': 'print_complex({object});', 'print_float': 'printf("%f\\n", {object});', 'print_function': 'display_python({object});', 'print_instance': 'display_generic({object});', 'print_int': 'printf("%i\\n", {object});', 'print_obj': 'display_obj({object});', 'print_object': 'display_json_object({object});', 'print_ply': 'display_ply({object});', 'print_schema': 'display_schema({object});', 'print_string': 'printf("%s\\n", {object});', 'print_uint': 'printf("%u\\n", {object});', 'print_unicode': 'printf("%s\\n", {object});', 'python_init': 'init_python_API();', 'quote': '"', 'recv_function': 'yggRecvRealloc', 'recv_heap': 'yggRecvRealloc', 'recv_stack': 'yggRecv', 'return': 'return {output_var};', 'send_function': 'yggSend', 'true': 'true', 'true_flag': '1', 'while_begin': 'while ({cond}) {{'}¶
- classmethod get_native_type(const=False, **kwargs)[source]¶
Get the native type.
- Parameters:
type (str, optional) – Name of yggdrasil extended JSON type or JSONSchema dictionary defining a datatype.
const (bool, optional) – If True, the native type will be marked as constant. Defaults to False.
**kwargs – Additional keyword arguments may be used in determining the precise declaration that should be used.
- Returns:
The native type.
- Return type:
- classmethod get_testing_options(**kwargs)[source]¶
Method to return a dictionary of testing options for this class.
- Parameters:
**kwargs – Additional keyword arguments are passed to the parent class.
- Returns:
- Dictionary of variables to use for testing. Key/value pairs:
kwargs (dict): Keyword arguments for driver instance. deps (list): Dependencies to install.
- Return type:
- include_channel_obj = True¶
- classmethod input2output(var)[source]¶
Perform conversion necessary to turn a variable extracted from a function definition from an input to an output.
- interface_dependencies = ['rapidjson']¶
- interface_directories = ['/opt/hostedtoolcache/Python/3.8.17/x64/lib/python3.8/site-packages/yggdrasil/languages/C']¶
- interface_library = 'ygg'¶
- interface_map = {'call': 'flag = rpcCall({channel_obj}, {outputs}, {inputs})', 'client': 'yggRpcClientType("{channel_name}", {datatype_out}, {datatype_in})', 'import': '#include "YggInterface.h"', 'input': 'yggInputType("{channel_name}", {datatype})', 'output': 'yggOutputType("{channel_name}", {datatype})', 'recv': 'flag = yggRecv({channel_obj}, {input_refs})', 'send': 'flag = yggSend({channel_obj}, {outputs})', 'server': 'yggRpcServerType("{channel_name}", {datatype_in}, {datatype_out})', 'timesync': 'yggTimesync("{channel_name}", "{time_units}")'}¶
- internal_libraries = {'datatypes': {'compiler_flags': ['-fPIC'], 'directory': '/opt/hostedtoolcache/Python/3.8.17/x64/lib/python3.8/site-packages/yggdrasil/languages/C/datatypes', 'external_dependencies': ['rapidjson', 'python', 'numpy', 'm'], 'include_dirs': [], 'internal_dependencies': ['regex'], 'language': 'c++', 'libtype': 'object'}, 'regex': {'directory': '/opt/hostedtoolcache/Python/3.8.17/x64/lib/python3.8/site-packages/yggdrasil/languages/C/regex', 'external_dependencies': [], 'internal_dependencies': [], 'language': 'c', 'libtype': 'header_only', 'source': 'regex_posix.h'}, 'regex_posix': {'directory': '/opt/hostedtoolcache/Python/3.8.17/x64/lib/python3.8/site-packages/yggdrasil/languages/C/regex', 'external_dependencies': [], 'internal_dependencies': [], 'language': 'c', 'libtype': 'header_only', 'source': 'regex_posix.h'}, 'regex_win32': {'directory': '/opt/hostedtoolcache/Python/3.8.17/x64/lib/python3.8/site-packages/yggdrasil/languages/C/regex', 'external_dependencies': [], 'internal_dependencies': [], 'language': 'c++', 'libtype': 'object', 'source': 'regex_win32.cpp'}, 'ygg': {'compiler_flags': ['-fPIC'], 'external_dependencies': ['rapidjson', 'python', 'numpy', 'm'], 'include_dirs': ['/opt/hostedtoolcache/Python/3.8.17/x64/lib/python3.8/site-packages/yggdrasil/languages/C/communication', '/opt/hostedtoolcache/Python/3.8.17/x64/lib/python3.8/site-packages/yggdrasil/languages/C/serialize', '/opt/hostedtoolcache/Python/3.8.17/x64/lib/python3.8/site-packages/yggdrasil/languages/C', '/opt/hostedtoolcache/Python/3.8.17/x64/lib/python3.8/site-packages/yggdrasil/languages/C'], 'internal_dependencies': ['regex', 'datatypes'], 'language': 'c', 'linker_language': 'c++', 'source': '/opt/hostedtoolcache/Python/3.8.17/x64/lib/python3.8/site-packages/yggdrasil/languages/C/YggInterface.c'}}¶
- inverse_type_map = None¶
- is_typed = True¶
- language = 'c'¶
- language_ext = ['.c', '.h']¶
- locked_buildfile = 'datatypes.o'¶
- classmethod output2input(var, in_definition=True)[source]¶
Perform conversion necessary to turn an output variable into an corresponding input that can be used to format a function definition.
- Parameters:
- Returns:
Updated variable definition.
- Return type:
- outputs_in_inputs = True¶
- classmethod parse_var_definition(io, value, **kwargs)[source]¶
Extract information about input/output variables from a string definition.
- Parameters:
- Returns:
- List of information about the variables contained in
the provided string.
- Return type:
- Raises:
AssertionError – If io is not ‘inputs’ or ‘outputs’.
NotImplementedError – If the def_regex for the specified io is not defined.
- classmethod prepare_output_variables(vars_list, in_definition=False, in_inputs=False, for_yggdrasil=False)[source]¶
Concatenate a set of output variables such that it can be passed as a single string to the function_call parameter.
- Parameters:
vars_list (list) – List of variable names to concatenate as output from a function call.
in_definition (bool, optional) – If True, the returned sequence will be of the format required for specifying output variables in a function definition. Defaults to False.
in_inputs (bool, optional) – If True, the output variables should be formated to be included as input variables. Defaults to False.
for_yggdrasil (bool, optional) – If True, the variables will be prepared in the formated expected by calls to yggdarsil send/recv methods. Defaults to False.
- Returns:
Concatentated variables list.
- Return type:
- classmethod prepare_variables(vars_list, in_definition=False, for_yggdrasil=False)[source]¶
Concatenate a set of input variables such that it can be passed as a single string to the function_call parameter.
- Parameters:
vars_list (list) – List of variable dictionaries containing info (e.g. names) that should be used to prepare a string representing input/output to/from a function call.
in_definition (bool, optional) – If True, the returned sequence will be of the format required for specifying variables in a function definition. Defaults to False.
for_yggdrasil (bool, optional) – If True, the variables will be prepared in the formated expected by calls to yggdarsil send/recv methods. Defaults to False.
- Returns:
Concatentated variables list.
- Return type:
- classmethod requires_length_var(var)[source]¶
Determine if a variable requires a separate length variable.
- classmethod requires_shape_var(var)[source]¶
Determine if a variable requires a separate shape variable.
- classmethod set_env_class(**kwargs)[source]¶
Set environment variables that are instance independent.
- Parameters:
**kwargs – Additional keyword arguments are passed to the parent class’s method and update_ld_library_path.
- Returns:
Environment variables for the model process.
- Return type:
- standard_libraries = ['m']¶
- supported_comm_options = {'ipc': {'platforms': ['MacOS', 'Linux']}, 'zmq': {'libraries': ['zmq', 'czmq']}}¶
- supported_comms = ['ipc', 'zmq']¶
- type_class_map = {}¶
- type_map = {'1darray': '*', 'any': 'generic_t', 'array': 'json_array_t', 'boolean': 'bool', 'bytes': 'string_t', 'class': 'python_class_t', 'comm': 'comm_t*', 'complex': 'complex_X', 'dtype': 'dtype_t*', 'flag': 'int', 'float': 'double', 'function': 'python_function_t', 'instance': 'python_instance_t', 'int': 'intX_t', 'integer': 'int', 'length': 'size_t', 'ndarray': '*', 'null': 'void*', 'number': 'double', 'obj': 'obj_t', 'object': 'json_object_t', 'ply': 'ply_t', 'schema': 'schema_t', 'string': 'char*', 'uint': 'uintX_t', 'unicode': 'unicode_t'}¶
- classmethod update_ld_library_path(env, paths_to_add=None, add_to_front=False, add_libpython_dir=False, toolname=None, env_var=None, **kwargs)[source]¶
Update provided dictionary of environment variables so that LD_LIBRARY_PATH includes the interface directory containing the interface libraries.
- Parameters:
env (dict) – Dictionary of enviroment variables to be updated.
paths_to_add (list, optional) – Paths that should be added. If not provided, defaults to [cls.get_language_dir()].
add_to_front (bool, optional) – If True, new paths are added to the front, rather than the end. Defaults to False.
add_libpython_dir (bool, optional) – If True, the directory containing the Python C library will be added. Defaults to False.
toolname (str, optional) – Name of compiler tool that should be used. Defaults to None and the default compiler for the language will be used.
env_var (str, optional) – Environment variable where the paths should be added. Defaults to None and is only set for linux (LD_LIBRARY_PATH) and windows (PATH).
**kwargs – Additional keyword arguments are ignored.
- Returns:
Updated dictionary of environment variables.
- Return type:
- classmethod update_python_path(env)[source]¶
Update provided dictionary of environment variables so that PYTHONPATH and PYTHONHOME are set as needed (primarily on windows).
- classmethod write_assign_to_output(dst_var, src_var, outputs_in_inputs=False, dont_add_lengths=False, use_length_prefix=False, **kwargs)[source]¶
Write lines assigning a value to an output variable.
- Parameters:
dst_var (str, dict) – Name or information dictionary for variable being assigned to.
src_var (str, dict) – Name or information dictionary for value being assigned to dst_var.
outputs_in_inputs (bool, optional) – If True, outputs are passed as input parameters. In some languages, this means that a pointer or reference is passed (e.g. C) and so the assignment should be to the memory indicated rather than the variable. Defaults to False.
dont_add_lengths (bool, optional) – If True, length variables are not added for arrays. Defaults to False.
use_length_prefix (bool, optional) – If True and length variables are added, they will be named using prefixes. Otherwise, suffixes will be used. Defaults to False.
**kwargs – Additional keyword arguments are passed to the parent class’s method.
- Returns:
Lines achieving assignment.
- Return type:
- classmethod write_declaration(var, **kwargs)[source]¶
Return the lines required to declare a variable with a certain type.
- classmethod write_free(var, **kwargs)[source]¶
Return the lines required to free a variable with a certain type.
- classmethod write_function_def(function_name, dont_add_lengths=False, use_length_prefix=False, **kwargs)[source]¶
Write a function definition.
- Parameters:
function_name (str) – Name fo the function being defined.
dont_add_lengths (bool, optional) – If True, length variables are not added for arrays. Defaults to False.
use_length_prefix (bool, optional) – If True and length variables are added, they will be named using prefixes. Otherwise, suffixes will be used. Defaults to False.
**kwargs – Additional keyword arguments are passed to the parent class’s method.
- Returns:
Lines completing the function call.
- Return type:
- Raises:
ValueError – If outputs_in_inputs is not True and more than one output variable is specified.
- classmethod write_initialize_oiter(var, value=None, **kwargs)[source]¶
Get the lines necessary to initialize an array for iteration output.
- Parameters:
- Returns:
The lines initializing the variable.
- Return type:
- classmethod write_model_function_call(model_function, flag_var, inputs, outputs, **kwargs)[source]¶
Write lines necessary to call the model function.
- Parameters:
model_function (str) – Handle of the model function that should be called.
flag_var (str) – Name of variable that should be used as a flag.
inputs (list) – List of dictionaries describing inputs to the model.
outputs (list) – List of dictionaries describing outputs from the model.
**kwargs – Additional keyword arguments are passed to the parent class’s method.
- Returns:
- Lines required to carry out a call to a model function in
this language.
- Return type:
- classmethod write_model_recv(channel, recv_var, **kwargs)[source]¶
Write a model receive call include checking the return flag.
- Parameters:
- Returns:
Lines required to carry out a receive call in this language.
- Return type:
- class yggdrasil.drivers.CModelDriver.ClangCompiler(**kwargs)[source]¶
Bases:
CCompilerBase
Interface class for clang compiler/linker.
- asan_flags = ['-fsanitize=address']¶
- combine_with_linker = True¶
- compatible_toolsets = ['llvm']¶
- default_archiver = 'libtool'¶
- default_executable = 'clang'¶
- default_flags = ['-g', '-Wall']¶
- default_linker = 'clang'¶
- flag_options = {'definitions': '-D%s', 'include_dirs': '-I%s', 'isysroot': {'key': '-isysroot', 'prepend': True}, 'mmacosx-version-min': '-mmacosx-version-min=%s', 'sysroot': '--sysroot'}¶
- is_gnu = False¶
- is_linker = False¶
- object_tool = 'otool -L'¶
- platforms = ['MacOS', 'Linux', 'Windows']¶
- preload_envvar = 'DYLD_INSERT_LIBRARIES'¶
- toolname = 'clang'¶
- toolset = 'llvm'¶
- class yggdrasil.drivers.CModelDriver.ClangLinker(**kwargs)[source]¶
Bases:
LDLinker
Interface class for clang linker (calls to ld).
- aliases = []¶
- asan_flags = ['-fsanitize=address', '-shared-libasan']¶
- static before_registration(cls)[source]¶
Operations that should be performed to modify class attributes prior to registration including things like platform dependent properties and checking environment variables for default settings.
- compatible_toolsets = ['llvm']¶
- default_executable = 'clang'¶
- default_flags = []¶
- flag_options = {'library_dirs': '-L%s', 'library_libs': {'allow_duplicate_values': True, 'key': '-l%s'}, 'library_libs_nonstd': '', 'library_rpath': '-rpath', 'linker-version': '-mlinker-version=%s'}¶
- is_gnu = False¶
- languages = ['c']¶
- library_ext = '.so'¶
- platforms = ['MacOS', 'Linux', 'Windows']¶
- search_path_flags = ['-Xlinker', '-v']¶
- search_regex = ['\\t([^\\t\\n]+)\\n']¶
- search_regex_begin = 'Library search paths:'¶
- classmethod tool_version(**kwargs)[source]¶
Determine the version of this tool.
- Parameters:
**kwargs – Keyword arguments are passed to cls.call.
- Returns:
Version of the tool.
- Return type:
- toolname = 'clang'¶
- toolset = 'llvm'¶
- class yggdrasil.drivers.CModelDriver.GCCCompiler(**kwargs)[source]¶
Bases:
CCompilerBase
Interface class for gcc compiler/linker.
- aliases = ['gnu-cc', 'gnu-gcc']¶
- asan_flags = ['-fsanitize=address']¶
- combine_with_linker = True¶
- compatible_toolsets = ['gnu']¶
- default_archiver = 'ar'¶
- default_executable = 'gcc'¶
- default_flags = ['-g', '-Wall']¶
- default_linker = 'gcc'¶
- dll2a(dll, dst=None, overwrite=False)[source]¶
Convert a window’s .dll library into a static library.
- Parameters:
dll (str) – Full path to .dll library to convert.
dst (str, optional) – Full path to location where the new library should be saved. Defaults to None and will be set based on lib or will be placed in the same directory as dll.
overwrite (bool, optional) – If True, the static file will be created even if it already exists. Defaults to False.
- Returns:
Full path to new .a static library.
- Return type:
- is_gnu = True¶
- classmethod is_installed()[source]¶
Determine if this tool is installed by looking for the executable.
- Returns:
True if the tool is installed, False otherwise.
- Return type:
- is_linker = False¶
- object_tool = 'ldd'¶
- platforms = ['MacOS', 'Linux', 'Windows']¶
- preload_envvar = 'LD_PRELOAD'¶
- toolname = 'gcc'¶
- toolset = 'gnu'¶
- class yggdrasil.drivers.CModelDriver.GCCLinker(**kwargs)[source]¶
Bases:
LDLinker
Interface class for gcc linker (calls to ld).
- aliases = ['gnu-cc', 'gnu-gcc']¶
- compatible_toolsets = ['gnu']¶
- default_executable = 'gcc'¶
- default_flags = []¶
- flag_options = {'library_dirs': '-L%s', 'library_libs': {'allow_duplicate_values': True, 'key': '-l%s'}, 'library_libs_nonstd': {'allow_duplicate_values': True, 'key': '-l:%s'}, 'library_rpath': '-Wl,-rpath'}¶
- is_gnu = True¶
- languages = ['c']¶
- library_ext = '.so'¶
- platforms = ['MacOS', 'Linux', 'Windows']¶
- search_path_flags = ['-Xlinker', '--verbose']¶
- search_regex = ['SEARCH_DIR\\("=([^"]+)"\\);']¶
- toolname = 'gcc'¶
- toolset = 'gnu'¶
- class yggdrasil.drivers.CModelDriver.LDLinker(**kwargs)[source]¶
Bases:
LinkerBase
Linker class for ld tool.
- asan_flags = ['-fsanitize=address']¶
- default_executable = 'ld'¶
- default_executable_env = 'LD'¶
- default_flags = []¶
- default_flags_env = 'LDFLAGS'¶
- is_gnu = False¶
- languages = ['c']¶
- library_ext = '.so'¶
- search_path_envvar = ['LIBRARY_PATH', 'LD_LIBRARY_PATH']¶
- classmethod tool_version(**kwargs)[source]¶
Determine the version of this tool.
- Parameters:
**kwargs – Keyword arguments are passed to cls.call.
- Returns:
Version of the tool.
- Return type:
- toolname = 'ld'¶
- version_flags = ['-v']¶
- class yggdrasil.drivers.CModelDriver.LibtoolArchiver(**kwargs)[source]¶
Bases:
ArchiverBase
Archiver class for libtool tool.
- asan_flags = []¶
- compatible_toolsets = ['clang']¶
- default_executable = 'libtool'¶
- default_executable_env = 'LIBTOOL'¶
- default_flags = []¶
- is_gnu = False¶
- languages = ['c', 'c++']¶
- library_ext = '.a'¶
- search_path_envvar = ['LIBRARY_PATH']¶
- static_library_flag = '-static'¶
- toolname = 'libtool'¶
- toolset = 'clang'¶
- class yggdrasil.drivers.CModelDriver.MSVCArchiver(**kwargs)[source]¶
Bases:
ArchiverBase
Microsoft Visual Studio C Archiver.
- compatible_toolsets = ['msvc', 'llvm']¶
- default_executable = 'LIB'¶
- default_flags = []¶
- is_gnu = False¶
- languages = ['c', 'c++']¶
- library_ext = '.a'¶
- output_key = '/OUT:%s'¶
- platforms = ['Windows']¶
- search_path_envvar = ['LIB']¶
- static_library_flag = None¶
- toolname = 'LIB'¶
- toolset = 'msvc'¶
- class yggdrasil.drivers.CModelDriver.MSVCCompiler(**kwargs)[source]¶
Bases:
CCompilerBase
Microsoft Visual Studio C Compiler.
- static before_registration(cls)[source]¶
Operations that should be performed to modify class attributes prior to registration including things like platform dependent properties and checking environment variables for default settings.
- combine_with_linker = True¶
- compatible_toolsets = ['msvc']¶
- default_archiver = 'LIB'¶
- default_executable = 'cl'¶
- default_flags = ['/W4', '/Zi', '/FS', '/EHsc', '/bigobj', '/TP', '/nologo', '-D_CRT_SECURE_NO_WARNINGS']¶
- default_linker = 'LINK'¶
- is_gnu = False¶
- linker_attributes = {'default_executable': None, 'default_executable_env': 'LINK', 'default_flags_env': 'LDFLAGS', 'flag_options': {'import_lib': '/IMPLIB:%s', 'library_dirs': '/LIBPATH:%s', 'library_libs': '', 'library_libs_nonstd': ''}, 'output_first': True, 'output_first_library': False, 'output_key': '/OUT:%s', 'search_path_envvar': ['LIB'], 'search_path_flags': None, 'shared_library_flag': '/DLL'}¶
- linker_switch = '/link'¶
- output_first = True¶
- output_key = '/Fo%s'¶
- platforms = ['Windows']¶
- product_exts = ['.dir', '.ilk', '.pdb', '.sln', '.vcxproj', '.vcxproj.filters', '.exp', '.lib']¶
- search_path_envvar = ['INCLUDE']¶
- search_path_flags = None¶
- classmethod tool_version(**kwargs)[source]¶
Determine the version of this tool.
- Parameters:
**kwargs – Keyword arguments are passed to cls.call.
- Returns:
Version of the tool.
- Return type:
- toolname = 'cl'¶
- toolset = 'msvc'¶
- version_flags = []¶
yggdrasil.drivers.CPPModelDriver module¶
- class yggdrasil.drivers.CPPModelDriver.CPPCompilerBase(**kwargs)[source]¶
Bases:
CCompilerBase
Base class for C++ compilers.
- cpp_std = 'c++14'¶
- default_executable = None¶
- default_executable_env = 'CXX'¶
- default_flags_env = 'CXXFLAGS'¶
- default_linker = None¶
- classmethod handle_standard_flag(flags, skip_standard_flag=False)[source]¶
Add or remove standard flag from a list of flags.
- languages = ['c++']¶
- search_path_flags = ['-E', '-v', '-xc++', '/dev/null']¶
- class yggdrasil.drivers.CPPModelDriver.CPPModelDriver(*args, **kwargs)[source]¶
Bases:
CModelDriver
Class for running C++ models.
- static after_registration(cls, **kwargs)[source]¶
Operations that should be performed to modify class attributes after registration.
- classmethod allows_realloc(var)[source]¶
Determine if a variable allows the receive call to perform realloc.
- base_languages = ['c']¶
- cfg = <yggdrasil.config.YggConfigParser object>¶
- default_archiver = 'ar'¶
- default_archiver_flags = None¶
- default_compiler = 'g++'¶
- default_compiler_flags = None¶
- default_linker = 'g++'¶
- default_linker_flags = None¶
- dont_declare_channel = True¶
- function_param = {'and': '&&', 'assign': '{name} = {value};', 'assign_copy': 'memcpy({name}, {value}, {N}*sizeof({native_type}));', 'block_end': '}', 'break': 'break;', 'comment': '//', 'copy_any': '{name}.CopyFrom({value}, {name}.GetAllocator(), true);', 'copy_array': '{name}.CopyFrom({value}, {name}.GetAllocator(), true);', 'copy_class': '{name} = copy_python({value});', 'copy_function': '{name} = copy_python({value});', 'copy_instance': 'copy_generic_into(&{name}, {value});', 'copy_object': '{name}.CopyFrom({value}, {name}.GetAllocator(), true);', 'copy_schema': '{name}.CopyFrom({value}, {name}.GetAllocator(), true);', 'declare': '{type_name} {variable};', 'error': 'throw "{error_msg}";', 'exec_begin': 'int main() {', 'exec_end': ' return 0;\n}', 'exec_prefix': '#include <iostream>\n#include <exception>\n', 'false': 'false', 'false_flag': '0', 'flag_cond': '{flag_var} >= 0', 'for_begin': 'for ({iter_var} = {iter_begin}; {iter_var} < {iter_end}; {iter_var}++) {{', 'fprintf': 'printf("{message}\\n", {variables});', 'free': 'if ({variable} != NULL) {{ free({variable}); {variable} = NULL; }}', 'free_any': 'free_generic({variable});', 'free_array': 'free_json_array({variable});', 'free_class': 'destroy_python({variable});', 'free_function': 'destroy_python({variable});', 'free_instance': 'free_generic({variable});', 'free_obj': 'free_obj({variable});', 'free_object': 'free_json_object({variable});', 'free_ply': 'free_ply({variable});', 'free_schema': 'free_schema({variable});', 'function_def_begin': '{output_type} {function_name}({input_var}) {{', 'function_def_regex': '(?P<flag_type>.+?)\\s*{function_name}\\s*\\(\\s*(?P<inputs>(?:(?:const\\s+[^{{\\&]+\\s+\\&[^{{\\&]+)|(?:[^{{\\&]+))(?:\\s*,\\s*(?:const\\s+[^{{\\&]+\\s+\\&[^{{\\&]+)|(?:[^{{\\&]+))*?)(?:,\\s*(?P<outputs>(?:\\s*(?:[^\\s\\&]+)(?:(?:\\&\\s+)|(?:\\s+(?:\\()?\\&))(?:[^{{])+)+))?\\)\\s*\\{{(?P<body>(?:.*?\\n?)*?)(?:(?:return +(?P<flag_var>.+?)?;(?:.*?\\n?)*?\\}})|(?:\\}}))', 'if_begin': 'if ({cond}) {{', 'if_elif': '}} else if ({cond}) {{', 'if_else': '}} else {{', 'import': '#include "{filename}"', 'indent': ' ', 'index': '{variable}[{index}]', 'init_class': 'init_python()', 'init_function': 'init_python()', 'init_instance': 'init_generic()', 'init_type_1darray': 'create_dtype_1darray("{subtype}", {precision}, {length}, "{units}", {use_generic})', 'init_type_array': 'create_dtype_json_array({nitems}, {items}, {use_generic})', 'init_type_default': 'create_dtype_default("{type}", {use_generic})', 'init_type_empty': 'create_dtype_empty({use_generic})', 'init_type_from_schema': 'create_dtype_from_schema("{schema}", {use_generic})', 'init_type_ndarray': 'create_dtype_ndarray("{subtype}", {precision}, {ndim}, {shape}, "{units}", {use_generic})', 'init_type_ndarray_arr': 'create_dtype_ndarray_arr("{subtype}", {precision}, {ndim}, {shape}, "{units}", {use_generic})', 'init_type_obj': 'create_dtype_obj({use_generic})', 'init_type_object': 'create_dtype_json_object({nitems}, {keys}, {values}, {use_generic})', 'init_type_ply': 'create_dtype_ply({use_generic})', 'init_type_pyobj': 'create_dtype_pyobj("{type}", {use_generic})', 'init_type_scalar': 'create_dtype_scalar("{subtype}", {precision}, "{units}", {use_generic})', 'init_type_schema': 'create_dtype_schema({use_generic})', 'input': 'YggInput {channel}("{channel_name}", {channel_type});', 'inputs_def_regex': '\\s*(?:const\\s+)?(?P<native_type>(?:[^\\s\\&\\<\\*])+(?:\\<(?P<subtypes>\\s*.+?(?:\\s*,\\s*.+?)*\\s*)\\>)?(\\s+)?(?P<ptr>\\*+)?)(?:\\s*\\&)?(?(ptr)(?(3)(?:\\s*)|(?:\\s+)))(\\((?P<name_ptr>\\*+)?)?(?P<name>[^\\&\\>\\*]+?)(?(5)(?:\\)))(?P<shape>(?:\\[.+?\\])+)?\\s*(?:,|$)(?:\\n)?', 'interface': '#include "{interface_library}"', 'line_end': ';', 'not': '!', 'not_flag_cond': '{flag_var} < 0', 'null': 'NULL', 'output': 'YggOutput {channel}("{channel_name}", {channel_type});', 'outputs_def_regex': '\\s*(?P<native_type>(?:[^\\s])+)(\\s+)?(\\()?(?P<ref>\\&)(?(1)(?:\\s*)|(?:\\s+))(?P<name>.+?)(?(2)(?:\\)|(?:)))(?P<shape>(?:\\[.+?\\])+)?\\s*(?:,|$)(?:\\n)?', 'print': 'std::cout << "{message}" << std::endl;', 'print_any': 'std::cout << document2string({object}) << std::endl;', 'print_array': 'std::cout << document2string({object}) << std::endl;', 'print_bytes': 'printf("%s\\n", {object});', 'print_class': 'display_python({object});', 'print_complex': 'print_complex({object});', 'print_float': 'printf("%f\\n", {object});', 'print_function': 'display_python({object});', 'print_instance': 'display_generic({object});', 'print_int': 'printf("%i\\n", {object});', 'print_object': 'std::cout << document2string({object}) << std::endl;', 'print_schema': 'std::cout << document2string({object}) << std::endl;', 'print_string': 'printf("%s\\n", {object});', 'print_uint': 'printf("%u\\n", {object});', 'print_unicode': 'printf("%s\\n", {object});', 'python_init': 'init_python_API();', 'quote': '"', 'recv_function': '{channel}.recvRealloc', 'recv_heap': '{channel}.recvRealloc', 'recv_stack': '{channel}.recv', 'return': 'return {output_var};', 'send_function': '{channel}.send', 'true': 'true', 'true_flag': '1', 'try_begin': 'try {', 'try_error_type': 'const std::exception&', 'try_except': '}} catch ({error_type} {error_var}) {{', 'vector_regex': '(?:std\\:\\:)?vector\\<\\s*(?P<type>.*)\\s*\\>', 'while_begin': 'while ({cond}) {{'}¶
- classmethod get_testing_options(**kwargs)[source]¶
Method to return a dictionary of testing options for this class.
- Parameters:
**kwargs – Additional keyword arguments are passed to the parent class.
- Returns:
- Dictionary of variables to use for testing. Key/value pairs:
kwargs (dict): Keyword arguments for driver instance. deps (list): Dependencies to install.
- Return type:
- include_arg_count = True¶
- include_channel_obj = False¶
- interface_library = 'ygg++'¶
- interface_map = {'call': 'flag = {channel_obj}.call({nargs}, {outputs}, {input_refs})', 'client': 'YggRpcClient {channel_obj}("{channel_name}", {datatype_out}, {datatype_in})', 'import': '#include "YggInterface.hpp"', 'input': 'YggInput {channel_obj}("{channel_name}")', 'output': 'YggOutput {channel_obj}("{channel_name}")', 'recv': 'flag = {channel_obj}.recv({nargs}, {input_refs})', 'send': 'flag = {channel_obj}.send({nargs}, {outputs})', 'server': 'YggRpcServer {channel_obj}("{channel_name}", {datatype_in}, {datatype_out})', 'timesync': 'YggTimesync {channel_obj}("{channel_name}", "{time_units}")'}¶
- internal_libraries = {'datatypes': {'compiler_flags': ['-fPIC'], 'directory': '/opt/hostedtoolcache/Python/3.8.17/x64/lib/python3.8/site-packages/yggdrasil/languages/C/datatypes', 'external_dependencies': ['rapidjson', 'python', 'numpy', 'm'], 'include_dirs': [], 'internal_dependencies': ['regex'], 'language': 'c++', 'libtype': 'object'}, 'regex': {'directory': '/opt/hostedtoolcache/Python/3.8.17/x64/lib/python3.8/site-packages/yggdrasil/languages/C/regex', 'external_dependencies': [], 'internal_dependencies': [], 'language': 'c', 'libtype': 'header_only', 'source': 'regex_posix.h'}, 'regex_posix': {'directory': '/opt/hostedtoolcache/Python/3.8.17/x64/lib/python3.8/site-packages/yggdrasil/languages/C/regex', 'external_dependencies': [], 'internal_dependencies': [], 'language': 'c', 'libtype': 'header_only', 'source': 'regex_posix.h'}, 'regex_win32': {'directory': '/opt/hostedtoolcache/Python/3.8.17/x64/lib/python3.8/site-packages/yggdrasil/languages/C/regex', 'external_dependencies': [], 'internal_dependencies': [], 'language': 'c++', 'libtype': 'object', 'source': 'regex_win32.cpp'}, 'ygg++': {'compiler_flags': ['-fPIC'], 'external_dependencies': ['rapidjson', 'python', 'numpy', 'm'], 'include_dirs': ['/opt/hostedtoolcache/Python/3.8.17/x64/lib/python3.8/site-packages/yggdrasil/languages/C/communication', '/opt/hostedtoolcache/Python/3.8.17/x64/lib/python3.8/site-packages/yggdrasil/languages/C/serialize', '/opt/hostedtoolcache/Python/3.8.17/x64/lib/python3.8/site-packages/yggdrasil/languages/C', '/opt/hostedtoolcache/Python/3.8.17/x64/lib/python3.8/site-packages/yggdrasil/languages/C', '/opt/hostedtoolcache/Python/3.8.17/x64/lib/python3.8/site-packages/yggdrasil/languages/CPP'], 'internal_dependencies': ['regex', 'datatypes'], 'language': 'c++', 'linker_language': 'c++', 'source': '/opt/hostedtoolcache/Python/3.8.17/x64/lib/python3.8/site-packages/yggdrasil/languages/CPP/YggInterface.cpp'}}¶
- inverse_type_map = None¶
- language = 'c++'¶
- language_aliases = ['cpp', 'cxx']¶
- language_ext = ['.cpp', '.CPP', '.cxx', '.C', '.c++', '.cc', '.cp', '.tcc', '.hpp', '.HPP', '.hxx', '.H', '.h++', '.hh', '.hp', '.h']¶
- classmethod output2input(var, in_definition=True)[source]¶
Perform conversion necessary to turn an output variable into an corresponding input that can be used to format a function definition.
- Parameters:
- Returns:
Updated variable definition.
- Return type:
- classmethod prepare_input_variables(vars_list, in_definition=False, for_yggdrasil=False)[source]¶
Concatenate a set of input variables such that it can be passed as a single string to the function_call parameter.
- Parameters:
vars_list (list) – List of variable dictionaries containing info (e.g. names) that should be used to prepare a string representing input to a function call.
in_definition (bool, optional) – If True, the returned sequence will be of the format required for specifying input variables in a function definition. Defaults to False.
for_yggdrasil (bool, optional) – If True, the variables will be prepared in the formated expected by calls to yggdarsil send/recv methods. Defaults to False.
- Returns:
Concatentated variables list.
- Return type:
- classmethod requires_length_var(var)[source]¶
Determine if a variable requires a separate length variable.
- classmethod set_env_class(**kwargs)[source]¶
Set environment variables that are instance independent.
- Parameters:
**kwargs – Additional keyword arguments are passed to the parent class’s method and update_ld_library_path.
- Returns:
Environment variables for the model process.
- Return type:
- type_map = {'1darray': '*', 'any': 'rapidjson::Document', 'array': 'rapidjson::Document', 'boolean': 'bool', 'bytes': 'string_t', 'class': 'python_class_t', 'comm': 'comm_t*', 'complex': 'complex_X', 'dtype': 'dtype_t*', 'flag': 'int', 'float': 'double', 'function': 'python_function_t', 'instance': 'python_instance_t', 'int': 'intX_t', 'integer': 'int', 'length': 'size_t', 'ndarray': '*', 'null': 'void*', 'number': 'double', 'obj': 'rapidjson::ObjWavefront', 'object': 'rapidjson::Document', 'ply': 'rapidjson::Ply', 'schema': 'rapidjson::Document', 'string': 'char*', 'uint': 'uintX_t', 'unicode': 'unicode_t'}¶
- classmethod write_doc2vars(channel, std, var_list)[source]¶
Generate the lines of code required to unpack a document into a list of variables.
- classmethod write_model_recv(channel, recv_var, **kwargs)[source]¶
Write a model receive call include checking the return flag.
- Parameters:
- Returns:
Lines required to carry out a receive call in this language.
- Return type:
- classmethod write_model_send(channel, send_var, **kwargs)[source]¶
Write a model send call include checking the return flag.
- Parameters:
channel (str) – Name of variable that the channel being sent to was stored in.
send_var (dict, list) – Information on one or more variables containing information that will be sent.
flag_var (str, optional) – Name of flag variable that the flag should be stored in. Defaults to ‘flag’,
allow_failure (bool, optional) – If True, the returned lines will call a break if the flag is False. Otherwise, the returned lines will issue an error. Defaults to False.
- Returns:
Lines required to carry out a send call in this language.
- Return type:
- classmethod write_try_except(try_contents, except_contents, error_var='e', error_type=None, **kwargs)[source]¶
Return the lines required to complete a try/except block.
- Parameters:
try_contents (list) – Lines of code that should be executed inside the try block.
except_contents (list) – Lines of code that should be executed inside the except block.
error_var (str, optional) – Name of variable where the caught error should be stored. Defaults to ‘e’. If ‘…’, the catch clause will catch all errors, but there will not be a name error.
error_type (str, optional) – Name of error type that should be caught. If not provided, defaults to None and will be set based on the class function_param entry for ‘try_error_type’. If ‘…’, the catch clause will catch all errors and error_var will be ignored.
**kwargs – Additional keyword arguments are passed to the parent class’s method.
- Returns:
Lines of code perfoming a try/except block.
- class yggdrasil.drivers.CPPModelDriver.ClangPPCompiler(**kwargs)[source]¶
Bases:
CPPCompilerBase
,ClangCompiler
Interface class for clang++ compiler.
- static before_registration(cls)[source]¶
Operations that should be performed to modify class attributes prior to registration including things like platform dependent properties and checking environment variables for default settings.
- default_executable = 'clang++'¶
- default_flags = ['-g', '-Wall']¶
- default_linker = 'clang++'¶
- classmethod get_executable_command(args, skip_flags=False, unused_kwargs=None, **kwargs)[source]¶
Determine the command required to run the tool using the specified arguments and options.
- Parameters:
args (list) – The arguments that should be passed to the tool. If skip_flags is False, these are treated as input files that will be used by the tool.
**kwargs – Additional keyword arguments will be passed to the parent class’s method.
- Returns:
Output to stdout from the command execution.
- Return type:
- is_gnu = False¶
- is_linker = False¶
- toolname = 'clang++'¶
- class yggdrasil.drivers.CPPModelDriver.ClangPPLinker(**kwargs)[source]¶
Bases:
ClangLinker
Interface class for clang++ linker (calls to ld).
- aliases = []¶
- default_executable = 'clang++'¶
- default_flags = []¶
- is_gnu = False¶
- languages = ['c++']¶
- library_ext = '.so'¶
- toolname = 'clang++'¶
- toolset = 'llvm'¶
- class yggdrasil.drivers.CPPModelDriver.GPPCompiler(**kwargs)[source]¶
Bases:
CPPCompilerBase
,GCCCompiler
Interface class for G++ compiler/linker.
- aliases = ['gnu-c++']¶
- default_executable = 'g++'¶
- default_flags = ['-g', '-Wall']¶
- default_linker = 'g++'¶
- is_gnu = True¶
- is_linker = False¶
- toolname = 'g++'¶
- class yggdrasil.drivers.CPPModelDriver.GPPLinker(**kwargs)[source]¶
Bases:
GCCLinker
Interface class for clang++ linker (calls to ld).
- aliases = ['gnu-c++']¶
- default_executable = 'g++'¶
- default_flags = []¶
- is_gnu = True¶
- languages = ['c++']¶
- library_ext = '.so'¶
- toolname = 'g++'¶
- toolset = 'gnu'¶
- class yggdrasil.drivers.CPPModelDriver.MSVCPPCompiler(**kwargs)[source]¶
Bases:
CPPCompilerBase
,MSVCCompiler
Inteface class for MSVC compiler when compiling C++.
- static before_registration(cls)[source]¶
Operations that should be performed to modify class attributes prior to registration including things like platform dependent properties and checking environment variables for default settings.
- default_archiver = 'LIB'¶
- default_executable = 'cl'¶
- default_flags = ['/W4', '/Zi', '/FS', '/EHsc', '/bigobj', '/TP', '/nologo', '-D_CRT_SECURE_NO_WARNINGS']¶
- default_linker = 'LINK'¶
- dont_create_linker = True¶
- is_gnu = False¶
- search_path_flags = None¶
- toolname = 'cl++'¶
yggdrasil.drivers.CompiledModelDriver module¶
- class yggdrasil.drivers.CompiledModelDriver.ArchiverBase(**kwargs)[source]¶
Bases:
LinkerBase
Base class for archivers.
- static_library_flag¶
Flag that should be prepended to the archiver tool arguments to indicated that a static library should be produced.
- Type:
- library_name_key¶
Option key indicating the name of a library that should be linked against.
- Type:
- library_directory_key¶
Option key indicating a directory that should be included in the linker search path for libraries.
- Type:
- static before_registration(cls)[source]¶
Operations that should be performed to modify class attributes prior to registration including things like platform dependent properties and checking environment variables for default settings.
- flag_options = {}¶
- classmethod get_flags(**kwargs)[source]¶
Get a list of flags for this archiver tool.
- Parameters:
**kwargs – Additional keyword arguments are passed to the parent class’s method.
- Returns:
Archiver flags.
- Return type:
- classmethod get_output_file(obj, **kwargs)[source]¶
Determine the appropriate output file that will result when linking a given object file.
- library_ext = None¶
- static_library_flag = '-static'¶
- tooltype = 'archiver'¶
- class yggdrasil.drivers.CompiledModelDriver.BuildToolBase(**kwargs)[source]¶
Bases:
CompilerBase
Base class for build tools which are used to coordinate compilation.
- Parameters:
buildfile (str, optional) – File containing information about the build. Defaults to default_buildfile class attribute, if set.
builddir (str, optional) – Directory where build files should be placed. Defaults to directory where build is called.
sourcedir (str, optional) – Directory where source files are stored. Defaults to directory where build is called.
target (str, optional) – Build target. If not provided, build will be created without a target.
Class Attributes:
- default_buildfile = None¶
- flag_options = {}¶
- tooltype = 'buildtool'¶
- class yggdrasil.drivers.CompiledModelDriver.CompilationToolBase(**kwargs)[source]¶
Bases:
object
Base class for compilation command line tools.
- Class Attributes:
- toolname (str): Tool name used for registration and as a default for the
executable. [REQUIRED]
aliases (list): Alternative names that the tool might have. tooltype (str): Tool type. One of ‘compiler’, ‘linker’, or ‘archiver’.
[AUTOMATED]
- languages (list): Programming languages that this tool can be used on.
[REQUIRED]
- platforms (list): Platforms that the tool is available on. Defaults to
[‘Windows’, ‘MacOS’, ‘Linux’].
- default_executable (str): The default tool executable command if
different than the toolname.
- default_executable_env (str): Environment variable where the executable
command might be stored.
- default_flags (list): Default flags that should be used when calling the
tool (e.g. for verbose output or enhanced warnings).
- default_flags_env (str): Environment variable where default flags for
the tools might be stored.
output_key (str): Option key indicating the output file name. output_first (bool): If True, the output key (and its value) are put in
front of the other flags.
- flag_options (collections.OrderedDict): Mappings between keyword
arguments passed to get_flags and command line tool flags. Keys indicate the keyword argument that will be processed in Python and values are the string used with the tool on the command line to indicate the desired flag. Flags that contain ‘%s’ will be formatted with values passed to get_flags as the designated keyword argument. Flags that do not contain ‘%s’ will assumed to act on the following argument. If the value passed to get_flags under the designated keyword argument is not a boolean, it will be appended to the flag list following the corresponding flag. If the value is a boolean and it is True, only the flag will be added to the list of flags. The order of entries indicates the order the flags should be added to the list.
- search_path_envvar (list): Environment variables containing a list of paths
to search for library files. Either search_path_envvar or search_path_flags must be set. [REQUIRED]
- search_path_env (list): Paths relative to the env prefix that should
be searched if the VIRTUAL_ENV or CONDA_PREFIX environment variable is set.
- search_path_flags (list): Flags that should be passed to the tool
executable in order to locate the search path. Either search_path_envvar or search_path_flags must be set. [REQUIRED]
- search_regex_begin (str): Search string indicating where the set of
paths begins in the output from running the tool executable with the search_path_flags. If None, the search is performed from the very beginning of the output.
- search_regex_end (str): Search string indicating where the set of
paths ends in the output from running the tool executable with the search_path_flags. If None, the search is performed to the very end of the output.
- search_regex (list): Regex strings that should be used to locate paths
in the output from running the tool executable with the search_path_flags.
- product_exts (list): List of extensions that will be added to the
output file’s base to get a list of products that might be produced by calling the compilation tool.
- product_files (list): List of file basenames that will be joined with
the directory containing each output to get a list of products that might be produced by calling the compilation tool.
- remove_product_exts (list): List of extensions or directories matching
entries in product_exts and product_files that should be removed during cleanup. Be careful when adding files to this list.
asan_flags (list): Flags added when with_asan is specified.
- aliases = []¶
- classmethod append_flags(out, key, value, **kwargs)[source]¶
Append one ore more flag(s) to a list of flags based on a key value/set.
- Parameters:
out (list) – Existing list that the new flag should be appended to.
key (str) – String identifying the type of flag. See create_flag for additional details.
value (object) – Value that should be set in the flag. If a list, multiple flags are added, one for each item in the list.
prepend (bool, optional) – If True, new flags are prepended to the front of the list rather than the end. Defaults to False. This keyword argument is ignoerd if position is provided.
position (int, optional) – If not None, this is the position that the new elements should be added to the existing flags. Positive positions indicate indexes into the existing list of flags. Negative are relative to the end of the existing list such that -1 is the same as just appending the new flags to the end of the list. Defaults to None and prepend takes precedence.
no_duplicates (bool, optional) – If True, the new flags being added will be checked against the existing ones to ensure that there are not duplicates. If False, the new flags are added reguardless of the existing flags. Defaults to False.
allow_duplicate_values (bool, optional) – If True, the same key can be added with the same value more than once. Otherwise, only the first instance of the value is added. Defaults to False.
- Raises:
ValueError – If there are unexpected keyword arguments.
ValueError – If no_duplicates is True and the existing list of flags already contains a flag matching the provided flag key.
- classmethod append_product(products, src, new, new_dir=None, dont_append_src=False)[source]¶
Append a product to the specified list along with additional values indicated by cls.product_exts.
- Parameters:
products (list) – List of of existing products that new product should be appended to.
src (list) – Input arguments to compilation call that was used to generate the output file (usually one or more source files).
new (str) – New product that should be appended to the list.
new_dir (str, optional) – Directory that should be used as base when adding files listed in cls.product_files. Defaults to os.path.dirname(new).
dont_append_src (bool, optional) – If True and src is in the list of products, it will be removed. Defaults to False.
- asan_flags = None¶
- static before_registration(cls)[source]¶
Operations that should be performed to modify class attributes prior to registration including things like platform dependent properties and checking environment variables for default settings.
- classmethod call(args, language=None, toolname=None, skip_flags=False, dry_run=False, out=None, overwrite=False, products=None, allow_error=False, working_dir=None, additional_args=None, suffix='', cache_key=None, **kwargs)[source]¶
Call the tool with the provided arguments. If the first argument resembles the name of the tool executable, the executable will not be added.
- Parameters:
args (list) – The arguments that should be passed to the tool.
language (str, optional) – Language of tool that should be used. If different than the languages supported by the current tool, the correct tool is used instead. Defaults to None and is ignored.
toolname (str, optional) – Name of compilation tool that should be used. Defaults to None and the default tool for the language will be used.
skip_flags (bool, optional) – If True, args is assumed to include any necessary flags. If False, args are assumed to the files that the tool is called on and flags are determined from them. Defaults to False.
dry_run (bool, optional) – If True, the tool won’t be called, but the products will be updated. Defautls to False.
out (str, optional) – Full path to output file that should be created. If None, the path will be determined from the path to the first argument provided. Defaults to None. This keyword argument will be ignored if skip_flags is True.
overwrite (bool, optional) – If True, the existing compile file will be overwritten. Otherwise, it will be kept and this function will return without recompiling the source file.
products (list, optional) – Existing Python list that additional products produced by the compilation should be appended to. Defaults to None and is ignored.
allow_error (bool, optional) – If True and there is an error when call the executable, it will be ignored. If False, errors will result in an exception being raised. Defaults to False.
working_dir (str, optional) – Working directory where tool should be called from. This will also be used to construct the path for the output file. Defaults to None and is ignored.
additional_args (list, optional) – Additional arguments that should be appended to args before continuing. Defaults to None and is ignored.
suffix (str, optional) – Suffix that should be added to the output file (before the extension). Defaults to “”.
cache_key (str, optional) – Key that should be used to cache results so that they may be used multiple times. Defaults to None and is ignored.
**kwargs – Additional keyword arguments are passed to cls.get_executable_command. and tools.popen_nobuffer.
- Returns:
- Output to stdout from the command execution if skip_flags is
True, produced file otherwise.
- Return type:
- Raises:
RuntimeError – If there is an error when running the command and allow_error is False.
- compatible_toolsets = []¶
- classmethod create_flag(key, value)[source]¶
Create a flag from a key/value set.
- Parameters:
key (str) – String identifying the type of flag. If key contains ‘%s’, it is assumed that the flag will be produced by formatting the value according to key. If key dosn’t contain ‘%s’, it is assumed that key indicates that value is the following item and they both will be returned. If key is an empty string, then the value is assumed to constitute the entire flag.
value (object) – Value that should be set in the flag. If a list, multiple flags are returned, one for each item in the list.
- Returns:
Items representing the flag.
- Return type:
- default_executable = None¶
- default_executable_env = None¶
- default_flags = []¶
- default_flags_env = None¶
- classmethod env_matches_tool(use_sysconfig=False, env=None, with_flags=False)[source]¶
Determine if the executable pointed to by any environment variable matches this compilation tool.
- Parameters:
use_sysconfig (bool, optional) – If True, check the sysconfig variables, otherwise check os.environ. Defaults to False.
env (dict, optional) – Existing dictionary that should be updated with variables. Defaults to None and is ignored.
with_flags (bool, optional) – If True, preserve any flags included in the environment variable. Defaults to False.
- Returns:
True if the environment variable matches, False otherwise.
- Return type:
- flag_options = {}¶
- classmethod get_alternate_class(toolname=None, language=None)[source]¶
Return an alternate class to use if the provided toolname dosn’t match the current tool.
- Parameters:
- Returns:
- The compilation tool that corresponds
to the provided toolname.
- Return type:
- classmethod get_env_flags()[source]¶
Get a list of flags stored in the environment variables.
- Returns:
Flags for the tool.
- Return type:
- classmethod get_env_prefixes()[source]¶
Determine the virtualenv/conda path prefixes.
- Returns:
- Virtualenv/conda path prefixes. Empty list will be
returned if virtualenv/conda are not active.
- Return type:
- classmethod get_executable(full_path=False)[source]¶
Determine the executable that should be used to call this tool.
- classmethod get_executable_command(args, skip_flags=False, unused_kwargs=None, use_ccache=False, **kwargs)[source]¶
Determine the command required to run the tool using the specified arguments and options.
- Parameters:
args (list) – The arguments that should be passed to the tool. If skip_flags is False, these are treated as input files that will be used by the tool.
skip_flags (bool, optional) – If True, args is assumed to include any necessary flags. If False, args are assumed to the files that the tool is called on and flags are determined from them. Defaults to False.
unused_kwargs (dict, optional) – Existing Python dictionary that unused keyword arguments will be added to. Defaults to None and is initialized to an empty dict.
use_ccache (bool, optional) – If True, ccache will be added to the compilation executable. Defaults to False.
**kwargs – Additional keyword arguments are ignored and stored in unused_kwargs if provided.
- Returns:
Output to stdout from the command execution.
- Return type:
- classmethod get_flags(flags=None, outfile=None, output_first=None, unused_kwargs=None, skip_defaults=False, dont_skip_env_defaults=False, with_asan=False, **kwargs)[source]¶
Get a list of flags for the tool.
- Parameters:
flags (list, optional) – User defined flags that should be included. Defaults to empty list.
outfile (str, optional) – If provided, it is appended to the end of the flags following the cls.output_key flag to indicate that this is the name of the output file. Defaults to None and is ignored.
output_first (bool, optional) – If True, output flag(s) will be placed at the front of the returned flags. If False, they are placed at the end. Defaults to None and is set by cls.output_first.
unused_kwargs (dict, optional) – Existing dictionary that unused keyword arguments should be added to. Defaults to None and is ignored.
skip_defaults (bool, optional) – If True, the default flags will not be added. Defaults to False.
dont_skip_env_defaults (bool, optional) – If skip_defaults is True, and this keyword is True, the flags from the environment variable will be added. Defaults to False.
remove_flags (list, optional) – List of flags to remove. Defaults to None and is ignored.
**kwargs – Additional keyword arguments are ignored and added to unused_kwargs if provided.
- Returns:
Flags for the tool.
- Return type:
- classmethod get_language_ext()[source]¶
Get the extensions associated with the language that this tool can handle.
- Returns:
Language file extensions.
- Return type:
- classmethod get_search_path(env_only=False, libtype=None, cfg=None)[source]¶
Determine the paths searched by the tool for external library files.
- Parameters:
env_only (bool, optional) – If True, only the search paths as indicated by a virtualenv/conda environment are returned. Defaults to False.
libtype (str, optional) – Library type being searched for. Defaults to None.
cfg (YggConfigParser, optional) – Configuration object currently being updated. Defaults to the global configuration.
- Returns:
List of paths that the tools will search.
- Return type:
- classmethod get_source_products(products, source_products=[])[source]¶
Get the list of products that should be removed without checking for source files based on cls.remove_product_exts.
- Parameters:
- Returns:
- Products that should be removed without checking for source
files.
- Return type:
- classmethod get_tool_suffix()[source]¶
Get the string that should be added to tool products based on the tool used.
- Returns:
- Suffix that should be added to tool products to indicate the
tool used.
- Return type:
- is_build_tool = False¶
- is_gnu = False¶
- classmethod is_installed()[source]¶
Determine if this tool is installed by looking for the executable.
- Returns:
True if the tool is installed, False otherwise.
- Return type:
- languages = []¶
- classmethod locate_file(fname, libtype=None, verbose=False, **kwargs)[source]¶
Locate a library file.
- Parameters:
- Returns:
Full path to located library file.
- Return type:
- object_tool = None¶
- output_first = False¶
- output_key = '-o'¶
- platforms = ['Windows', 'MacOS', 'Linux']¶
- product_exts = []¶
- product_files = []¶
- remove_product_exts = []¶
- search_path_env = None¶
- search_path_envvar = None¶
- search_path_flags = None¶
- search_regex = ['([^\n]+)']¶
- search_regex_begin = None¶
- search_regex_end = None¶
- classmethod set_env(existing=None, **kwargs)[source]¶
Set environment variables required for compilation.
- source_product_exts = []¶
- tool_suffix_format = '_%sx'¶
- classmethod tool_version(**kwargs)[source]¶
Get the version of the compilation tool.
- Returns:
Version.
- Return type:
- toolname = None¶
- toolset = None¶
- tooltype = None¶
- version_flags = ['--version']¶
- class yggdrasil.drivers.CompiledModelDriver.CompilationToolMeta(name, bases, class_dict)[source]¶
Bases:
type
Meta class for registering compilers.
- class yggdrasil.drivers.CompiledModelDriver.CompiledModelDriver(*args, **kwargs)[source]¶
Bases:
ModelDriver
Base class for models written in compiled languages.
- Parameters:
name (str) – Driver name.
args (str or list) – The model executable and any arguments that should be passed to the model executable.
source_files (list, optional) – Source files that should be compiled into an executable. Defaults to an empty list and the driver will search for a source file based on the model executable (the first model argument).
compiler (str, optional) – Command or path to executable that should be used to compile the model. If not provided, the compiler will be determined based on configuration options for the language (if present) and the registered compilers that are available on the current operating system.
compiler_flags (list, optional) – Flags that should be passed to the compiler during compilation. If nto provided, the compiler flags will be determined based on configuration options for the language (if present), the compiler defaults, and the default_compiler_flags class attribute.
linker (str, optional) – Command or path to executable that should be used to link the model. If not provided, the linker will be determined based on configuration options for the language (if present) and the registered linkers that are available on the current operating system
linker_flags (list, optional) – Flags that should be passed to the linker during compilation. If not provided, the linker flags will be determined based on configuration options for the language (if present), the linker defaults, and the default_linker_flags class attribute.
disable_python_c_api (bool, optional) – If True, the Python C API will be disabled. Defaults to False.
with_asan (bool, optional) – If True, the model will be compiled and linked with the address sanitizer enabled (if there is one available for the selected compiler).
**kwargs – Additional keyword arguments are passed to parent class.
- Class Attributes:
- default_compiler (str): Name of compiler that will be used if not
set explictly by instance or config file.
- default_compiler_flags (list): Flags that should be passed to the
compiler by default for this language.
- default_linker (str): Name of linker that will be used if not
set explictly by instance or config file
- default_linker_flags (list): Flags that should be passed to the
linker by default for this language.
- allow_parallel_build (bool): If True, a file can be compiled by
two processes simultaneously. If False, it cannot and an MPI barrier will be used to prevent simultaneous compilation. Defaults to False.
- compiler_tool¶
Compiler tool that will be used.
- Type:
- linker_tool¶
Linker tool that will be used.
- Type:
- static after_registration(cls, **kwargs)[source]¶
Operations that should be performed to modify class attributes after registration. For compiled languages this includes selecting the default compiler. The order of precedence is the config file ‘compiler’ option for the language, followed by the environment variable set by _compiler_env, followed by the existing class attribute.
- allow_parallel_build = False¶
- classmethod call_compiler(src, language=None, toolname=None, dont_build=None, **kwargs)[source]¶
Compile a source file into an executable or linkable object file, checking for errors.
- Parameters:
src (str) – Full path to source file.
out (str, optional) – Full path to the output object file that should be created. Defaults to None and is created from the provided source file.
flags (list, optional) – Compilation flags. Defaults to []. If compiler_flags is present, flags is replaced by compiler_flags.
compiler_flags (list, optional) – Alternative to flags. Ignored if not provided.
dont_link (bool, optional) – If True, the command will result in a linkable object file rather than an executable. Defaults to False.
dont_build (bool, optional) – If True, cmake configuration/generation will be run, but the project will not be built. Defaults to None. If provided, this overrides dont_link.
overwrite (bool, optional) – If True, the existing compile file will be overwritten. Otherwise, it will be kept and this function will return without recompiling the source file.
language (str, optional) – Language that should be used to compile the files. Defaults to None and the language of the current driver is used.
toolname (str, optional) – Name of compiler tool that should be used. Defaults to None and the default compiler for the language will be used.
products (list, optional) – Existing Python list that additional products produced by the compilation should be appended to. Defaults to None and is ignored.
**kwargs – Additional keyword arguments are passed to run_executable. and call_linker if dont_link is False.
- Returns:
Full path to compiled source.
- Return type:
- Raises:
RuntimeError – If there is an error in calling the compiler.
RuntimeError – If the compilation command dosn’t yield the specified output file.
- classmethod call_linker(obj, language=None, toolname=None, **kwargs)[source]¶
Link several object files to create an executable or library (shared or static), checking for errors.
- Parameters:
obj (list) – Object files that should be linked.
language (str, optional) – Language that should be used to link the files. Defaults to None and the language of the current driver is used.
toolname (str, optional) – Name of compiler tool that should be used. Defaults to None and the default compiler for the language will be used.
**kwargs – Additional keyword arguments are passed to run_executable.
- Returns:
Full path to compiled source.
- Return type:
- classmethod cleanup_dependencies(products=None, verbose=False, **kwargs)[source]¶
Cleanup dependencies.
- classmethod compile_dependencies(toolname=None, dep=None, **kwargs)[source]¶
Compile any required internal libraries, including the interface.
- compile_dependencies_instance(*args, **kwargs)[source]¶
Compile dependencies specifically for this instance.
- compile_model(source_files=None, skip_interface_flags=False, **kwargs)[source]¶
Compile model executable(s).
- Parameters:
source_files (list, optional) – Source files that will be compiled. Defaults to None and is set to the source_files attribute.
skip_interface_flags (bool, optional) – If True, interface flags will not be added. This includes the logger flag specifying the current logging level. Defaults to False.
**kwargs – Keyword arguments are passed on to the call_compiler method.
- Returns:
Compiled model file path.
- Return type:
- classmethod configuration_steps()[source]¶
Get a list of configuration steps with tuples of flags and boolean values.
- Returns:
- Pairs of descriptions and states for
different steps in the configuration all steps must be True for the language to be configured.
- Return type:
OrderedDict
- classmethod configure(cfg, **kwargs)[source]¶
Add configuration options for this language.
- Parameters:
cfg (CisConfigParser) – Config class that options should be set for.
**kwargs – Additional keyword arguments are used to set tool configuration options (e.g. ‘compiler’).
- Returns:
- Section, option, description tuples for options that could not
be set.
- Return type:
- classmethod configure_executable_type(cfg)[source]¶
Add configuration options specific in the executable type before the libraries are configured.
- Parameters:
cfg (CisConfigParser) – Config class that options should be set for.
- Returns:
- Section, option, description tuples for options that could not
be set.
- Return type:
- classmethod configure_libraries(cfg)[source]¶
Add configuration options for external libraries in this language.
- Parameters:
cfg (CisConfigParser) – Config class that options should be set for.
- Returns:
- Section, option, description tuples for options that could not
be set.
- Return type:
- classmethod configure_library(cfg, k)[source]¶
Add configuration options for an external library.
- Parameters:
cfg (YggConfigParser) – Config class that options should be set for.
- Returns:
- Section, option, description tuples for options that could not
be set.
- Return type:
- default_archiver = None¶
- default_archiver_flags = None¶
- default_compiler = None¶
- default_compiler_flags = None¶
- default_linker = None¶
- default_linker_flags = None¶
- classmethod executable_command(args, exec_type='compiler', toolname=None, **kwargs)[source]¶
Compose a command for running a program using the compiler for this language and the provied arguments. If not already present, the compiler command and compiler flags are prepended to the provided arguments.
- Parameters:
args (list) – The program that returned command should run and any arguments that should be provided to it. For the compiler, this means the source files, for the linker, this means the object files.
exec_type (str, optional) – Type of executable command that will be returned. If ‘compiler’, a command using the compiler is returned, if ‘linker’, a command using the linker is returned, and if ‘direct’, the raw args being provided are returned. Defaults to ‘compiler’.
toolname (str, optional) – Name of compiler tool that should be used. Defaults to None and the default compiler for the language will be used.
**kwargs – Additional keyword arguments are passed to either get_linker_flags or get_compiler_flags.
- Returns:
- Arguments composing the command required to run the program
from the command line using the compiler for this language.
- Return type:
- Raises:
ValueError – If exec_type is not ‘compiler’, ‘linker’, or ‘direct’.
- executable_type = 'compiler'¶
- external_libraries = {}¶
- classmethod get_available_tools(tooltype)[source]¶
Return the registry of compilation tools for this language.
- classmethod get_buildfile_lock(fname=None, context=None, instance=None, **kwargs)[source]¶
Get a lock for a buildfile to prevent simultaneous access, creating one as necessary.
- Parameters:
name (str) – Build file.
context (threading.Context) – Threading context.
instance (ModelDriver) – Driver instance that should be used.
**kwargs – Additional keyword arguments are passed to the FileLock initialization.
- Returns:
Lock for the buildfile.
- Return type:
FileLock
- classmethod get_compiler_flags(toolname=None, compiler=None, **kwargs)[source]¶
Determine the flags required by the current compiler.
- Parameters:
toolname (str, optional) – Name of compiler tool that should be used. Defaults to None and the default compiler for the language will be used.
compiler (CompilerBase, optional) – Compilation tool class for the compiler that should be used. Defaults to None and is set based on toolname.
**kwargs – Keyword arguments are passed to cls.update_compiler_kwargs first and then the compiler’s get_flags method.
- Returns:
Flags for the compiler.
- Return type:
- classmethod get_dependency_include_dirs(dep, toolname=None, default=None)[source]¶
Get the include directories for a dependency.
- Parameters:
dep (str) – Name of internal or external dependency or full path to the library.
toolname (str, optional) – Name of compiler tool that should be used. Defaults to None and the default compiler for the language will be used.
default (str, optional) – Default that should be used if a value cannot be determined form internal/external dependencies or if dep is not a valid file. Defaults to None and is ignored.
- Returns:
- Full paths to the directories containing the dependency’s
header(s).
- Return type:
- Raises:
ValueError – If the include directory cannot be determined for the specified dependency and default is None.
- classmethod get_dependency_info(dep, toolname=None, default=None)[source]¶
Get the dictionary of information associated with a dependency.
- Parameters:
dep (str) – Name of internal or external dependency.
toolname (str, optional) – Name of compiler tool that should be used. Defaults to None and the default compiler for the language will be used.
default (dict, optional) – Information dictionary that should be returned if dep cannot be located. Defaults to None and an error will be raised if dep cannot be found.
- Returns:
Dependency info.
- Return type:
- classmethod get_dependency_library(dep, default=None, libtype=None, commtype=None, toolname=None, disable_python_c_api=False, with_asan=False)[source]¶
Get the library location for a dependency.
- Parameters:
dep (str) – Name of internal or external dependency or full path to the library.
default (str, optional) – Default that should be used if a value cannot be determined form internal/external dependencies or if dep is not a valid file. Defaults to None and is ignored.
libtype (str, optional) – Library type that should be returned. Valid values are ‘static’ and ‘shared’. Defaults to None and will be set on the dependency’s libtype (if it has one) or the _default_libtype parameter (if it doesn’t).
commtype (str, optional) – If provided, this is the communication type that should be used for the model and flags for just that comm type will be included. If None, flags for all installed comm types will be included. Default to None. This keyword is only used in the names of internal libraries.
toolname (str, optional) – Name of compiler tool that should be used. Defaults to None and the default compiler for the language will be used.
disable_python_c_api (bool, optional) – If True, the Python C API will be disabled. Defaults to False.
with_asan (bool, optional) – If True, the model will be compiled and linked with the address sanitizer enabled (if there is one available for the selected compiler).
- Returns:
- Full path to the library file. For header only libraries,
an empty string will be returned.
- Return type:
- Raises:
ValueError – If libtype is not ‘static’ or ‘shared’.
ValueError – If the path to the library cannot be determined for the specified dependency and default is None.
- classmethod get_dependency_object(dep, default=None, commtype=None, toolname=None, disable_python_c_api=False, with_asan=False)[source]¶
Get the location of an object file for a dependency.
- Parameters:
dep (str) – Name of internal or external dependency or full path to the object file.
default (str, optional) – Default that should be used if a value cannot be determined form internal/external dependencies or if dep is not a valid file. Defaults to None and is ignored.
commtype (str, optional) – If provided, this is the communication type that should be used for the model and flags for just that comm type will be included. If None, flags for all installed comm types will be included. Default to None. This keyword is only used in the names of internal libraries.
toolname (str, optional) – Name of compiler tool that should be used. Defaults to None and the default compiler for the language will be used.
disable_python_c_api (bool, optional) – If True, the Python C API will be disabled. Defaults to False.
with_asan (bool, optional) – If True, the model will be compiled and linked with the address sanitizer enabled (if there is one available for the selected compiler).
- Returns:
Full path to the object file.
- Return type:
- classmethod get_dependency_order(deps, toolname=None, disable_python_c_api=False)[source]¶
Get the correct dependency order, including any dependencies for the direct dependencies.
- Parameters:
- Returns:
Dependency order.
- Return type:
- classmethod get_dependency_source(dep, toolname=None, default=None)[source]¶
Get the path to the library source files (or header files) for a dependency.
- Parameters:
dep (str) – Name of internal or external dependency or full path to the library.
toolname (str, optional) – Name of compiler tool that should be used. Defaults to None and the default compiler for the language will be used.
default (str, optional) – Default that should be used if a value cannot be determined form internal/external dependencies or if dep is not a valid file. Defaults to None and is ignored.
- Returns:
- Full path to the library source file. For header only libraries
this will be the header location.
- Return type:
- classmethod get_external_libraries(no_comm_libs=False)[source]¶
Determine the external libraries that are required based on the default comm.
- Parameters:
no_comm_libs (bool, optional) – If True, libraries for the installed comms are not included in the returned list. Defaults to False.
- Returns:
- The names of external libraries required by the interface
library, including the dependency libraries for the installed comm libraries.
- Return type:
- classmethod get_internal_suffix(commtype=None, disable_python_c_api=False, with_asan=False)[source]¶
Determine the suffix that should be used for internal libraries.
- Parameters:
commtype (str, optional) – If provided, this is the communication type that should be used for the model. If None, the default comm is used.
disable_python_c_api (bool, optional) – If True, the Python C API will be disabled. Defaults to False.
with_asan (bool, optional) – If True, the model will be compiled and linked with the address sanitizer enabled (if there is one available for the selected compiler).
- Returns:
- Suffix that should be added to internal libraries to
differentiate between different dependencies.
- Return type:
- classmethod get_linker_flags(toolname=None, **kwargs)[source]¶
Determine the flags required by the current linker.
- Parameters:
toolname (str, optional) – Name of compiler tool that should be used. Defaults to None and the default compiler for the language will be used.
**kwargs – Keyword arguments are passed to cls.update_linker_kwargs first and then the linker’s get_flags method.
- Returns:
Flags for the linker.
- Return type:
- classmethod get_testing_options(**kwargs)[source]¶
Method to return a dictionary of testing options for this class.
- Parameters:
**kwargs – Additional keyword arguments are passed to the parent class.
- Returns:
- Dictionary of variables to use for testing. Key/value pairs:
kwargs (dict): Keyword arguments for driver instance. deps (list): Dependencies to install.
- Return type:
- classmethod get_tool(*args, **kwargs)[source]¶
Get tool from a driver class.
- Parameters:
*args – Arguments are passed to the get_tool_static method.
**kwargs – Keyword arguments are passed to the get_tool_static method.
- Returns:
- Class providing an interface to the specified
compilation tool.
- Return type:
- get_tool_instance(*args, **kwargs)[source]¶
Get tool from a driver instance.
- Parameters:
*args – Arguments are passed to the get_tool_static method.
**kwargs – Keyword arguments are passed to the get_tool_static method.
- Returns:
- Class providing an interface to the specified
compilation tool.
- Return type:
- static get_tool_static(cls, tooltype, toolname=None, return_prop='tool', default=False, language=None)[source]¶
Get the class associated with the specified compilation tool for this language.
- Parameters:
cls (class, instance) – Compiled driver class or instance of compiled driver class to get tool for.
tooltype (str) – Type of compilation tool that should be returned.
toolname (str, optional) – Name of the tool that should be returned. Defaults to None and the tool name associated with the provided class/instance will be used.
return_prop (str, optional) – Value that should be returned. If ‘tool’, the tool is returned. If ‘name’, the tool name is returned. If ‘flags’, the tool flags are returned. Defaults to ‘tool’.
default (object, optiona) – Tool that should be returned if one cannot be identified. If False, an error will be raised when a tool cannot be located. Defaults to False.
language (str, optional) – Language of tools that should be returned. Defaults to None if not provided.
- Returns:
- Class providing an interface to the specified
compilation tool.
- Return type:
- Raises:
NotImplementedError – If a tool is not specified.
ValueError – If return_prop is not ‘tool’, ‘name’, or ‘flags’.
- classmethod identify_source_files(args=None, working_dir=None, source_files=None, **kwargs)[source]¶
Determine the source file based on model arguments.
- internal_libraries = {}¶
- is_build_tool = False¶
- classmethod is_language_installed()[source]¶
Determine if the interpreter/compiler for the associated programming language is installed.
- Returns:
True if the language interpreter/compiler is installed.
- Return type:
- classmethod is_library_installed(lib, cfg=None)[source]¶
Determine if a dependency is installed by check for the appropriate config options setting the path to the library files.
- classmethod is_tool_installed(tooltype)[source]¶
Determine if a compilation tool of a certain is installed for this language.
- kwargs_in_suffix = ['with_asan', 'disable_python_c_api', 'commtype']¶
- classmethod language_executable(toolname=None)[source]¶
Command required to compile/run a model written in this language from the command line.
- classmethod language_version(toolname=None, **kwargs)[source]¶
Determine the version of this language.
- locked_buildfile = None¶
- model_command()[source]¶
Return the command that should be used to run the model.
- Returns:
- Any commands/arguments needed to run the model from the
command line.
- Return type:
- parse_arguments(args, **kwargs)[source]¶
Sort model arguments to determine which one is the executable and which ones are arguments.
- Parameters:
args (list) – List of arguments provided.
**kwargs – Additional keyword arguments are passed to the parent class’s method.
- classmethod partner_buildfile_lock(self)[source]¶
Actions completing buildfile lock on MPIPartnerModels.
- run_model(**kwargs)[source]¶
Run the model. Unless overridden, the model will be run using run_executable.
- Parameters:
**kwargs – Keyword arguments are passed to run_executable.
- set_env(for_compile=False, compile_kwargs=None, toolname=None, **kwargs)[source]¶
Get environment variables that should be set for the model process.
- Parameters:
for_compile (bool, optional) – If True, environment variables are set that are necessary for compiling. Defaults to False.
compile_kwargs (dict, optional) – Keyword arguments that should be passed to the compiler’s set_env method. Defaults to empty dict.
toolname (str, optional) – Name of compiler tool that should be used. Defaults to None and the default compiler for the language will be used.
**kwargs – Additional keyword arguments are passed to the parent class’s method.
- Returns:
Environment variables for the model process.
- Return type:
- classmethod set_env_compiler(compiler=None, toolname=None, **kwargs)[source]¶
Get environment variables that should be set for the compilation process.
- Parameters:
compiler (CompilerBase, optional) – Compiler that set_env shoudl be called for. If not provided, the default compiler for this language will be used.
toolname (str, optional) – Name of compiler tool that should be used. Defaults to None and the default compiler for the language will be used.
**kwargs – Additional keyword arguments are passed to the parent class’s method.
- Returns:
Environment variables for the model process.
- Return type:
- set_target_language()[source]¶
Set the language of the target being compiled (usually the same as the language associated with this driver.
- Returns:
Name of language.
- Return type:
- standard_libraries = []¶
- classmethod update_compiler_kwargs(for_api=False, for_model=False, commtype=None, toolname=None, directory=None, include_dirs=None, definitions=None, skip_interface_flags=False, **kwargs)[source]¶
Update keyword arguments supplied to the compiler get_flags method for various options.
- Parameters:
dont_link (bool, optional) – If True, the command will result in a linkable object file rather than an executable. Defaults to False.
for_api (bool, optional) – If True, flags are added that are required for compiling internal api libraries in this language. This includes external communication libraries. Defaults to False.
for_model (bool, optional) – If True, flags are added that are required for including the interface library. Defaults to False.
commtype (str, optional) – If provided, this is the communication type that should be used for the model and flags for just that comm type will be included. If None, flags for all installed comm types will be included. Default to None. This keyword is only used if for_model is True.
toolname (str, optional) – Name of compiler tool that should be used. Defaults to None and the default compiler for the language will be used.
include_dirs (list, optional) – If provided, each list element will be added as an included directory flag. Defaults to None and is initialized as an empty list.
definitions (list, optional) – If provided, each list element will be added as a defintion. Defaults to None and is initialized to an empty list.
skip_interface_flags (bool, optional) – If True, interface flags will not be added. Defaults to False.
internal_dependencies (list, optional) – If provided, a list of names of internal libraries that are required or linkable object files for dependencies. Defaults to an empty list.
external_dependencies (list, optional) – If provided, a list of names of external libraries that are required or linkable object files for dependencies. Defaults to an empty list.
**kwargs – Additional keyword arguments are passed to the compiler class’s ‘get_flags’ method and get_linker_flags if dont_link is False.
- Returns:
- Keyword arguments for a get_flags method providing compiler
flags.
- Return type:
- classmethod update_linker_kwargs(for_api=False, for_model=False, commtype=None, toolname=None, libtype='object', skip_interface_flags=False, use_library_path_internal=False, **kwargs)[source]¶
Update keyword arguments supplied to the linker/archiver get_flags method for various options.
- Parameters:
for_api (bool, optional) – If True, flags are added that are required for linking internal api libraries in this language. This includes external communication libraries. Defaults to False.
for_model (bool, optional) – If True, flags are added that are required for including the interface library. Defaults to False.
commtype (str, optional) – If provided, this is the communication type that should be used for the model and flags for just that comm type will be included. If None, flags for all installed comm types will be included. Default to None. This keyword is only used if for_model is True.
toolname (str, optional) – Name of compiler tool that should be used. Defaults to None and the default compiler for the language will be used.
libtype (str, optional) – Library type that should be created by the linker/archiver. Valid values are ‘static’, ‘shared’, or ‘object’. Defaults to ‘object’.
skip_interface_flags (bool, optional) – If True, interface flags will not be added. Defaults to False.
libraries (list, optional) – Full paths to libraries that should be linked against. Defaults to an empty list.
internal_dependencies (list, optional) – If provided, a list of names of internal libraries that are required or linkable object files for dependencies. Defaults to an empty list.
external_dependencies (list, optional) – If provided, a list of names of external libraries that are required or linkable object files for dependencies. Defaults to an empty list.
use_library_path_internal (bool, optional) – If True, internal dependencies are included as full paths. Defaults to False.
**kwargs – Additional keyword arguments are passed to the linker (or archiver if static is True) ‘get_flags’ method.
- Returns:
- Keyword arguments for a get_flags method providing linker/
archiver flags.
- Return type:
- class yggdrasil.drivers.CompiledModelDriver.CompilerBase(**kwargs)[source]¶
Bases:
CompilationToolBase
Base class for compilers.
- Parameters:
linker (str, optional) – Name of the linker that should be used for linking compiled objects. Defaults to None if not provided and default_linker will be used.
archiver (str, optional) – Name of the archiver that should be used for combining compiled objects into a static library. Defaults to None if not provided and default_archiver will be used.
linker_flags (list, optional) – Flags that should be used when linking compiled objects. Defaults to default_linker_flags if not provided.
archiver_flags (list, optional) – Flags that should be used for combining compiled objects into a static library. Defaults to default_archiver_flags if not provided.
- Class Attributes:
- compile_only_flag (str): Flag that should prepended to compiler/linker
combination tool arguments to indicate that only compilation should be performed.
- default_linker (str): Name of linker that should be used after compiling
with this compiler. If not set, it is assumed that this compiler is also a linker.
- default_archiver (str): Name of archiver that should be used to create
a static library after compiling with this compiler. If not set, it is assumed that this compiler is also a linker.
- default_linker_flags (list): Flags that should be used with the linker
if no other flags are provided.
- default_archiver_flags (list): Flags that should be used with the
archiver if no other flags are provided.
- linker_switch (str): Flag to indicate beginning of flags that should be
passed to the linker from a call to a compiler/linker combination tools (e.g. /link on Windows).
object_ext (str): Extension that should be used for object files. is_linker (bool): If True, the tool also serves as a linker and a
separate linker class will be automatically generating from the linker_attributes dictionary. This will be set to True if no_separate_linking is True.
- no_separate_linking (bool): If True, the tool severs as linker but
cannot be called for just compilation or linking alone.
- linker_attributes (dict): Attributes that should be added to the linker
class created for this tool if is_linker is True.
- linker_base_classes (tuple): Base classes that should be used to create
the default linker from the compiler tool. If None, (LinkerBase, ) is used if no_separate_linking is False and (DummyLinkerBase, ) is used if no_separate_linking is True.
- combine_with_linker (bool): If True, the compiler and linker flags can
be combined and passed to the compiler executable to perform both operations in succession. If False, the compilation and linking steps must be performed separately. If None, this is determined by checking if the compiler and linker names match.
- classmethod archiver()[source]¶
Get the associated archiver class.
- Returns:
Archiver class associated with this compiler.
- Return type:
ArchiverToolBase
- static before_registration(cls)[source]¶
Operations that should be performed to modify class attributes prior to registration including things like platform dependent properties and checking environment variables for default settings.
- classmethod call(args, dont_link=None, skip_flags=False, out=None, libtype=None, additional_objs=None, **kwargs)[source]¶
Call the tool with the provided arguments. If the first argument resembles the name of the tool executable, the executable will not be added.
- Parameters:
args (list) – The arguments that should be passed to the tool.
dont_link (bool, optional) – If True, the command will result in a linkable object file rather than an executable or library. Defaults to True if cls.no_separate_linking is True or libtype is ‘object’ and False otherwise.
skip_flags (bool, optional) – If True, args is assumed to include any necessary flags. If False, args are assumed to the files that the tool is called on and flags are determined from them. Defaults to False.
out (str, optional) – Full path to output file that should be created. If None, the path will be determined from the path to the first arguments provided. Defaults to None. This keyword argument will be ignored if skip_flags is True.
libtype (str, optional) – Library type that should be created by the linker/archiver. Defaults to None.
additional_objs (list, optional) – Additional linkable object files that should be supplied to the linker/archiver if dont_link is False. Defaults to None and is ignored.
**kwargs – Additional keyword arguments are passed to the parent class’s method and the associated linker/archiver’s call method if dont_link is False.
- Returns:
- Output to stdout from the command execution if skip_flags is
True, produced file otherwise.
- Return type:
- combine_with_linker = None¶
- compile_only_flag = '-c'¶
- default_archiver = None¶
- default_archiver_flags = None¶
- default_linker = None¶
- default_linker_flags = None¶
- flag_options = {'definitions': '-D%s', 'include_dirs': '-I%s'}¶
- classmethod get_flags(dont_link=None, add_linker_switch=False, libtype=None, logging_level=None, disable_python_c_api=False, **kwargs)[source]¶
Get a list of compiler flags.
- Parameters:
dont_link (bool, optional) – If True, the command will result in a linkable object file rather than an executable or library. Defaults to True if cls.no_separate_linking is True or libtype is ‘object’ and False otherwise.
add_linker_switch (bool, optional) – If True, the linker_switch flag will be added to the flags even if dont_link is True as long as the flag is not None. Defaults to False.
libtype (str, optional) – Library type that should be created by the linker/archiver. Defaults to None.
logging_level (int, optional) – Logging level that should be passed as a definition to the C compiler. Defaults to None and will be ignored.
disable_python_c_api (bool, optional) – If True, the Python C API will be disabled. Defaults to False.
**kwargs – Additional keyword arguments are passed to the parent class’s method and get_linker_flags if dont_link is False.
- Returns:
Compiler flags.
- Return type:
- Raises:
ValueError – If dont_link is False and cls.combine_with_linker is False.
- classmethod get_library_tool(libtype=None, **kwargs)[source]¶
Determine the tool that should be used based on the provided arguments.
- Parameters:
libtype (str, optional) – Library type that should be created by the linker/archiver. If ‘static’, the archiver is returned. If ‘shared’ or any other value, the linker is returned. Defaults to None.
**kwargs – Additional keyword arguments are ignored.
- Returns:
Linker/archiver that should be used.
- Return type:
- classmethod get_output_file(src, dont_link=False, working_dir=None, libtype=None, no_src_ext=False, no_tool_suffix=False, suffix='', **kwargs)[source]¶
Determine the appropriate output file that will result when compiling a given source file.
- Parameters:
src (str) – Source file being compiled that name base will be taken from.
dont_link (bool, optional) – If True, the result assumes that the source is just compiled and not linked. If False, the result will be the final result after linking. Defaults to None and will be set to True if libtype is ‘object’ and False otherwise.
working_dir (str, optional) – Working directory where output file should be located. Defaults to None and is ignored.
libtype (str, optional) – Library type that should be created by the linker/archiver. Defaults to None.
no_src_ext (bool, optional) – If True, the source extension will not be added to the object file name. Defaults to False. Ignored if dont_link is False.
no_tool_suffix (bool, optional) – If True, the tool suffix will not be added to the object file name. Defaults to False.
suffix (str, optional) – Suffix that should be added to the output file (before the extension). Defaults to “”.
**kwargs – Additional keyword arguments are ignored unless dont_link is False; then they are passed to the linker’s get_output_file method.
- Returns:
Full path to file that will be produced.
- Return type:
- is_linker = True¶
- classmethod linker()[source]¶
Get the associated linker class.
- Returns:
Linker class associated with this compiler.
- Return type:
- linker_attributes = {}¶
- linker_base_classes = None¶
- linker_switch = None¶
- no_separate_linking = False¶
- object_ext = '.o'¶
- classmethod preload_env(libs, env)[source]¶
Get environment variables necessary to preload libraries.
- search_path_env = ['include']¶
- tooltype = 'compiler'¶
- class yggdrasil.drivers.CompiledModelDriver.DummyLinkerBase(**kwargs)[source]¶
Bases:
LinkerBase
Base class for a dummy linker in the case that the linking step cannot be split into a separate call.
- classmethod get_flags(**kwargs)[source]¶
Raises an error to ward off getting flags for the dummy linker.
- is_dummy = True¶
- toolname = 'dummy'¶
- class yggdrasil.drivers.CompiledModelDriver.GFortranLinker(**kwargs)¶
Bases:
LinkerBase
- aliases = []¶
- compatible_toolsets = ['gnu']¶
- default_executable = 'gfortran'¶
- default_executable_env = 'FC'¶
- default_flags = []¶
- default_flags_env = 'LFLAGS'¶
- is_gnu = True¶
- languages = ['fortran']¶
- library_ext = '.so'¶
- platforms = ['MacOS', 'Linux', 'Windows']¶
- search_path_envvar = ['LIBRARY_PATH', 'LD_LIBRARY_PATH']¶
- toolname = 'gfortran'¶
- toolset = 'gnu'¶
- class yggdrasil.drivers.CompiledModelDriver.LinkerBase(**kwargs)[source]¶
Bases:
CompilationToolBase
Base class for linkers.
Flag that should be prepended to the linker tool arguments to indicate that a shared/dynamic library should be produced instead of an executable.
- Type:
- library_name_key¶
Option key indicating the name of a library that should be linked against.
- Type:
- library_directory_key¶
Option key indicating a directory that should be included in the linker search path for libraries.
- Type:
- output_first_library¶
If True, the output key (and its value) are put in front of the other flags when building a library. A value of None causes the output_first attribute to be used (unless explicitly set in the method call).
- Type:
- all_library_ext = ['.so', '.a']¶
- static before_registration(cls)[source]¶
Operations that should be performed to modify class attributes prior to registration including things like platform dependent properties and checking environment variables for default settings.
- executable_ext = '.out'¶
- classmethod extract_kwargs(kwargs, compiler=None, add_kws_link=[], add_kws_both=[])[source]¶
Extract linker kwargs, leaving behind just compiler kwargs.
- Parameters:
kwargs (dict) – Keyword arguments passed to the compiler that should be sorted into kwargs used by either the compiler or linker or both. Keywords that are not used by the compiler will be removed from this dictionary.
compiler (CompilerBase, optional) – Compiler tool that linker kwargs are being extracted in order to call. Defaults to None and is ignored.
add_kws_link (list, optional) – Addition keywords that should be added to the list of those reserved for the linker. Defaults to [].
add_kws_both (list, optional) – Additional keywords that should be added to the list of those that are valid for both the linker and compiler. Defaults to [].
- Returns:
Keyword arguments that should be passed to the linker.
- Return type:
- flag_options = {'library_dirs': '-L%s', 'library_libs': {'allow_duplicate_values': True, 'key': '-l%s'}, 'library_libs_nonstd': {'allow_duplicate_values': True, 'key': '-l:%s'}}¶
- classmethod get_flags(build_library=False, skip_library_libs=False, use_library_path=False, **kwargs)[source]¶
Get a list of linker flags.
- Parameters:
libraries (list, optional) – Full paths to libraries that should be linked against. Defaults to an empty list.
library_dirs (list, optional) – Directories that should be searched for libraries. Defaults to an empty list.
library_libs (list, optional) – Names of libraries that should be linked against. Defaults to an empty list.
library_libs_nonstd (list, optional) – Names of libraries w/ non-standard naming conventions that should be linked against. Defaults to an empty list.
library_flags (list, optional) – Existing list that library flags should be appended to instead of the returned flags if skip_library_libs is True. Defaults to [].
build_library (bool, optional) – If True, a shared library is built. If False, an executable is created. Defaults to False.
skip_library_libs (bool, optional) – If True, the library_libs will not be added to the returned flags. Instead, any additional required library flags will be appended to the provided library_flags list which should then be added to the compilation command by the user in the appropriate location. Defaults to False.
use_library_path (bool, optional) – If True, the included libraries will be added to the output list as complete paths rather than as separate flags for library and library search directory. Defaults to False.
**kwargs – Additional keyword arguments are passed to the parent class’s method.
- Returns:
Linker flags.
- Return type:
- classmethod get_output_file(obj, build_library=False, working_dir=None, suffix='', no_tool_suffix=False, **kwargs)[source]¶
Determine the appropriate output file that will result when linking a given object file.
- Parameters:
obj (str) – Object file being linked that name base will be taken from.
build_library (bool, optional) – If True, a shared library path is returned. If False, an executable file name is returned. Defaults to False.
working_dir (str, optional) – Working directory where output file should be located. Defaults to None and is ignored.
suffix (str, optional) – Suffix that should be added to the output file (before the extension). Defaults to “”.
no_tool_suffix (bool, optional) – If True, the tool suffix will not be added to the object file name. Defaults to False.
**kwargs – Additional keyword arguments are ignored.
- Returns:
Full path to file that will be produced.
- Return type:
- classmethod is_standard_libname(libname)[source]¶
Determine if the provided file name conforms to the standards expected by this linker.
- library_ext = None¶
- library_prefix = 'lib'¶
- output_first_library = None¶
- search_path_env = ['lib']¶
- shared_library_flag = '-shared'¶
- tooltype = 'linker'¶
- class yggdrasil.drivers.CompiledModelDriver.LockedFile(fname, context, when_to_lock='init')[source]¶
Bases:
object
Class for locking files during compilation.
- class yggdrasil.drivers.CompiledModelDriver.MSVCLinker(**kwargs)¶
Bases:
LinkerBase
- aliases = []¶
- compatible_toolsets = ['msvc']¶
- default_executable = 'LINK'¶
- default_executable_env = 'LINK'¶
- default_flags = []¶
- default_flags_env = 'LDFLAGS'¶
- flag_options = {'import_lib': '/IMPLIB:%s', 'library_dirs': '/LIBPATH:%s', 'library_libs': '', 'library_libs_nonstd': ''}¶
- is_gnu = False¶
- languages = ['c']¶
- library_ext = '.so'¶
- output_first = True¶
- output_first_library = False¶
- output_key = '/OUT:%s'¶
- platforms = ['Windows']¶
- search_path_envvar = ['LIB']¶
- search_path_flags = None¶
- toolname = 'LINK'¶
- toolset = 'msvc'¶
- class yggdrasil.drivers.CompiledModelDriver.MakeLinker(**kwargs)¶
Bases:
DummyLinkerBase
- aliases = []¶
- default_executable = 'make'¶
- default_executable_env = None¶
- default_flags = []¶
- executable_ext = ''¶
- is_gnu = False¶
- languages = ['make']¶
- library_ext = '.so'¶
- platforms = ['MacOS', 'Linux']¶
- tool_suffix_format = ''¶
- toolname = 'make'¶
- toolset = None¶
- class yggdrasil.drivers.CompiledModelDriver.NMakeLinker(**kwargs)¶
Bases:
DummyLinkerBase
- aliases = []¶
- default_executable = 'nmake'¶
- default_executable_env = None¶
- default_flags = []¶
- executable_ext = ''¶
- is_gnu = False¶
- languages = ['make']¶
- library_ext = '.so'¶
- platforms = ['Windows']¶
- tool_suffix_format = ''¶
- toolname = 'nmake'¶
- toolset = None¶
- yggdrasil.drivers.CompiledModelDriver.find_compilation_tool(tooltype, language, allow_failure=False, dont_check_installation=False)[source]¶
Return the prioritized class for a compilation tool of a certain type that can handle the specified language.
- Parameters:
tooltype (str) – Type of tool. Valid values include ‘compiler’, ‘linker’, and ‘archiver’.
allow_failure (bool, optional) – If True and a tool cannot be located, None will be returned. Otherwise, an error will be raised if a tool cannot be located. Defaults to False.
dont_check_installation (bool, optional) – If True, the first tool in the registry will be returned even if it is not installed. Defaults to False.
- Returns:
Name of the determined tool type.
- Return type:
- Raises:
RuntimeError – If a tool cannot be located for the specified language on the current platform and allow_failure is False.
- yggdrasil.drivers.CompiledModelDriver.get_compatible_tool(tool, tooltype, language, default=False)[source]¶
Get a compatible compilation tool that can be used in conjunction with the one provided based on the registry of compilation toolsets.
- Parameters:
tool (CompilationToolBase, str) – Compilation tool or name of a compilation tool to get compatible counterpart to.
tooltype (str) – Type of compilation tool that should be returned.
language (str) – Language that compilation tool should handle.
default (CompilationToolBase, optional) – Default tool that should be returned if not compatible tool can be located. Defaults to False and an error will be raised if a tool cannot be located.
- Returns:
Compatible compilation tool class.
- Return type:
- yggdrasil.drivers.CompiledModelDriver.get_compilation_tool(tooltype, name, default=False)[source]¶
Return the class providing information about a compilation tool.
- Parameters:
- Returns:
Class providing access to the specified tool.
- Return type:
- Raises:
ValueError – If a tool with the provided name cannot be located.
- yggdrasil.drivers.CompiledModelDriver.get_compilation_tool_registry(tooltype, init_languages=None)[source]¶
Return the registry containing compilation tools of the specified type.
- Parameters:
- Returns:
Registry for specified type.
- Return type:
- Raises:
ValueError – If tooltype is not a valid value (i.e. ‘compiler’, ‘linker’, or ‘archiver’).
yggdrasil.drivers.ConnectionDriver module¶
Module for funneling messages from one comm to another.
- class yggdrasil.drivers.ConnectionDriver.ConnectionDriver(*args, **kwargs)[source]¶
Bases:
Driver
Class that continuously passes messages from one comm to another.
- Parameters:
name (str) – Name that should be used to set names of input/output comms.
inputs (list, optional) – One or more dictionaries containing keyword arguments for constructing input communicators. Defaults to an empty dictionary if not provided.
outputs (list, optional) – One or more dictionaries containing keyword arguments for constructing output communicators. Defaults to an empty dictionary if not provided.
input_pattern (str, optional) –
The communication pattern that should be used to handle incoming messages when there is more than one input communicators present. Defaults to ‘cycle’. Options include:
’cycle’: Receive from the next available input communicator. ‘gather’: Receive lists of messages with one element from each
communicator where a message is only returned when there is a message from each.
output_pattern (str, optional) –
The communication pattern that should be used to handling outgoing messages when there is more than one output communicator present. Defaults to ‘broadcast’. Options include:
- ’cycle’: Rotate through output comms, sending one message to
each.
’broadcast’: Send the same message to each comm. ‘scatter’: Send part of message (must be a list) to each comm.
transform (str, func, optional) – Function or string specifying function that should be used to translate messages from the input communicator before passing them to the output communicator. If a string, the format should be “<package.module>:<function>” so that <function> can be imported from <package>. Defaults to None and messages are passed directly. This can also be a list of functions/strings that will be called on the messages in the order they are provided.
timeout_send_1st (float, optional) – Time in seconds that should be waited before giving up on the first send. Defaults to self.timeout.
single_use (bool, optional) – If True, the driver will be stopped after one loop. Defaults to False.
onexit (str, optional) – Class method that should be called when a model that the connection interacts with exits, but before the connection driver is shut down. Defaults to None.
**kwargs – Additonal keyword arguments are passed to the parent class.
- transform¶
Function that will be used to translate messages from the input communicator before passing them to the output communicator.
- Type:
func
- timeout_send_1st¶
Time in seconds that should be waited before giving up on the first send.
- Type:
- onexit¶
Class method that should be called when the corresponding model exits, but before the driver is shut down.
- Type:
- graceful_stop(timeout=None, **kwargs)[source]¶
Stop the driver, first waiting for the input comm to be empty.
- Parameters:
timeout (float, optional) – Max time that should be waited. Defaults to None and is set to attribute timeout.
**kwargs – Additional keyword arguments are passed to the parent class’s graceful_stop method.
- property model_env¶
Mapping between model name and opposite comm environment variables that need to be provided to the model.
- Type:
- on_eof(msg)[source]¶
Actions to take when EOF received.
- Parameters:
msg (CommMessage) – Message object that provided the EOF.
- Returns:
Value that should be returned by recv_message on EOF.
- Return type:
- on_model_exit_remote(direction, name, errors=False)[source]¶
Drain input and then close it (on the remote process).
- printStatus(beg_msg='', end_msg='', verbose=False, return_str=False)[source]¶
Print information on the status of the ConnectionDriver.
- Parameters:
beg_msg (str, optional) – Additional message to print at beginning.
end_msg (str, optional) – Additional message to print at end.
verbose (bool, optional) – If True, the status of individual comms will be displayed. Defaults to False.
return_str (bool, optional) – If True, the message string is returned. Defaults to False.
- recv_message(**kwargs)[source]¶
Get a new message to send.
- Parameters:
**kwargs – Additional keyword arguments are passed to the appropriate recv method.
- Returns:
False if no more messages, message otherwise.
- Return type:
- run_loop()[source]¶
Run the driver. Continue looping over messages until there are not any left or the communication channel is closed.
- send_message(msg, **kwargs)[source]¶
Send a single message.
- Parameters:
msg (CommMessage) – Message being sent.
*kwargs – Keyword arguments are passed to the output comm send method.
- Returns:
Success or failure of send.
- Return type:
- class yggdrasil.drivers.ConnectionDriver.RemoteTaskLoop(*args, **kwargs)[source]¶
Bases:
YggTaskLoop
Class to handle running tasks on the connection loop process.
- exception yggdrasil.drivers.ConnectionDriver.TaskThreadError[source]¶
Bases:
RuntimeError
yggdrasil.drivers.DSLModelDriver module¶
- class yggdrasil.drivers.DSLModelDriver.DSLModelDriver(*args, **kwargs)[source]¶
Bases:
InterpretedModelDriver
Class for running domain specific lanugage models.
- after_loop()[source]¶
Actions to perform after run_loop has finished. Mainly checking if there was an error and then handling it.
- base_languages = ['python']¶
- executable_type = 'dsl'¶
- full_language = False¶
- function_param = None¶
- is_dsl = True¶
- classmethod is_language_installed()[source]¶
Determine if this model driver is installed on the current machine.
- Returns:
- Truth of if this model driver can be run on the current
machine.
- Return type:
- classmethod language_version(**kwargs)[source]¶
Determine the version of this language.
- Parameters:
**kwargs – Keyword arguments are passed to cls.run_executable.
- Returns:
Version of compiler/interpreter for this language.
- Return type:
- run_model(return_process=True, **kwargs)[source]¶
Run the model. Unless overridden, the model will be run using run_executable.
- Parameters:
return_process (bool, optional) – If True, the process running the model is returned. If False, the process will block until the model finishes running. Defaults to True.
**kwargs – Keyword arguments are passed to run_executable.
yggdrasil.drivers.Driver module¶
- class yggdrasil.drivers.Driver.Driver(*args, **kwargs)[source]¶
Bases:
YggTaskLoop
Base class for all drivers.
- Parameters:
name (str) – Driver name.
yml (dict, optional) – Dictionary of yaml specification options for this driver. Defaults to empty dict.
env (dict, optional) – Dictionary of environment variables that should be set when the driver starts. Defaults to {}.
comm_env (dict, optional) – Dictionary of environment variables for paired IO communication drivers. Defaults to {}.
namespace (str, optional) – Namespace for set of drivers running together. If not provided, the config option (‘rmq’, ‘namespace’) is used.
rank (int, optional) – Rank of the integration. Defaults to None.
yggdrasil.drivers.DummyModelDriver module¶
- class yggdrasil.drivers.DummyModelDriver.DummyModelDriver(*args, **kwargs)[source]¶
Bases:
InterpretedModelDriver
Class that stands-in to act as a model utilizing unmatched input/output channels.
- base_languages = ['python']¶
- cfg = <yggdrasil.config.YggConfigParser object>¶
- comms_implicit = True¶
- classmethod configuration_steps()[source]¶
Get a list of configuration steps with tuples of flags and boolean values.
- Returns:
- Pairs of descriptions and states for
different steps in the configuration all steps must be True for the language to be configured.
- Return type:
OrderedDict
- default_interpreter = 'dummy'¶
- default_interpreter_flags = []¶
- executable_type = 'other'¶
- full_language = False¶
- inverse_type_map = None¶
- classmethod is_language_installed()[source]¶
Determine if this model driver is installed on the current machine.
- Returns:
- Truth of if this model driver can be run on the current
machine.
- Return type:
- language = 'dummy'¶
- language_ext = []¶
- classmethod language_version(**kwargs)[source]¶
Determine the version of this language.
- Parameters:
**kwargs – Keyword arguments are passed to cls.run_executable.
- Returns:
Version of compiler/interpreter for this language.
- Return type:
- no_executable = True¶
yggdrasil.drivers.DuplicatedModelDriver module¶
- class yggdrasil.drivers.DuplicatedModelDriver.DuplicatedModelDriver(*args, **kwargs)[source]¶
Bases:
Driver
Base class for Model drivers and for running executable based models.
- Parameters:
name (str) – Unique name used to identify the model. This will be used to report errors associated with the model.
*args – Additional arguments are passed to the models in the set.
**kwargs – Additional keyword arguments are passed to the models in the set.
Attributes:
- Raises:
RuntimeError – If both with_strace and with_valgrind are True.
- classmethod get_yaml_copies(yml)[source]¶
Get a list of yamls for creating duplicate models for the model described by the provided yaml.
- name_format = '%s_copy%d'¶
yggdrasil.drivers.ExecutableModelDriver module¶
- class yggdrasil.drivers.ExecutableModelDriver.ExecutableModelDriver(*args, **kwargs)[source]¶
Bases:
ModelDriver
Class for running executable based models.
- static before_registration(cls)[source]¶
Operations that should be performed to modify class attributes prior to registration including things like platform dependent properties and checking environment variables for default settings.
- cfg = <yggdrasil.config.YggConfigParser object>¶
- comms_implicit = True¶
- classmethod configuration_steps()[source]¶
Get a list of configuration steps with tuples of flags and boolean values.
- Returns:
- Pairs of descriptions and states for
different steps in the configuration all steps must be True for the language to be configured.
- Return type:
OrderedDict
- classmethod executable_command(args, unused_kwargs=None, **kwargs)[source]¶
Compose a command for running a program using the exectuable for this language (compiler/interpreter) with the provided arguments.
- Parameters:
- Returns:
- Arguments composing the command required to run the program
from the command line using the executable for this language.
- Return type:
- executable_type = 'other'¶
- full_language = False¶
- inverse_type_map = None¶
- classmethod is_language_installed()[source]¶
Determine if the interpreter/compiler for the associated programming language is installed.
- Returns:
True if the language interpreter/compiler is installed.
- Return type:
- language = 'executable'¶
- classmethod language_version(version_flags=None, **kwargs)[source]¶
Determine the version of this language.
- Parameters:
**kwargs – Keyword arguments are passed to cls.run_executable.
- Returns:
Version of compiler/interpreter for this language.
- Return type:
- no_executable = True¶
yggdrasil.drivers.FileInputDriver module¶
- class yggdrasil.drivers.FileInputDriver.FileInputDriver(*args, **kwargs)[source]¶
Bases:
InputDriver
Class that sends messages read from a file.
yggdrasil.drivers.FileOutputDriver module¶
- class yggdrasil.drivers.FileOutputDriver.FileOutputDriver(*args, **kwargs)[source]¶
Bases:
OutputDriver
Class to handle output of received messages to a file.
yggdrasil.drivers.FortranModelDriver module¶
- class yggdrasil.drivers.FortranModelDriver.FortranCompilerBase(**kwargs)[source]¶
Bases:
CompilerBase
Base class for Fortran compilers.
- classmethod append_product(products, src, new, new_dir=None, dont_append_src=False)[source]¶
Append a product to the specified list along with additional values indicated by cls.product_exts.
- Parameters:
products (list) – List of of existing products that new product should be appended to.
src (list) – Input arguments to compilation call that was used to generate the output file (usually one or more source files).
new (str) – New product that should be appended to the list.
new_dir (str, optional) – Directory that should be used as base when adding files listed in cls.product_files. Defaults to os.path.dirname(new).
dont_append_src (bool, optional) – If True and src is in the list of products, it will be removed. Defaults to False.
- default_archiver = None¶
- default_executable = None¶
- default_executable_env = 'FC'¶
- default_flags = ['-g', '-Wall', '-cpp', '-pedantic-errors', '-ffree-line-length-0']¶
- default_flags_env = 'FFLAGS'¶
- default_linker = None¶
- classmethod get_flags(**kwargs)[source]¶
Get a list of flags for the tool.
- Parameters:
**kwargs – Keyword arguments are passed to the parent class’s method.
- Returns:
Flags for the tool.
- Return type:
- languages = ['fortran']¶
- linker_attributes = {'default_flags_env': 'LFLAGS', 'search_path_envvar': ['LIBRARY_PATH', 'LD_LIBRARY_PATH']}¶
- product_exts = ['mod']¶
- search_path_envvar = []¶
- class yggdrasil.drivers.FortranModelDriver.FortranModelDriver(*args, **kwargs)[source]¶
Bases:
CompiledModelDriver
Class for running Fortran models.
- Parameters:
standard (str, optional) – Fortran standard that should be used. Defaults to ‘f2003’.
**kwargs – Additional keyword arguments are passed to parent class.
- classmethod allows_realloc(var, from_native_type=False)[source]¶
Determine if a variable allows the receive call to perform realloc.
- base_languages = ['c']¶
- static before_registration(cls)[source]¶
Operations that should be performed to modify class attributes prior to registration including things like platform dependent properties and checking environment variables for default settings.
- cfg = <yggdrasil.config.YggConfigParser object>¶
- compile_model(**kwargs)[source]¶
Compile model executable(s).
- Parameters:
**kwargs – Keyword arguments are passed to the parent class’s
method. –
- Returns:
Compiled model file path.
- Return type:
- default_archiver = 'ar'¶
- default_archiver_flags = None¶
- default_compiler = 'gfortran'¶
- default_compiler_flags = None¶
- default_linker = 'gfortran'¶
- default_linker_flags = None¶
- default_type_precision = {'integer': 4, 'real': 4}¶
- external_libraries = {}¶
- classmethod format_function_param_index(extra=None, **kwargs)[source]¶
Return the formatted version of the index key.
- classmethod format_function_param_len(extra=None, **kwargs)[source]¶
Return the formatted version of the len key.
- function_param = {'and': '.and.', 'assign': '{name} = {value}', 'block_end': 'END', 'break': 'EXIT', 'comment': '!', 'continuation_after': ' &', 'continuation_before': '&', 'continuation_break': (',', '{', ' '), 'copy_any': 'call copy_generic_into({name}, {value})', 'copy_array': '{name} = yggarr(copy_generic(ygggeneric({value})))', 'copy_class': '{name} = copy_python({value})', 'copy_function': '{name} = yggpyfunc(copy_python(yggpython({value})))', 'copy_generic': 'call copy_generic_into({name}, {value})', 'copy_instance': '{name} = yggpyinst(copy_generic(ygggeneric({value})))', 'copy_obj': '{name} = copy_obj({value})', 'copy_object': '{name} = yggmap(copy_generic(ygggeneric({value})))', 'copy_ply': '{name} = copy_ply({value})', 'copy_schema': '{name} = yggschema(copy_generic(ygggeneric({value})))', 'declare': '{type_name} :: {variable}', 'definition_regex': '\\s*(?P<type>(?:(?: )|(?:.))+)\\s*::\\s*(?P<name>.+)(?:\\s*=\\s*(?P<value>.+))?\\n', 'error': 'write(*, \'("{error_msg}")\')\nstop 1', 'escaped_double_quote': '""', 'exec_begin': 'PROGRAM main\n use iso_c_binding\n use fygg', 'exec_end': ' stop\nEND PROGRAM main', 'false': '.false.', 'flag_cond': '{flag_var}', 'for_begin': 'DO {iter_var} = {iter_begin}, {iter_end}', 'for_end': 'END DO', 'fprintf': 'write(*, \'("{message}")\') {variables}', 'free': 'DEALLOCATE({variable})', 'free_any': 'call free_generic({variable})', 'free_array': 'call free_generic(ygggeneric({variable}))', 'free_class': 'call free_python({variable})', 'free_function': 'call free_python(yggpython({variable}))', 'free_instance': 'call free_generic(ygggeneric({variable}))', 'free_obj': 'call free_obj({variable})', 'free_object': 'call free_generic(ygggeneric({variable}))', 'free_ply': 'call free_ply({variable})', 'free_schema': 'call free_generic(ygggeneric({variable}))', 'function_call_noout': 'call {function_name}({input_var})', 'function_def_begin': 'FUNCTION {function_name}({input_var}) result({output_var})', 'function_def_end': 'END FUNCTION {function_name}', 'function_def_regex': '(?P<procedure_type>(?i:(?:subroutine)|(?:function)))\\s+{function_name}\\s*\\((?P<inputs>(?:[^\\(]*?))\\)\\s*(?:result\\s*\\((?P<flag_var>.+)\\))?\\s*\\n(?P<preamble>(?:[^:]*?\\n)*?)(?P<definitions>(?:(?:(?: )|(?:.))+\\s*::\\s*(?:.+)\\n)+)(?P<body>(?:.*?\\n?)*?)(?i:end\\s+(?P=procedure_type))\\s+{function_name}', 'if_begin': 'IF ({cond}) THEN', 'if_elif': 'ELSE IF ({cond}) THEN', 'if_else': 'ELSE', 'if_end': 'END IF', 'import': '#include "{filename}"', 'import_nofile': 'use {function}', 'indent': ' ', 'index': '{variable}({index})', 'init_any': 'init_generic()', 'init_array': 'yggarr(init_generic())', 'init_class': 'init_python()', 'init_function': 'yggpyfunc(init_python())', 'init_instance': 'yggpyinst(init_generic())', 'init_obj': 'init_obj()', 'init_object': 'yggmap(init_generic())', 'init_ply': 'init_ply()', 'init_schema': 'yggschema(init_generic())', 'init_type_1darray': 'create_dtype_1darray("{subtype}", {precision}, {length}, "{units}", {use_generic})', 'init_type_array': 'create_dtype_json_array({nitems}, {items}, {use_generic})', 'init_type_default': 'create_dtype_default("{type}", {use_generic})', 'init_type_empty': 'create_dtype_empty({use_generic})', 'init_type_from_schema': 'create_dtype_from_schema("{schema}", {use_generic})', 'init_type_ndarray': 'create_dtype_ndarray("{subtype}", {precision}, {ndim}, {shape}, "{units}", {use_generic})', 'init_type_ndarray_arr': 'create_dtype_ndarray("{subtype}", {precision}, {ndim}, {shape}, "{units}", {use_generic})', 'init_type_obj': 'create_dtype_obj({use_generic})', 'init_type_object': 'create_dtype_json_object({nitems}, {keys}, {values}, {use_generic})', 'init_type_ply': 'create_dtype_ply({use_generic})', 'init_type_pyobj': 'create_dtype_pyobj("{type}", {use_generic})', 'init_type_scalar': 'create_dtype_scalar("{subtype}", {precision}, "{units}", {use_generic})', 'init_type_schema': 'create_dtype_schema({use_generic})', 'input': '{channel} = ygg_input_type("{channel_name}", {channel_type})', 'inputs_def_regex': '\\s*(?P<name>.+?)\\s*(?:,|$)(?:\\n)?', 'interface': 'use fygg', 'len': 'size({variable},1)', 'not': '.not.', 'not_flag_cond': '.not.{flag_var}', 'null': 'c_null_ptr', 'or': '.or.', 'output': '{channel} = ygg_output_type("{channel_name}", {channel_type})', 'outputs_def_regex': '\\s*(?P<name>.+?)\\s*(?:,|$)(?:\\n)?', 'print': 'write(*, \'("{message}")\')', 'print_any': 'call display_generic({object})', 'print_array': 'call display_generic(ygggeneric({object}))', 'print_class': 'call display_python({object})', 'print_function': 'call display_python(yggpython({object}))', 'print_generic': 'write(*, *) {object}', 'print_instance': 'call display_generic(ygggeneric({object}))', 'print_null': 'call display_null({object})', 'print_obj': 'call display_obj({object})', 'print_object': 'call display_generic(ygggeneric({object}))', 'print_ply': 'call display_ply({object})', 'print_schema': 'call display_generic(ygggeneric({object}))', 'python_init': 'call init_python_API()', 'quote': "'", 'recv_function': 'ygg_recv_var_realloc', 'recv_heap': 'ygg_recv_var_realloc', 'recv_stack': 'ygg_recv_var', 'send_function': 'ygg_send_var', 'subroutine_def_begin': 'SUBROUTINE {function_name}({input_var}) ', 'subroutine_def_end': 'END SUBROUTINE {function_name}', 'true': '.true.', 'type_regex': '(type\\()?(?P<type>[^,\\(]+)(?(1)(?:\\)))(?:\\s*\\(\\s*(?:kind\\s*=\\s*(?:(?P<precision>\\d*)|(?P<precision_var>.+?)))?\\s*,?\\s*(?:len\\s*=\\s*(?:(?P<length>(?:\\d+))|(?P<length_var>.+?)))?\\))?(?:\\s*,\\s*dimension\\((?:(?P<shape>(?:\\d)+(?:,\\s*(?:\\d)+)*?)|(?P<shape_var>.+?(?:,\\s*.+)*?))\\))?(?:\\s*,\\s*(?P<pointer>pointer))?(?:\\s*,\\s*(?P<target>target))?(?:\\s*,\\s*(?P<allocatable>allocatable))?(?:\\s*,\\s*(?P<parameter>parameter))?(?:\\s*,\\s*intent\\((?P<intent>.*?)\\))?', 'while_begin': 'DO WHILE ({cond})', 'while_end': 'END DO'}¶
- classmethod get_internal_suffix(commtype=None, **kwargs)[source]¶
Determine the suffix that should be used for internal libraries.
- Parameters:
commtype (str, optional) – If provided, this is the communication type that should be used for the model. If None, the default comm is used.
**kwargs – Additional keyword arguments will be passed to the parent class’s method.
- Returns:
- Suffix that should be added to internal libraries to
differentiate between different dependencies.
- Return type:
- classmethod get_inverse_type_map()[source]¶
Get the inverse type map.
- Returns:
Mapping from native type to JSON type.
- Return type:
- classmethod get_testing_options(**kwargs)[source]¶
Method to return a dictionary of testing options for this class.
- Parameters:
**kwargs – Additional keyword arguments are passed to the parent class.
- Returns:
- Dictionary of variables to use for testing. Key/value pairs:
kwargs (dict): Keyword arguments for driver instance. deps (list): Dependencies to install.
- Return type:
- global_scope_macro = '#define WITH_GLOBAL_SCOPE(COMM) call set_global_comm(); COMM; call unset_global_comm()'¶
- include_channel_obj = True¶
- interface_inside_exec = True¶
- interface_library = 'fygg'¶
- interface_map = {'call': 'flag = ygg_rpc_call({channel_obj}, [yggarg({outputs})], [yggarg({inputs})])', 'client': 'ygg_rpc_client_type("{channel_name}", {datatype_out}, {datatype_in})', 'import': 'use fygg', 'input': 'ygg_input_type("{channel_name}", {datatype})', 'output': 'ygg_output_type("{channel_name}", {datatype})', 'recv': 'flag = ygg_recv_var({channel_obj}, [yggarg({inputs})])', 'send': 'flag = ygg_send_var({channel_obj}, [yggarg({outputs})])', 'server': 'ygg_rpc_server_type("{channel_name}", {datatype_in}, {datatype_out})', 'timesync': 'yggTimesync("{channel_name}", "{time_units}")'}¶
- internal_libraries = {'c_wrappers': {'external_dependencies': [('c', 'rapidjson'), ('c', 'python'), ('c', 'numpy'), ('c', 'm')], 'include_dirs': ['/opt/hostedtoolcache/Python/3.8.17/x64/lib/python3.8/site-packages/yggdrasil/languages/fortran'], 'internal_dependencies': [('c', 'ygg')], 'language': 'c', 'libtype': 'object', 'source': '/opt/hostedtoolcache/Python/3.8.17/x64/lib/python3.8/site-packages/yggdrasil/languages/fortran/c_wrappers.c'}, 'fygg': {'external_dependencies': [('c', 'rapidjson'), ('c', 'python'), ('c', 'numpy'), ('c', 'm'), 'stdc++'], 'include_dirs': ['/opt/hostedtoolcache/Python/3.8.17/x64/lib/python3.8/site-packages/yggdrasil/languages/C/communication', '/opt/hostedtoolcache/Python/3.8.17/x64/lib/python3.8/site-packages/yggdrasil/languages/C/serialize', '/opt/hostedtoolcache/Python/3.8.17/x64/lib/python3.8/site-packages/yggdrasil/languages/C', '/opt/hostedtoolcache/Python/3.8.17/x64/lib/python3.8/site-packages/yggdrasil/languages/C'], 'internal_dependencies': [('c', 'regex'), ('c', 'datatypes'), ('c', 'ygg'), 'c_wrappers'], 'libtype': 'static', 'source': '/opt/hostedtoolcache/Python/3.8.17/x64/lib/python3.8/site-packages/yggdrasil/languages/fortran/YggInterface.f90'}}¶
- inverse_type_map = None¶
- is_typed = True¶
- language = 'fortran'¶
- language_ext = ['.f90', '.f77', '.f', '.h']¶
- locked_buildfile = 'fygg.mod'¶
- max_line_width = 72¶
- outputs_in_inputs = True¶
- classmethod parse_function_definition(model_file, model_function, **kwargs)[source]¶
Get information about the inputs & outputs to a model from its defintition if possible.
- Parameters:
- Returns:
Parameters extracted from the function definitions.
- Return type:
- classmethod prepare_variables(vars_list, for_yggdrasil=False, **kwargs)[source]¶
Concatenate a set of input variables such that it can be passed as a single string to the function_call parameter.
- Parameters:
vars_list (list) – List of variable dictionaries containing info (e.g. names) that should be used to prepare a string representing input/output to/from a function call.
for_yggdrasil (bool, optional) – If True, the variables will be prepared in the formated expected by calls to yggdarsil send/recv methods. Defaults to False.
**kwargs – Additional keyword arguments are passed to the parent class’s method.
- Returns:
Concatentated variables list.
- Return type:
- classmethod set_env_class(**kwargs)[source]¶
Set environment variables that are instance independent.
- Parameters:
**kwargs – Additional keyword arguments are passed to the parent class’s method and update_ld_library_path.
- Returns:
Environment variables for the model process.
- Return type:
- classmethod split_line(line, length=None, force_split=False)[source]¶
Split a line as close to (or before) a given character as possible.
- Parameters:
- Returns:
Set of lines resulting from spliting the provided line.
- Return type:
- standard_libraries = ['stdc++']¶
- supported_comm_options = {'ipc': {'platforms': ['MacOS', 'Linux']}, 'zmq': {'libraries': [('c', 'zmq'), ('c', 'czmq')]}}¶
- type_map = {'1darray': '*', '1darray_pointer': '{type}{precision}_1d', 'any': 'ygggeneric', 'array': 'yggarr', 'boolean': 'logical(kind = X)', 'bytes': 'character(len = X)', 'class': 'yggpython', 'comm': 'yggcomm', 'complex': 'complex(kind = X)', 'dtype': 'yggdtype', 'flag': 'logical', 'float': 'real(kind = X)', 'function': 'yggpyfunc', 'instance': 'yggpyinst', 'int': 'integer(kind = X)', 'integer': 'integer', 'ndarray': '*', 'ndarray_pointer': '{type}{precision}_{ndim}d', 'null': 'yggnull', 'number': 'real(kind = 8)', 'obj': 'yggobj', 'object': 'yggmap', 'ply': 'yggply', 'schema': 'yggschema', 'string': 'character(len = X)', 'uint': 'ygguintX', 'unicode': "character(kind = selected_char_kind('ISO_10646'), len = X)"}¶
- types_in_funcdef = False¶
- classmethod update_io_from_function(model_file, model_function, **kwargs)[source]¶
Update inputs/outputs from the function definition.
- Parameters:
- Returns:
- Flag variable used by the model. If None, the
model does not use a flag variable.
- Return type:
dict, None
- classmethod write_declaration(var, **kwargs)[source]¶
Return the lines required to declare a variable with a certain type.
- classmethod write_executable(lines, **kwargs)[source]¶
Return the lines required to complete a program that will run the provided lines.
- Parameters:
lines (list) – Lines of code to be wrapped as an executable.
**kwargs – Additional keyword arguments are passed to the parent class’s method.
- Returns:
- Lines of code wrapping the provided lines with the
necessary code to run it as an executable (e.g. C/C++’s main).
- Return type:
lines
- classmethod write_executable_import(module=False, **kwargs)[source]¶
Add import statements to executable lines.
- Parameters:
module (str, optional) – If provided, the include statement importing code will be wrapped in a module of the provided name. Defaults to False and the include will not be wrapped.
**kwargs – Keyword arguments for import statement.
- Returns:
Lines required to complete the import.
- Return type:
- classmethod write_initialize_oiter(var, value=None, **kwargs)[source]¶
Get the lines necessary to initialize an array for iteration output.
- Parameters:
- Returns:
The lines initializing the variable.
- Return type:
- classmethod write_model_recv(channel, recv_var, **kwargs)[source]¶
Write a model receive call include checking the return flag.
- Parameters:
- Returns:
Lines required to carry out a receive call in this language.
- Return type:
- classmethod write_model_send(channel, send_var, **kwargs)[source]¶
Write a model send call include checking the return flag.
- Parameters:
channel (str) – Name of variable that the channel being sent to was stored in.
send_var (dict, list) – Information on one or more variables containing information that will be sent.
flag_var (str, optional) – Name of flag variable that the flag should be stored in. Defaults to ‘flag’,
allow_failure (bool, optional) – If True, the returned lines will call a break if the flag is False. Otherwise, the returned lines will issue an error. Defaults to False.
- Returns:
Lines required to carry out a send call in this language.
- Return type:
- classmethod write_print_var(var, **kwargs)[source]¶
Get the lines necessary to print a variable in this language.
- classmethod write_type_decl(name, datatype, **kwargs)[source]¶
Get lines declaring the datatype within the language.
- classmethod write_type_def(name, datatype, **kwargs)[source]¶
Get lines declaring the data type within the language.
- zero_based = False¶
- class yggdrasil.drivers.FortranModelDriver.GFortranCompiler(**kwargs)[source]¶
Bases:
FortranCompilerBase
Interface class for gfortran compiler/linker.
- combine_with_linker = True¶
- compatible_toolsets = ['gnu', 'llvm']¶
- default_archiver = 'ar'¶
- default_executable = 'gfortran'¶
- default_flags = ['-g', '-Wall', '-cpp', '-pedantic-errors', '-ffree-line-length-0', '-x', 'f95-cpp-input']¶
- default_linker = 'gfortran'¶
- flag_options = {'definitions': '-D%s', 'include_dirs': '-I%s', 'module-dir': '-J%s', 'module-search-path': '-I%s', 'standard': '-std=%s'}¶
- is_gnu = True¶
- platforms = ['MacOS', 'Linux', 'Windows']¶
- toolname = 'gfortran'¶
- toolset = 'gnu'¶
yggdrasil.drivers.InputDriver module¶
- class yggdrasil.drivers.InputDriver.InputDriver(*args, **kwargs)[source]¶
Bases:
ConnectionDriver
Driver for receiving input from another model’s comm via a local comm.
yggdrasil.drivers.InterpretedModelDriver module¶
- class yggdrasil.drivers.InterpretedModelDriver.InterpretedModelDriver(*args, **kwargs)[source]¶
Bases:
ModelDriver
Base class for models written in interpreted languages.
- Parameters:
name (str) – Driver name.
args (str or list) – Argument(s) for running the model on the command line. This driver will check to see if there is an interpreter included in the args provided. If not, one will be added unless skip_interpreter is True.
interpreter (str, optional) – Name or path of interpreter executable that should be used to run the model. If not provided, the interpreter will be determined based on configuration options for the language (if present) and the default_interpreter class attribute.
interpreter_flags (list, optional) – Flags that should be passed to the interpreter when running the model. If not provided, the flags are determined based on configuration options for the language (if present) and the default_interpreter_flags class attribute.
skip_interpreter (bool, optional) – If True, no interpreter will be added to the arguments. This should only be used for subclasses that will not be invoking the model via the command line. Defaults to False.
**kwargs – Additional keyword arguments are passed to the parent class.
- Class Attributes:
- default_interpreter (str): Name of interpreter that will be used if not
set explicitly by instance or config file. Defaults to the language name if not set.
- default_interpreter_flags (list): Flags that will be passed to the
interpreter when running the model by default if not set explicitly by instance or config file.
- path_env_variable¶
Name of the environment variable containing path information for the interpreter for this language.
- Type:
- paths_to_add¶
Paths that should be added to the path_env_variable for this language on the process the model is run in.
- Type:
- comm_atexit¶
Function taking a comm instance as input that performs any necessary operations during exit. If None, no additional actions are taken.
- Type:
function
- comm_linger¶
If True, interface comms will linger during close. This should only be required if the language will disreguard Python threads at exit (e.g. when using a Matlab engine).
- Type:
- decode_format (function
Function decoding format string created in this language. If None, no additional actions are taken.
- recv_converters¶
Mapping between the names of message types (e.g. ‘array’, ‘pandas’) and functions that should be used to prepare such objects for return when they are received.
- Type:
- send_converters¶
Mapping between the names of message types (e.g. ‘array’, ‘pandas’) and functions that should be used to prepare such objects for sending.
- Type:
- static after_registration(cls, **kwargs)[source]¶
Operations that should be performed to modify class attributes after registration. For compiled languages this includes selecting the default compiler. The order of precedence is the config file ‘compiler’ option for the language, followed by the environment variable set by _compiler_env, followed by the existing class attribute.
- classmethod are_dependencies_installed(**kwargs)[source]¶
Determine if the dependencies are installed for the interface (not including dependencies needed by a particular communication type).
- Returns:
True if the dependencies are installed. False otherwise.
- Return type:
- comm_atexit = None¶
- comm_linger = False¶
- decode_format = None¶
- default_interpreter = None¶
- default_interpreter_flags = []¶
- classmethod executable_command(args, exec_type='interpreter', unused_kwargs=None, skip_interpreter_flags=False, interpreter=None, interpreter_flags=None, **kwargs)[source]¶
Compose a command for running a program in this language with the provied arguments. If not already present, the interpreter command and interpreter flags are prepended to the provided arguments.
- Parameters:
args (list) – The program that returned command should run and any arguments that should be provided to it.
exec_type (str, optional) – Type of executable command that will be returned. If ‘interpreter’, a command using the interpreter is returned and if ‘direct’, the raw args being provided are returned. Defaults to ‘interpreter’.
skip_interpreter_flags (bool, optional) – If True, interpreter flags will not be added to the command after the interpreter. Defaults to False. Interpreter flags will not be added, reguardless of this keyword, if the first element of args is already an interpreter.
unused_kwargs (dict, optional) – Existing dictionary that unused keyword arguments should be added to. Defaults to {}.
**kwargs – Additional keyword arguments are ignored.
- Returns:
- Arguments composing the command required to run the program
from the command line using the interpreter for this language.
- Return type:
- Raises:
ValueError – If exec_type is not ‘interpreter’ or ‘direct’.
- executable_type = 'interpreter'¶
- classmethod get_interpreter()[source]¶
Command required to run a model written in this language from the command line.
- Returns:
Name of (or path to) interpreter executable.
- Return type:
- classmethod get_interpreter_flags()[source]¶
Get the flags that should be passed to the interpreter when using it to run a model on the command line.
- Returns:
- Flags that should be passed to the interpreter on the command
line.
- Return type:
- classmethod language2python(pyobj)[source]¶
Prepare an object from the target language for receipt in Python.
- classmethod language_executable()[source]¶
Command required to compile/run a model written in this language from the command line.
- Returns:
- Name of (or path to) compiler/interpreter executable required
to run the compiler/interpreter from the command line.
- Return type:
- parse_arguments(*args, **kwargs)[source]¶
Sort model arguments to determine which one is the executable and which ones are arguments.
- Parameters:
*args – Arguments are passed to the parent class’s method.
**kwargs – Keyword arguments are passed to the parent class’s method.
- path_env_variable = None¶
- paths_to_add = ['/opt/hostedtoolcache/Python/3.8.17/x64/lib/python3.8/site-packages/yggdrasil', '/opt/hostedtoolcache/Python/3.8.17/x64/lib/python3.8/site-packages/yggdrasil/languages/MATLAB', '/opt/hostedtoolcache/Python/3.8.17/x64/lib/python3.8/site-packages/yggdrasil/languages/SBML', '/opt/hostedtoolcache/Python/3.8.17/x64/lib/python3.8/site-packages/yggdrasil/languages/Python', '/opt/hostedtoolcache/Python/3.8.17/x64/lib/python3.8/site-packages/yggdrasil/languages/R', '/opt/hostedtoolcache/Python/3.8.17/x64/lib/python3.8/site-packages/yggdrasil/languages/LPy', '/opt/hostedtoolcache/Python/3.8.17/x64/lib/python3.8/site-packages/yggdrasil/languages/dummy', '/opt/hostedtoolcache/Python/3.8.17/x64/lib/python3.8/site-packages/yggdrasil/languages/Julia']¶
- classmethod python2language(pyobj)[source]¶
Prepare a python object for transformation in target language.
- recv_converters = {}¶
- run_model(*args, **kwargs)[source]¶
Run the model. Unless overridden, the model will be run using run_executable.
- Parameters:
*args – Arguments are passed to the parent class’s method.
**kwargs – Keyword arguments are passed to the parent class’s method.
- send_converters = {}¶
yggdrasil.drivers.JuliaModelDriver module¶
- class yggdrasil.drivers.JuliaModelDriver.JuliaModelDriver(*args, **kwargs)[source]¶
Bases:
InterpretedModelDriver
Class for running Julia models.
- base_languages = ['python']¶
- cfg = <yggdrasil.config.YggConfigParser object>¶
- default_interpreter = 'julia'¶
- default_interpreter_flags = []¶
- function_param = {'and': '&&', 'assign': 'global {name} = {value}', 'block_end': 'end', 'break': 'break', 'comment': '#', 'error': 'error("{error_msg}")', 'false': 'false', 'first_index': 1, 'for_begin': 'for {iter_var} in {iter_begin}:{iter_end}', 'fprintf': '@printf("{message}", {variables})', 'function_def_begin': 'function {function_name}({input_var})', 'function_def_regex': '\\n?( *)function +{function_name}(?P<outtype>\\:\\:[^\\(]+?)? *\\((?P<inputs>(?:[^\\)]+?)?)\\) *(?P<body>(?:(?:\\1(?: *)(?!return)[^ ].*?\\n)|(?: *\\n))*)(?:\\1(?: *)(?:return *)?(?P<outputs>.*?) *\\n)?', 'if_begin': 'if {cond}', 'if_elif': 'elseif {cond}', 'if_else': 'else', 'import': 'include("{filename}")', 'import_nofile': 'using {function}', 'indent': ' ', 'index': '{variable}[{index}]', 'input': '{channel} = Yggdrasil.YggInterface("YggInput", "{channel_name}")', 'inputs_def_regex': '\\s*(?P<name>.+?)\\s*(?:,|$)', 'interface': 'using {interface_library}', 'istype': '{variable} isa {type}', 'len': 'length({variable})', 'not': '!', 'or': '||', 'output': '{channel} = Yggdrasil.YggInterface("YggOutput", "{channel_name}")', 'outputs_def_regex': '\\s*(?P<name>.+?)\\s*(?:,|$)', 'print': 'println("{message}")', 'print_generic': 'println({object})', 'python_interface': '{channel} = Yggdrasil.YggInterface("{python_interface}", "{channel_name}")', 'python_interface_format': '{channel} = Yggdrasil.YggInterface("{python_interface}", "{channel_name}", "{format_str}")', 'quote': '"', 'recv_function': '{channel}.recv', 'return': 'return {output_var}', 'send_function': '{channel}.send', 'true': 'true', 'try_begin': 'try', 'try_except': 'catch', 'while_begin': 'while {cond}'}¶
- classmethod get_testing_options(**kwargs)[source]¶
Method to return a dictionary of testing options for this class.
- Parameters:
**kwargs – Additional keyword arguments are passed to the parent class.
- Returns:
- Dictionary of variables to use for testing. Key/value pairs:
kwargs (dict): Keyword arguments for driver instance. deps (list): Dependencies to install.
- Return type:
- interface_dependencies = ['PyCall', 'Unitful']¶
- interface_library = 'Yggdrasil'¶
- interface_map = {'call': 'flag, {inputs} = {channel_obj}.call({outputs})', 'client': 'Yggdrasil.YggInterface("YggRpcClient", "{channel_name}")', 'import': 'import Yggdrasil: commtype', 'input': 'Yggdrasil.YggInterface("YggInput", "{channel_name}")', 'output': 'Yggdrasil.YggInterface("YggOutput", "{channel_name}")', 'recv': 'flag, {inputs} = {channel_obj}.recv()', 'send': 'flag = {channel_obj}.send({outputs})', 'server': 'Yggdrasil.YggInterface("YggRpcServer", "{channel_name}")', 'timesync': 'Yggdrasil.YggInterface("YggTimesync", "{channel_name}")'}¶
- inverse_type_map = None¶
- language = 'julia'¶
- language_ext = ['.jl']¶
- classmethod set_env_class(**kwargs)[source]¶
Get environment variables that should be set for the model process.
- Returns:
Environment variables for the model process.
- Return type:
- type_map = {'1darray': 'Array{X}', 'array': 'Array', 'boolean': 'Bool', 'bytes': 'CodeUnits{UInt8,String}', 'complex': 'Complex', 'float': 'Float', 'int': 'Int', 'ndarray': 'Array{X}', 'null': 'Nothing', 'obj': 'ObjDict', 'object': 'Dict{AbstractString,Any}', 'ply': 'PlyDict', 'schema': 'Dict', 'string': 'String', 'uint': 'Uint', 'unicode': 'String'}¶
- classmethod write_executable_import(**kwargs)[source]¶
Add import statements to executable lines.
- Parameters:
**kwargs – Keyword arguments for import statement.
- Returns:
Lines required to complete the import.
- Return type:
- classmethod write_finalize_oiter(var)[source]¶
Get the lines necessary to finalize an array after iteration.
- classmethod write_initialize_oiter(var, value=None, **kwargs)[source]¶
Get the lines necessary to initialize an array for iteration output.
- Parameters:
- Returns:
The lines initializing the variable.
- Return type:
- zero_based = False¶
yggdrasil.drivers.LPyModelDriver module¶
- class yggdrasil.drivers.LPyModelDriver.LPyModelDriver(*args, **kwargs)[source]¶
Bases:
PythonModelDriver
Class for running LPy models.
- cfg = <yggdrasil.config.YggConfigParser object>¶
- default_interpreter = '/opt/hostedtoolcache/Python/3.8.17/x64/bin/python'¶
- default_interpreter_flags = ['/opt/hostedtoolcache/Python/3.8.17/x64/lib/python3.8/site-packages/yggdrasil/languages/LPy/lpy_model.py']¶
- executable_type = 'dsl'¶
- full_language = False¶
- function_param = None¶
- classmethod get_testing_options(**kwargs)[source]¶
Method to return a dictionary of testing options for this class.
- Parameters:
**kwargs – Additional keyword arguments are passed to the parent class.
- Returns:
- Dictionary of variables to use for testing. Key/value pairs:
kwargs (dict): Keyword arguments for driver instance. deps (list): Dependencies to install.
- Return type:
- interface_dependencies = ['openalea.lpy']¶
- inverse_type_map = None¶
- is_dsl = True¶
- language = 'lpy'¶
- language_ext = ['.lpy']¶
- classmethod language_version(**kwargs)[source]¶
Determine the version of this language.
- Parameters:
**kwargs – Keyword arguments are passed to cls.run_executable.
- Returns:
Version of compiler/interpreter for this language.
- Return type:
- supported_comms = ['rmq_async', 'ipc', 'buffer', 'rest', 'value', 'rmq', 'mpi', 'zmq']¶
yggdrasil.drivers.MPIPartnerModel module¶
- class yggdrasil.drivers.MPIPartnerModel.MPIPartnerModel(*args, **kwargs)[source]¶
Bases:
ModelDriver
Class for shadowing a model run on another MPI process.
- base_languages = []¶
- cfg = <yggdrasil.config.YggConfigParser object>¶
- comms_implicit = True¶
- classmethod configuration_steps()[source]¶
Get a list of configuration steps with tuples of flags and boolean values.
- Returns:
- Pairs of descriptions and states for
different steps in the configuration all steps must be True for the language to be configured.
- Return type:
OrderedDict
- executable_type = 'other'¶
- full_language = False¶
- inverse_type_map = None¶
- classmethod is_comm_installed(**kwargs)[source]¶
Determine if a comm is installed for the associated programming language.
- Parameters:
**kwargs – Keyword arguments are ignored.
- Returns:
True if a comm is installed for this language.
- Return type:
- classmethod is_language_installed()[source]¶
Determine if this model driver is installed on the current machine.
- Returns:
- Truth of if this model driver can be run on the current
machine.
- Return type:
- language = 'mpi'¶
- classmethod language_executable(**kwargs)[source]¶
Command required to compile/run a model written in this language from the command line.
- Returns:
- Name of (or path to) compiler/interpreter executable required
to run the compiler/interpreter from the command line.
- Return type:
- language_ext = []¶
- classmethod language_version(**kwargs)[source]¶
Determine the version of this language.
- Parameters:
**kwargs – Keyword arguments are passed to cls.run_executable.
- Returns:
Version of compiler/interpreter for this language.
- Return type:
- property model_process_complete¶
Has the process finished or not. Returns True if the process has not started.
- Type:
yggdrasil.drivers.MakeModelDriver module¶
- class yggdrasil.drivers.MakeModelDriver.MakeCompiler(**kwargs)[source]¶
Bases:
BuildToolBase
Make configuration tool.
- Parameters:
makefile (str, optional) – Path to make file either absolute, relative to makedir (if provided), or relative to working_dir. Defaults to Makefile.
makedir (str, optional) – Directory where make should be invoked from if it is not the same as the directory containing the makefile. Defaults to directory containing makefile if provided, otherwise working_dir.
**kwargs – Additional keyword arguments are passed to parent class.
- static before_registration(cls)[source]¶
Operations that should be performed to modify class attributes prior to registration including things like platform dependent properties and checking environment variables for default settings.
- build_language = 'make'¶
- combine_with_linker = True¶
- compile_only_flag = None¶
- default_archiver = False¶
- default_executable = 'make'¶
- default_flags = ['--always-make']¶
- default_linker = 'make'¶
- flag_options = {'makefile': {'key': '-f', 'position': 0}}¶
- classmethod get_executable_command(args, target=None, **kwargs)[source]¶
Determine the command required to run the tool using the specified arguments and options.
- Parameters:
args (list) – The arguments that should be passed to the tool. If skip_flags is False, these are treated as input files that will be used by the tool.
target (str, optional) – Target that should be built. Defaults to to None and is set to the base name of first element in the provided arguments.
**kwargs – Additional keyword arguments are passed to the parent class’s method.
- Returns:
Output to stdout from the command execution.
- Return type:
- classmethod get_flags(target=None, **kwargs)[source]¶
Get compilation flags, replacing outfile with target.
- classmethod get_output_file(src, target=None, **kwargs)[source]¶
Determine the appropriate output file that will result when compiling a target.
- Parameters:
src (str) – Make target or source file being compiled that will be used to determine the path to the output file.
target (str, optional) – Target that will be used to create the output file instead of src if provided. Defaults to None and is ignored.
**kwargs – Additional keyword arguments are passed to the parent class’s method.
- Returns:
Full path to file that will be produced.
- Return type:
- is_gnu = False¶
- is_linker = True¶
- languages = ['make']¶
- linker_attributes = {'executable_ext': '', 'tool_suffix_format': ''}¶
- no_separate_linking = True¶
- output_key = ''¶
- platforms = ['MacOS', 'Linux']¶
- classmethod tool_version(**kwargs)[source]¶
Determine the version of this language.
- Parameters:
**kwargs – Keyword arguments are passed to cls.call.
- Returns:
Version of compiler/interpreter for this language.
- Return type:
- toolname = 'make'¶
- class yggdrasil.drivers.MakeModelDriver.MakeModelDriver(*args, **kwargs)[source]¶
Bases:
BuildModelDriver
Class for running make file compiled drivers. Before running the make command, the necessary compiler & linker flags for the interface’s C/C++ library are stored the environment variables CFLAGS and LDFLAGS respectively. These should be used in the make file to correctly compile with the interface’s C/C++ libraries.
- Parameters:
name (str) – Driver name.
args (str, list) – Executable that should be created (make target) and any arguments for the executable.
makefile (str, optional) – Path to make file either absolute, relative to makedir (if provided), or relative to working_dir. Defaults to Makefile.
makedir (str, optional) – Directory where make should be invoked from if it is not the same as the directory containing the makefile. Defaults to directory containing makefile if provided, otherwise working_dir.
**kwargs – Additional keyword arguments are passed to parent class.
- Raises:
RuntimeError – If neither the IPC or ZMQ C libraries are available.
- static before_registration(cls)[source]¶
Operations that should be performed to modify class attributes prior to registration including things like platform dependent properties and checking environment variables for default settings.
- buildfile_base = 'Makefile'¶
- built_where_called = True¶
- cfg = <yggdrasil.config.YggConfigParser object>¶
- compile_model(target=None, **kwargs)[source]¶
Compile model executable(s).
- Parameters:
target (str, optional) – Target to build.
**kwargs – Keyword arguments are passed on to the parent class’s method.
- default_archiver = None¶
- default_archiver_flags = None¶
- default_compiler = 'make'¶
- default_compiler_flags = None¶
- default_linker = 'make'¶
- default_linker_flags = None¶
- classmethod get_buildfile_lock(**kwargs)[source]¶
Get a lock for a buildfile to prevent simultaneous access, creating one as necessary.
- classmethod get_language_for_buildfile(buildfile, target=None)[source]¶
Determine the target language based on the contents of a build file.
- classmethod get_target_language_info(*args, **kwargs)[source]¶
Get a dictionary of information about language compilation tools.
- Parameters:
*args – Arguments are passed to the parent class’s method.
**kwargs – Keyword arguments are passed to the parent class’s method.
- Returns:
Information about language compilers and linkers.
- Return type:
- inverse_type_map = None¶
- language = 'make'¶
- parse_arguments(args, **kwargs)[source]¶
Sort arguments based on their syntax to determine if an argument is a source file, compilation flag, or runtime option/flag that should be passed to the model executable.
- Parameters:
args (list) – List of arguments provided.
**kwargs – Additional keyword arguments are passed to the parent class’s method.
- class yggdrasil.drivers.MakeModelDriver.NMakeCompiler(**kwargs)[source]¶
Bases:
MakeCompiler
- compile_only_flag = None¶
- default_executable = 'nmake'¶
- default_flags = ['/NOLOGO']¶
- default_linker = 'nmake'¶
- flag_options = {'makefile': '/f'}¶
- is_gnu = False¶
- is_linker = True¶
- platforms = ['Windows']¶
- toolname = 'nmake'¶
yggdrasil.drivers.MatlabModelDriver module¶
- class yggdrasil.drivers.MatlabModelDriver.MatlabModelDriver(*args, **kwargs)[source]¶
Bases:
InterpretedModelDriver
Base class for running Matlab models.
- Parameters:
name (str) – Driver name.
args (str or list) – Argument(s) for running the model in matlab. Generally, this should be the full path to a Matlab script.
use_symunit (bool, optional) – If True, input/output variables with units will be represented in Matlab using symunit. Defaults to False.
**kwargs – Additional keyword arguments are passed to parent class’s __init__ method.
- Raises:
RuntimeError – If Matlab is not installed.
Note
Matlab models that call exit will shut down the shared engine.
- after_loop()[source]¶
Actions to perform after run_loop has finished. Mainly checking if there was an error and then handling it.
- static after_registration(cls, **kwargs)[source]¶
Operations that should be performed to modify class attributes after registration. For compiled languages this includes selecting the default compiler. The order of precedence is the config file ‘compiler’ option for the language, followed by the environment variable set by _compiler_env, followed by the existing class attribute.
- base_languages = ['python']¶
- static before_registration(cls)[source]¶
Operations that should be performed to modify class attributes prior to registration including things like platform dependent properties and checking environment variables for default settings.
- cfg = <yggdrasil.config.YggConfigParser object>¶
- check_exits()[source]¶
Check to make sure the program dosn’t contain any exits as exits will shut down the Matlab engine as well as the program.
- Raises:
RuntimeError – If there are any exit calls in the file.
- classmethod comm_atexit(comm)[source]¶
Operations performed on comm at exit including draining receive.
- Parameters:
comm (CommBase) – Communication object.
- comm_linger = False¶
- classmethod configure(cfg, disable_engine=None, hide_matlab_libiomp=None)[source]¶
Add configuration options for this language. This includes locating any required external libraries and setting option defaults.
- Parameters:
cfg (YggConfigParser) – Config class that options should be set for.
disable_engine (bool, optional) – Disable the use of the Python engine for Matlab. If not provided, this argument will be ignored.
hide_matlab_libiomp (bool, optional) – Hide the Matlab version of libiomp by moving it and recording the name of the file. If False, the file will be restored if it exists. If not provided, this argument will be ignored.
- Returns:
- Section, option, description tuples for options that could not
be set.
- Return type:
- classmethod decode_format(format_str)[source]¶
Method for decoding format strings created in this language.
- default_interpreter = 'matlab'¶
- default_interpreter_flags = ['-nodisplay', '-nosplash', '-nodesktop', '-nojvm', '-r']¶
- classmethod executable_command(args, **kwargs)[source]¶
Compose a command for running a program in this language with the provied arguments. If not already present, the interpreter command and interpreter flags are prepended to the provided arguments.
- Parameters:
args (list) – The program that returned command should run and any arguments that should be provided to it.
**kwargs – Additional keyword arguments are ignored.
- Returns:
- Arguments composing the command required to run the program
from the command line using the interpreter for this language.
- Return type:
- function_param = {'and': '&&', 'assign': '{name} = {value};', 'block_end': 'end', 'break': 'break;', 'comment': '%', 'eol': ';', 'error': "error('{error_msg}');", 'expand_mult': '{name} = {value}{{:}};', 'false': 'false', 'first_index': 1, 'for_begin': 'for {iter_var} = {iter_begin}:{iter_end}', 'fprintf': "fprintf('{message}', {variables});", 'function_def_begin': 'function {output_var} = {function_name}({input_var})', 'function_def_regex': 'function *(\\[ *)?(?P<outputs>.*?)(?(1)\\]) *= *{function_name} *\\((?P<inputs>(?:.|\\n)*?)\\)\\n(?:(?P<body>(?:\\s*if(?:.*?\\n?)*?end;?)|(?:\\s*for(?:.*?\\n?)*?end;?)|(?:\\s*parfor(?:.*?\\n?)*?end;?)|(?:\\s*switch(?:.*?\\n?)*?end;?)|(?:\\s*try(?:.*?\\n?)*?end;?)|(?:\\s*while(?:.*?\\n?)*?end;?)|(?:\\s*arguments(?:.*?\\n?)*?end;?)|(?:(?:.*?\\n?)*?))(?:\\s*end;?))?', 'functions_defined_last': True, 'if_begin': 'if ({cond})', 'if_elif': 'elseif ({cond})', 'if_else': 'else', 'indent': ' ', 'index': '{variable}{{{index}}}', 'input': "{channel} = YggInterface('YggInput', '{channel_name}');", 'inputs_def_regex': '\\s*(?P<name>.+?)\\s*(?:(?:,(?: *... *\\n)?)|$)', 'istype': "isa({variable}, '{type}')", 'len': 'length({variable})', 'line_end': ';', 'multiple_outputs': '[{outputs}]', 'not': 'not', 'output': "{channel} = YggInterface('YggOutput', '{channel_name}');", 'outputs_def_regex': '\\s*(?P<name>.+?)\\s*(?:,|$)', 'print': "disp('{message}');", 'print_generic': 'disp({object});', 'python_interface': "{channel} = YggInterface('{python_interface}', '{channel_name}');", 'python_interface_format': "{channel} = YggInterface('{python_interface}', '{channel_name}', '{format_str}');", 'quote': "'", 'recv_function': '{channel}.recv', 'send_function': '{channel}.send', 'true': 'true', 'try_begin': 'try', 'try_except': 'catch {error_var}', 'while_begin': 'while ({cond})'}¶
- classmethod get_matlab_info()[source]¶
Determine the root directory where Matlab is installed and the version that is installed (if Matlab is installed at all). This will fail if Matlab is not installed, cannot be started, or does not operate as expected.
- Returns:
Matlab root directory and Matlab version string.
- Return type:
- Raises:
RuntimeError – If Matlab cannot be started or the root directory or release cannot be determiend.
- classmethod get_testing_options(**kwargs)[source]¶
Method to return a dictionary of testing options for this class.
- Parameters:
**kwargs – Additional keyword arguments are passed to the parent class.
- Returns:
- Dictionary of variables to use for testing. Key/value pairs:
kwargs (dict): Keyword arguments for driver instance. deps (list): Dependencies to install.
- Return type:
- interface_map = {'call': '[flag, {inputs}] = {channel_obj}.call({outputs})', 'client': "YggInterface('YggRpcClient', '{channel_name}')", 'import': '', 'input': "YggInterface('YggInput', '{channel_name}')", 'output': "YggInterface('YggOutput', '{channel_name}')", 'recv': '[flag, {inputs}] = {channel_obj}.recv()', 'send': 'flag = {channel_obj}.send({outputs})', 'server': "YggInterface('YggRpcServer', '{channel_name}')", 'timesync': "YggInterface('YggTimesync', '{channel_name}')"}¶
- inverse_type_map = None¶
- language = 'matlab'¶
- language_ext = ['.m']¶
- parse_arguments(args)[source]¶
Sort model arguments to determine which one is the executable and which ones are arguments.
- Parameters:
args (list) – List of arguments provided.
- path_env_variable = 'MATLABPATH'¶
- recv_converters = {'pandas': 'array'}¶
- classmethod run_code(lines, **kwargs)[source]¶
Run code by first writing it as an executable and then calling the driver.
- Parameters:
lines (list) – Lines of code to be wrapped as an executable.
**kwargs – Additional keyword arguments are passed to the write_executable method.
- classmethod run_executable(args, dont_wrap_error=False, fname_wrapper=None, matlab_engine=None, **kwargs)[source]¶
Run a program using the executable for this language and the provided arguments.
- Parameters:
args (list) – The program that should be run and any arguments that should be provided to it.
dont_wrap_error (bool, optional) – If False, the executable will be wrapped in a try/catch block to prevent errors from stopping Matlab shutdown. If True, the command will be executed as is with the Matlab interpreter. Defaults to False.
fname_wrapper (str, optional) – File where wrapper should be saved. If not provided, one is created. Defaults to None.
matlab_engine (MatlabEngine, optional) – Matlab engine that should be used to run the command. If not provided, the Matlab interpreter is used instead. Defaults to None.
**kwargs – Additional keyword arguments are passed to cls.executable_command and tools.popen_nobuffer.
- Returns:
Output to stdout from the run command.
- Return type:
- Raises:
RuntimeError – If the language is not installed.
RuntimeError – If there is an error when running the command.
- send_converters = {'pandas': <function consolidate_array>, 'table': <function consolidate_array>}¶
- set_env()[source]¶
Get environment variables that should be set for the model process.
- Returns:
Environment variables for the model process.
- Return type:
- type_map = {'1darray': 'mat', 'array': 'cell', 'boolean': 'logical', 'bytes': 'char (utf-8)', 'complex': 'complex', 'float': 'single, double', 'int': 'intX', 'ndarray': 'mat', 'null': 'NaN', 'obj': 'containers.Map', 'object': 'containers.Map', 'ply': 'containers.Map', 'schema': 'containers.Map', 'string': 'char', 'uint': 'uintX', 'unicode': 'char'}¶
- version_flags = ["fprintf('R%s', version('-release')); exit();"]¶
- classmethod write_error_wrapper(fname, try_lines, env=None, matlab_engine=None)[source]¶
Write a wrapper for the model that encloses it in a try except so that the error can be propagated appropriately.
- Parameters:
fname (str) – File where the wrapper should be written.
try_lines (list) – List of lines to go in the try block.
model_file (str) – Path to model that should be wrapped.
env (dict, optional) – Dictionary of environment variables that should be set before calling the model. Defaults to None and is ignored.
matlab_engine (MatlabEngine, optional) – Matlab engine that will be used to call the wrapper. If not provided, it is assumed the error will be called using the Matlab interpreter on the command line. Defautls to None.
Raises:
- classmethod write_finalize_iiter(var, **kwargs)[source]¶
Get the lines necessary to initialize an array for iteration output.
- Parameters:
- Returns:
The lines initializing the variable.
- Return type:
- classmethod write_finalize_oiter(var)[source]¶
Get the lines necessary to finalize an array after iteration.
- classmethod write_initialize_oiter(var, value=None, **kwargs)[source]¶
Get the lines necessary to initialize an array for iteration output.
- Parameters:
- Returns:
The lines initializing the variable.
- Return type:
- zero_based = False¶
- class yggdrasil.drivers.MatlabModelDriver.MatlabProcess(*args, **kwargs)[source]¶
Bases:
YggClass
Add features to mimic subprocess.Popen while running Matlab function asynchronously.
- Parameters:
target (func) – Matlab function that should be called.
args (list, tuple) – Arguments that should be passed to target.
kwargs (dict, optional) – Keyword arguments that should be passed to target. Defaults to empty dict.
name (str, optional) – A name for the process. Generated if not provided.
matlab_engine (MatlabEngine, optional) – MatlabEngine that should be used to get errors. Defaults to None and errors will not be recovered unless passed through stdout and stderr before shutdown.
- stdout¶
File like string buffer that stdout from target will be written to.
- Type:
StringIO
- stderr¶
File like string buffer that stderr from target will be written to.
- Type:
StringIO
- target¶
Matlab function that should be called.
- Type:
func
- future¶
Future result from async function. This will be None until start is called.
- Type:
MatlabFutureResult
- matlab_engine¶
MatlabEngine that should be used to get errors.
- Type:
MatlabEngine
- Raises:
RuntimeError – If Matlab is not installed.
- yggdrasil.drivers.MatlabModelDriver.connect_matlab_engine(matlab_session, first_connect=False)[source]¶
Connect to Matlab engine.
- Parameters:
- Returns:
Matlab engine that was connected.
- Return type:
MatlabEngine
- yggdrasil.drivers.MatlabModelDriver.install_matlab_engine()[source]¶
Install the MATLAB engine API for Python.
- yggdrasil.drivers.MatlabModelDriver.is_matlab_running()[source]¶
Determine if there is a Matlab engine running.
- Returns:
True if there is a Matlab engine running, False otherwise.
- Return type:
- yggdrasil.drivers.MatlabModelDriver.locate_matlab_engine_processes()[source]¶
Get all of the active matlab sharedEngine processes.
- Returns:
Active matlab sharedEngine processes.
- Return type:
- yggdrasil.drivers.MatlabModelDriver.locate_matlabroot()[source]¶
Find directory that servers as matlab root.
- Returns:
Full path to matlabroot directory.
- Return type:
- yggdrasil.drivers.MatlabModelDriver.start_matlab_engine(skip_connect=False, timeout=None)[source]¶
Start a Matlab shared engine session inside a detached screen session.
- Parameters:
- Returns:
- Information on the started session including the name of the
screen session running matlab, the created engine object, the name of the matlab session, and the matlab engine process.
- Return type:
- Raises:
RuntimeError – If Matlab is not installed.
- yggdrasil.drivers.MatlabModelDriver.stop_matlab_engine(screen_session, matlab_engine, matlab_session, matlab_process, keep_engine=False)[source]¶
Stop a Matlab shared engine session running inside a detached screen session.
- Parameters:
screen_session (str) – Name of the screen session that the shared Matlab session was started in.
matlab_engine (MatlabEngine) – Matlab engine that should be stopped.
matlab_session (str) – Name of Matlab session that the Matlab engine is connected to.
matlab_process (psutil.Process) – Process running the Matlab shared engine.
keep_engine (bool, optional) – If True, the references to the engine will be removed so it is not deleted. Defaults to False.
- Raises:
RuntimeError – If Matlab is not installed.
yggdrasil.drivers.ModelDriver module¶
- class yggdrasil.drivers.ModelDriver.ModelDriver(*args, **kwargs)[source]¶
Bases:
Driver
Base class for Model drivers and for running executable based models.
- Parameters:
name (str) – Unique name used to identify the model. This will be used to report errors associated with the model.
args (str or list) – The path to the file containing the model program that will be run by the driver for the model’s language and/or a list of arguments that should be passed as input to the model program or language executable (e.g. source code or configuration file for a domain specific language).
products (list, optional) – Paths to files created by the model that should be cleaned up when the model exits. Entries can be absolute paths or paths relative to the working directory. Defaults to [].
function (str, optional) – If provided, an integrated model is created by wrapping the function named here. The function must be located within the file specified by the source file listed in the first argument. If not provided, the model must contain it’s own calls to the yggdrasil interface.
iter_function_over (array, optional) – Variable(s) that should be received or sent as an array, but iterated over. Defaults to an empty array and is ignored.
source_products (list, optional) – Files created by running the model that are source files. These files will be removed without checking their extension so users should avoid adding files to this list unless they are sure they should be deleted. Defaults to [].
is_server (bool, dict, optional) – If True, the model is assumed to be a server for one or more client models and an instance of
yggdrasil.drivers.ServerDriver
is started. The corresponding channel that should be passed to the yggdrasil API will be the name of the model. If is_server is a dictionary, it should contain an ‘input’ key and an ‘output’ key. These are required to be the names of existing input and output channels in the model that will be co-opted by the server. (Note: This requires that the co-opted output channel’s send method is called once for each time the co-opted input channel’s recv method is called. If used with the function parameter, is_server must be a dictionary. Defaults to False.client_of (str, list, optional) – The names of one or more models that this model will call as a server. If there are more than one, this should be specified as a sequence collection (list). The corresponding channel(s) that should be passed to the yggdrasil API will be the name of the server model joined with the name of the client model with an underscore <server_model>_<client_model>. There will be one channel created for each server the model is a client of. Defaults to empty list. Use of client_of with function is not currently supported.
timesync (bool, str, optional) – If set, the model is assumed to call a send then receive of the state at each timestep for syncronization with other models that are also integrating in time. If a string is provided, it is assumed to be the name of the server that will handle timestep synchronization. If a boolean is provided, the name of the server will be assumed to be ‘timestep’. Defaults to False.
overwrite (bool, optional) – If True, any existing model products (compilation products, wrapper scripts, etc.) are removed prior to the run. If False, the products are not removed. Defaults to True. Setting this to False can improve the performance, particularly for models that take a long time to compile, but this should only be done once the model has been fully debugged to ensure that each run is tested on a clean copy of the model. The value of this keyword also determines whether or not products are removed after a run.
preserve_cache (bool, optional) – If True model products will be kept following the run, otherwise all products will be cleaned up. Defaults to False. This keyword is superceeded by overwrite.
with_strace (bool, optional) – If True, the command is run with strace (on Linux) or dtrace (on MacOS). Defaults to False.
strace_flags (list, optional) – Flags to pass to strace (or dtrace). Defaults to [].
with_valgrind (bool, optional) – If True, the command is run with valgrind. Defaults to False.
valgrind_flags (list, optional) – Flags to pass to valgrind. Defaults to [].
model_index (int, optional) – Index of model in list of models being run. Defaults to 0.
copy_index (int, optional) – Index of model in set of copies. Defaults to -1 indicating there is only one copy of the model.
outputs_in_inputs (bool, optional) – If True, outputs from wrapped model functions are passed by pointer as inputs for modification and the return value will be a flag. If False, outputs are limited to return values. Defaults to the value of the class attribute outputs_in_inputs.
logging_level (str, optional) – The level of logging messages that should be displayed by the model. Defaults to the logging level as determined by the configuration file and environment variables.
allow_threading (bool, optional) – If True, comm connections will be set up so that the model-side comms can be used by more than one thread. Defaults to False.
copies (int, optional) – The number of copies of the model that should be created. Defaults to 1.
repository_url (str, optional) – URL for the git repository containing the model source code. If provided, relative paths in the model YAML definition will be considered relative to the repository root directory.
repository_commit (str, optional) – Commit that should be checked out in the model repository specified by repository_url. If not provided, the most recent commit on the default branch will be used.
description (str, optional) – Description of the model. This parameter is only used in the model repository or when providing the model as a service.
contact_email (str, optional) – Email address that should be used to contact the maintainer of the model. This parameter is only used in the model repository.
validation_command (str, optional) – Path to a validation command that can be used to verify that the model ran as expected. A non-zero return code is taken to indicate failure.
dependencies (list, optional) – A list of packages required by the model that are written in the same language as the model. If the package requires dependencies outside the language of the model. use the additional_dependencies parameter to provide them. If you need a version of the package from a specific package manager, a mapping with ‘package’ and ‘package_manager’ fields can be provided instead of just the name of the package.
additional_dependencies (dict, optional) – A mapping between languages and lists of packages in those languages that are required by the model.
with_debugger (str, optional) – Debugger tool that should be used to run models. This string should include the tool executable and any flags that should be passed to it.
**kwargs – Additional keyword arguments are passed to parent class.
- Class Attributes:
- language (str): Primary name for the programming language that this
compiler should be used for. [REQUIRED]
- language_aliases (list): Additional/alternative names that the language
may be known by.
- language_ext (list): Extensions for programs written in the target
language. [REQUIRED]
- base_languages (list): Other programming languages that this driver
and the interpreter for the target language are dependent on (e.g. Matlab models require Python).
- executable_type (str): ‘compiler’ or ‘interpreter’ to indicate the type
of the executable for the language. [AUTOMATED]
- interface_library (list): Name of the library containing the yggdrasil
interface for the target language. [REQUIRED]
- interface_directories (list): Directories containing code in the
interface library for the target language.
- interface_dependencies (list): List of names of libraries that are
required to use the interface on the current platform. This dosn’t include libraries required by specific communication types which are described by supported_comm_options.
- supported_comms (list): Name of comms supported in the target language.
[REQUIRED]
- supported_comm_options (dict): Options for the supported comms like the
platforms they are available on and the external libraries required to use them. [REQUIRED]
- external_libraries (dict): Information on external libraries required
for running models in the target language using yggdrasil.
- internal_libraries (dict): Information on internal libraries required
for running models in the target language using yggdrasil.
- type_map (dict): Mapping of yggdrasil extended JSON types to
datatypes in the target programming language. [REQUIRED]
- function_param (dict): Options specifying how different operations
would be encoded in the target language (e.g. if statements, for loops, while loops). [REQUIRED]
- version_flags (list): Flags that should be called with the language
executable to determine the version of the compiler/interpreter. Defaults to [’–version’].
- outputs_in_inputs (bool): If True, outputs are passed by pointer as
inputs for modification and the return value should be a flag. Defaults to False.
- include_arg_count (bool): If True, the number of arguments passed
to send/recv calls is prepended to the arguments to the function. Defaults to False.
- include_channel_obj (bool): If True, the channel object is passed as
input to the send/recv calls (after the argument count if it is also present due to include_arg_count being True). Defaults to False.
is_typed (bool): True if the language is typed, False otherwise. brackets (tuple): A pair of opening and clossing characters that
are used by the language to mark blocks. Set to None and ignored by default.
- no_executable (bool): True if there is not an executable associated
with the language driver. Defaults to False.
- comms_implicit (bool): True if the comms installed for this driver
are not explicitly defined (depend on input parameters). Defaults to False.
- model_src¶
Full path to the model source code. For interpreted languages, this will be the same as model_file.
- Type:
- model_function_info¶
Parameters recovered by parsing the provided model function definition.
- Type:
- overwrite¶
If True, any existing compilation products will be overwritten by compilation and cleaned up following the run. Otherwise, existing products will be used and will remain after the run.
- Type:
- products¶
Files created by running the model. This includes compilation products such as executables and/or object files.
- Type:
- source_products¶
Files created by running the model that are source files. These files will be removed without checking their extension so users should avoid adding files to this list unless they are sure they should be deleted.
- Type:
- process¶
Process used to run the model.
- Type:
- iter_function_over¶
Variable(s) that should be received or sent as an array, but iterated over.
- Type:
array
- is_server¶
If True, the model is assumed to be a server and an instance of
yggdrasil.drivers.ServerDriver
is started. If a dict, the input/output channels with the specified names in the dict will be replaced with a server.
- timesync¶
If set, the name of the server performing timestep synchronization for the model.
- Type:
- modified_files¶
List of pairs of originals and copies of files that should be restored during cleanup.
- Type:
- allow_threading¶
If True, comm connections will be set up so that the model-side comms can be used by more than one thread.
- Type:
- repository_url¶
URL for the git repository containing the model source code. If provided, relative paths in the model YAML definition will be considered relative to the repository root directory.
- Type:
- repository_commit¶
Commit that should be checked out in the model repository specified by repository_url.
- Type:
- description¶
Description of the model. This parameter is only used in the model repository or when providing the model as a service.
- Type:
- contact_email¶
Email address that should be used to contact the maintainer of the model. This parameter is only used in the model repository.
- Type:
- validation_command¶
Path to a validation command that can be used to verify that the model ran as expected. A non-zero return code is taken to indicate failure.
- Type:
- dependencies¶
A list of packages required by the model that are written in the same language as the model. If the package requires dependencies outside the language of the model, use the additional_dependencies parameter to provide them. If you need a version of the package from a specific package manager, a mapping
with ‘package’ and ‘package_manager’ fields can be provided instead of just the name of the package.
- Type:
- additional_dependencies¶
A mapping between languages and lists of packages in those languages that are required by the model.
- Type:
- Raises:
RuntimeError – If both with_strace and with_valgrind are True.
- after_loop()[source]¶
Actions to perform after run_loop has finished. Mainly checking if there was an error and then handling it.
- static after_registration(cls, cfg=None, second_pass=False)[source]¶
Operations that should be performed to modify class attributes after registration. For compiled languages this includes selecting the default compiler. The order of precedence is the config file ‘compiler’ option for the language, followed by the environment variable set by _compiler_env, followed by the existing class attribute.
- Parameters:
cfg (YggConfigParser, optional) – Config class that should be used to set options for the driver. Defaults to None and yggdrasil.config.ygg_cfg is used.
second_pass (bool, optional) – If True, the class as already been registered. Defaults to False.
- classmethod are_base_languages_installed(missing=None)[source]¶
Determine if the base languages are installed.
- classmethod are_dependencies_installed()[source]¶
Determine if the dependencies are installed for the interface (not including dependencies needed by a particular communication type).
- Returns:
True if the dependencies are installed. False otherwise.
- Return type:
- base_languages = []¶
- static before_registration(cls)[source]¶
Operations that should be performed to modify class attributes prior to registration including things like platform dependent properties and checking environment variables for default settings.
- before_start(no_queue_thread=False, **kwargs)[source]¶
Actions to perform before the run starts.
- Parameters:
no_queue_thread (bool, optional) – If True, the queue_thread is not created/started. Defaults to False.
**kwargs – Keyword arguments are pased to run_model.
- brackets = None¶
- classmethod check_flag_var(info, outputs_in_inputs=None)[source]¶
Check if the flag variable should be treated as an output.
- comms_implicit = False¶
- classmethod configuration_steps()[source]¶
Get a list of configuration steps with tuples of flags and boolean values.
- Returns:
- Pairs of descriptions and states for
different steps in the configuration all steps must be True for the language to be configured.
- Return type:
OrderedDict
- classmethod configure(cfg, **kwargs)[source]¶
Add configuration options for this language.
- Parameters:
cfg (CisConfigParser) – Config class that options should be set for.
- Returns:
- Section, option, description tuples for options that could not
be set.
- Return type:
- classmethod configure_executable_type(cfg)[source]¶
Add configuration options specific in the executable type before the libraries are configured.
- Parameters:
cfg (YggConfigParser) – Config class that options should be set for.
- Returns:
- Section, option, description tuples for options that could not
be set.
- Return type:
- classmethod configure_libraries(cfg)[source]¶
Add configuration options for external libraries in this language.
- Parameters:
cfg (YggConfigParser) – Config class that options should be set for.
- Returns:
- Section, option, description tuples for options that could not
be set.
- Return type:
- dont_declare_channel = False¶
- classmethod executable_command(args, unused_kwargs=None, **kwargs)[source]¶
Compose a command for running a program using the exectuable for this language (compiler/interpreter) with the provided arguments.
- Parameters:
- Returns:
- Arguments composing the command required to run the program
from the command line using the executable for this language.
- Return type:
- executable_type = None¶
- classmethod expand_server_io(inputs, outputs, client_comms=[])[source]¶
Update inputs/outputs w/ information about server that will be using them.
- external_libraries = {}¶
- classmethod finalize_function_io(direction, x)[source]¶
Finalize info for an input/output channel following function parsing.
- static finalize_registration(cls)[source]¶
Operations that should be performed after a class has been fully initialized and registered.
- classmethod format_function_param(key, default=None, replacement=None, ignore_method=False, **kwargs)[source]¶
Return the formatted version of the specified key.
- Parameters:
key (str) – Key in cls.function_param mapping that should be formatted.
default (str, optional) – Format that should be returned if key is not in cls.function_param. Defaults to None.
replacement (str, optional) – Format that should be used instead of the one in cls.function_param. Defaults to None.
**kwargs – Additional keyword arguments are used in formatting the request function parameter.
- Returns:
Formatted string.
- Return type:
- Raises:
NotImplementedError – If key is not in cls.function_param and default is not set.
- full_language = True¶
- function_param = None¶
- classmethod get_inverse_type_map()[source]¶
Get the inverse type map.
- Returns:
Mapping from native type to JSON type.
- Return type:
- get_io_env(input_drivers=None, output_drivers=None)[source]¶
Get environment variables set by the input/output drivers.
- classmethod get_language_ext()[source]¶
Return the language extension, including from the base classes.
- classmethod get_language_for_source(fname, languages=None, early_exit=False, **kwargs)[source]¶
Determine the language that can be used with the provided source file(s). If more than one language applies to a set of multiple files, the language that applies to the most files is returned.
- Parameters:
fname (str, list) – The full path to one or more files. If more than one
languages (list, optional) – The list of languages that are acceptable. Defaults to None and any language will be acceptable.
early_exit (bool, optional) – If True, the first language identified will be returned if fname is a list of files. Defaults to False.
**kwargs – Additional keyword arguments are passed to recursive calls.
- Returns:
The language that can operate on the specified file.
- Return type:
- classmethod get_testing_options(**kwargs)[source]¶
Method to return a dictionary of testing options for this class.
- Returns:
- Dictionary of variables to use for testing. Key/value pairs:
kwargs (dict): Keyword arguments for driver instance. deps (list): Dependencies to install.
- Return type:
- classmethod identify_source_files(args=None, working_dir=None, **kwargs)[source]¶
Determine the source file based on model arguments.
- include_arg_count = False¶
- include_channel_obj = False¶
- classmethod input2output(var)[source]¶
Perform conversion necessary to turn a variable extracted from a function definition from an input to an output.
- classmethod install_dependency(package=None, package_manager=None, arguments=None, command=None, always_yes=False, command_kwargs=None)[source]¶
Install a dependency.
- Parameters:
package (str) – Name of the package that should be installed. If the package manager supports it, this can include version requirements.
package_manager (str, optional) – Package manager that should be used to install the package.
arguments (str, optional) – Additional arguments that should be passed to the package manager.
command (list, optional) – Command that should be used to install the package.
always_yes (bool, optional) – If True, the package manager will not ask users for input during installation. Defaults to False.
command_kwargs (dict, optional) – Keyword arguments that should be passed to the subprocess call for the installation.
- classmethod install_model_dependencies(dependencies, always_yes=False)[source]¶
Install any dependencies required by the model.
- interface_dependencies = []¶
- interface_directories = []¶
- interface_inside_exec = False¶
- interface_library = None¶
- internal_libraries = {}¶
- inverse_type_map = None¶
- classmethod is_comm_installed(commtype=None, skip_config=False, **kwargs)[source]¶
Determine if a comm is installed for the associated programming language.
- Parameters:
commtype (str, optional) – If provided, this method will only test for installation of the specified communication type. Defaults to None and will check for any installed comm.
skip_config (bool, optional) – If True, the config list of comms installed for this language will not be used to determine if the comm is installed and the class attribute supported_comm_options will be processed. Defaults to False and config options are used in order to improve performance after initial configuration.
platforms (list, optional) – Platforms on which the comm can be installed. Defaults to None and is ignored unless there is a value for the commtype in supported_comm_options. This keyword argument is ignored if skip_config is False.
libraries (list, optional) – External libraries that are required by the specified commtype. Defaults to None and is ignored unless there is a value for the commtype in supported_comm_options. This keyword argument is ignored if skip_config is False.
**kwargs – Additional keyword arguments are passed to either is_comm_installed for the base languages, supported languages, or is_library_installed as appropriate.
- Returns:
True if a comm is installed for this language.
- Return type:
- classmethod is_configured()[source]¶
Determine if the appropriate configuration has been performed (e.g. installation of supporting libraries etc.)
- Returns:
True if the language has been configured.
- Return type:
- is_dsl = False¶
- classmethod is_installed()[source]¶
Determine if this model driver is installed on the current machine.
- Returns:
- Truth of if this model driver can be run on the current
machine.
- Return type:
- classmethod is_interface_installed()[source]¶
Determine if the interface library for the associated programming language is installed.
- Returns:
True if the interface library is installed.
- Return type:
- classmethod is_language_installed()[source]¶
Determine if the interpreter/compiler for the associated programming language is installed.
- Returns:
True if the language interpreter/compiler is installed.
- Return type:
- classmethod is_source_file(fname)[source]¶
Determine if the provided file name points to a source files for the associated programming language by checking the extension.
- is_typed = False¶
- language = None¶
- language_aliases = []¶
- classmethod language_executable(**kwargs)[source]¶
Command required to compile/run a model written in this language from the command line.
- Returns:
- Name of (or path to) compiler/interpreter executable required
to run the compiler/interpreter from the command line.
- Return type:
- language_ext = None¶
- classmethod language_version(version_flags=None, **kwargs)[source]¶
Determine the version of this language.
- Parameters:
**kwargs – Keyword arguments are passed to cls.run_executable.
- Returns:
Version of compiler/interpreter for this language.
- Return type:
- max_line_width = None¶
- model_command()[source]¶
Return the command that should be used to run the model.
- Returns:
- Any commands/arguments needed to run the model from the
command line.
- Return type:
- property model_process_complete¶
Has the process finished or not. Returns True if the process has not started.
- Type:
- property model_process_returncode¶
Return code for the model process where non-zero values indicate that there was an error.
- Type:
- no_executable = False¶
- classmethod output2input(var, in_definition=True)[source]¶
Perform conversion necessary to turn an output variable into an corresponding input that can be used to format a function definition.
- Parameters:
- Returns:
Updated variable definition.
- Return type:
- outputs_in_inputs = False¶
- parse_arguments(args, default_model_dir=None)[source]¶
Sort model arguments to determine which one is the executable and which ones are arguments.
- classmethod parse_function_definition(model_file, model_function, contents=None, match=None, expected_outputs=[], outputs_in_inputs=None)[source]¶
Get information about the inputs & outputs to a model from its defintition if possible.
- Parameters:
model_file (str) – Full path to the file containing the model function’s declaration.
model_function (str) – Name of the model function.
contents (str, optional) – String containing the function definition. If not provided, the function definition is read from model_file.
match (re.Match, optional) – Match object for the function regex. If not provided, a search is performed using function_def_regex.
expected_outputs (list, optional) – List of names or variable information dictionaries for outputs that are expected to be extracted from the function’s definition. This variable is only used if outputs_in_inputs is True and outputs are not extracted from the function’s defintion using the regex for this language. Defaults to [].
outputs_in_inputs (bool, optional) – If True, the outputs are presented in the function definition as inputs. Defaults to False.
- Returns:
Parameters extracted from the function definitions.
- Return type:
- classmethod parse_var_definition(io, value, outputs_in_inputs=None)[source]¶
Extract information about input/output variables from a string definition.
- Parameters:
- Returns:
- List of information about the variables contained in
the provided string.
- Return type:
- Raises:
AssertionError – If io is not ‘inputs’ or ‘outputs’.
NotImplementedError – If the def_regex for the specified io is not defined.
- classmethod prepare_input_variables(vars_list, in_definition=False, for_yggdrasil=False)[source]¶
Concatenate a set of input variables such that it can be passed as a single string to the function_call parameter.
- Parameters:
vars_list (list) – List of variable dictionaries containing info (e.g. names) that should be used to prepare a string representing input to a function call.
in_definition (bool, optional) – If True, the returned sequence will be of the format required for specifying input variables in a function definition. Defaults to False.
for_yggdrasil (bool, optional) – If True, the variables will be prepared in the formated expected by calls to yggdarsil send/recv methods. Defaults to False.
- Returns:
Concatentated variables list.
- Return type:
- classmethod prepare_output_variables(vars_list, in_definition=False, in_inputs=False, for_yggdrasil=False)[source]¶
Concatenate a set of output variables such that it can be passed as a single string to the function_call parameter.
- Parameters:
vars_list (list) – List of variable dictionaries containing info (e.g. names) that should be used to prepare a string representing output from a function call.
in_definition (bool, optional) – If True, the returned sequence will be of the format required for specifying output variables in a function definition. Defaults to False.
in_inputs (bool, optional) – If True, the output variables should be formated to be included as input variables. Defaults to False.
for_yggdrasil (bool, optional) – If True, the variables will be prepared in the formated expected by calls to yggdarsil send/recv methods. Defaults to False.
- Returns:
Concatentated variables list.
- Return type:
- classmethod prepare_variables(vars_list, in_definition=False, for_yggdrasil=False)[source]¶
Concatenate a set of input variables such that it can be passed as a single string to the function_call parameter.
- Parameters:
vars_list (list) – List of variable dictionaries containing info (e.g. names) that should be used to prepare a string representing input/output to/from a function call.
in_definition (bool, optional) – If True, the returned sequence will be of the format required for specifying variables in a function definition. Defaults to False.
for_yggdrasil (bool, optional) – If True, the variables will be prepared in the formated expected by calls to yggdarsil send/recv methods. Defaults to False.
- Returns:
Concatentated variables list.
- Return type:
- classmethod preparse_function(yml)[source]¶
Extract information about inputs and outputs based on the function being wrapped.
- python_interface = {'array_input': 'YggArrayInput', 'array_output': 'YggArrayOutput', 'pandas_input': 'YggPandasInput', 'pandas_output': 'YggPandasOutput', 'table_input': 'YggAsciiTableInput', 'table_output': 'YggAsciiTableOutput'}¶
- classmethod run_code(lines, process_kwargs={}, **kwargs)[source]¶
Run code by first writing it as an executable and then calling the driver.
- classmethod run_executable(args, return_process=False, debug_flags=None, **kwargs)[source]¶
Run a program using the executable for this language and the provided arguments.
- Parameters:
args (list) – The program that should be run and any arguments that should be provided to it.
return_process (bool, optional) – If True, the process class is returned without checking the process output. If False, communicate is called on the process and the output is parsed for errors. Defaults to False.
debug_flags (list, optional) – Debug executable and flags that should be prepended to the executable command. Defaults to None and is ignored.
**kwargs – Additional keyword arguments are passed to cls.executable_command and tools.popen_nobuffer.
- Returns:
- Output to stdout from the run command if return_process is
False, the process if return_process is True.
- Return type:
- Raises:
RuntimeError – If the language is not installed.
RuntimeError – If there is an error when running the command.
- run_model(command=None, return_process=True, **kwargs)[source]¶
Run the model. Unless overridden, the model will be run using run_executable.
- Parameters:
command (list, optional) – Command to run. Defaults to None and is created by the model_command method.
return_process (bool, optional) – If True, the process running the model is returned. If False, the process will block until the model finishes running. Defaults to True.
**kwargs – Keyword arguments are passed to run_executable.
- set_env(existing=None, **kwargs)[source]¶
Get environment variables that should be set for the model process.
- classmethod set_env_class(existing=None, **kwargs)[source]¶
Set environment variables that are instance independent.
- classmethod split_line(line, length=None, force_split=False)[source]¶
Split a line as close to (or before) a given character as possible.
- Parameters:
- Returns:
Set of lines resulting from spliting the provided line.
- Return type:
- stop_mpi_partner(msg=None, dest=0, tag=None)[source]¶
Send a message to stop the MPI partner model on the main process.
- supported_comm_options = {}¶
- supported_comms = []¶
- type_map = None¶
- types_in_funcdef = True¶
- classmethod update_io_from_function(model_file, model_function, inputs=[], outputs=[], contents=None, outputs_in_inputs=None, iter_function_over=[])[source]¶
Update inputs/outputs from the function definition.
- Parameters:
model_file (str) – Full path to the file containing the model function’s declaration.
model_function (str) – Name of the model function.
inputs (list, optional) – List of model inputs including types. Defaults to [].
outputs (list, optional) – List of model outputs including types. Defaults to [].
contents (str, optional) – Contents of file to parse rather than re-reading the file. Defaults to None and is ignored.
outputs_in_inputs (bool, optional) – If True, the outputs are presented in the function definition as inputs. Defaults to False.
iter_function_over (array, optional) – Variable(s) that should be received or sent as an array, but iterated over. Defaults to an empty array and is ignored.
- Returns:
- Flag variable used by the model. If None, the
model does not use a flag variable.
- Return type:
dict, None
- version_flags = ['--version']¶
- wait_process(timeout=None, key=None, key_suffix=None)[source]¶
Wait for some amount of time for the process to finish.
- Parameters:
- Returns:
True if the process completed. False otherwise.
- Return type:
- classmethod write_assign_to_output(dst_var, src_var, copy=False, outputs_in_inputs=False, **kwargs)[source]¶
Write lines assigning a value to an output variable.
- Parameters:
dst_var (str, dict) – Name or information dictionary for variable being assigned to.
src_var (str, dict) – Name or information dictionary for value being assigned to dst_var.
copy (bool, optional) – If True, the assigned value is copied during assignment. Defaults to False.
outputs_in_inputs (bool, optional) – If True, outputs are passed as input parameters. In some languages, this means that a pointer or reference is passed (e.g. C) and so the assignment should be to the memory indicated rather than the variable. Defaults to False.
- Returns:
Lines achieving assignment.
- Return type:
- classmethod write_channel_def(key, datatype=None, **kwargs)[source]¶
Write an channel definition.
- Parameters:
- Returns:
Lines required to declare and define an output channel.
- Return type:
- classmethod write_declaration(var, value=None, requires_freeing=None, definitions=None, is_argument=False)[source]¶
Return the lines required to declare a variable with a certain type.
- Parameters:
var (dict, str) – Name or information dictionary for the variable being declared.
value (str, optional) – Value that should be assigned to the variable after it is declared.
requires_freeing (list, optional) – Existing list that variables requiring freeing should be appended to. Defaults to None and is ignored.
definitions (list, optional) – Existing list that variable definitions should be added to. Defaults to None if not provided and definitions will be included in the returned lines.
dont_define (bool, optional) – If True, the variable will not be defined. Defaults to False.
is_argument (bool, optional) – If True, the variable being declared is an input argument. Defaults to False.
- Returns:
The lines declaring the variable.
- Return type:
- classmethod write_executable(lines, prefix=None, suffix=None, function_definitions=None, imports=None, model_name=None)[source]¶
Return the lines required to complete a program that will run the provided lines.
- Parameters:
lines (list) – Lines of code to be wrapped as an executable.
prefix (list, optional) – Lines of code that should proceed the wrapped code. Defaults to None and is ignored. (e.g. C/C++ include statements).
suffix (list, optional) – Lines of code that should follow the wrapped code. Defaults to None and is ignored.
function_definitions (list, optional) – Lines of code defining functions that will beused by the code contained in lines. Defaults to None and is ignored.
imports (list, optional) – Kwargs for packages that should be imported for use by the executable. Defaults to None and is ignored.
model_name (str, optional) – Name given to the model. Defaults to None.
- Returns:
- Lines of code wrapping the provided lines with the
necessary code to run it as an executable (e.g. C/C++’s main).
- Return type:
lines
- classmethod write_executable_import(model_name=None, **kwargs)[source]¶
Add import statements to executable lines.
- Parameters:
**kwargs – Keyword arguments for import statement.
- Returns:
Lines required to complete the import.
- Return type:
- classmethod write_expand_single_element(output_var, add_cond=False)[source]¶
Write lines allowing extraction of the only element from a single element array as a stand-alone variable if the variable is an array and only has one element.
- Parameters:
- Returns:
- Lines added the conditional expansion of single element
arrays.
- Return type:
- classmethod write_finalize_iiter(var)[source]¶
Get the lines necessary to finalize an input array for iteration.
- classmethod write_finalize_oiter(var, value=None, requires_freeing=None)[source]¶
Get the lines necessary to finalize an array after iteration.
- Parameters:
- Returns:
The lines finalizing the variable.
- Return type:
- classmethod write_for_loop(iter_var, iter_begin, iter_end, loop_contents)[source]¶
Return the lines required to complete a for loop.
- classmethod write_free(var, **kwargs)[source]¶
Return the lines required to free a variable with a certain type.
- classmethod write_function_call(function_name, inputs=[], outputs=[], include_arg_count=False, outputs_in_inputs=False, **kwargs)[source]¶
Write a function call.
- Parameters:
function_name (str) – Name of the function being called.
inputs (list, optional) – List of inputs to the function. Defaults to [].
outputs (list, optional) – List of outputs from the function. Defaults to [].
include_arg_count (bool, optional) – If True, the count of input arguments is included as the first argument. Defaults to False.
outputs_in_inputs (bool, optional) – If True, the outputs are presented in the function definition as inputs. Defaults to False.
**kwargs – Additional keyword arguments are passed to cls.format_function_param.
- Returns:
Lines completing the function call.
- Return type:
- classmethod write_function_def(function_name, inputs=[], outputs=[], input_var=None, output_var=None, function_contents=[], outputs_in_inputs=False, opening_msg=None, closing_msg=None, print_inputs=False, print_outputs=False, skip_interface=False, function_keys=None, verbose=False, **kwargs)[source]¶
Write a function definition.
- Parameters:
function_name (str) – Name fo the function being defined.
inputs (list, optional) – List of inputs to the function. Defaults to []. Ignored if input_var provided.
outputs (list, optional) – List of outputs from the function. Defaults to []. If not provided, no return call is added to the function body. Ignored if output_var provided.
input_var (str, optional) – Full string specifying input in the function definition. If not provided, this will be created based on the contents of the inputs variable.
output_var (str, optional) – Full string specifying output in the function definition. If not provided, this will be created based on the contents of the outputs variable.
function_contents (list, optional) – List of lines comprising the body of the function. Defaults to [].
outputs_in_inputs (bool, optional) – If True, the outputs are presented in the function definition as inputs. Defaults to False.
opening_msg (str, optional) – String that should be printed before the function contents (and inputs if print_inputs is True). Defaults to None and is ignored.
closing_msg (str, optional) – String that should be printed after the function contents (and outputs if print_outputs is True). Defaults to None and is ignored.
print_inputs (bool, optional) – If True, the input variables will be printed before the function contents. Defaults to False.
print_outputs (bool, optional) – If True, the output variables will be printed after the function contents. Defaults to False.
skip_interface (bool, optional) – If True, the line including the interface will be skipped. Defaults to False.
function_keys (tuple, optional) – 2 element tuple that specifies the keys for the function_param entries that should be used to begin & end a function definition. Defaults to (‘function_def_begin’, function_def_end’).
verbose (bool, optional) – If True, the contents of the created file are displayed. Defaults to False.
**kwargs – Additional keyword arguments are passed to cls.format_function_param.
- Returns:
Lines completing the function call.
- Return type:
- Raises:
NotImplementedError – If the function_param attribute for the class is not defined.
- classmethod write_if_block(cond, block_contents, else_block_contents=False)[source]¶
Return the lines required to complete a conditional block.
- Parameters:
cond (str) – Conditional that should determine block execution.
block_contents (list) – Lines of code that should be executed inside the block.
else_block_contents (list, optional) – Lines of code that should be executed inside the else clause of the block. Defaults to False if not provided and an else clause is omitted.
- Returns:
Lines of code performing conditional execution of a block.
- Return type:
- classmethod write_initialize(var, value=None, requires_freeing=None)[source]¶
Get the code necessary to initialize a variable.
- Parameters:
var (dict, str) – Name or information dictionary for the variable being declared.
value (str, optional) – Value that should be assigned to the variable after it is declared.
requires_freeing (list, optional) – Existing list that variables requiring freeing should be appended to. Defaults to None and is ignored.
- Returns:
The lines initializing the variable.
- Return type:
- classmethod write_initialize_oiter(var, value=None, requires_freeing=None)[source]¶
Get the lines necessary to initialize an array for iteration output.
- Parameters:
- Returns:
The lines initializing the variable.
- Return type:
- classmethod write_model_function_call(model_function, flag_var, inputs, outputs, outputs_in_inputs=None, on_failure=None, format_not_flag_cond=None, format_flag_cond=None, iter_function_idx=None)[source]¶
Write lines necessary to call the model function.
- Parameters:
model_function (str) – Handle of the model function that should be called.
flag_var (str) – Name of variable that should be used as a flag.
inputs (list) – List of dictionaries describing inputs to the model.
outputs (list) – List of dictionaries describing outputs from the model.
outputs_in_inputs (bool, optional) – If True, the outputs are presented in the function definition as inputs. Defaults to the class attribute outputs_in_inputs.
on_failure (list, optional) – Lines to be executed if the model call fails. Defaults to an error message. This variable is only used if flag_var is not None and outputs_in_inputs is True.
format_not_flag_cond (str, optional) – Format string that produces a conditional expression that evaluates to False when the model flag indicates a failure. Defaults to None and the class’s value for ‘not_flag_cond’ in function_param is used if it exists. If it does not exist, format_flag_cond is used.
format_flag_cond (str, optional) – Format string that produces a conditional expression that evaluates to True when the model flag indicates a success. Defaults to None and the defaults class’s value for ‘flag_cond’ in function_param is used if it exists. If it does not exist, the flag is directly evaluated as if it were a boolean.
iter_function_idx (dict, optional) – Variable that serves as an index to iterate over variables. Defaults to None.
- Returns:
- Lines required to carry out a call to a model function in
this language.
- Return type:
- classmethod write_model_recv(channel, recv_var, flag_var='flag', iter_var=None, allow_failure=False, alt_recv_function=None, include_arg_count=None)[source]¶
Write a model receive call include checking the return flag.
- Parameters:
channel (str) – Name of variable that the channel being received from was stored in.
recv_var (dict, list) – Information of one or more variables that receieved information should be stored in.
flag_var (str, optional) – Name of flag variable that the flag should be stored in. Defaults to ‘flag’,
iter_var (str, optional) – Name of flag signifying when the model is in it’s first iteration. If allow_failure is True and iter_var is provided, an error will be raised if iter_var is True. Defaults to None.
allow_failure (bool, optional) – If True, the returned lines will call a break if the flag is False. Otherwise, the returned lines will issue an error. Defaults to False.
alt_recv_function (str, optional) – Alternate receive function format string. Defaults to None and is ignored.
include_arg_count (bool, optional) – If True, the arguments to the receive call will be proceeded with an argument count. If not provided, the class attribute of the same name will be used.
- Returns:
Lines required to carry out a receive call in this language.
- Return type:
- classmethod write_model_send(channel, send_var, flag_var='flag', allow_failure=False, alt_send_function=None, include_arg_count=None)[source]¶
Write a model send call include checking the return flag.
- Parameters:
channel (str) – Name of variable that the channel being sent to was stored in.
send_var (dict, list) – Information on one or more variables containing information that will be sent.
flag_var (str, optional) – Name of flag variable that the flag should be stored in. Defaults to ‘flag’,
allow_failure (bool, optional) – If True, the returned lines will call a break if the flag is False. Otherwise, the returned lines will issue an error. Defaults to False.
alt_send_function (str, optional) – Alternate send function format string. Defaults to None and is ignored.
include_arg_count (bool, optional) – If True, the arguments to the send call will be proceeded with an argument count. If not provided, the class attribute of the same name will be used.
- Returns:
Lines required to carry out a send call in this language.
- Return type:
- classmethod write_model_wrapper(model_file, model_function, inputs=[], outputs=[], model_flag=None, outputs_in_inputs=None, verbose=False, copies=1, iter_function_over=[], verbose_model=False, skip_update_io=False, model_name=None)[source]¶
Return the lines required to wrap a model function as an integrated model.
- Parameters:
model_file (str) – Full path to the file containing the model function’s declaration.
model_function (str) – Name of the model function.
inputs (list, optional) – List of model inputs including types. Defaults to [].
outputs (list, optional) – List of model outputs including types. Defaults to [].
model_flag (dict, optional) – Information about the flag that should be used to track the success of yggdrasil send/recv calls. This should only be provided if update_io_from_function has already been called. Defaults to None and is determined by update_io_from_function.
outputs_in_inputs (bool, optional) – If True, the outputs are presented in the function definition as inputs. Defaults to the class attribute outputs_in_inputs.
verbose (bool, optional) – If True, the contents of the created file are displayed. Defaults to False.
copies (int, optional) – Number of times the model driver is duplicated. If more than one, no error will be raised in the event there is never a call the the function. Defaults to 1.
iter_function_over (array, optional) – Variable(s) that should be received or sent as an array, but iterated over. Defaults to an empty array and is ignored.
skip_update_io (bool, optional) – If True, update_io_from_function will not be called. Defaults to False.
verbose_model (bool, optional) – If True, print statements will be added after every line in the model. Defaults to False.
model_name (str, optional) – Name given to the model. Defaults to None.
- Returns:
- Lines of code wrapping the provided model with the necessary
code to run it as part of an integration.
- Return type:
- classmethod write_print_input_var(var, **kwargs)[source]¶
Get the lines necessary to print an input variable in this language.
- classmethod write_print_output_var(var, in_inputs=False, **kwargs)[source]¶
Get the lines necessary to print an output variable in this language.
- Parameters:
- Returns:
Lines printing the specified variable.
- Return type:
- classmethod write_print_var(var, prefix_msg=None)[source]¶
Get the lines necessary to print a variable in this language.
- classmethod write_try_except(try_contents, except_contents, error_var='e', error_type=None)[source]¶
Return the lines required to complete a try/except block.
- Parameters:
try_contents (list) – Lines of code that should be executed inside the try block.
except_contents (list) – Lines of code that should be executed inside the except block.
error_var (str, optional) – Name of variable where the caught error should be stored. Defaults to ‘e’.
error_type (str, optional) – Name of error type that should be caught. If not provided, defaults to None and will be set based on the class function_param entry for ‘try_error_type’.
- Returns:
Lines of code perfoming a try/except block.
- classmethod write_type_decl(name, datatype, name_base=None, requires_freeing=None, definitions=None, no_decl=False)[source]¶
Get lines declaring the datatype within the language.
- Parameters:
name (str) – Name of variable that should be declared.
datatype (dict) – Type definition.
requires_freeing (list, optional) – List that variables requiring freeing should be appended to. Defaults to None.
definitions (list, optional) – Existing list that variable definitions should be added to. Defaults to None if not provided and definitions will be included in the returned lines.
no_decl (bool, optional) – If True, the variable is not declared, but supporting variables will be. Defaults to False.
- Returns:
Lines required to define a type declaration.
- Return type:
- classmethod write_type_def(name, datatype, name_base=None, use_generic=False)[source]¶
Get lines declaring the data type within the language.
- Parameters:
- Returns:
Lines required to define a type definition.
- Return type:
- classmethod write_while_loop(cond, loop_contents)[source]¶
Return the lines required to complete a for loop.
- write_wrappers(**kwargs)[source]¶
Write any wrappers needed to compile and/or run a model.
- Parameters:
**kwargs – Keyword arguments are ignored (only included to allow cascade from child classes).
- Returns:
Full paths to any created wrappers.
- Return type:
- zero_based = True¶
- yggdrasil.drivers.ModelDriver.remove_product(product, check_for_source=False, **kwargs)[source]¶
Delete a single product after checking that the product is not (or does not contain, in the case of directories), source files.
- Parameters:
product (str) – Full path to a file or directory that should be removed.
check_for_source (bool, optional) – If True, the specified product will be checked to ensure that no source files are present. If a source file is present, a RuntimeError will be raised. Defaults to False.
**kwargs – Additional keyword arguments are passed to tools.remove_path.
- Raises:
RuntimeError – If the specified product is a source file and check_for_source is False.
RuntimeError – If the specified product is a directory that contains a source file and check_for_source is False.
RuntimeError – If the product cannot be removed.
yggdrasil.drivers.OSRModelDriver module¶
- class yggdrasil.drivers.OSRModelDriver.OSRModelDriver(*args, **kwargs)[source]¶
Bases:
ExecutableModelDriver
Class for running OpenSimRoot model.
- Parameters:
sync_vars_in (list, optional) – Variables that should be synchronized from other models. Defaults to [].
sync_vars_out (list, optional) – Variables that should be synchronized to other models. Defaults to [].
copy_xml_to_osr (bool, optional) – If True, the XML file(s) will be copied to the OSR repository InputFiles direcitory before running. This is necessary if the XML file(s) use any of the files located there since OSR always assumes the included file paths are relative. Defaults to False.
update_interval (float, optional) – Max simulation interval at which synchronization should occur (in days). Defaults to 1.0 if not provided. If the XML input file loads additional export modules that output at a shorter rate, the existing table of values will be extrapolated.
- static after_registration(cls, **kwargs)[source]¶
Operations that should be performed to modify class attributes after registration.
- base_languages = ['c++']¶
- cfg = <yggdrasil.config.YggConfigParser object>¶
- classmethod compile_dependencies(target='OpenSimRootYgg', toolname=None, **kwargs)[source]¶
Compile the OpenSimRoot executable with the yggdrasil flag set.
- Parameters:
target (str, optional) – Make target that should be build. Defaults to ‘OpenSimRootYgg’ (the yggdrasil-instrumented version of the OSR executable).
toolname (str, optional) – C++ compiler that should be used. Forced to be ‘cl.exe’ on windows. Otherwise the default C++ compiler will be used.
**kwargs – Additional keyword arguments are passed to the compile_dependencies methods of the base classes.
- classmethod configure_executable_type(cfg)[source]¶
Add configuration options specific in the executable type before the libraries are configured.
- Parameters:
cfg (CisConfigParser) – Config class that options should be set for.
- Returns:
- Section, option, description tuples for options that could not
be set.
- Return type:
- classmethod executable_command(args, **kwargs)[source]¶
Compose a command for running a program using the exectuable for this language (compiler/interpreter) with the provided arguments.
- Parameters:
args (list) – The program that returned command should run and any arguments that should be provided to it.
unused_kwargs (dict, optional) – Existing dictionary that unused keyword arguments should be added to. Defaults to None and is ignored.
**kwargs – Additional keyword arguments are passed to the parent class.
- Returns:
- Arguments composing the command required to run the program
from the command line using the executable for this language.
- Return type:
- executable_path = '/tmp/OpenSimRoot/OpenSimRoot/StaticBuild/OpenSimRootYgg'¶
- executable_type = 'dsl'¶
- classmethod get_testing_options(**kwargs)[source]¶
Method to return a dictionary of testing options for this class.
- Returns:
- Dictionary of variables to use for testing. Key/value pairs:
kwargs (dict): Keyword arguments for driver instance. deps (list): Dependencies to install.
- Return type:
- interface_dependencies = ['make']¶
- inverse_type_map = None¶
- classmethod is_language_installed()[source]¶
Determine if the interpreter/compiler for the associated programming language is installed.
- Returns:
True if the language interpreter/compiler is installed.
- Return type:
- language = 'osr'¶
- classmethod language_executable(**kwargs)[source]¶
Command required to compile/run a model written in this language from the command line.
- Returns:
- Name of (or path to) compiler/interpreter executable required
to run the compiler/interpreter from the command line.
- Return type:
- language_ext = ['.xml']¶
- classmethod language_version(version_flags=None, **kwargs)[source]¶
Determine the version of this language.
- Parameters:
**kwargs – Keyword arguments are passed to cls.run_executable.
- Returns:
Version of compiler/interpreter for this language.
- Return type:
- parse_arguments(*args, **kwargs)[source]¶
Sort model arguments to determine which one is the executable and which ones are arguments.
- Parameters:
*args – Additional arguments are passed to the parent class’s method.
**kwargs – Additional keyword arguments are passed to the parent class’s method.
- repository = '/tmp/OpenSimRoot'¶
- repository_branch = 'volatile_active'¶
- repository_url = 'https://gitlab.com/langmm/OpenSimRoot.git'¶
- classmethod set_env_class(**kwargs)[source]¶
Set environment variables that are instance independent.
- Parameters:
**kwargs – Additional keyword arguments are passed to the parent class’s method.
- Returns:
Environment variables for the model process.
- Return type:
yggdrasil.drivers.OutputDriver module¶
- class yggdrasil.drivers.OutputDriver.OutputDriver(*args, **kwargs)[source]¶
Bases:
ConnectionDriver
Driver for sending output to another model’s comm via a local comm.
yggdrasil.drivers.PyTorchModelDriver module¶
- class yggdrasil.drivers.PyTorchModelDriver.PyTorchModelDriver(*args, **kwargs)[source]¶
Bases:
DSLModelDriver
Class for handling PyTorch models.
- cfg = <yggdrasil.config.YggConfigParser object>¶
- default_interpreter = 'pytorch'¶
- default_interpreter_flags = []¶
- classmethod get_testing_options(**kwargs)[source]¶
Method to return a dictionary of testing options for this class.
- Returns:
- Dictionary of variables to use for testing. Key/value pairs:
kwargs (dict): Keyword arguments for driver instance. deps (list): Dependencies to install.
- Return type:
- interface_dependencies = ['torch']¶
- inverse_type_map = None¶
- language = 'pytorch'¶
- language_ext = ['.py']¶
- classmethod language_version(**kwargs)[source]¶
Determine the version of this language.
- Parameters:
**kwargs – Keyword arguments are passed to cls.run_executable.
- Returns:
Version of compiler/interpreter for this language.
- Return type:
yggdrasil.drivers.PythonModelDriver module¶
- class yggdrasil.drivers.PythonModelDriver.PythonModelDriver(*args, **kwargs)[source]¶
Bases:
InterpretedModelDriver
Class for running Python models.
- cfg = <yggdrasil.config.YggConfigParser object>¶
- default_interpreter = '/opt/hostedtoolcache/Python/3.8.17/x64/bin/python'¶
- default_interpreter_flags = []¶
- static finalize_registration(cls)[source]¶
Operations that should be performed after a class has been fully initialized and registered.
- classmethod format_function_param(key, default=None, **kwargs)[source]¶
Return the formatted version of the specified key.
- Parameters:
- Returns:
Formatted string.
- Return type:
- Raises:
NotImplementedError – If key is not in cls.function_param and default is not set.
- function_param = {'and': 'and', 'assign': '{name} = {value}', 'block_end': '', 'break': 'break', 'comment': '#', 'error': 'raise Exception("{error_msg}")', 'exec_begin': 'def main():', 'exec_suffix': 'if __name__ == "__main__":\n main()', 'false': 'False', 'for_begin': 'for {iter_var} in range({iter_begin}, {iter_end}):', 'fprintf': 'print("{message}" % ({variables}))', 'function_def_begin': 'def {function_name}({input_var}):', 'function_def_regex': '\\n?( *)def +{function_name} *\\((?P<inputs>(?:.|\\n)*?)\\)? *:(?P<body>(?:\\1(?: )+(?!return).*\\n)|(?: *\\n))*(?:\\1(?: )+return *(?P<outputs>.*)?)?', 'if_begin': 'if ({cond}):', 'if_elif': 'elif ({cond}):', 'if_else': 'else:', 'import': 'from {filename} import {function}', 'import_nofile': 'import {function}', 'indent': ' ', 'index': '{variable}[{index}]', 'input': "{channel} = ygg.YggInput('{channel_name}')", 'inputs_def_regex': '\\s*(?P<name>.+?)\\s*(?:,|$)', 'interface': 'import {interface_library} as ygg', 'istype': 'isinstance({variable}, {type})', 'len': 'len({variable})', 'multiple_outputs': '[{outputs}]', 'not': 'not', 'output': "{channel} = ygg.YggOutput('{channel_name}')", 'outputs_def_regex': '\\s*(?P<name>.+?)\\s*(?:,|$)', 'print': 'print("{message}")', 'print_generic': 'from yggdrasil.tools import print_encoded; print_encoded({object})', 'python_interface': "{channel} = ygg.{python_interface}('{channel_name}')", 'python_interface_format': "{channel} = ygg.{python_interface}('{channel_name}', '{format_str}')", 'quote': '"', 'recv_function': '{channel}.recv', 'return': 'return {output_var}', 'send_function': '{channel}.send', 'true': 'True', 'try_begin': 'try:', 'try_error_type': 'BaseException', 'try_except': 'except {error_type} as {error_var}:', 'while_begin': 'while ({cond}):'}¶
- classmethod get_testing_options(**kwargs)[source]¶
Method to return a dictionary of testing options for this class.
- Parameters:
**kwargs – Additional keyword arguments are passed to the parent class.
- Returns:
- Dictionary of variables to use for testing. Key/value pairs:
kwargs (dict): Keyword arguments for driver instance. deps (list): Dependencies to install.
- Return type:
- classmethod install_dependency(package=None, package_manager=None, **kwargs)[source]¶
Install a dependency.
- Parameters:
package (str) – Name of the package that should be installed. If the package manager supports it, this can include version requirements.
package_manager (str, optional) – Package manager that should be used to install the package.
**kwargs – Additional keyword arguments are passed to the parent class.
- interface_library = 'yggdrasil.interface.YggInterface'¶
- interface_map = {'call': 'flag, {inputs} = {channel_obj}.call({outputs})', 'client': 'YggRpcClient("{channel_name}")', 'import': 'from yggdrasil.languages.Python.YggInterface import {commtype}', 'input': 'YggInput("{channel_name}")', 'output': 'YggOutput("{channel_name}")', 'recv': 'flag, {inputs} = {channel_obj}.recv()', 'send': 'flag = {channel_obj}.send({outputs})', 'server': 'YggRpcServer("{channel_name}")', 'timesync': 'YggTimesync("{channel_name}")'}¶
- inverse_type_map = None¶
- classmethod is_language_installed()[source]¶
Determine if this model driver is installed on the current machine.
- Returns:
- Truth of if this model driver can be run on the current
machine.
- Return type:
- language = 'python'¶
- language_ext = ['.py']¶
- set_env(**kwargs)[source]¶
Get environment variables that should be set for the model process.
- Parameters:
**kwargs – Additional keyword arguments are passed to the parent class’s method.
- Returns:
Environment variables for the model process.
- Return type:
- supported_comm_options = {'ipc': {'libraries': ['sysv_ipc'], 'platforms': ['MacOS', 'Linux']}, 'mpi': {'libraries': ['mpi4py']}, 'rest': {'libraries': ['requests']}, 'rmq': {'libraries': ['pika']}, 'zmq': {'libraries': ['zmq']}}¶
- supported_comms = ['rmq_async', 'ipc', 'buffer', 'rest', 'value', 'rmq', 'mpi', 'zmq']¶
- type_map = {'1darray': 'numpy.ndarray', 'array': 'list', 'boolean': 'bool', 'bytes': 'bytes', 'complex': 'numpy.complexX', 'float': 'numpy.floatX', 'int': 'numpy.intX', 'ndarray': 'numpy.ndarray', 'null': 'None', 'obj': 'ObjDict', 'object': 'dict', 'ply': 'PlyDict', 'schema': 'dict', 'string': 'str', 'uint': 'numpy.uintX', 'unicode': 'str'}¶
- classmethod write_finalize_oiter(var)[source]¶
Get the lines necessary to finalize an array after iteration.
yggdrasil.drivers.RModelDriver module¶
- class yggdrasil.drivers.RModelDriver.RModelDriver(*args, **kwargs)[source]¶
Bases:
InterpretedModelDriver
Base class for running R models.
- Parameters:
- base_languages = ['python']¶
- brackets = ('{', '}')¶
- classmethod call_compiler(package_dir, toolname=None, flags=None, language='c++', verbose=False, use_ccache=False, disable_python_c_api=False, with_asan=False)[source]¶
Build an R package w/ the yggdrasil compilers.
- Parameters:
package_dir (str) – Full path to the package directory.
toolname (str, optional) – Compilation tool that should be used. Defaults to None and the default tools will be used.
flags (list, optional) – Additional flags that should be passed to the build command. Defaults to [].
language (str, optional) – Language that the package is written in (e.g. c, fortran). Defautls to ‘c++’.
verbose (bool, optional) – If True, information about the build process will be displayed. Defaults to False.
use_ccache (bool, optional) – If True, ccache will be added to the compilation executable. Defaults to False.
disable_python_c_api (bool, optional) – If True, the Python C API will be disabled. Defaults to False.
- cfg = <yggdrasil.config.YggConfigParser object>¶
- classmethod comm_atexit(comm)[source]¶
Operations performed on comm at exit including draining receive.
- Parameters:
comm (CommBase) – Communication object.
- default_interpreter = 'Rscript'¶
- default_interpreter_flags = ['--default-packages=methods,utils']¶
- function_param = {'and': '&&', 'assign': '{name} <- {value}', 'assign_mult': '{name} %<-% {value}', 'block_end': '}', 'comment': '#', 'error': 'stop("{error_msg}")', 'false': 'FALSE', 'first_index': 1, 'for_begin': 'for ({iter_var} in {iter_begin}:{iter_end}) {{', 'fprintf': 'print(sprintf("{message}", {variables}))', 'function_def_begin': '{function_name} <- function({input_var}) {{', 'function_def_regex': '{function_name} *(?:(?:\\<-)|(?:=)) *function\\((?P<inputs>(?:.|(?:\\r?\\n))*?)\\)\\s*\\{{(?P<body>(?:.|(?:\\r?\\n))*?)(?:return\\((list\\()?(?P<outputs>(?:.|(?:\\r?\\n))*?)(?(3)\\))\\)(?:.|(?:\\r?\\n))*?\\}})|(?:\\}})', 'if_begin': 'if ({cond}) {{', 'if_elif': '}} else if ({cond}) {{', 'if_else': '}} else {{', 'import': 'reticulate::py_config(); source("{filename}")', 'indent': ' ', 'index': '{variable}[[{index}]]', 'input': '{channel} <- YggInterface("YggInput", "{channel_name}")', 'inputs_def_regex': '\\s*(?P<name>.+?)\\s*(?:,|$)', 'interface': 'library(yggdrasil)', 'interface_regex': "(?P<indent>[ \\t]*)(?P<variable>[a-zA-Z\\_]+[a-zA-Z\\_0-9]*)\\s*\\<\\-\\s*YggInterface\\(\\'(?P<class>[a-zA-Z\\_]+[a-zA-Z\\_0-9]*)\\'\\s*\\,\\s*\\'(?P<channel>[a-zA-Z\\_]+[a-zA-Z\\_0-9]*)\\'\\s*(?P<args>[^\\)]*)\\)", 'istype': 'is({variable}, "{type}")', 'len': 'length({variable})', 'multiple_outputs': 'c({outputs})', 'multiple_outputs_def': 'list({outputs})', 'not': '!', 'output': '{channel} <- YggInterface("YggOutput", "{channel_name}")', 'outputs_def_regex': '\\s*(?P<name>.+?)\\s*(?:,|$)', 'print': 'print("{message}")', 'print_generic': 'print({object})', 'python_interface': '{channel} <- YggInterface("{python_interface}", "{channel_name}")', 'python_interface_format': '{channel} <- YggInterface("{python_interface}", "{channel_name}", "{format_str}")', 'quote': '"', 'recv_function': '{channel}$recv', 'return': 'return({output_var})', 'send_function': '{channel}$send', 'true': 'TRUE', 'try_begin': 'tryCatch({', 'try_end': '})', 'try_except': '}}, error = function({error_var}) {{', 'while_begin': 'while ({cond}) {{'}¶
- classmethod get_testing_options(**kwargs)[source]¶
Method to return a dictionary of testing options for this class.
- Parameters:
**kwargs – Additional keyword arguments are passed to the parent class.
- Returns:
- Dictionary of variables to use for testing. Key/value pairs:
kwargs (dict): Keyword arguments for driver instance. deps (list): Dependencies to install.
- Return type:
- classmethod install_dependency(package, package_manager=None, **kwargs)[source]¶
Install a dependency.
- Parameters:
package (str) – Name of the package that should be installed. If the package manager supports it, this can include version requirements.
package_manager (str, optional) – Package manager that should be used to install the package.
**kwargs – Additional keyword arguments are passed to the parent class.
- interface_dependencies = ['units', 'R6', 'Rcpp', 'bit64', 'zeallot', 'reticulate']¶
- interface_library = 'yggdrasil'¶
- interface_map = {'call': 'c(flag, {inputs}) %<-% {channel_obj}$call({outputs})', 'client': "YggInterface('YggRpcClient', '{channel_name}')", 'import': 'library(yggdrasil)', 'input': "YggInterface('YggInput', '{channel_name}')", 'output': "YggInterface('YggOutput', '{channel_name}')", 'recv': 'c(flag, {inputs}) %<-% {channel_obj}$recv()', 'send': 'flag = {channel_obj}$send({outputs})', 'server': "YggInterface('YggRpcServer', '{channel_name}')", 'timesync': "YggInterface('YggTimesync', '{channel_name}')"}¶
- inverse_type_map = None¶
- language = 'R'¶
- language_aliases = ['r']¶
- language_ext = ['.R']¶
- classmethod language_version(**kwargs)[source]¶
Determine the version of this language.
- Parameters:
**kwargs – Keyword arguments are passed to the parent class’s method.
- Returns:
Version of compiler/interpreter for this language.
- Return type:
- run_model(*args, **kwargs)[source]¶
Run the model. Unless overridden, the model will be run using run_executable.
- Parameters:
*args – Arguments are passed to the parent class’s method.
**kwargs – Keyword arguments are passed to the parent class’s method.
- send_converters = {'table': <function consolidate_array>}¶
- set_env(**kwargs)[source]¶
Get environment variables that should be set for the model process.
- Returns:
Environment variables for the model process.
- Return type:
- type_map = {'1darray': 'list', 'array': 'list', 'boolean': 'logical', 'bytes': 'char (utf-8)', 'complex': 'complex', 'float': 'double', 'int': 'integer, bit64::integer64', 'ndarray': 'list', 'null': 'NA', 'number': 'double', 'obj': 'ObjDict', 'object': 'list', 'ply': 'PlyDict', 'schema': 'list', 'string': 'character', 'uint': 'integer', 'unicode': 'char'}¶
- classmethod write_executable_import(**kwargs)[source]¶
Add import statements to executable lines.
- Parameters:
**kwargs – Keyword arguments for import statement.
- Returns:
Lines required to complete the import.
- Return type:
- classmethod write_expand_single_element(output_var, add_cond=False)[source]¶
Write lines allowing extraction of the only element from a single element array as a stand-alone variable if the variable is an array and only has one element.
- Parameters:
- Returns:
- Lines added the conditional expansion of single element
arrays.
- Return type:
- classmethod write_finalize_oiter(var)[source]¶
Get the lines necessary to finalize an array after iteration.
- classmethod write_initialize_oiter(var, value=None, **kwargs)[source]¶
Get the lines necessary to initialize an array for iteration output.
- Parameters:
- Returns:
The lines initializing the variable.
- Return type:
- classmethod write_model_wrapper(model_file, model_function, **kwargs)[source]¶
Return the lines required to wrap a model function as an integrated model.
- Parameters:
- Returns:
- Lines of code wrapping the provided model with the necessary
code to run it as part of an integration.
- Return type:
- zero_based = False¶
yggdrasil.drivers.RPCRequestDriver module¶
- class yggdrasil.drivers.RPCRequestDriver.RPCRequestDriver(*args, **kwargs)[source]¶
Bases:
ConnectionDriver
Class for handling client side RPC type communication.
- Parameters:
model_request_name (str) – The name of the channel used by the client model to send requests.
**kwargs – Additional keyword arguments are passed to parent class.
- property model_env¶
Mapping between model name and opposite comm environment variables that need to be provided to the model.
- Type:
- on_eof(msg)[source]¶
On EOF, decrement number of clients. Only send EOF if the number of clients drops to 0.
- Parameters:
msg (CommMessage) – Message object that provided the EOF.
- Returns:
Value that should be returned by recv_message on EOF.
- Return type:
- run_loop()[source]¶
Run the driver. Continue looping over messages until there are not any left or the communication channel is closed.
- send_message(msg, **kwargs)[source]¶
Start a response driver for a request message and send message with header.
- Parameters:
msg (CommMessage) – Message being sent.
**kwargs – Keyword arguments are passed to parent class send_message.
- Returns:
Success or failure of send.
- Return type:
yggdrasil.drivers.RPCResponseDriver module¶
- class yggdrasil.drivers.RPCResponseDriver.RPCResponseDriver(*args, **kwargs)[source]¶
Bases:
ConnectionDriver
Class for handling client side RPC type communication.
- Parameters:
- send_message(msg, **kwargs)[source]¶
Propagate the request_id.
- Parameters:
msg (CommMessage) – Message being sent.
**kwargs – Keyword arguments are passed to parent class send_message.
- Returns:
Success or failure of send.
- Return type:
yggdrasil.drivers.SBMLModelDriver module¶
- class yggdrasil.drivers.SBMLModelDriver.SBMLModelDriver(*args, **kwargs)[source]¶
Bases:
DSLModelDriver
Class for running SBML models.
- Parameters:
start_time (float, optional) – Time that simulation should be started from. If ‘reset’ is True, the start time will always be the provided value, otherwise, the start time will be the end of the previous call after the first call. Defaults to 0.0.
steps (int, optional) – Number of steps that should be output. Defaults to None.
reset (bool, optional) – If True, the simulation will be reset to it’s initial values before each call (including the start time). Defaults to False.
selections (list, optional) – Variables to include in the output. Defaults to None and the time/floating selections will be returned.
integrator (str, optional) – Name of integrator that should be used. Valid options include [‘cvode’, ‘gillespie’, ‘rk4’, ‘rk45’]. Defaults to ‘cvode’.
integrator_settings (dict, optional) – Settings for the integrator. Defaults to empty dict.
variable_step (bool, optional) – If True, the output steps will have a variable spacing. Defaults to False.
only_output_final_step (bool, optional) – If True, only the final timestep is output. Defaults to False.
skip_start_time (bool, optional) – If True, the results for the initial time step will not be output. Defaults to False. This option is ignored if only_output_final_step is True.
- classmethod call_model(model, curr_time, end_time, steps, reset=False, start_time=None, selections=None, variable_step=False)[source]¶
Call the model.
- cfg = <yggdrasil.config.YggConfigParser object>¶
- default_interpreter = 'sbml'¶
- default_interpreter_flags = []¶
- classmethod get_testing_options(**kwargs)[source]¶
Method to return a dictionary of testing options for this class.
- Parameters:
**kwargs – Additional keyword arguments are passed to the parent class.
- Returns:
- Dictionary of variables to use for testing. Key/value pairs:
kwargs (dict): Keyword arguments for driver instance. deps (list): Dependencies to install.
- Return type:
- interface_dependencies = ['roadrunner']¶
- inverse_type_map = None¶
- language = 'sbml'¶
- language_ext = ['.xml']¶
- classmethod language_version(**kwargs)[source]¶
Determine the version of this language.
- Parameters:
**kwargs – Keyword arguments are passed to cls.run_executable.
- Returns:
Version of compiler/interpreter for this language.
- Return type:
yggdrasil.drivers.TimeSyncModelDriver module¶
- class yggdrasil.drivers.TimeSyncModelDriver.TimeSyncModelDriver(*args, **kwargs)[source]¶
Bases:
DSLModelDriver
Class for synchronizing states for timesteps between two models.
- Parameters:
synonyms (dict, optional) –
Mapping from model names to mappings from base variables names to information about one or more alternate variable names used by the named model that should be converted to the base variable. Values for providing information about alternate variables can either be strings (implies equivalence with the base variable in everything but name and units) or mappings with the keys:
- alt (str, list): Name of one or more variables used by
the model that should be used to calculate the named base variable.
- alt2base (function): Callable object that takes the
alternate variables named by the ‘alt’ property as input and returns the base variable.
- base2alt (function): Callable object that takes the base
variable as input and returns the alternate variables named by the ‘alt’ property.
Defaults to an empty dictionary.
aggregation (str, dict, optional) – Method(s) that should be used to aggregate synonymous variables across models. This can be a single method that should be used for all synonymous variables or a dictionary mapping between synonymous variables and the method that should be used by that variable. If a variable is not present in the dictionary or a values is not provided, ‘mean’ will be used. See the documentation for pandas.DataFrame.aggregate for available options.
interpolation (str, dict, optional) – Method(s) or keyword arguments that should be used to interpolate missing timesteps. This can be a single method or a dictionary mapping between model name and the interpolation methods (or keyword arguments) that should be used for variables from that model. Defaults to ‘index’. See the documentation for pandas.DataFrame.interpolate for available options.
additional_variables (dict, optional) – Mapping from model name to a list of variables from other models that are not provided by the model, but should still be returned to the model. Defaults to empty dictionary.
- cfg = <yggdrasil.config.YggConfigParser object>¶
- classmethod check_for_data(time, tables, table_units, table_lock, open_clients)[source]¶
Check for a time in the tables to determine if there is sufficient data available to calculate the state.
- Parameters:
time (pandas.Timedelta) – Time that state is requested at.
tables (dict) – Mapping from model name to pandas DataFrames containing variables supplied by the model.
table_units (dict) – Mapping from model name to dictionaries mapping from variable names to units.
table_lock (RLock) – Thread-safe lock for accessing table.
open_clients (list) – Clients that are still open.
- Returns:
True if there is sufficient data, False otherwise.
- Return type:
- default_interpreter = 'timesync'¶
- default_interpreter_flags = []¶
- executable_type = 'other'¶
- inverse_type_map = None¶
- language = 'timesync'¶
- classmethod merge(tables, table_units, table_lock, open_clients, synonyms, interpolation, aggregation)[source]¶
Merge tables from models to get data.
- Parameters:
tables (dict) – Mapping from model name to pandas DataFrames containing variables supplied by the model.
table_units (dict) – Mapping from model name to dictionaries mapping from variable names to units.
table_lock (RLock) – Thread-safe lock for accessing table.
open_clients (list) – Clients that are still open.
synonyms (dict) – Dictionary mapping from base variables to alternate variables and mapping functions used to convert between the variables. Defaults to empty dict and no conversions are performed.
interpolation (dict) – Mapping from model name to the interpolation kwargs that should be used. Defaults to empty dictionary.
aggregation (dict) – Mapping from variable name to the aggregation method that should be used. Defaults to empty dictionary.
- classmethod model_wrapper(name, synonyms, interpolation, aggregation, additional_variables, env=None)[source]¶
Model wrapper.
- parse_arguments(args, **kwargs)[source]¶
Sort model arguments to determine which one is the executable and which ones are arguments.
- Parameters:
args (list) – List of arguments provided.
**kwargs – Additional keyword arguments are ignored.
- classmethod response_loop(client_model, request_id, rpc, time, internal_variables, external_variables, tables, table_units, table_lock, synonyms, interpolation, aggregation)[source]¶
Check for available data and send response if it is available.
- Parameters:
client_model (str) – Name of model that made the request.
request_id (str) – ID associated with request that should be responded to.
rpc (ServerComm) – Server RPC comm that should be used to reply to the request when the data is available.
time (pandas.Timedelta) – Time to get variables at.
internal_variables (list) – Variables that model is requesting that it also calculates.
external_variables (list) – Variables that model is requesting that will be provided by other models.
tables (dict) – Mapping from model name to pandas DataFrames containing variables supplied by the model.
table_units (dict) – Mapping from model name to dictionaries mapping from variable names to units.
table_lock (RLock) – Thread-safe lock for accessing table.
synonyms (dict) – Dictionary mapping from base variables to alternate variables and mapping functions used to convert between the variables. Defaults to empty dict and no conversions are performed.
interpolation (dict) – Mapping from model name to the interpolation kwargs that should be used. Defaults to empty dictionary.
aggregation (dict) – Mapping from variable name to the aggregation method that should be used. Defaults to empty dictionary.
Module contents¶
IO and Model drivers.
- yggdrasil.drivers.create_driver(driver=None, name=None, args=None, **kwargs)[source]¶
Dynamically create a driver based on a string and other driver properties.
- Parameters:
driver (str) – Name of the driver that should be created.
name (str) – Name to give the driver.
args (object, optional) – Second argument for drivers which take a minimum of two arguments. If None, the driver is assumed to take a minimum of one argument. Defaults to None.
**kwargs – Additional keyword arguments are passed to the driver class.
- Returns:
Instance of the requested driver.
- Return type: