Skip to content

Commit

Permalink
Add dakota.rst restart capability to python env
Browse files Browse the repository at this point in the history
  • Loading branch information
wvangeit committed Aug 8, 2024
1 parent f63e1e1 commit 393cd80
Show file tree
Hide file tree
Showing 6 changed files with 115 additions and 251 deletions.
248 changes: 3 additions & 245 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,251 +1,9 @@
# Created by https://www.toptal.com/developers/gitignore/api/cmake,python,c++,linux
# Edit at https://www.toptal.com/developers/gitignore?templates=cmake,python,c++,linux

### C++ ###
# Prerequisites
*.d

# Compiled Object files
*.slo
*.lo
*.o
*.obj

# Precompiled Headers
*.gch
*.pch

# Compiled Dynamic libraries
*.so
*.dylib
*.dll

# Fortran module files
# *.mod NOTE: used in the Neuron simulator to describe channel kinetics
*.smod

# Compiled Static libraries
*.lai
*.la
*.a
*.lib

# Executables
*.exe
*.out
*.app

### CMake ###
CMakeLists.txt.user
CMakeCache.txt
CMakeFiles
CMakeScripts
Testing
cmake_install.cmake
install_manifest.txt
compile_commands.json
CTestTestfile.cmake
_deps

### CMake Patch ###
# External projects
*-prefix/

### Linux ###
*~

# temporary files which can be created if a process still has a handle open of a deleted file
.fuse_hidden*

# KDE directory preferences
.directory

# Linux trash folder which might appear on any partition or disk
.Trash-*

# .nfs files are created when an open file is removed but is still being accessed
.nfs*

### Python ###
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
__pycache__
.python-version
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock

# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/#use-with-ide
.pdm.toml

# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/

# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/

### Python Patch ###
# Poetry local configuration file - https://python-poetry.org/docs/configuration/#local-configuration
poetry.toml

# ruff
.ruff_cache/

# LSP config files
pyrightconfig.json

# End of https://www.toptal.com/developers/gitignore/api/cmake,python,c++,linux




# Custom
.py-build-cmake_cache/
build.sh
dakota
dakota_wheel-*
wheelhouse
itis_dakota/.version
itis_dakota/_version.py
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ get-dakota-src:
git submodule update --init packages/pecos && \
git submodule update --init packages/surfpack && \
git apply ../src_patches/dakota-src.patch && \
git apply ../src_patches/dakenv_restart.patch && \
git apply --whitespace=nowarn ../src_patches/adaptsampl_batch.patch && \
find . \( -name \*.cpp -o -name \*.hpp -o -name \*.c -o -name \*.h \) -exec \
sed -i -E -f ../src_patches/replace_old_macros_numpy.sed {} +
Empty file added build_backend/__init__.py
Empty file.
40 changes: 40 additions & 0 deletions build_backend/build.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import subprocess
import sys

import py_build_cmake.build


def build_wheel(
wheel_directory, config_settings=None, metadata_directory=None
):
# Run setuptools_scm
subprocess.run(
[
sys.executable,
"-m",
"setuptools_scm",
"--force-write-version-files",
],
check=True,
)

# Run the py_build_cmake build
return py_build_cmake.build.build_wheel(
wheel_directory, config_settings, metadata_directory
)


def build_sdist(sdist_directory, config_settings=None):
# Run setuptools_scm
subprocess.run(
[
sys.executable,
"-m",
"setuptools_scm",
"--force-write-version-files",
],
check=True,
)

# Run the py_build_cmake build
return py_build_cmake.build.build_sdist(sdist_directory, config_settings)
10 changes: 4 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,13 @@ issues = "https://github.com/ITISFoundation/itis-dakota/issues"
[build-system]
requires = [
"py-build-cmake",
"numpy",
"h5py",
"auditwheel",
"flit",
"flit-core",
"setuptools",
"setuptools_scm"
"setuptools_scm",
"numpy"
]
build-backend = "py_build_cmake.build"
build-backend = "build_backend.build"
backend-path = "."

[tool.setuptools]
packages = ["itis_dakota"]
Expand Down
67 changes: 67 additions & 0 deletions src_patches/dakenv_restart.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
diff --git a/src/dakota_python.cpp b/src/dakota_python.cpp
index 3c717bc..0def5df 100644
--- a/src/dakota_python.cpp
+++ b/src/dakota_python.cpp
@@ -92,7 +92,8 @@ namespace python {
return resp.function_value(0);
}

- Dakota::LibraryEnvironment* create_libEnv( const std::string& input_string) {
+ Dakota::LibraryEnvironment* create_libEnv( const std::string& input_string,
+ const std::string& read_restart) {

assert(!input_string.empty());

@@ -101,6 +102,10 @@ namespace python {
// avoid calling std::exit and taking down the Python instance too
opts.exit_mode("throw");
opts.input_string(input_string);
+ if (!read_restart.empty())
+ {
+ opts.read_restart_file(read_restart);
+ };

auto p_libEnv = new Dakota::LibraryEnvironment(opts);

@@ -170,10 +175,11 @@ PYBIND11_MODULE(environment, m) {
py::class_<Dakota::LibraryEnvironment>(m, "study")
.def(py::init
([](py::object callback,
- const std::string& input_string)
+ const std::string& input_string,
+ const std::string& read_restart = "")
{
assert(!input_string.empty());
- auto p_libEnv = Dakota::python::create_libEnv(input_string);
+ auto p_libEnv = Dakota::python::create_libEnv(input_string, read_restart);

// Associate the single python callback with all Pybind11Interface interfaces
Dakota::InterfaceList & interfaces = p_libEnv->problem_description_db().interface_list();
@@ -187,14 +193,15 @@ PYBIND11_MODULE(environment, m) {

return p_libEnv;
})
- , py::arg("callback"), py::arg("input_string"))
+ , py::arg("callback"), py::arg("input_string"), py::arg("read_restart") = "")

.def(py::init
([]( py::dict callbacks,
- const std::string& input_string)
+ const std::string& input_string,
+ const std::string& read_restart = "")
{
assert(!input_string.empty());
- auto p_libEnv = Dakota::python::create_libEnv(input_string);
+ auto p_libEnv = Dakota::python::create_libEnv(input_string, read_restart);

// Associate callbacks with interface specs
auto callbacks_map = callbacks.cast< std::map<std::string,py::function> >();
@@ -220,7 +227,7 @@ PYBIND11_MODULE(environment, m) {

return p_libEnv;
})
- , py::arg("callbacks"), py::arg("input_string"))
+ , py::arg("callbacks"), py::arg("input_string"), py::arg("read_restart") = "")

.def("execute", &Dakota::LibraryEnvironment::execute)
.def("variables_results", &Dakota::LibraryEnvironment::variables_results)

0 comments on commit 393cd80

Please sign in to comment.