Skip to content

Commit

Permalink
Merge branch 'refactor-py-module' into 'master'
Browse files Browse the repository at this point in the history
Python wheels for module and ogs binaries

See merge request ogs/ogs!4263
  • Loading branch information
bilke committed Sep 19, 2022
2 parents 93bb8a9 + dfd918f commit 5d0ac0c
Show file tree
Hide file tree
Showing 37 changed files with 550 additions and 98 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,9 @@ CMakeUserPresets.json
nohup.out

/Documentation/.vale

# Python build
/_skbuild
*.egg-info/
/wheelhouse
.ipynb_checkpoints
1 change: 1 addition & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ include:
- local: "/scripts/ci/jobs/build-win.yml"
- local: "/scripts/ci/jobs/build-mac.yml"
- local: "/scripts/ci/jobs/build-container.yml"
- local: "/scripts/ci/jobs/build-wheels.yml"
- local: "/scripts/ci/jobs/jupyter.yml"
- local: "/scripts/ci/jobs/code-quality.yml"
- local: "/scripts/ci/jobs/code-coverage.yml"
Expand Down
47 changes: 0 additions & 47 deletions Applications/CLI/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,31 +45,6 @@ if(OGS_USE_PYTHON)
$<$<BOOL:${BUILD_SHARED_LIBS}>:PRIVATE
OGS_BUILD_SHARED_LIBS>
)

# Create OpenGeoSys python module
# https://pybind11.readthedocs.io/en/stable/compiling.html#building-with-cmake
if(OGS_BUILD_PYTHON_MODULE)
pybind11_add_module(
OpenGeoSys MODULE ogs_python_module.cpp
CommandLineArgumentParser.cpp
)

# lld linker strips out PyInit_OpenGeoSys symbol. Use standard linker.
get_target_property(_link_options OpenGeoSys LINK_OPTIONS)
if(_link_options)
list(REMOVE_ITEM _link_options -fuse-ld=lld)
set_target_properties(
OpenGeoSys PROPERTIES LINK_OPTIONS "${_link_options}"
)
endif()

target_link_libraries(
OpenGeoSys PRIVATE ApplicationsLib BaseLib GitInfoLib tclap
pybind11::pybind11
)

install(TARGETS OpenGeoSys LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
endif()
endif()

ogs_add_executable(ogs ogs.cpp CommandLineArgumentParser.cpp)
Expand All @@ -94,28 +69,6 @@ target_link_libraries(
add_test(NAME ogs_no_args COMMAND ogs)
set_tests_properties(ogs_no_args PROPERTIES WILL_FAIL TRUE LABELS "default")

if(OGS_BUILD_PYTHON_MODULE AND NOT (WIN32 AND "${CMAKE_BUILD_TYPE}" STREQUAL
"Release")
)
# TODO: does not work on Windows Release
add_test(
NAME ogs_python_module
COMMAND
${Python_EXECUTABLE}
${CMAKE_CURRENT_SOURCE_DIR}/ogs_python_module.py
${CMAKE_SOURCE_DIR}/Tests/Data/Parabolic/LiquidFlow/Flux/cube_1e3_calculatesurfaceflux.prj
)
set_tests_properties(
ogs_python_module
PROPERTIES
LABELS
"default"
ENVIRONMENT_MODIFICATION
PYTHONPATH=path_list_append:$<TARGET_FILE_DIR:OpenGeoSys>:${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}
DISABLED
$<NOT:$<TARGET_EXISTS:LiquidFlow>>
)
endif()
# ---- Installation ----
install(TARGETS ogs RUNTIME DESTINATION bin)

Expand Down
19 changes: 0 additions & 19 deletions Applications/CLI/ogs_python_module.py

This file was deleted.

4 changes: 4 additions & 0 deletions Applications/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,7 @@ endif() # OGS_BUILD_CLI
if(OGS_USE_INSITU)
add_subdirectory(InSituLib)
endif()

if(OGS_BUILD_PYTHON_MODULE)
add_subdirectory(Python)
endif()
1 change: 1 addition & 0 deletions Applications/Python/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add_subdirectory(ogs.simulator)
21 changes: 21 additions & 0 deletions Applications/Python/ogs.simulator/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Create OpenGeoSys python module
# https://pybind11.readthedocs.io/en/stable/compiling.html#building-with-cmake
pybind11_add_module(
simulator MODULE ogs_python_module.cpp
../../CLI/CommandLineArgumentParser.cpp
)

# lld linker strips out PyInit_OpenGeoSys symbol. Use standard linker.
get_target_property(_link_options simulator LINK_OPTIONS)
if(_link_options)
list(REMOVE_ITEM _link_options -fuse-ld=lld)
set_target_properties(simulator PROPERTIES LINK_OPTIONS "${_link_options}")
endif()

target_link_libraries(
simulator PRIVATE ApplicationsLib BaseLib CMakeInfoLib GitInfoLib tclap
)
target_include_directories(simulator PRIVATE ../../CLI)

# Install into root dir (in Python module, enables 'import ogs.simulator')
install(TARGETS simulator LIBRARY DESTINATION .)
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,9 @@ void finalize()
}

/// python module name is OpenGeoSys
PYBIND11_MODULE(OpenGeoSys, m)
PYBIND11_MODULE(simulator, m)
{
m.attr("__name__") = "ogs.simulator";
m.doc() = "pybind11 ogs example plugin";
m.def("initialize", &initOGS, "init OGS");
m.def("currentTime", &currentTime, "get current OGS time");
Expand Down
Empty file.
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import os
import platform
import subprocess
import sys

binaries_list = [
"addDataToRaster",
"AddElementQuality",
"AddFaultToVoxelGrid",
"AddLayer",
"appendLinesAlongPolyline",
"AssignRasterDataToMesh",
"checkMesh",
"ComputeNodeAreasFromSurfaceMesh",
"computeSurfaceNodeIDsInPolygonalRegion",
"constructMeshesFromGeometry",
"convertGEO",
"convertToLinearMesh",
"convertVtkDataArrayToVtkDataArray",
"CreateBoundaryConditionsAlongPolylines",
"createIntermediateRasters",
"createLayeredMeshFromRasters",
"createMeshElemPropertiesFromASCRaster",
"createNeumannBc",
"createQuadraticMesh",
"createRaster",
"editMaterialID",
"ExtractBoundary",
"ExtractMaterials",
"ExtractSurface",
"generateGeometry",
"generateMatPropsFromMatID",
"generateStructuredMesh",
"geometryToGmshGeo",
"GMSH2OGS",
"GocadSGridReader",
"GocadTSurfaceReader",
"identifySubdomains",
"IntegrateBoreholesIntoMesh",
"Layers2Grid",
"MapGeometryToMeshSurface",
"Mesh2Raster",
"MoveGeometry",
"MoveMesh",
"moveMeshNodes",
"mpmetis",
"NodeReordering",
"ogs",
"OGS2VTK",
"partmesh",
"PVD2XDMF",
"queryMesh",
"Raster2Mesh",
"RemoveGhostData",
"removeMeshElements",
"ResetPropertiesInPolygonalRegion",
"reviseMesh",
"scaleProperty",
"swapNodeCoordinateAxes",
"TecPlotTools",
"tetgen",
"TIN2VTK",
"VTK2OGS",
"VTK2TIN",
"vtkdiff",
"Vtu2Grid",
]

if "PEP517_BUILD_BACKEND" not in os.environ:
OGS_BIN_DIR = os.path.join(os.path.join(os.path.dirname(__file__), "..", "bin"))

if platform.system() == "Windows":
os.add_dll_directory(OGS_BIN_DIR)

def _program(name, args):
return subprocess.run([os.path.join(OGS_BIN_DIR, name)] + args).returncode

FUNC_TEMPLATE = """def {0}(): raise SystemExit(_program("{0}", sys.argv[1:]))"""
for f in binaries_list:
exec(FUNC_TEMPLATE.format(f))
10 changes: 9 additions & 1 deletion Applications/Utils/GeoTools/addDataToRaster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "GeoLib/AABB.h"
#include "GeoLib/Point.h"
#include "GeoLib/Raster.h"
#include "InfoLib/GitInfo.h"

double compute2DGaussBellCurveValues(GeoLib::Point const& point,
GeoLib::AABB const& aabb)
Expand Down Expand Up @@ -51,7 +52,14 @@ double computeSinXSinY(GeoLib::Point const& point, GeoLib::AABB const& aabb)

int main(int argc, char* argv[])
{
TCLAP::CmdLine cmd("Add values to raster.", ' ', "0.1");
TCLAP::CmdLine cmd(
"Add values to raster.\n\n"
"OpenGeoSys-6 software, version " +
GitInfoLib::GitInfo::ogs_version +
".\n"
"Copyright (c) 2012-2022, OpenGeoSys Community "
"(http://www.opengeosys.org)",
' ', GitInfoLib::GitInfo::ogs_version);

TCLAP::ValueArg<std::string> out_raster_arg(
"o",
Expand Down
11 changes: 9 additions & 2 deletions Applications/Utils/GeoTools/createRaster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,18 @@
#include "GeoLib/AABB.h"
#include "GeoLib/Point.h"
#include "GeoLib/Raster.h"
#include "InfoLib/GitInfo.h"

int main(int argc, char* argv[])
{
TCLAP::CmdLine cmd("Create a raster where every pixel is zero.", ' ',
"0.1");
TCLAP::CmdLine cmd(
"computeSurfaceNodeIDsInPolygonalRegion\n\n"
"OpenGeoSys-6 software, version " +
GitInfoLib::GitInfo::ogs_version +
".\n"
"Copyright (c) 2012-2022, OpenGeoSys Community "
"(http://www.opengeosys.org)",
' ', GitInfoLib::GitInfo::ogs_version);

TCLAP::ValueArg<std::string> output_arg("o", "output",
"Name of the output raster (*.asc)",
Expand Down
2 changes: 1 addition & 1 deletion Applications/Utils/MeshEdit/appendLinesAlongPolyline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ int main(int argc, char* argv[])
"the name of the geometry file");
cmd.add(geoFileArg);

TCLAP::ValueArg<std::string> gmsh_path_arg("g", "gmsh-path",
TCLAP::ValueArg<std::string> gmsh_path_arg("", "gmsh-path",
"the path to the gmsh binary",
false, "", "path as string");
cmd.add(gmsh_path_arg);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ int main(int argc, char* argv[])
true, "", "file name of input geometry");
cmd.add(geo_in);

TCLAP::ValueArg<std::string> gmsh_path_arg("g", "gmsh-path",
TCLAP::ValueArg<std::string> gmsh_path_arg("", "gmsh-path",
"the path to the gmsh binary",
false, "", "path as string");
cmd.add(gmsh_path_arg);
Expand Down
7 changes: 2 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,9 @@ cmake_minimum_required(VERSION 3.22)
project(OGS-6)

option(OGS_USE_PYTHON "Interface with Python" ON)
include(CMakeDependentOption)
cmake_dependent_option(
OGS_BUILD_PYTHON_MODULE "Should the OGS Python module be built?" ON
"OGS_USE_PYTHON" OFF
)
option(OGS_BUILD_PYTHON_MODULE "Should the OGS Python module be built?" ON)

include(CMakeDependentOption)
include(scripts/cmake/DownloadCpmCache.cmake)
include(scripts/cmake/CPM.cmake)
include(scripts/cmake/CMakeSetup.cmake)
Expand Down
41 changes: 41 additions & 0 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,39 @@
"OGS_USE_PYTHON": "OFF",
"OGS_USE_UNITY_BUILDS": "OFF"
}
},
{
"name": "wheel",
"inherits": "release",
"cacheVariables": {
"HDF5_USE_STATIC_LIBRARIES": "ON",
"OGS_BUILD_HDF5": "ON",
"OGS_USE_PYTHON": "OFF",
"OGS_BUILD_PYTHON_MODULE": "ON",
"OGS_BUILD_TESTING": "OFF",
"OGS_INSTALL_DEPENDENCIES": "OFF",
"OGS_USE_PIP": "OFF",
"OGS_USE_MFRONT": "ON",
"BUILD_SHARED_LIBS": "ON"
},
"condition": {
"type": "notEquals",
"lhs": "${hostSystemName}",
"rhs": "Windows"
}
},
{
"name": "wheel-win",
"inherits": "wheel",
"cacheVariables": {
"OGS_USE_MFRONT": "OFF",
"OGS_BUILD_PROCESS_TH2M": "OFF"
},
"condition": {
"type": "equals",
"lhs": "${hostSystemName}",
"rhs": "Windows"
}
}
],
"buildPresets": [
Expand Down Expand Up @@ -270,6 +303,14 @@
{
"name": "ci-no-unity",
"configurePreset": "ci-no-unity"
},
{
"name": "wheel",
"configurePreset": "wheel"
},
{
"name": "wheel-win",
"configurePreset": "wheel-win"
}
],
"testPresets": [
Expand Down
3 changes: 3 additions & 0 deletions MaterialLib/SolidModels/Ehlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -842,6 +842,9 @@ SolidEhlers<DisplacementDim>::getInternalVariables() const
template class SolidEhlers<2>;
template class SolidEhlers<3>;

template struct StateVariables<2>;
template struct StateVariables<3>;

template <>
MathLib::KelvinVector::KelvinMatrixType<3> sOdotS<3>(
MathLib::KelvinVector::KelvinVectorType<3> const& v)
Expand Down
10 changes: 6 additions & 4 deletions MaterialLib/SolidModels/Ehlers.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,10 @@

#include "BaseLib/Error.h"
#include "MathLib/KelvinVector.h"
#include "MechanicsBase.h"
#include "NumLib/NewtonRaphson.h"
#include "ParameterLib/Parameter.h"

#include "MechanicsBase.h"

namespace MaterialLib
{
namespace Solids
Expand Down Expand Up @@ -250,8 +249,8 @@ struct StateVariables
Damage damage_prev; ///< \copydoc damage

#ifndef NDEBUG
friend std::ostream& operator<<(
std::ostream& os, StateVariables<DisplacementDim> const& m)
friend std::ostream& operator<<(std::ostream& os,
StateVariables<DisplacementDim> const& m)
{
os << "State:\n"
<< "eps_p_D: " << m.eps_p.D << "\n"
Expand Down Expand Up @@ -358,6 +357,9 @@ class SolidEhlers final : public MechanicsBase<DisplacementDim>

extern template class SolidEhlers<2>;
extern template class SolidEhlers<3>;

extern template struct StateVariables<2>;
extern template struct StateVariables<3>;
} // namespace Ehlers
} // namespace Solids
} // namespace MaterialLib
Loading

0 comments on commit 5d0ac0c

Please sign in to comment.