Skip to content
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

Write eos in cpp #24

Open
wants to merge 23 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
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
6 changes: 5 additions & 1 deletion .azure-templates/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,17 @@ jobs:
- script: |
conda config --system --set always_yes yes --set changeps1 no
conda config --system --append channels conda-forge
conda install -n base conda-devenv conda=4.6.14
conda install -n base conda-devenv
displayName: 'Configuring conda'

- script: |
conda devenv
displayName: 'Running conda devenv'

- script: |
mkdir build ; cd build ; cmake ../ ; cmake --build . --target install --config Release; cd ..
displayName: 'Build and Install'

- script: |
source activate gibbs-py$(py_version)
pytest -n auto --cov-config=.coveragerc --junitxml=junit/test-results.xml --cov-report=xml --cov-report=html --cov=gibbs
Expand Down
6 changes: 5 additions & 1 deletion .azure-templates/osx.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,17 @@ jobs:
- script: |
conda config --system --set always_yes yes --set changeps1 no
conda config --system --append channels conda-forge
conda install -n base conda-devenv conda=4.6.14
conda install -n base conda-devenv
displayName: 'Configuring conda'

- script: |
conda devenv
displayName: 'Running conda devenv'

- script: |
mkdir build ; cd build ; cmake ../ ; cmake --build . --target install --config Release; cd ..
displayName: 'Build and Install'

- script: |
source activate gibbs-py$(py_version)
pytest --cov-config=.coveragerc --junitxml=junit/test-results.xml --cov-report=xml --cov-report=html --cov=gibbs
Expand Down
6 changes: 5 additions & 1 deletion .azure-templates/win.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,18 @@ jobs:
- script: |
conda config --system --set always_yes yes --set changeps1 no
conda config --system --append channels conda-forge
conda install -n base conda-devenv conda=4.6.14
conda install -n base conda-devenv
displayName: 'Configuring conda'

- script: |
conda info -a
conda devenv
displayName: 'Running conda devenv'

- script: |
mkdir build ; cd build ; cmake ../ ; cmake --build . --target install --config Release; cd ..
displayName: 'Build and Install'

- script: |
call activate gibbs-py$(py_version)
pytest -n auto --cov-config=.coveragerc --junitxml=junit/test-results.xml --cov-report=xml --cov-report=html --cov=gibbs
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,6 @@ __pycache__/

# VI/VIM
*.swp

# Cpp
*.so
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ env:

os:
- linux
- osx

before_install:
- if [ "$TRAVIS_OS_NAME" = "linux" ]; then OS=Linux-x86_64; else OS=MacOSX-x86_64; fi
Expand All @@ -24,11 +25,12 @@ before_install:
- export CONDA=$CONDA_BIN/conda
- $CONDA config --system --set always_yes yes --set changeps1 false
- $CONDA config --system --append channels conda-forge
- $CONDA install -n base conda-devenv conda=4.6.14
- $CONDA install -n base conda-devenv

install:
- $CONDA devenv
- source $CONDA_BIN/activate gibbs-py$PY_VERSION
- mkdir build ; cd build ; cmake ../ ; cmake --build . --target install --config Release; cd ..

script:
- pytest -n auto --cov-config=.coveragerc --cov-report xml --cov=gibbs
Expand Down
63 changes: 63 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
cmake_minimum_required(VERSION 2.8.12)

# Identifying and locating conda dir
if (EXISTS $ENV{HOME}/miniconda )
set(miniconda "miniconda")
elseif(EXISTS $ENV{HOME}/miniconda3 )
set(miniconda "miniconda3")
endif ()

set(PYTHON_EXECUTABLE $ENV{HOME}/${miniconda}/envs/gibbs-py36/bin/python)
set(conda_env_path $ENV{HOME}/${miniconda})
set(INCLUDE_CONDA ${conda_env_path}/include)

# Better don't use the following set command, but to get the right compilers form conda envs, it's necessary,
# unfortunately.
set(CMAKE_CXX_COMPILER $ENV{HOME}/${miniconda}/envs/gibbs-py36/bin/g++)
set(CMAKE_CXX_STANDARD 17)

project(eos LANGUAGES CXX C)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif()
set(CMAKE_CXX_FLAGS_DEBUG "-g")
set(CMAKE_CXX_FLAGS_RELEASE "-O3")
add_compile_options("-fPIC") # Necessary for the linking

# Eigen is header-only, so it only needs to include the directory with the headers
set(Eigen3_INCLUDE_DIR $ENV{HOME}/${miniconda}/envs/gibbs-py36/include/eigen3)
if( NOT Eigen3_INCLUDE_DIR )
message(FATAL_ERROR "Please point the environment variable Eigen3_INCLUDE_DIR to the include directory of your
Eigen3 installation.")
endif()
include_directories("${Eigen3_INCLUDE_DIR}")

find_package(pybind11 REQUIRED)
#find_package(Boost REQUIRED)

set(ARTIFACTS_PATH ${CMAKE_SOURCE_DIR}/gibbs/_cpp_binding)

add_subdirectory(gibbs)
target_link_libraries(eos)

include_directories(gibbs/eos_cpp)

message("\n*** Dependencies and infos:")
message("-- miniconda: $ENV{HOME}/${miniconda}")
message("-- cmake project root: ${CMAKE_SOURCE_DIR}")
message("-- conda path: ${conda_env_path}")
message("-- conda include path: ${INCLUDE_CONDA}")
message("-- Eigen3 path: ${Eigen3_INCLUDE_DIR}")
message("-- pybind11_DIR: " ${pybind11_DIR})
message("-- Python executable: " ${PYTHON_EXECUTABLE})
if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
message("-- CXX compiler: Clang")
add_compile_options("-fsized-deallocation")
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
message("-- CXX compiler: GNU")
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel")
message("-- CXX compiler: Intel")
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
message("-- CXX compiler: MSVC")
endif()
message("***\n")
1 change: 1 addition & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ install:
- cmd: conda install -n base conda-devenv
- cmd: conda devenv
- cmd: activate gibbs-py36
- cmd: mkdir build ; cd build ; cmake ../ ; cmake --build . --target install --config Release; cd ..
test_script:
- cmd: pytest -n auto
- cmd: cd notebooks
Expand Down
14 changes: 13 additions & 1 deletion environment.devenv.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
{% set CONDA_PY = os.environ.get('CONDA_PY', '36') %}
name: gibbs-py{{ CONDA_PY }}

channels:
- conda-forge
dependencies:
# Cpp stack
- clangdev >=6.0
- cmake < 3.15
- make
- eigen
- cxx-compiler

# For the bindings
- pybind11

# Python stack
- python=3.6
- attrs
- numpy
Expand Down
8 changes: 8 additions & 0 deletions environment.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
# generated by conda-devenv, do not modify and do not commit to VCS
channels:
- conda-forge
dependencies:
- altair
- attrs
- clangdev >=6.0
- cmake < 3.15
- codecov
- cxx-compiler
- eigen
- git
- hypothesis
- jupyter
- jupyter_contrib_nbextensions
- jupyter_nbextensions_configurator
- make
- matplotlib
- nbval
- numpy
- pandas
- pybind11
- pygmo
- pylint
- pytest
Expand Down
3 changes: 3 additions & 0 deletions gibbs/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
project(root)
add_subdirectory(eos_cpp)
add_subdirectory(bindings)
Empty file added gibbs/_cpp_binding/__init__.py
Empty file.
8 changes: 8 additions & 0 deletions gibbs/_cpp_wrapper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import gibbs._cpp_binding._eos as eos_cpp

Mixture = eos_cpp.Mixture
PengRobinson = eos_cpp.PengRobinson
SoaveRedlichKwong = eos_cpp.SoaveRedlichKwong
PengRobinson78 = eos_cpp.PengRobinson78
_cubic_cardano_real_positive_roots = eos_cpp._cubic_cardano_real_positive_roots
_cubic_cardano_real_roots = eos_cpp._cubic_cardano_real_roots
28 changes: 28 additions & 0 deletions gibbs/bindings/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
project(_eos)
find_package(pybind11 REQUIRED)
#set(pybind11_DIR third_party/pybind11/tools)
#include(pybind11Tools)

if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
add_compile_options("-fsized-deallocation")
endif()

include_directories("${CMAKE_SOURCE_DIR}/gibbs")

# Generate Python module with pybind11
pybind11_add_module(
_eos
_eos.cpp
)

target_link_libraries(
_eos
PRIVATE
eos
)
install(
TARGETS _eos
RUNTIME DESTINATION ${ARTIFACTS_PATH}
LIBRARY DESTINATION ${ARTIFACTS_PATH}
ARCHIVE DESTINATION ${ARTIFACTS_PATH}
)
Loading