3
0
mirror of https://github.com/triqs/dft_tools synced 2024-07-11 05:43:48 +02:00

First draft of the triqs application skeleton

This commit is contained in:
Nils Wentzell 2018-03-22 18:11:39 +01:00
parent dcce274810
commit 2b76c51f12
32 changed files with 943 additions and 0 deletions

45
.clang-format Normal file
View File

@ -0,0 +1,45 @@
BasedOnStyle: LLVM
AccessModifierOffset: 0
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: true
AlignConsecutiveDeclarations: false
AlignEscapedNewlinesLeft: false
AlignOperands: false
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine: true
AllowShortCaseLabelsOnASingleLine: true
AllowShortFunctionsOnASingleLine: All
AllowShortIfStatementsOnASingleLine: true
AllowShortLoopsOnASingleLine: true
AlwaysBreakBeforeMultilineStrings: true
AlwaysBreakTemplateDeclarations: false
BinPackArguments: true
BinPackParameters: true
BreakBeforeBinaryOperators: NonAssignment
BreakBeforeBraces: Attach
BreakBeforeTernaryOperators: false
BreakConstructorInitializersBeforeComma: false
BreakStringLiterals: false
ColumnLimit: 150
ConstructorInitializerAllOnOneLineOrOnePerLine: true
ConstructorInitializerIndentWidth: 3
ContinuationIndentWidth: 3
Cpp11BracedListStyle: true
DerivePointerBinding : false
IndentCaseLabels: true
IndentWidth: 2
Language: Cpp
MaxEmptyLinesToKeep: 1
NamespaceIndentation : All
PointerAlignment: Right
ReflowComments: false
SortIncludes: false
SpaceAfterControlStatementKeyword: true
SpaceBeforeAssignmentOperators: true
SpaceInEmptyParentheses: false
SpacesInParentheses: false
Standard: Cpp11
TabWidth: 2
UseTab: Never

1
.clang-tidy Normal file
View File

@ -0,0 +1 @@
Checks: '-*,modernize-*,cppcoreguidelines-*'

51
.travis.yml Normal file
View File

@ -0,0 +1,51 @@
language: cpp
sudo: required
dist: trusty
compiler:
- gcc
# - clang
before_install:
- sudo add-apt-repository 'deb http://apt.llvm.org/trusty/ llvm-toolchain-trusty-5.0 main' -y
- wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key|sudo apt-key add -
- sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y
- sudo apt-get update
- sudo apt-get install -y --allow-unauthenticated g++-7 clang-5.0
- export LIBRARY_PATH=/usr/lib/llvm-5.0/lib:$LIBRARY_PATH
- sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-7 60 --slave /usr/bin/g++ g++ /usr/bin/g++-7
- sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-5.0 60 --slave /usr/bin/clang++ clang++ /usr/bin/clang++-5.0
- sudo apt-get install -y --allow-unauthenticated libboost-all-dev cmake git libgfortran3 gfortran openmpi-bin openmpi-common openmpi-doc libopenmpi-dev libblas-dev liblapack-dev libfftw3-dev libgmp-dev hdf5-tools libhdf5-serial-dev python-h5py python-dev python-numpy python-scipy python-jinja2 python-virtualenv python-matplotlib python-tornado python-zmq python-mpi4py python-mako clang-format-5.0 libclang-5.0-dev python-clang-5.0 python-sphinx libjs-mathjax valgrind libnfft3-dev
install: true
script:
# ===== Set up Cpp2Py
- git clone https://github.com/triqs/cpp2py
- mkdir cpp2py/build && cd cpp2py/build
- git checkout master
- cmake .. -DCMAKE_CXX_COMPILER=/usr/bin/${CXX} -DPYTHON_INTERPRETER=/usr/bin/python -DCMAKE_INSTALL_PREFIX=$TRAVIS_BUILD_DIR/root_install
- make -j8 install
- cd $TRAVIS_BUILD_DIR
- source root_install/share/cpp2pyvars.sh
# ===== Set up TRIQS
- git clone https://github.com/TRIQS/triqs --branch unstable
- mkdir triqs/build && cd triqs/build
- git checkout unstable
- cmake .. -DCMAKE_CXX_COMPILER=/usr/bin/${CXX} -DBuild_Tests=OFF -DCMAKE_INSTALL_PREFIX=$TRAVIS_BUILD_DIR/root_install -DCMAKE_BUILD_TYPE=Debug
- make -j8 install
- cd $TRAVIS_BUILD_DIR
- source root_install/share/triqsvars.sh
# ===== Set up CTINT and Test using fsanitize=address
- mkdir build && cd build
- cmake .. -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_COMPILER=/usr/bin/${CXX} -DGTAU_IS_COMPLEX=ON -DINTERACTION_IS_COMPLEX=ON -DCMAKE_CXX_FLAGS='-fsanitize=address -fno-omit-frame-pointer -fuse-ld=gold -Wno-register -Wno-macro-redefined'
- make -j8
- export ASAN_SYMBOLIZER_PATH=/usr/lib/llvm-5.0/bin/llvm-symbolizer
- export ASAN_OPTIONS=symbolize=1:detect_leaks=0
- export CTEST_OUTPUT_ON_FAILURE=1
- cd test/c++ && ctest
- if [ "$CXX" = g++ ]; then export LD_PRELOAD=/usr/lib/gcc/x86_64-linux-gnu/7/libasan.so; elif [ "$CXX" = clang++ ]; then export LD_PRELOAD=/usr/lib/llvm-5.0/lib/clang/5.0.1/lib/linux/libclang_rt.asan-x86_64.so; fi
- cd ../python && ctest
- cd ../../
- unset LD_PRELOAD

60
CMakeLists.txt Normal file
View File

@ -0,0 +1,60 @@
# Version number
set (APP4TRIQS_VERSION "1.5")
# Start configuration
cmake_minimum_required(VERSION 2.8)
project(app4triqs CXX)
# Default to Release build type
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release CACHE STRING "Type of build" FORCE)
endif()
message( STATUS "-------- BUILD-TYPE: ${CMAKE_BUILD_TYPE} -------------")
# Use shared libraries
set(BUILD_SHARED_LIBS ON)
# Load TRIQS and Cpp2Py
find_package(TRIQS 1.5 EXACT REQUIRED)
find_package(Cpp2Py 1.5 EXACT REQUIRED)
# We will need the FindNNFT of triqs, so we adjust CMake Module Path to find it
list(APPEND CMAKE_MODULE_PATH ${TRIQS_ROOT}/share/cmake)
# Default Install directory to TRIQS_ROOT if not given. Checks an absolute name is given.
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT OR (NOT IS_ABSOLUTE ${CMAKE_INSTALL_PREFIX}))
message(STATUS " No install prefix given (or invalid). Defaulting to TRIQS_ROOT")
set(CMAKE_INSTALL_PREFIX ${TRIQS_ROOT} CACHE PATH "default install path" FORCE)
endif()
message(STATUS "-------- CMAKE_INSTALL_PREFIX: ${CMAKE_INSTALL_PREFIX} -------------")
# Macro defined in TRIQS which picks the hash of repo.
triqs_get_git_hash_of_source_dir(APP4TRIQS_GIT_HASH)
message(STATUS "Git hash: ${APP4TRIQS_GIT_HASH}")
# Common to all targets (c++, python, tests).
include_directories(c++)
# Set up the rpath for compiled executable
triqs_set_rpath_for_all_targets()
add_subdirectory(c++/app4triqs)
if(${TRIQS_WITH_PYTHON_SUPPORT})
add_subdirectory(python/app4triqs)
endif()
# Tests
enable_testing()
add_subdirectory(test)
# Additional configuration files
add_subdirectory(share)
option(Build_Documentation "Build documentation" OFF)
if(${Build_Documentation})
if(NOT ${TRIQS_WITH_DOCUMENTATION})
message("Error: TRIQS library has not been compiled with its documentation")
else()
add_subdirectory(doc)
endif()
endif()

10
Dockerfile Normal file
View File

@ -0,0 +1,10 @@
# See ../triqs/packaging for other options
FROM flatironinstitute/triqs:master-ubuntu-clang
COPY . ${SRC}/app4triqs
WORKDIR ${BUILD}/app4triqs
RUN chown build .
USER build
RUN cmake ${SRC}/app4triqs -DTRIQS_ROOT=${INSTALL} && make -j2 && make test
USER root
RUN make install

113
Jenkinsfile vendored Normal file
View File

@ -0,0 +1,113 @@
def app4triqsBranch = env.CHANGE_TARGET ?: env.BRANCH_NAME
def app4triqsProject = '/TRIQS/app4triqs/' + app4triqsBranch.replaceAll('/', '%2F')
properties([
disableConcurrentBuilds(),
buildDiscarder(logRotator(numToKeepStr: '10', daysToKeepStr: '30')),
pipelineTriggers([
upstream(
threshold: 'SUCCESS',
upstreamProjects: app4triqsProject
)
])
])
def platforms = [:]
def dockerPlatforms = ["ubuntu-clang", "ubuntu-gcc", "centos-gcc"]
for (int i = 0; i < dockerPlatforms.size(); i++) {
def platform = dockerPlatforms[i]
platforms[platform] = { -> stage(platform) {
timeout(time: 1, unit: 'HOURS') {
node('docker') {
checkout scm
/* construct a Dockerfile for this base */
sh """
( echo "FROM flatironinstitute/app4triqs:${app4triqsBranch}-${env.STAGE_NAME}" ; sed '0,/^FROM /d' Dockerfile ) > Dockerfile.jenkins
mv -f Dockerfile.jenkins Dockerfile
"""
/* build and tag */
def img = docker.build("flatironinstitute/app4triqs:${env.BRANCH_NAME}-${env.STAGE_NAME}")
/* but we don't need the tag so clean it up (alternatively, could refacter to run in container) */
sh "docker rmi ${img.imageName()}"
}
}
} }
}
def osxPlatforms = [
["gcc", ['CC=gcc-7', 'CXX=g++-7']],
["clang", ['CC=/usr/local/opt/llvm/bin/clang', 'CXX=/usr/local/opt/llvm/bin/clang++', 'CXXFLAGS=-I/usr/local/opt/llvm/include', 'LDFLAGS=-L/usr/local/opt/llvm/lib']]
]
for (int i = 0; i < osxPlatforms.size(); i++) {
def platformEnv = osxPlatforms[i]
def platform = platformEnv[0]
platforms["osx-$platform"] = { -> stage("osx-$platform") {
timeout(time: 1, unit: 'HOURS') {
node('osx && triqs') {
def srcDir = pwd()
def tmpDir = pwd(tmp:true)
def buildDir = "$tmpDir/build"
def installDir = "$tmpDir/install"
dir(installDir) {
deleteDir()
}
copyArtifacts(projectName: app4triqsProject, selector: upstream(fallbackToLastSuccessful: true), filter: "osx-${platform}.zip")
unzip(zipFile: "osx-${platform}.zip", dir: installDir)
/* fixup zip-stripped permissions (JENKINS-13128) */
sh "chmod +x $installDir/bin/*"
checkout scm
dir(buildDir) { withEnv(platformEnv[1]+[
"PATH=$installDir/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin",
"CPATH=$installDir/include",
"LIBRARY_PATH=$installDir/lib",
"CMAKE_PREFIX_PATH=$installDir/share/cmake"]) {
deleteDir()
sh "cmake $srcDir -DTRIQS_ROOT=$installDir"
sh "make -j2"
try {
sh "make test"
} catch (exc) {
archiveArtifacts(artifacts: 'Testing/Temporary/LastTest.log')
throw exc
}
sh "make install"
} }
// zip(zipFile: "osx-${platform}.zip", archive: true, dir: installDir)
}
}
} }
}
try {
parallel platforms
} catch (err) {
emailext(
subject: "\$PROJECT_NAME - Build # \$BUILD_NUMBER - FAILED",
body: """\$PROJECT_NAME - Build # \$BUILD_NUMBER - FAILED
$err
Check console output at \$BUILD_URL to view full results.
Building \$BRANCH_NAME for \$CAUSE
\$JOB_DESCRIPTION
Chages:
\$CHANGES
End of build log:
\${BUILD_LOG,maxLines=60}
""",
to: 'nils.wentzell@gmail.com, dsimon@flatironinstitute.org',
recipientProviders: [
[$class: 'DevelopersRecipientProvider'],
],
replyTo: '$DEFAULT_REPLYTO'
)
throw err
}

View File

@ -0,0 +1,19 @@
file(GLOB_RECURSE sources RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.cpp)
add_library(app4triqs_c ${sources})
target_link_libraries(app4triqs_c PUBLIC triqs)
target_compile_options(app4triqs_c PUBLIC -std=c++17)
target_compile_definitions(app4triqs_c PUBLIC
APP4TRIQS_GIT_HASH=${APP4TRIQS_GIT_HASH}
TRIQS_GIT_HASH=${TRIQS_GIT_HASH}
$<$<CONFIG:Debug>:DEBUG_APP4TRIQS>
$<$<CONFIG:Debug>:TRIQS_ARRAYS_ENFORCE_BOUNDCHECK>
#$<$<BOOL:${MyOption}>:MYOPTION> # Add compile definintions for option
)
# Install
install(TARGETS app4triqs_c DESTINATION lib)
# If other applications need our headers, we can install them as well
# install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} DESTINATION include FILES_MATCHING PATTERN "*.hpp" PATTERN "*.h")

37
c++/app4triqs/toto.cpp Normal file
View File

@ -0,0 +1,37 @@
#include <cmath>
#include "./toto.hpp"
namespace app4triqs {
toto &toto::operator+=(toto const &b) {
this->i += b.i;
return *this;
}
toto toto::operator+(toto const &b) const {
auto res = *this;
res += b;
return res;
}
bool toto::operator==(toto const &b) const { return (this->i == b.i); }
void h5_write(triqs::h5::group grp, std::string subgroup_name, toto const &m) {
grp = subgroup_name.empty() ? grp : grp.create_group(subgroup_name);
h5_write(grp, "i", m.i);
h5_write_attribute(grp, "TRIQS_HDF5_data_scheme", toto::hdf5_scheme());
}
void h5_read(triqs::h5::group grp, std::string subgroup_name, toto &m) {
grp = subgroup_name.empty() ? grp : grp.open_group(subgroup_name);
int i;
h5_read(grp, "i", i);
m = toto(i);
}
int chain(int i, int j) {
int n_digits_j = j > 0 ? (int)log10(j) + 1 : 1;
return i * int(pow(10, n_digits_j)) + j;
}
} // namespace app4triqs

68
c++/app4triqs/toto.hpp Normal file
View File

@ -0,0 +1,68 @@
#pragma once
#include <cpp2py.hpp>
#include <triqs/gfs.hpp>
namespace app4triqs {
/**
* A very useful and important class
*
* @note A Useful note
*/
class toto {
int i = 0.0;
public:
toto() = default;
// Copy construction
toto(toto const &) = default;
toto(toto &&) = default;
/**
* Construct from integer
*
* @param i_ a scalar
*/
toto(int i_) : i(i_) {}
/// Copy assignment
toto &operator=(toto const &) = default;
toto &operator=(toto &&) = default;
/// Simple accessor
int get_i() const { return i; }
/// Arithmetic operations
toto operator+(toto const &b) const;
toto &operator+=(toto const &b);
/// Comparison
bool operator==(toto const &b) const;
/// HDF5
static std::string hdf5_scheme() { return "Toto"; }
friend void h5_write(triqs::h5::group grp, std::string subgroup_name, toto const &m);
friend void h5_read(triqs::h5::group grp, std::string subgroup_name, toto &m);
/// Serialization
template <class Archive> void serialize(Archive &ar, const unsigned int version) { ar &i; }
};
/**
* Chain digits of two integers
*
* Chain the decimal digits of two integers i and j, and return the result
*
* @param :math:`i` The first integer
* @param :math:`j` The second integer
* @return An integer containing the digits of both i and j
*
* @remark
*/
int chain(int i, int j);
} // namespace app4triqs

58
doc/CMakeLists.txt Normal file
View File

@ -0,0 +1,58 @@
# Generate the conf.py
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/conf.py.in ${CMAKE_CURRENT_BINARY_DIR}/conf.py @ONLY)
# ---------------------------------
# Top Sphinx target
# ---------------------------------
# Sources
file(GLOB_RECURSE sources *.rst)
set(sphinx_top ${CMAKE_CURRENT_BINARY_DIR}/html/contents.html)
add_custom_command(OUTPUT ${sphinx_top} DEPENDS ${sources}
COMMAND ${TRIQS_SPHINXBUILD_EXECUTABLE} -c . -j8 -b html ${CMAKE_CURRENT_BINARY_DIR} html)
add_custom_target(docs_sphinx ALL DEPENDS ${sphinx_top} ${CMAKE_CURRENT_BINARY_DIR})
# Application must be compiled first
add_dependencies(docs_sphinx app4triqs_c)
# ------------------------------------------------------------------------------------------------
# Copy the directory substructure and link all files with relevant extensions
# cp_rs is a script in cpp2py/bin, it mimics cp -rs on Linux
# and filters the relevant extension
# ------------------------------------------------------------------------------------------------
set(EXT_FOR_DOC "rst png txt css_t conf css js gif jpg py html bib")
execute_process(COMMAND cp_rs ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} ${EXT_FOR_DOC})
# ---------------------------------
# Generate C++ doc with c++2rst
# ---------------------------------
add_custom_target(docs_cpp2rst)
macro(generate_docs header_file)
add_custom_command (TARGET docs_cpp2rst
COMMAND c++2rst
${header_file}
-N app4triqs
--output_directory ${CMAKE_CURRENT_BINARY_DIR}/cpp2rst_generated
--cxxflags="-std=c++17"
-I ${CMAKE_SOURCE_DIR}/c++
-I ${TRIQS_ROOT}/include
2>&1 >> cpp2rst.log
)
endmacro(generate_docs)
generate_docs(${CMAKE_SOURCE_DIR}/c++/app4triqs/toto.hpp)
add_dependencies(docs_sphinx docs_cpp2rst)
# ---------------------------------
# Install
# ---------------------------------
install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/html/ COMPONENT documentation DESTINATION share/doc/app4triqs
FILES_MATCHING
REGEX "\\.(html|pdf|png|gif|jpg|js|xsl|css|py|txt|inv|bib)$"
PATTERN "_*"
)

BIN
doc/_static/logo_erc.jpg vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 190 KiB

7
doc/_templates/sideb.html vendored Normal file
View File

@ -0,0 +1,7 @@
<p>
<a href="http://ipht.cea.fr"> <img style="width: 80px; margin: 10px 5px 0 0" src='_static/logo_cea.png' alt="CEA"/> </a>
<a href="http://www.cpht.polytechnique.fr"> <img style="width: 80px; margin: 10px 5px 0 5px" src='_static/logo_x.png' alt="Ecole Polytechnique"/> </a>
<br>
<a href="http://www.cnrs.fr"> <img style="width: 80px; margin: 10px 0 0 5px" src='_static/logo_cnrs.png' alt="CNRS"/> </a>
<img style="width: 80px; margin: 10px 0 0 5px" src='_static/logo_erc.jpg' alt="ERC"/>
</p>

3
doc/about.rst Normal file
View File

@ -0,0 +1,3 @@
.. _about:
An example application using cpp2py and triqs.

32
doc/conf.py.in Normal file
View File

@ -0,0 +1,32 @@
# -*- coding: utf-8 -*-
#
# TRIQS documentation build configuration file
extensions = ['sphinx.ext.autodoc',
'sphinx.ext.mathjax',
'sphinx.ext.intersphinx',
'matplotlib.sphinxext.plot_directive']
source_suffix = '.rst'
project = u'APP4TRIQS - An example triqs application'
copyright = u'2018 - The TRIQS Developers'
mathjax_path = "@TRIQS_MATHJAX_PATH@/MathJax.js?config=default"
templates_path = ['@CMAKE_SOURCE_DIR@/doc/_templates']
html_theme = 'triqs'
html_theme_path = ['@TRIQS_THEMES_PATH@']
html_show_sphinx = False
html_context = {'header_title': 'app4triqs',
'header_subtitle': 'An example application using cpp2py and triqs',
'header_links': [['Install', 'install'],
['Documentation', 'documentation'],
['Issues', 'issues'],
['About app4triqs', 'about']]}
html_static_path = ['@CMAKE_SOURCE_DIR@/doc/_static']
html_sidebars = {'index': ['sideb.html', 'searchbox.html']}
htmlhelp_basename = 'TRIQSIntdoc'
intersphinx_mapping = {'python': ('http://docs.python.org/2.7', None), 'triqslibs': ('http://ipht.cea.fr/triqs', None)}

12
doc/contents.rst Normal file
View File

@ -0,0 +1,12 @@
Table of contents
=================
.. toctree::
:maxdepth: 5
index
documentation
install
issues
about

12
doc/documentation.rst Normal file
View File

@ -0,0 +1,12 @@
.. _documentation:
Documentation
=============
Reference manual
----------------
.. toctree::
:maxdepth: 1
cpp2rst_generated/app4triqs/compute_Sigma_Hedin

11
doc/index.rst Normal file
View File

@ -0,0 +1,11 @@
.. _welcome:
App4Triqs
=========
An example application using cpp2py and triqs.
This documentation is generated based on the doc/\*.rst files and
the comments in the sources and headers.
Lets have a look at the :ref:`documentation`.

62
doc/install.rst Normal file
View File

@ -0,0 +1,62 @@
.. highlight:: bash
.. _install:
Installation
============
Prerequisite
-------------------
#. The :ref:`TRIQS <triqslibs:welcome>` toolbox (see :ref:`TRIQS installation instruction <triqslibs:installation>`).
In the following, we will suppose that it is installed in the ``path_to_triqs`` directory.
Installation steps
------------------
#. Download the sources from github::
$ git clone https://github.com/triqs/app4triqs.git app4triqs.src
#. Create an empty build directory where you will compile the code::
$ mkdir app4triqs.build && cd app4triqs.build
#. Make sure that you have added the TRIQS and Cpp2Py installation to your environment variables::
$ source path_to_triqs/share/cpp2pyvarsh.sh
$ source path_to_triqs/share/triqsvarsh.sh
#. In the build directory call cmake::
$ cmake ../app4triqs.src
#. Compile the code, run the tests and install the application::
$ make
$ make test
$ make install
Version compatibility
---------------------
Be careful that the version of the TRIQS library and of the solver must be
compatible (more information on the :ref:`TRIQS website <triqslibs:versions>`).
As the TRILEX project is currently still in alpha phase (unstable), it can
only be compiled against the unstable branch of triqs.
Custom CMake options
--------------------
Functionality of ``app4triqs`` can be tweaked using extra compile-time options passed to CMake::
cmake -DOPTION1=value1 -DOPTION2=value2 ... ../app4triqs.src
+-----------------------------------------------------------------------+-----------------------------------------------+
| Options | Syntax |
+=======================================================================+===============================================+
| Specify an installation path other than path_to_triqs | -DCMAKE_INSTALL_PREFIX=path_to_app4triqs |
+-----------------------------------------------------------------------+-----------------------------------------------+
| Build the documentation locally | -DBuild_Documentation=ON |
+-----------------------------------------------------------------------+-----------------------------------------------+

23
doc/issues.rst Normal file
View File

@ -0,0 +1,23 @@
.. _issues:
Reporting issues
================
Please report all problems and bugs directly at the github issue page
`<https://github.com/TRIQS/app4triqs/issues>`_. In order to make it easier for us
to solve the issue please follow these guidelines:
#. In all cases specify which version of the application you are using. You can
find the version number in the file :file:`CMakeLists.txt` at the root of the
application sources.
#. If you have a problem during the installation, give us information about
your operating system and the compiler you are using. Include the outputs of
the ``cmake`` and ``make`` commands as well as the ``CMakeCache.txt`` file
which is in the build directory. Please include these outputs in a
`gist <http://gist.github.com/>`_ file referenced in the issue.
#. If you are experiencing a problem during the execution of the application, provide
a script which allows to quickly reproduce the problem.
Thanks!

View File

@ -0,0 +1,21 @@
# Build the python module
add_cpp2py_module(toto_module)
target_link_libraries(toto_module app4triqs_c)
# We need to include the convertes.hxx files
target_include_directories(toto_module PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
# Configure the version
configure_file(version.py.in version.py)
# All Python files. Copy them in the build dir to have a complete package for the tests.
set(PYTHON_SOURCES __init__.py)
foreach(f ${PYTHON_SOURCES})
configure_file(${f} ${f} COPYONLY)
endforeach()
# Install python module to proper location
set(PYTHON_LIB_DEST ${CPP2PY_PYTHON_LIB_DEST_ROOT}/app4triqs)
install(TARGETS toto_module DESTINATION ${PYTHON_LIB_DEST})
install(FILES ${PYTHON_SOURCES} ${CMAKE_CURRENT_BINARY_DIR}/version.py DESTINATION ${PYTHON_LIB_DEST})

View File

@ -0,0 +1,29 @@
################################################################################
#
# App4Triqs: Test application for Triqs
#
# Copyright (C) 2018 by The Simons Foundation
# Author: H. U.R. Strand
#
# App4Triqs is free software: you can redistribute it and/or modify it under the
# terms of the GNU General Public License as published by the Free Software
# Foundation, either version 3 of the License, or (at your option) any later
# version.
#
# App4Triqs is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# App4Triqs. If not, see <http://www.gnu.org/licenses/>.
#
################################################################################
r"""
DOC
"""
from toto_module import Toto, chain
__all__ = ['Toto', 'chain']

View File

@ -0,0 +1,51 @@
# Generated automatically using the command :
# c++2py ../../c++/app4triqs/toto.hpp -p --members_read_only -N app4triqs -a app4triqs -m toto_module -o toto_module -C pytriqs --cxxflags="-std=c++17"
from cpp2py.wrap_generator import *
# The module
module = module_(full_name = "toto_module", doc = "", app_name = "app4triqs")
# Imports
# Add here all includes
module.add_include("app4triqs/toto.hpp")
# Add here anything to add in the C++ code at the start, e.g. namespace using
module.add_preamble("""
#include <cpp2py/converters/string.hpp>
#include <triqs/cpp2py_converters/h5.hpp>
using namespace app4triqs;
""")
# The class toto
c = class_(
py_type = "Toto", # name of the python class
c_type = "app4triqs::toto", # name of the C++ class
doc = """A very useful and important class\n\n @note A Useful note""", # doc of the C++ class
hdf5 = True,
arithmetic = ("add_only"),
comparisons = "==",
serializable = "tuple",
)
c.add_constructor("""()""", doc = """""")
c.add_constructor("""(int i_)""", doc = """Construct from integer\n\n :param i_: a scalar""")
c.add_method("""std::string hdf5_scheme ()""",
is_static = True,
doc = """HDF5""")
c.add_property(name = "i",
getter = cfunction("int get_i ()"),
doc = """Simple accessor""")
module.add_class(c)
module.add_function ("int app4triqs::chain (int i, int j)", doc = """Chain digits of two integers\n\n Chain the decimal digits of two integers i and j, and return a new \n\n @param :math:`i` The first integer\n @param :math:`j` The second integer \n @return An integer containing the digits of both i and j\n\n @remark""")
module.generate_code()

View File

@ -0,0 +1,31 @@
################################################################################
#
# App4Triqs: Test application for Triqs
#
# Copyright (C) 2018 by The Simons Foundation
# Author: H. U.R. Strand
#
# App4Triqs is free software: you can redistribute it and/or modify it under the
# terms of the GNU General Public License as published by the Free Software
# Foundation, either version 3 of the License, or (at your option) any later
# version.
#
# App4Triqs is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# App4Triqs. If not, see <http://www.gnu.org/licenses/>.
#
################################################################################
version = "@APP4TRIQS_VERSION@"
triqs_hash = "@TRIQS_GIT_HASH@"
app4triqs_hash = "@APP4TRIQS_GIT_HASH@"
def show_version():
print "\nYou are using app4triqs version %s, release %s\n"%(version, release)
def show_git_hash():
print "\nYou are using app4triqs git hash %s based on triqs git hash %s\n"%(app4triqs_hash, triqs_hash)

17
share/CMakeLists.txt Normal file
View File

@ -0,0 +1,17 @@
if(NOT CMAKE_INSTALL_PREFIX STREQUAL TRIQS_ROOT)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/app4triqs.modulefile.in ${CMAKE_CURRENT_BINARY_DIR}/app4triqs.modulefile @ONLY)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/app4triqs.modulefile DESTINATION ${CMAKE_INSTALL_PREFIX}/share)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/app4triqsvars.sh.in ${CMAKE_CURRENT_BINARY_DIR}/app4triqsvars.sh @ONLY)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/app4triqsvars.sh DESTINATION ${CMAKE_INSTALL_PREFIX}/share)
message(STATUS "***************************************************************")
message(STATUS "* Custom install Location. Use: ")
message(STATUS "* ")
message(STATUS "* source ${CMAKE_INSTALL_PREFIX}/share/app4triqsvars.sh ")
message(STATUS "* ")
message(STATUS "* to set up the environment variables ")
message(STATUS "***************************************************************")
endif()

View File

@ -0,0 +1,39 @@
#%Module1.0
#
# To be installed as ${MODULEPATH}/app4triqs/@APP4TRIQS_VERSION@
set name app4triqs
set version @APP4TRIQS_VERSION@
set root @CMAKE_INSTALL_PREFIX@
set git_hash @APP4TRIQS_GIT_HASH@
set url "https://github.com/TRIQS/app4triqs"
set description "An example application using cpp2py and triqs."
module-whatis "$description"
proc ModulesHelp { } {
global description url version git_hash
puts stderr "Description: $description"
puts stderr "URL: $url"
puts stderr "Version: $version"
puts stderr "Git hash: $git_hash"
}
# You may need to edit the next line if cpp2py module is installed
# under a different name in your setup.
prereq cpp2py/@CPP2PY_VERSION@
# Only one version of app4triqs can be loaded at a time
conflict $name
setenv APP4TRIQS_ROOT $root
setenv APP4TRIQS_VERSION $version
setenv APP4TRIQS_GIT_HASH $git_hash
prepend-path PATH $root/bin
prepend-path CPATH $root/include
prepend-path LIBRARY_PATH $root/lib
prepend-path LD_LIBRARY_PATH $root/lib
prepend-path PYTHONPATH $root/@CPP2PY_PYTHON_LIB_DEST_ROOT@
prepend-path CMAKE_PREFIX_PATH $root/share/cmake

13
share/app4triqsvars.sh.in Normal file
View File

@ -0,0 +1,13 @@
# Source this in your environment.
export TRIQS_ROOT=@CMAKE_INSTALL_PREFIX@
export CPATH=@CMAKE_INSTALL_PREFIX@/include:$CPATH
export PATH=@CMAKE_INSTALL_PREFIX@/bin:$PATH
export LIBRARY_PATH=@CMAKE_INSTALL_PREFIX@/lib:$LIBRARY_PATH
export LD_LIBRARY_PATH=@CMAKE_INSTALL_PREFIX@/lib:$LD_LIBRARY_PATH
export PYTHONPATH=@CMAKE_INSTALL_PREFIX@/@CPP2PY_PYTHON_LIB_DEST_ROOT@:$PYTHONPATH
export CMAKE_PREFIX_PATH=@CMAKE_INSTALL_PREFIX@/share/cmake:$CMAKE_PREFIX_PATH

4
test/CMakeLists.txt Normal file
View File

@ -0,0 +1,4 @@
add_subdirectory(c++)
if (${TRIQS_WITH_PYTHON_SUPPORT})
add_subdirectory(python)
endif()

11
test/c++/CMakeLists.txt Normal file
View File

@ -0,0 +1,11 @@
# Copy reference h5 files to binary dir
file(GLOB all_h5_files *.h5)
file(COPY ${all_h5_files} DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
set(all_tests toto)
foreach(t ${all_tests})
add_executable(${t} ${CMAKE_CURRENT_SOURCE_DIR}/${t}.cpp)
target_link_libraries(${t} app4triqs_c gtest)
add_test(${t} ${CMAKE_CURRENT_BINARY_DIR}/${t})
endforeach()

32
test/c++/toto.cpp Normal file
View File

@ -0,0 +1,32 @@
#include <triqs/test_tools/gfs.hpp>
#include <app4triqs/toto.hpp>
using namespace app4triqs;
TEST(Toto, Add) {
toto a(0);
toto b(2);
auto c = a + b;
EXPECT_EQ(c, b);
}
TEST(Toto, H5) {
toto a(0);
{ // Local scope for file
triqs::h5::file f("f.h5", H5F_ACC_TRUNC);
h5_write(f, "a", a);
}
toto a2;
{
triqs::h5::file f("f.h5", H5F_ACC_RDWR);
h5_read(f, "a", a2);
}
EXPECT_EQ(a, a2);
}
MAKE_MAIN;

View File

@ -0,0 +1,12 @@
# Copy h5 files to binary dir
file(GLOB all_h5_files *.h5)
file(COPY ${all_h5_files} DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
set(all_tests Toto chain)
foreach(t ${all_tests})
add_test(NAME ${t} COMMAND python ${CMAKE_CURRENT_SOURCE_DIR}/${t}.py)
endforeach()
# Set the PythonPath : put the build dir first (in case there is an installed version).
set_property(TEST ${all_tests} PROPERTY ENVIRONMENT PYTHONPATH=${CMAKE_BINARY_DIR}/python:$ENV{PYTHONPATH} )

42
test/python/Toto.py Normal file
View File

@ -0,0 +1,42 @@
#!/usr/bin/env python
import unittest
from app4triqs import Toto
from pytriqs.archive import *
from pytriqs.utility import mpi
class test_toto(unittest.TestCase):
def test_add(self):
a=Toto(0)
b=Toto(2)
c=a+b
self.assertEqual(c, b)
def test_h5(self):
a=Toto(0)
with HDFArchive("f.h5",'a') as A:
A["a"] = a
with HDFArchive("f.h5",'r') as A:
a_read = A["a"]
self.assertEqual(a, a_read)
def test_mpi(self):
a=Toto(0)
if mpi.is_master_node():
a=Toto(1)
mpi.bcast(a)
self.assertEqual(a, Toto(1))
if __name__ == '__main__':
unittest.main()

17
test/python/chain.py Normal file
View File

@ -0,0 +1,17 @@
#!/usr/bin/env python
import unittest
from app4triqs import chain
class test_chain(unittest.TestCase):
def test_chain(self):
i = 111
j = 222
ij = chain(i,j)
self.assertEqual(ij, 111222)
if __name__ == '__main__':
unittest.main()