Commit 11a57df6 authored by Mccaskey, Alex's avatar Mccaskey, Alex
Browse files

moving xacc-python to framework


Signed-off-by: Mccaskey, Alex's avatarAlex McCaskey <mccaskeyaj@ornl.gov>
parent 019168ce
...@@ -90,12 +90,31 @@ ExternalProject_Add(xacc-quantum ...@@ -90,12 +90,31 @@ ExternalProject_Add(xacc-quantum
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
-DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS} -DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}
-DXACC_ROOT=${CMAKE_CURRENT_SOURCE_DIR} -DXACC_ROOT=${CMAKE_CURRENT_SOURCE_DIR}
-DBOOST_ROOT=${BOOST_ROOT} -DBOOST_ROOT=${BOOST_ROOT}
-DCPPUS_INCLUDE_DIR=${CppMicroServices_INCLUDE_DIR} -DCPPUS_INCLUDE_DIR=${CppMicroServices_INCLUDE_DIR}
-DCPPUS_LIBRARY_DIR=${CppMicroServices_LIBRARY_DIR} -DCPPUS_LIBRARY_DIR=${CppMicroServices_LIBRARY_DIR}
-DXACC_INCLUDE_DIR=${CMAKE_INSTALL_PREFIX}/include/xacc #${XACC_INCLUDE_DIR} -DXACC_INCLUDE_DIR=${CMAKE_INSTALL_PREFIX}/include/xacc #${XACC_INCLUDE_DIR}
-DXACC_LIBRARY_DIR=${CMAKE_INSTALL_PREFIX}/lib #${XACC_LIBRARY_DIR} -DXACC_LIBRARY_DIR=${CMAKE_INSTALL_PREFIX}/lib #${XACC_LIBRARY_DIR}
CMAKE_CACHE_ARGS -DCMAKE_PREFIX_PATH:PATH=${CMAKE_PREFIX_PATH}
BUILD_ALWAYS 1
INSTALL_COMMAND ${CMAKE_MAKE_PROGRAM} install #DESTDIR=${CMAKE_BINARY_DIR}/stage
TEST_AFTER_INSTALL 1
)
ExternalProject_Add(xacc-python
DEPENDS xacc-core xacc-quantum
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/python
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
-DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}
-DXACC_ROOT=${CMAKE_CURRENT_SOURCE_DIR}
-DBOOST_ROOT=${BOOST_ROOT}
-DCPPUS_INCLUDE_DIR=${CppMicroServices_INCLUDE_DIR}
-DCPPUS_LIBRARY_DIR=${CppMicroServices_LIBRARY_DIR}
-DXACC_INCLUDE_DIR=${CMAKE_INSTALL_PREFIX}/include #${XACC_INCLUDE_DIR}
-DXACC_LIBRARY_DIR=${CMAKE_INSTALL_PREFIX}/lib #${XACC_LIBRARY_DIR}
CMAKE_CACHE_ARGS -DCMAKE_PREFIX_PATH:PATH=${CMAKE_PREFIX_PATH} CMAKE_CACHE_ARGS -DCMAKE_PREFIX_PATH:PATH=${CMAKE_PREFIX_PATH}
BUILD_ALWAYS 1 BUILD_ALWAYS 1
INSTALL_COMMAND ${CMAKE_MAKE_PROGRAM} install #DESTDIR=${CMAKE_BINARY_DIR}/stage INSTALL_COMMAND ${CMAKE_MAKE_PROGRAM} install #DESTDIR=${CMAKE_BINARY_DIR}/stage
...@@ -112,6 +131,7 @@ install(FILES "${CMAKE_SOURCE_DIR}/cmake/Modules/tests.cmake" DESTINATION share/ ...@@ -112,6 +131,7 @@ install(FILES "${CMAKE_SOURCE_DIR}/cmake/Modules/tests.cmake" DESTINATION share/
INSTALL( DIRECTORY "${CMAKE_SOURCE_DIR}/tpls/spdlog" DESTINATION include ) INSTALL( DIRECTORY "${CMAKE_SOURCE_DIR}/tpls/spdlog" DESTINATION include )
INSTALL( DIRECTORY "${CMAKE_SOURCE_DIR}/tpls/eigen" DESTINATION include ) INSTALL( DIRECTORY "${CMAKE_SOURCE_DIR}/tpls/eigen" DESTINATION include )
INSTALL( DIRECTORY "${CMAKE_SOURCE_DIR}/tpls/rapidjson" DESTINATION include ) INSTALL( DIRECTORY "${CMAKE_SOURCE_DIR}/tpls/rapidjson" DESTINATION include )
INSTALL( DIRECTORY "${CMAKE_SOURCE_DIR}/tpls/pybind11" DESTINATION include )
#install( DIRECTORY "${CMAKE_BINARY_DIR}/cppus_install/usr/local/bin/" DESTINATION bin PATTERN "bin/*" PERMISSIONS OWNER_EXECUTE) #install( DIRECTORY "${CMAKE_BINARY_DIR}/cppus_install/usr/local/bin/" DESTINATION bin PATTERN "bin/*" PERMISSIONS OWNER_EXECUTE)
#install( DIRECTORY "${CMAKE_BINARY_DIR}/cppus_install/usr/local/include/" DESTINATION include) #install( DIRECTORY "${CMAKE_BINARY_DIR}/cppus_install/usr/local/include/" DESTINATION include)
#install( DIRECTORY "${CMAKE_BINARY_DIR}/cppus_install/usr/local/lib/" DESTINATION lib) #install( DIRECTORY "${CMAKE_BINARY_DIR}/cppus_install/usr/local/lib/" DESTINATION lib)
......
cmake_minimum_required(VERSION 3.2 FATAL_ERROR)
project(xacc-python LANGUAGES CXX)
set(CMAKE_STANDARD_REQUIRED ON)
set(CMAKE_CXX_STANDARD 11)
message(STATUS "C++ version ${CXX_STANDARD} configured.")
# Make sure all build libraries have reference to their dependents
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
find_package(PythonLibs)
if(PythonLibs_FOUND)
set(CppMicroServices_DIR "${CPPUS_LIBRARY_DIR}/../share/cppmicroservices3/cmake")
# Modify our CMAKE_MODULE_PATH
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${XACC_ROOT}/cmake/Modules")
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CppMicroServices_DIR}")
include(tests)
include(CppMicroServicesConfig)
include(tests)
include(CppMicroServicesConfig)
find_package(Boost COMPONENTS system program_options filesystem chrono thread REQUIRED)
include_directories(${XACC_INCLUDE_DIR}/xacc)
include_directories(${XACC_INCLUDE_DIR}/quantum/gate)
include_directories(${XACC_INCLUDE_DIR}/quantum/aqc)
include_directories(${CPPUS_INCLUDE_DIR})
include_directories(${Boost_INCLUDE_DIRS})
include_directories(${XACC_ROOT}/tpls/rapidjson/include)
include_directories(${XACC_ROOT}/tpls/eigen)
include_directories(${XACC_ROOT}/tpls/pybind11/include)
include_directories(${XACC_ROOT}/tpls/spdlog)
include_directories(${PYTHON_INCLUDE_DIR})
link_directories(${XACC_LIBRARY_DIR})
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-strict-aliasing -O2 -g -pipe -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wformat -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv")
if(APPLE)
set(CMAKE_SHARED_LIBRARY_SUFFIX ".so")
endif(APPLE)
add_library(pyxacc SHARED xacc-py.cpp)
SET_TARGET_PROPERTIES(pyxacc PROPERTIES PREFIX "")
target_link_libraries(pyxacc ${PYTHON_LIBRARY} xacc xacc-quantum-gate xacc-quantum-aqc ${Boost_LIBRARIES})
install(TARGETS pyxacc DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/python)
endif()
\ No newline at end of file
#include "XACC.hpp"
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>
#include <pybind11/stl_bind.h>
#include <pybind11/eigen.h>
#include <pybind11/iostream.h>
#include <pybind11/operators.h>
#include "GateInstruction.hpp"
#include "GateFunction.hpp"
#include "GateQIR.hpp"
namespace py = pybind11;
using namespace xacc;
using namespace xacc::quantum;
std::shared_ptr<GateInstruction> create(const std::string& name, std::vector<int> qbits, std::vector<InstructionParameter> params = std::vector<InstructionParameter>{}) {
auto g = GateInstructionRegistry::instance()->create(name, qbits);
int idx = 0;
for (auto& a : params) {
g->setParameter(idx, a);
idx++;
}
return g;
}
PYBIND11_MODULE(pyxacc, m) {
m.doc() = "Python bindings for XACC. XACC provides a plugin infrastructure for "
"programming, compiling, and executing quantum kernels in a language and "
"hardware agnostic manner.";
// Expose the InstructionParameter
py::class_<xacc::InstructionParameter> ip(m, "InstructionParameter",
"The InstructionParameter provides a variant structure "
"to provide parameters to XACC Instructions at runtime. "
"This type can be an int, double, float, string, or complex value.");
ip.def(py::init<int>(), "Construct as an int.");
ip.def(py::init<double>(), "Construct as a double.");
ip.def(py::init<std::string>(), "Construct as a string.");
ip.def(py::init<std::complex<double>>(), "Construt as a complex double.");
ip.def(py::init<float>(), "Construct as a float.");
// Expose the Instruction interface
py::class_<xacc::Instruction, std::shared_ptr<xacc::Instruction>> inst(m, "Instruction", "Instruction wraps the XACC C++ Instruction class -"
" the base for all XACC intermediate representation instructions. Instructions, for example, can be common gates like Hadamard or CNOT.");
inst.def("getName", &xacc::Instruction::getName, "Return the name of this Instruction.");
// Expose the Function interface
py::class_<xacc::Function, xacc::Instruction, std::shared_ptr<xacc::Function>> f(m, "Function", "Functions are composed of Instructions.");
f.def("addInstruction", &xacc::Function::addInstruction, "Add an Instruction to this Function.");
f.def("nInstructions", &xacc::Function::nInstructions, "Return the number of Instructions in this Function.");
f.def("getInstruction", &xacc::Function::getInstruction, "Return the instruction at the provided index.");
// Expose the IR interface
py::class_<xacc::IR, std::shared_ptr<xacc::IR>> ir(m, "IR", "The XACC Intermediate Representation, "
"serves as a container for XACC Functions.");
ir.def("getKernels", &xacc::IR::getKernels, "Return the kernels in this IR");
// Expose the Kernel
py::class_<xacc::Kernel<>, std::shared_ptr<xacc::Kernel<>>> k(m, "Kernel", "The XACC Kernel is the "
"executable functor that executes XACC IR on the desired Accelerator.");
k.def("getIRFunction", &xacc::Kernel<>::getIRFunction, "Return the IR Function instance this Kernel wraps.");
k.def("execute", (void (xacc::Kernel<>::*)(std::shared_ptr<xacc::AcceleratorBuffer>, std::vector<xacc::InstructionParameter>)) &xacc::Kernel<>::operator()
, "Execute this Kernel with the given set of "
"InstructionParamters. This set can be empty if there are no parameters.");
py::class_<xacc::KernelList<>> klist(m, "KernelList", "The XACC KernelList is a vector of Kernels that provides a operator() implementation to execute multiple kernels at once.");
klist.def("execute",
(std::vector<std::shared_ptr<xacc::AcceleratorBuffer>> (xacc::KernelList<>::*)(
std::shared_ptr<xacc::AcceleratorBuffer>,
std::vector<xacc::InstructionParameter>)) &xacc::KernelList<>::operator(), "Execute a list of Kernels at once.");
klist.def("__getitem__", [](const xacc::KernelList<>& kl, int i) -> xacc::Kernel<> {
if (i >= kl.size()) throw py::index_error();
return kl[i];
});
klist.def("__setitem__", [](xacc::KernelList<>& kl, size_t i, xacc::Kernel<> v) {
if (i >= kl.size()) throw py::index_error();
kl[i] = v;
});
klist.def("__len__", &xacc::KernelList<>::size);
klist.def("__iter__", [](const xacc::KernelList<>& kl) {return py::make_iterator(kl.begin(), kl.end());}, py::keep_alive<0,1>());
klist.def("__getitem__",
[]( xacc::KernelList<>& s, py::slice slice) -> xacc::KernelList<>* {
size_t start, stop, step, slicelength;
if (!slice.compute(s.size(), &start, &stop, &step, &slicelength))
throw py::error_already_set();
xacc::KernelList<> *seq = new xacc::KernelList<>(s.getAccelerator());
for (size_t i = 0; i < slicelength; ++i) {
(*seq).push_back(s[start]);
start += step;
// (*seq)[i] = s[start]; start += step;
}
return seq;
});
// Expose the Accelerator
py::class_<xacc::Accelerator, std::shared_ptr<xacc::Accelerator>> acc(m,
"Accelerator", "Accelerator wraps the XACC C++ Accelerator class "
"and provides a mechanism for creating buffers of qubits. Execution "
"is handled by the XACC Kernels.");
acc.def("name", &xacc::Accelerator::name, "Return the name of this Accelerator.");
acc.def("createBuffer", (std::shared_ptr<xacc::AcceleratorBuffer> (xacc::Accelerator::*)(const std::string&, const int))
//py::overload_cast<const std::string&, const int>(
&xacc::Accelerator::createBuffer,
"Return a newly created register of qubits.");
// Expose the AcceleratorBuffer
py::class_<xacc::AcceleratorBuffer, std::shared_ptr<xacc::AcceleratorBuffer>> accb(m,
"AcceleratorBuffer", "The AcceleratorBuffer models a register of qubits.");
accb.def("printBuffer", (void (xacc::AcceleratorBuffer::*)()) &xacc::AcceleratorBuffer::print, "Print the AcceleratorBuffer to standard out.");
accb.def("getExpectationValueZ", &xacc::AcceleratorBuffer::getExpectationValueZ, "Return the expectation value with respect to the Z operator.");
accb.def("resetBuffer", &xacc::AcceleratorBuffer::resetBuffer, "Reset this buffer for use in another computation.");
accb.def("getMeasurementStrings", &xacc::AcceleratorBuffer::getMeasurementStrings, "");
accb.def("computeMeasurementProbability", &xacc::AcceleratorBuffer::computeMeasurementProbability, "");
// Expose the Compiler
py::class_<xacc::Compiler, std::shared_ptr<xacc::Compiler>> compiler(m,
"Compiler", "The XACC Compiler takes as input quantum kernel source code, "
"and compiles it to the XACC intermediate representation.");
compiler.def("name", &xacc::Compiler::name, "Return the name of this Compiler.");
compiler.def("compile", (std::shared_ptr<xacc::IR> (xacc::Compiler::*)(const std::string&, std::shared_ptr<xacc::Accelerator>)) &xacc::Compiler::compile, "Compile the "
"given source code against the given Accelerator.");
compiler.def("translate", &xacc::Compiler::translate, "Translate the given IR Function instance to source code in this Compiler's language.");
// Expose the Program object
py::class_<xacc::Program> program(m,
"Program", "The Program is the primary entrypoint for compilation and execution in XACC. Clients provide quantum kernel source "
"code and the Accelerator instance, and the Program handles compiling the code and provides Kernel instances to execute.");
program.def(py::init<std::shared_ptr<xacc::Accelerator>, const std::string &>(), "The constructor");
program.def(py::init<std::shared_ptr<xacc::Accelerator>, std::shared_ptr<xacc::IR>>(), "The constructor");
program.def("build", &xacc::Program::build, "Compile this program.");
program.def("getKernel", (xacc::Kernel<> (xacc::Program::*)(const std::string&)) &xacc::Program::getKernel<>, "Return a Kernel representing the source code.");
program.def("getKernels", &xacc::Program::getRuntimeKernels, "Return all Kernels.");
program.def("nKernels", &xacc::Program::nKernels, "Return the number of kernels compiled by this program");
// Expose XACC API functions
m.def("Initialize", (void (*)(std::vector<std::string>))
&xacc::Initialize,
"Initialize the framework. Can provide a list of strings to model command line arguments. For instance, "
"to print the XACC help message, pass ['--help'] to this function, or to set the compiler to use, ['--compiler','scaffold'].");
m.def("Initialize", (void (*)()) &xacc::Initialize,
"Initialize the framework. Use this if there are no command line arguments to pass.");
m.def("getAccelerator", (std::shared_ptr<xacc::Accelerator> (*)(const std::string&))
&xacc::getAccelerator,
"Return the accelerator with given name.");
m.def("getCompiler", (std::shared_ptr<xacc::Compiler> (*)(const std::string&))
&xacc::getCompiler,
"Return the Compiler of given name.");
m.def("setOption", &xacc::setOption, "Set an XACC framework option.");
m.def("getOption", &xacc::getOption, "Get an XACC framework option.");
m.def("optionExists", &xacc::optionExists, "Set an XACC framework option.");
m.def("translate", &xacc::translate, "Translate one language quantum kernel to another");
m.def("translateWithVisitor", &xacc::translateWithVisitor, "Translate one language quantum kernel to another");
m.def("Finalize", &xacc::Finalize, "Finalize the framework");
py::module gatesub = m.def_submodule("gate", "Gate model quantum computing data structures.");
py::class_<xacc::quantum::GateInstruction, xacc::Instruction,
std::shared_ptr<xacc::quantum::GateInstruction>> gateinst(gatesub,
"GateInstruction",
"GateInstruction models gate model quantum computing instructions.");
gateinst.def("getName", &xacc::quantum::GateInstruction::getName, "Return the name of this Instruction.");
gateinst.def("bits", &xacc::quantum::GateInstruction::bits, "Return the qubits this gate operates on");
gateinst.def("nParameters", &xacc::quantum::GateInstruction::nParameters, "Return the number of parameters this gate requires.");
gateinst.def("getParameter", &xacc::quantum::GateInstruction::getParameter, "Return the parameter at the given index");
gateinst.def("setParameter", &xacc::quantum::GateInstruction::setParameter, "Set the parameter value at the give index");
gateinst.def("toString", &xacc::quantum::GateInstruction::toString, "Return the instruction as a string representation.");
// py::class_<xacc::quantum::GateInstructionRegistry, std::shared_ptr<xacc::quantum::GateInstructionRegistry>> gatereg(gatesub,
// "GateInstructionRegistry", "Registry of available quantum gates.");
// gatereg.def_static("instance", &xacc::quantum::GateInstructionRegistry::instance, "Singleton instance method.");
// gatereg.def("create", &xacc::quantum::GateInstructionRegistry::create, "Create");
py::class_<xacc::quantum::GateFunction, xacc::Function, std::shared_ptr<xacc::quantum::GateFunction>> gatefunction(gatesub,
"GateFunction",
"GateFunction description, fill this in later");
gatefunction.def(py::init<const std::string&>(), "The constructor");
gatefunction.def(py::init<const std::string&, std::vector<xacc::InstructionParameter>>(), "The constructor");
gatefunction.def("getName", &xacc::quantum::GateFunction::getName, "Return the name of this Instruction.");
gatefunction.def("add", &xacc::quantum::GateFunction::addInstruction, "Add an Instruction to this function.");
gatefunction.def("toString", &xacc::quantum::GateFunction::toString, "Return the function as a string representation.");
py::class_<xacc::quantum::GateQIR, xacc::IR, std::shared_ptr<xacc::quantum::GateQIR>> gateqir(gatesub,
"GateQIR",
"GateQIR description, fill this in later");
gateqir.def(py::init<>(), "The constructor");
gateqir.def("addKernel", &xacc::quantum::GateQIR::addKernel, "Add an Kernel to this GateQIR.");
gatesub.def("create", &create, "", py::arg("name"), py::arg("qbits"), py::arg("params") = std::vector<InstructionParameter>{});
}
...@@ -28,18 +28,6 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CppMicroServices_DIR}") ...@@ -28,18 +28,6 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CppMicroServices_DIR}")
include(tests) include(tests)
include(CppMicroServicesConfig) include(CppMicroServicesConfig)
# We require MPI
#find_package(MPI)
#if (MPI_FOUND)
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DXACC_HAS_MPI")
# message(STATUS "FOUND MPI: ${MPI_CXX_INCLUDE_PATH} AND ${MPI_CXX_LIBRARIES}")
# We require Boost with MPI
# find_package(Boost COMPONENTS mpi system program_options filesystem chrono thread REQUIRED)
# include_directories(${MPI_CXX_INCLUDE_PATH})
#else()
# message(STATUS "MPI Not Found.")
# We require Boost without MPI # We require Boost without MPI
find_package(Boost COMPONENTS system program_options filesystem chrono thread REQUIRED) find_package(Boost COMPONENTS system program_options filesystem chrono thread REQUIRED)
#endif() #endif()
......
version: 1.0.{build}
image:
- Visual Studio 2017
- Visual Studio 2015
test: off
build:
parallel: true
platform:
- x64
- x86
environment:
matrix:
- PYTHON: 36
CPP: 14
CONFIG: Debug
- PYTHON: 27
CPP: 14
CONFIG: Debug
- CONDA: 36
CPP: latest
CONFIG: Release
matrix:
exclude:
- image: Visual Studio 2015
platform: x86
- image: Visual Studio 2015
CPP: latest
- image: Visual Studio 2017
CPP: latest
platform: x86
install:
- ps: |
if ($env:PLATFORM -eq "x64") { $env:CMAKE_ARCH = "x64" }
if ($env:APPVEYOR_JOB_NAME -like "*Visual Studio 2017*") {
$env:CMAKE_GENERATOR = "Visual Studio 15 2017"
$env:CMAKE_INCLUDE_PATH = "C:\Libraries\boost_1_64_0"
} else {
$env:CMAKE_GENERATOR = "Visual Studio 14 2015"
}
if ($env:PYTHON) {
if ($env:PLATFORM -eq "x64") { $env:PYTHON = "$env:PYTHON-x64" }
$env:PATH = "C:\Python$env:PYTHON\;C:\Python$env:PYTHON\Scripts\;$env:PATH"
pip install --disable-pip-version-check --user --upgrade pip wheel
pip install pytest numpy
} elseif ($env:CONDA) {
if ($env:CONDA -eq "27") { $env:CONDA = "" }
if ($env:PLATFORM -eq "x64") { $env:CONDA = "$env:CONDA-x64" }
$env:PATH = "C:\Miniconda$env:CONDA\;C:\Miniconda$env:CONDA\Scripts\;$env:PATH"
$env:PYTHONHOME = "C:\Miniconda$env:CONDA"
conda install -y -q pytest numpy scipy
}
- ps: |
Start-FileDownload 'http://bitbucket.org/eigen/eigen/get/3.3.3.zip'
7z x 3.3.3.zip -y > $null
$env:CMAKE_INCLUDE_PATH = "eigen-eigen-67e894c6cd8f;$env:CMAKE_INCLUDE_PATH"
build_script:
- cmake -G "%CMAKE_GENERATOR%" -A "%CMAKE_ARCH%"
-DPYBIND11_CPP_STANDARD=/std:c++%CPP%
-DPYBIND11_WERROR=ON
-DDOWNLOAD_CATCH=ON
-DCMAKE_SUPPRESS_REGENERATION=1
- set MSBuildLogger="C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll"
- cmake --build . --config %CONFIG% --target pytest -- /m /v:m /logger:%MSBuildLogger%
- cmake --build . --config %CONFIG% --target cpptest -- /m /v:m /logger:%MSBuildLogger%
- if "%CPP%"=="latest" (cmake --build . --config %CONFIG% --target test_cmake_build -- /m /v:m /logger:%MSBuildLogger%)
on_failure: if exist "tests\test_cmake_build" type tests\test_cmake_build\*.log*
CMakeCache.txt
CMakeFiles
Makefile
cmake_install.cmake
.DS_Store
*.so
*.pyd
*.dll
*.sln
*.sdf
*.opensdf
*.vcxproj
*.filters
example.dir
Win32
x64
Release
Debug
.vs
CTestTestfile.cmake
Testing
autogen
MANIFEST
/.ninja_*
/*.ninja
/docs/.build
*.py[co]
*.egg-info
*~
.DS_Store
/dist
/build
/cmake/
.cache/
sosize-*.txt
pybind11Config*.cmake
pybind11Targets.cmake
[submodule "tools/clang"]
path = tools/clang
url = https://github.com/wjakob/clang-cindex-python3
python:
version: 3
requirements_file: docs/requirements.txt
language: cpp
dist: trusty
sudo: false
matrix:
include:
- os: linux
env: PYTHON=2.7 CPP=11 GCC=4.8
addons:
apt:
packages: [cmake=2.\*, cmake-data=2.\*]
- os: linux
env: PYTHON=3.6 CPP=11 GCC=4.8
addons:
apt:
sources: [deadsnakes]
packages: [python3.6-dev python3.6-venv, cmake=2.\*, cmake-data=2.\*]
- sudo: true
services: docker
env: PYTHON=2.7 CPP=14 GCC=6
- sudo: true
services: docker
env: PYTHON=3.5 CPP=14 GCC=6 DEBUG=1
- sudo: true
services: docker
env: PYTHON=3.6 CPP=17 GCC=7
- os: linux
env: PYTHON=3.6 CPP=17 CLANG=5.0
addons:
apt:
sources: [deadsnakes, llvm-toolchain-trusty-5.0, ubuntu-toolchain-r-test]
packages: [python3.6-dev python3.6-venv clang-5.0 llvm-5.0-dev, lld-5.0]
- os: osx
osx_image: xcode7.3
env: PYTHON=2.7 CPP=14 CLANG
- os: osx
osx_image: xcode7.3
env: PYTHON=3.6 CPP=14 CLANG
# Test a PyPy 2.7 build
- os: linux
env: PYPY=5.8 PYTHON=2.7 CPP=11 GCC=4.8
addons:
apt:
packages: [libblas-dev, liblapack-dev, gfortran]
- sudo: true
services: docker
env: ARCH=i386 PYTHON=3.5 CPP=14 GCC=6
# This next one does a make install *before* testing, then builds the tests against the installed version:
- sudo: true
services: docker
env: PYTHON=3.5 CPP=14 CLANG=3.9 INSTALL=1
script:
- |
$SCRIPT_RUN_PREFIX sh -c "set -e
cmake ${CMAKE_EXTRA_ARGS} -DPYBIND11_INSTALL=1 -DPYBIND11_TEST=0
make install
cp -a tests /pybind11-tests
mkdir /build-tests && cd /build-tests
cmake ../pybind11-tests ${CMAKE_EXTRA_ARGS} -DPYBIND11_WERROR=ON
make pytest -j 2"
# A barebones build makes sure everything still works without optional deps (numpy/scipy/eigen)
# and also tests the automatic discovery functions in CMake (Python version, C++ standard).
- os: linux
env: BAREBONES PYTHON=3.5
install: $PY_CMD -m pip install --user --upgrade pytest
# Documentation build:
- os: linux
language: docs
env: DOCS STYLE LINT PIP
cache: false
install:
- export PATH="~/.local/bin:$PATH"
- $PY_CMD -m pip install --user --upgrade sphinx sphinx_rtd_theme breathe flake8 pep8-naming
- |
curl -fsSL ftp://ftp.stack.nl/pub/users/dimitri/doxygen-1.8.12.linux.bin.tar.gz | tar xz
export PATH="$PWD/doxygen-1.8.12/bin:$PATH"
script:
- $PY_CMD -m sphinx -W -b html docs docs/.build
- tools/check-style.sh
- flake8
- |
# Make sure setup.py distributes and installs all the headers
$PY_CMD setup.py sdist
$PY_CMD -m pip install --user -U ./dist/*
installed=$($PY_CMD -c "import pybind11; print(pybind11.get_include(True) + '/pybind11')")
diff -rq $installed ./include/pybind11
cache:
directories:
- $HOME/.local/bin
- $HOME/.local/lib
- $HOME/.local/include
- $HOME/Library/Python
before_install:
- |
# Configure build variables
if [ "$TRAVIS_OS_NAME" = "linux" ]; then
if [ -n "$CLANG" ]; then
export CXX=clang++-$CLANG CC=clang-$CLANG
COMPILER_PACKAGES="clang-$CLANG llvm-$CLANG-dev"
else
if [ -z "$GCC" ]; then GCC=4.8
else COMPILER_PACKAGES=g++-$GCC
fi
export CXX=g++-$GCC CC=gcc-$GCC
fi
if [ "$GCC" = "6" ] || [ "$CLANG" = "3.9" ]; then DOCKER=${ARCH:+$ARCH/}debian:stretch
elif [ "$GCC" = "7" ]; then DOCKER=debian:buster
fi
elif [ "$TRAVIS_OS_NAME" = "osx" ]; then
export CXX=clang++ CC=clang;
fi
if [ -n "$CPP" ]; then CPP=-std=c++$CPP; fi
if [ "${PYTHON:0:1}" = "3" ]; then PY=3; fi
if [ -n "$DEBUG" ]; then CMAKE_EXTRA_ARGS="${CMAKE_EXTRA_ARGS} -DCMAKE_BUILD_TYPE=Debug"; fi
- |
# Initialize environment
set -e
if [ -n "$DOCKER" ]; then
docker pull $DOCKER
containerid=$(docker run --detach --tty \
--volume="$PWD":/pybind11 --workdir=/pybind11 \
--env="CC=$CC" --env="CXX=$CXX" --env="DEBIAN_FRONTEND=$DEBIAN_FRONTEND" \
--env=GCC_COLORS=\ \
$DOCKER)
SCRIPT_RUN_PREFIX="docker exec --tty $containerid"
$SCRIPT_RUN_PREFIX sh -c 'for s in 0 15; do sleep $s; apt-get update && apt-get -qy dist-upgrade && break; done'
else
if [ "$PYPY" = "5.8" ]; then
curl -fSL https://bitbucket.org/pypy/pypy/downloads/pypy2-v5.8.0-linux64.tar.bz2 | tar xj
PY_CMD=$(echo `pwd`/pypy2-v5.8.0-linux64/bin/pypy)
CMAKE_EXTRA_ARGS="${CMAKE_EXTRA_ARGS} -DPYTHON_EXECUTABLE:FILEPATH=$PY_CMD"
else
PY_CMD=python$PYTHON
if [ "$TRAVIS_OS_NAME" = "osx" ]; then
if [ "$PY" = "3" ]; then
brew update; brew install python$PY;
else
curl -fsSL https://bootstrap.pypa.io/get-pip.py | $PY_CMD - --user
fi
fi
fi
if [ "$PY" = 3 ] || [ -n "$PYPY" ]; then
$PY_CMD -m ensurepip --user
fi
$PY_CMD -m pip install --user --upgrade pip wheel
fi
set +e
install:
- |
# Install dependencies
set -e
if [ -n "$DOCKER" ]; then
if [ -n "$DEBUG" ]; then
PY_DEBUG="python$PYTHON-dbg python$PY-scipy-dbg"
CMAKE_EXTRA_ARGS="${CMAKE_EXTRA_ARGS} -DPYTHON_EXECUTABLE=/usr/bin/python${PYTHON}dm"
fi
$SCRIPT_RUN_PREFIX sh -c "for s in 0 15; do sleep \$s; \
apt-get -qy --no-install-recommends install \
$PY_DEBUG python$PYTHON-dev python$PY-pytest python$PY-scipy \
libeigen3-dev libboost-dev cmake make ${COMPILER_PACKAGES} && break; done"
else
if [ "$CLANG" = "5.0" ]; then
if ! [ -d ~/.local/include/c++/v1 ]; then
# Neither debian nor llvm provide a libc++ 5.0 deb; luckily it's fairly quick
# to build, install (and cache), so do it ourselves:
git clone --depth=1 https://github.com/llvm-mirror/llvm.git llvm-source
git clone https://github.com/llvm-mirror/libcxx.git llvm-source/projects/libcxx -b release_50
git clone https://github.com/llvm-mirror/libcxxabi.git llvm-source/projects/libcxxabi -b release_50
mkdir llvm-build && cd llvm-build
# Building llvm requires a newer cmake than is provided by the trusty container:
CMAKE=cmake-3.8.0-Linux-x86_64
curl https://cmake.org/files/v3.8/$CMAKE.tar.gz | tar xz
./$CMAKE/bin/cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=~/.local ../llvm-source
make -j2 install-cxxabi install-cxx
cp -a include/c++/v1/*cxxabi*.h ~/.local/include/c++/v1
cd ..