Skip to content

translate configuration information into pynest status, config and setup attributes #3397

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,11 @@ configure_file(
"${PROJECT_BINARY_DIR}/pynest/nest/versionchecker.py" @ONLY
)

configure_file(
"${PROJECT_SOURCE_DIR}/pynest/nest/config.py.in"
"${PROJECT_BINARY_DIR}/pynest/nest/config.py" @ONLY
)


################################################################################
################## Install Extra Files ##################
Expand Down
1 change: 1 addition & 0 deletions pynest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ if ( HAVE_PYTHON )
install(DIRECTORY nest/ ${PROJECT_BINARY_DIR}/pynest/nest/
DESTINATION ${CMAKE_INSTALL_PREFIX}/${PYEXECDIR}/nest
PATTERN "versionchecker.py.in" EXCLUDE
PATTERN "config.py.in" EXCLUDE
)
install( TARGETS pynestkernel DESTINATION ${PYEXECDIR}/nest/ )

Expand Down
25 changes: 20 additions & 5 deletions pynest/nest/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,14 @@

import builtins # noqa
import importlib # noqa
import json # noqa
import sys # noqa
import types # noqa

from .ll_api_kernel_attributes import KernelAttribute # noqa
import numpy as np

try:
import versionchecker # noqa: F401
except ImportError:
pass
from .config import config, setup, status # noqa
from .ll_api_kernel_attributes import KernelAttribute # noqa


class NestModule(types.ModuleType):
Expand Down Expand Up @@ -108,6 +107,9 @@ def __init__(self, name):
type(self).spatial = _lazy_module_property("spatial") # noqa: F821
type(self).visualization = _lazy_module_property("visualization") # noqa: F821
type(self).voltage_trace = _lazy_module_property("voltage_trace") # noqa: F821
type(self).setup = setup
type(self).config = config
type(self).status = status

self.__version__ = ll_api.sli_func("statusdict /version get") # noqa: F821
# Finalize the nest module with a public API.
Expand All @@ -118,6 +120,19 @@ def __init__(self, name):
# Block setting of unknown attributes
type(self).__setattr__ = _setattr_error

def __del__(self):
"Report last kernelstatus when closing the nest module."

class NumpyEncoder(json.JSONEncoder):
def default(self, obj):
if isinstance(obj, np.ndarray):
return obj.tolist()
return super().default(obj)

print("// BEGIN NEST KERNELSTATUS //")
json.dump(self.GetKernelStatus(), sys.stdout, indent=2, cls=NumpyEncoder)
print("// END NEST KERNELSTATUS //")

def set(self, **kwargs):
"Forward kernel attribute setting to `SetKernelStatus()`."
return self.SetKernelStatus(kwargs)
Expand Down
129 changes: 129 additions & 0 deletions pynest/nest/config.py.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
import sys

status = { # mixed "HAVE_*", "NEST_*" and others...
# This list is defined in sli/slistartup.cc lines 285 and onwards
"argv": sys.argv.copy(),
"version": "@NEST_VERSION@", # NEST_VERSION
"version_git": {
"hash": "@NEST_VERSION_GIT_HASH@", # NEST_VERSION_GIT_HASH
"branch": "@NEST_VERSION_GIT_BRANCH@", # NEST_VERSION_GIT_BRANCH
"remote": "@NEST_VERSION_GIT_REMOTE@", # NEST_VERSION_GIT_REMOTE
} if "@NEST_VERSION_GIT@" else False, # NEST_VERSION_GIT
#"exitcode": "@EXIT_SUCCESS@", # EXIT_SUCCESS
#"built": "@__TIME__@", # __TIME__
#"prefix": "@NEST_INSTALL_PREFIX@", # NEST_INSTALL_PREFIX
"prefix": "@CMAKE_INSTALL_PREFIX@", # CMAKE_INSTALL_PREFIX
"cmake_prefix": "@CMAKE_INSTALL_PREFIX@", # CMAKE_INSTALL_PREFIX
"cmake_datadir": "@CMAKE_INSTALL_DATADIR@", # CMAKE_INSTALL_DATADIR
"cmake_full_datadir": "@CMAKE_INSTALL_FULL_DATADIR@", # CMAKE_INSTALL_FULL_DATADIR
"cmake_docdir": "@CMAKE_INSTALL_DOCDIR@", # CMAKE_INSTALL_DOCDIR
#"slilibdir": "@NEST_INSTALL_PREFIX@/@NEST_INSTALL_DATADIR@", # NEST_INSTALL_PREFIX/NEST_INSTALL_DATADIR
#"slidocdir": "@NEST_INSTALL_PREFIX@/@NEST_INSTALL_DOCDIR@", # NEST_INSTALL_PREFIX/NEST_INSTALL_DOCDIR
#"host": "@NEST_HOST@", # NEST_HOST
#"hostos": "@NEST_HOSTOS@", # NEST_HOSTOS
#"hostvendor": "@NEST_HOSTVENDOR@", # NEST_HOSTVENDOR
#"hostcpu": "@NEST_HOSTCPU@", # NEST_HOSTCPU
"host": {
"arch": "@NEST_HOST_ARCH@", # NEST_HOST_ARCH
"os": "@NEST_HOST_OS@", # NEST_HOST_OS
"vendor": "@NEST_HOST_VENDOR@", # NEST_HOST_VENDOR
},
"target": {
"arch": "@NEST_TARGET_ARCH@", # NEST_TARGET_ARCH
"os": "@NEST_TARGET_OS@", # NEST_TARGET_OS
"vendor": "@NEST_TARGET_VENDOR@", # NEST_TARGET_VENDOR
},
"nest_user_email": "@NEST_USER_EMAIL@", # NEST_USER_EMAIL
"platform": "default", # for backward compatibility with BlueGene
"threading": "@with-openmp@" != "OFF", # with-openmp, originally "threading" was to choose "ptreads" or "openmp"
"mpi": {
"mpiexec": "@MPIEXEC@", # MPIEXEC
"mpiexec_numproc_flag": "@MPIEXEC_NUMPROC_FLAG@", # MPIEXEC_NUMPROC_FLAG
"mpiexec_max_numprocs": "@MPIEXEC_MAX_NUMPROCS@", # MPIEXEC_MAX_NUMPROCS
"mpiexec_preflags": "@MPIEXEC_PREFLAGS@", # MPIEXEC_PREFLAGS
"mpiexec_postflags": "@MPIEXEC_POSTFLAGS@", # MPIEXEC_POSTFLAGS
} if "@HAVE_MPI@" != "OFF" else False, # HAVE_MPI
"have_mpi": "@HAVE_MPI@" != "OFF", # HAVE_MPI
"have_gsl": "@HAVE_GSL@" != "OFF", # HAVE_GSL
"have_music": "@HAVE_MUSIC@" != "OFF", # HAVE_MUSIC
"have_boost": "@HAVE_BOOST@" != "OFF", # HAVE_BOOST
"have_libneurosim": "@HAVE_LIBNEUROSIM@" != "OFF", # HAVE_LIBNEUROSIM
"have_sionlib": "@HAVE_SIONLIB@" != "", # HAVE_SIONLIB
"have_hdf5": "@HAVE_HDF5@" != "OFF", # HAVE_HDF5
"ndebug": "@NDEBUG@" != "", # NDEBUG, for "#ifdef NDEBUG" sections
#"architecture": { … }
#"exitcodes": {
# "success": "@EXIT_SUCCSESS@", # EXIT_SUCCSESS
# "skipped": "@EXITCODE_SKIPPED@", # EXITCODE_SKIPPED
# "success": "@EXITCODE_SKIPPED_NO_MPI@", # EXITCODE_SKIPPED_NO_MPI
# …
#}
#"environment": os.environ.copy(),
}

config = { # everything "HAVE_*"
"python": "@HAVE_PYTHON@",
"mpi": "@HAVE_MPI@",
"openmp": "@HAVE_OPENMP@",
"libneurosim": "@HAVE_LIBNEUROSIM@",
"music": "@HAVE_MUSIC@",
"sionlib": "@HAVE_SIONLIB@",
"boost": "@HAVE_BOOST@",
"hdf5": "@HAVE_HDF5@",
"readline": "@HAVE_READLINE@",
"ltdl": "@HAVE_LTDL@",
"gsl": "@HAVE_GSL@",
"modelset": "@HAVE_MODELSET@",
"models": "@HAVE_MODELS@",
"modelset": "@HAVE_MODELSET@",
"detailed-timers": "@HAVE_DETAILED-TIMERS@",
"optimize": "@HAVE_OPTIMIZE@",
"warning": "@HAVE_WARNING@",
"debug": "@HAVE_DEBUG@",
"cpp-std": "@HAVE_CPP-STD@",
"intel-compiler-flags": "@HAVE_INTEL-COMPILER-FLAGS@",
"libraries": "@HAVE_LIBRARIES@",
"includes": "@HAVE_INCLUDES@",
"defines": "@HAVE_DEFINES@",
"userdoc": "@HAVE_USERDOC@",
"devdoc": "@HAVE_DEVDOC@",
"full-logging": "@HAVE_FULL-LOGGING@",
"python": "@HAVE_PYTHON@",
"music": "@HAVE_MUSIC@",
"defines": "@HAVE_DEFINES@",
"libraries": "@HAVE_LIBRARIES@",
"includes": "@HAVE_INCLUDES@",
}
setup = { # everything "with-*"
"python": "@with-python@",
"mpi": "@with-mpi@",
"openmp": "@with-openmp@",
"libneurosim": "@with-libneurosim@",
"music": "@with-music@",
"sionlib": "@with-sionlib@",
"boost": "@with-boost@",
"hdf5": "@with-hdf5@",
"readline": "@with-readline@",
"ltdl": "@with-ltdl@",
"gsl": "@with-gsl@",
"modelset": "@with-modelset@",
"models": "@with-models@",
"modelset": "@with-modelset@",
"detailed-timers": "@with-detailed-timers@",
"optimize": "@with-optimize@",
"warning": "@with-warning@",
"debug": "@with-debug@",
"cpp-std": "@with-cpp-std@",
"intel-compiler-flags": "@with-intel-compiler-flags@",
"libraries": "@with-libraries@",
"includes": "@with-includes@",
"defines": "@with-defines@",
"userdoc": "@with-userdoc@",
"devdoc": "@with-devdoc@",
"full-logging": "@with-full-logging@",
"python": "@with-python@",
"music": "@with-music@",
"defines": "@with-defines@",
"libraries": "@with-libraries@",
"includes": "@with-includes@",
}
Loading