diff --git a/.travis.yml b/.travis.yml index 4b5da544a1ee..b99d7ae64eaa 100644 --- a/.travis.yml +++ b/.travis.yml @@ -51,7 +51,7 @@ stage_linux: &stage_linux dist: trusty language: python python: 3.5 - env: CMAKE_FLAGS="-D CMAKE_CXX_COMPILER=g++-5 -D ENABLE_TARGETS_QA=False" + env: CMAKE_FLAGS="-D CMAKE_CXX_COMPILER=g++-5 -D ENABLE_TARGETS_QA=False -D WHEEL_TAG=-pmanylinux1_x86_64 -D STATIC_LINKING=True" addons: apt: sources: @@ -66,7 +66,7 @@ stage_osx: &stage_osx os: osx osx_image: xcode9.2 language: generic - env: CMAKE_FLAGS="-D CMAKE_CXX_COMPILER=g++-6 -D ENABLE_TARGETS_QA=False" + env: CMAKE_FLAGS="-D CMAKE_CXX_COMPILER=g++-6 -D ENABLE_TARGETS_QA=False -D STATIC_LINKING=True" before_install: # Travis does not provide support for Python 3 under osx - it needs to be # installed manually. diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst index 0ca545015f8e..09eed6c5ee64 100644 --- a/CONTRIBUTING.rst +++ b/CONTRIBUTING.rst @@ -83,6 +83,65 @@ more info about where to find libphreads.a for later building. Furthermore, we are forcing CMake to generate MingGW makefiles, because we don't support other toolchain at the moment. +Useful CMake flags +------------------ + +There are some useful flags that can be set during cmake command invocation and +will help you change some default behavior. To make use of them, you just need to +pass them right after ``-D`` cmake argument. Example: +.. code:: + + qiskit-sdk-py/out$ cmake -DUSEFUL_FLAG=Value .. + +Flags: + +USER_LIB_PATH + This flag tells CMake to look for libraries that are needed by some of the native + components to be built, but they are not in a common place where CMake could find + it automatically. + Values: An absolute path with file included. + Default: No value. + Example: ``cmake -DUSER_LIB_PATH=C:\path\to\mingw64\lib\libpthreads.a ..`` + +STATIC_LINKING + Tells the build system whether to create static versions of the programs being built or not. + Notes: On MacOS static linking is not fully working for all versions of GNU G++/Clang + compilers, so enable this flag in this platform could cause errors. + Values: True|False + Default: False + Example: ``cmake -DSTATIC_LINKING=True ..`` + +CMAKE_BUILD_TYPE + Tells the build system to create executables/libraries for debugging purposes + or highly optimized binaries ready for distribution. + Values: Debug|Release + Default: "Release" + Example: ``cmake -DCMAKE_BUILD_TYPE="Debug" ..`` + +ENABLE_TARGETS_NON_PYTHON + We can enable or disable non-python code generation by setting this flag to True or False + respectively. This is mostly used in our CI systems so they can launch some fast tests + for the Python code (which is currently a majority). + Values: True|False + Default: True + Example: ``cmake -DENABLE_TARGETS_NON_PYTHON=True ..`` + +ENABLE_TARGETS_QA + We can enable or disable QA stuff (lintering, styling and testing) by setting this flag to + True or False respectively. This is mostly used in our CI systems so they can run light + stages pretty fast, and fail fast if they found any issues within the code. + Values: True|False + Default: True + Example: ``cmake -DENABLE_TARGETS_QA=True ..`` + +WHEEL_TAG + This is used to force platform specific tag name generation when creating wheels package + for Pypi. + Values: "-pWhateverTagName" + Default: No value. + Example: ``cmake -DWHEEL_TAG="-pmanylinux1_x86_64" ..`` + + Test ~~~~ diff --git a/cmake/defaults.cmake b/cmake/defaults.cmake index 56aedbbbb5bb..64c5f0c4cafa 100644 --- a/cmake/defaults.cmake +++ b/cmake/defaults.cmake @@ -1,9 +1,14 @@ # Default values for global scope variables. # They can be overriden by passing -DVARIABLE=Value to cmake, like: -# out$ cmake -DSTATIC_LINKING=False .. +# out$ cmake -DSTATIC_LINKING=True .. # set(CMAKE_BUILD_TYPE "Release") -set(STATIC_LINKING True CACHE BOOL "Static linking of executables") +set(STATIC_LINKING False CACHE BOOL "Static linking of executables") set(ENABLE_TARGETS_NON_PYTHON True CACHE BOOL "Enable targets for non Python code") set(ENABLE_TARGETS_QA True CACHE BOOL "Enable targets for QA targets") +if(CMAKE_SIZEOF_VOID_P EQUAL 8) + set(ARCH64 True CACHE BOOL "We are on a 64 bits platform") +elseif(CMAKE_SIZEOF_VOID_P EQUAL 4) + set(ARCH32 True CACHE BOOL "We are on a 32 bits platform") +endif() \ No newline at end of file diff --git a/cmake/python-build.cmake b/cmake/python-build.cmake index 26701f2bbeb7..3a93bcd5c831 100755 --- a/cmake/python-build.cmake +++ b/cmake/python-build.cmake @@ -23,11 +23,11 @@ function(add_pypi_package_target TARGET_NAME PACKAGE_TYPE) if(PACKAGE_TYPE STREQUAL "both") set(PIP_PACKAGE_SOURCE_DIST sdist --dist-dir ${CMAKE_CURRENT_BINARY_DIR}/dist) - set(PIP_PACKAGE_PLATFORM_WHEELS bdist_wheel -p manylinux1_x86_64 --dist-dir ${CMAKE_CURRENT_BINARY_DIR}/dist) + set(PIP_PACKAGE_PLATFORM_WHEELS bdist_wheel ${WHEEL_TAG} --dist-dir ${CMAKE_CURRENT_BINARY_DIR}/dist) elseif(PACKAGE_TYPE STREQUAL "sdist") set(PIP_PACKAGE_SOURCE_DIST sdist --dist-dir ${CMAKE_CURRENT_BINARY_DIR}/dist) elseif(PACKAGE_TYPE STREQUAL "bdist_wheel") - set(PIP_PACKAGE_PLATFORM_WHEELS bdist_wheel -p manylinux1_x86_64 --dist-dir ${CMAKE_CURRENT_BINARY_DIR}/dist) + set(PIP_PACKAGE_PLATFORM_WHEELS bdist_wheel ${WHEEL_TAG} --dist-dir ${CMAKE_CURRENT_BINARY_DIR}/dist) endif() # For ' make clean' target diff --git a/requirements.txt b/requirements.txt index 58f5ed868e23..4640894ea91e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -6,3 +6,4 @@ ply==3.10 scipy>=0.19,<1.1 sympy>=1.0 pillow>=4.2.1 +cmake>=3.11,<3.12 diff --git a/src/qasm-simulator-cpp/CMakeLists.txt b/src/qasm-simulator-cpp/CMakeLists.txt index a18ab6b70328..39cfa606cbdb 100755 --- a/src/qasm-simulator-cpp/CMakeLists.txt +++ b/src/qasm-simulator-cpp/CMakeLists.txt @@ -39,35 +39,40 @@ set_target_properties(qasm_simulator_cpp PROPERTIES LINKER_LANGUAGE CXX) # Toolchain options set_property(TARGET qasm_simulator_cpp PROPERTY CXX_STANDARD 11) -# Compiler flags -enable_cxx_compiler_flag_if_supported("-O3") -enable_cxx_compiler_flag_if_supported("-march=native") -enable_cxx_compiler_flag_if_supported("-fopenmp") - -# We force static linking on Windows -if(STATIC_LINKING OR MINGW) +if(STATIC_LINKING) # Hack: Seems like enable_cxx_compiler_flag_if_supported() is not properly # working on MacOS, when a flag is not supported, it cascades errors # to the rest of the flags being tested... and -static compilation on Mac # with gcc is failing... - if(NOT APPLE) - enable_cxx_compiler_flag_if_supported("-static") - enable_cxx_compiler_flag_if_supported("-static-libgcc") + if(APPLE AND CMAKE_CXX_COMPILER_ID MATCHES "Clang") + message(WARNING "Clang on MacOS doesn't support some -static-* flags. Switching to dyn compilation...") + else() + # MacOS compilers don't support -static flag either + if(NOT APPLE) + enable_cxx_compiler_flag_if_supported("-static") + endif() + # This is enough to build a semi-static executable on Mac + enable_cxx_compiler_flag_if_supported("-static-libgcc") + enable_cxx_compiler_flag_if_supported("-static-libstdc++") endif() - enable_cxx_compiler_flag_if_supported("-static-libstdc++") endif() -# Warnings and Errors -enable_cxx_compiler_flag_if_supported("-pedantic") -enable_cxx_compiler_flag_if_supported("-Wall") -enable_cxx_compiler_flag_if_supported("-Wfloat-equal") -enable_cxx_compiler_flag_if_supported("-Wundef") -enable_cxx_compiler_flag_if_supported("-Wcast-align") -enable_cxx_compiler_flag_if_supported("-Wwrite-strings") -enable_cxx_compiler_flag_if_supported("-Wmissing-declarations") -enable_cxx_compiler_flag_if_supported("-Wredundant-decls") -enable_cxx_compiler_flag_if_supported("-Wshadow") -enable_cxx_compiler_flag_if_supported("-Woverloaded-virtual") +if(NOT MSVC) + # Compiler flags + enable_cxx_compiler_flag_if_supported("-O3") + enable_cxx_compiler_flag_if_supported("-march=native") + # Warnings and Errors + enable_cxx_compiler_flag_if_supported("-pedantic") + enable_cxx_compiler_flag_if_supported("-Wall") + enable_cxx_compiler_flag_if_supported("-Wfloat-equal") + enable_cxx_compiler_flag_if_supported("-Wundef") + enable_cxx_compiler_flag_if_supported("-Wcast-align") + enable_cxx_compiler_flag_if_supported("-Wwrite-strings") + enable_cxx_compiler_flag_if_supported("-Wmissing-declarations") + enable_cxx_compiler_flag_if_supported("-Wredundant-decls") + enable_cxx_compiler_flag_if_supported("-Wshadow") + enable_cxx_compiler_flag_if_supported("-Woverloaded-virtual") +endif() target_include_directories(qasm_simulator_cpp PRIVATE ${QASM_SIMULATOR_CPP_SRC_DIR}) target_include_directories(qasm_simulator_cpp PRIVATE ${QASM_SIMULATOR_CPP_SRC_DIR}/backends) @@ -76,12 +81,21 @@ target_include_directories(qasm_simulator_cpp PRIVATE ${QASM_SIMULATOR_CPP_SRC_D target_include_directories(qasm_simulator_cpp PRIVATE ${QASM_SIMULATOR_CPP_SRC_DIR}/third-party/headers) # For header only libraries -SET(CMAKE_FIND_LIBRARY_PREFIXES ${CMAKE_FIND_LIBRARY_PREFIXES} "") +SET(CMAKE_FIND_LIBRARY_PREFIXES "" ${CMAKE_FIND_LIBRARY_PREFIXES}) SET(CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES} .hpp) -# We force static linking on Windows -if(STATIC_LINKING OR MINGW) - SET(CMAKE_FIND_LIBRARY_SUFFIXES .a .lib ${CMAKE_FIND_LIBRARY_SUFFIXES}) +if(STATIC_LINKING) + SET(CMAKE_FIND_LIBRARY_SUFFIXES .a ${CMAKE_FIND_LIBRARY_SUFFIXES}) + if(WIN32) + SET(CMAKE_FIND_LIBRARY_SUFFIXES .lib ${CMAKE_FIND_LIBRARY_SUFFIXES}) + endif() +endif() + +find_package(OpenMP) +if (OPENMP_FOUND) + set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}") + set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}") + set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_EXE_LINKER_FLAGS}") endif() # Looking for external libraries @@ -94,44 +108,33 @@ if(NOT LIB_JSON) message(FATAL_ERROR "JSON library not found!. Please provide with a USER_LIB_PATH to CMake so it can be searched there") endif() -find_library(LIB_LAPACK - NAMES lapack +find_library(BLAS_LIB + NAMES openblas mkl blas PATHS ${QASM_SIMULATOR_CPP_EXTERNAL_LIBS}) -if(NOT LIB_LAPACK) - message(FATAL_ERROR "LAPACK library not found!. Please provide with a USER_LIB_PATH to CMake so it can be searched there") +if(NOT BLAS_LIB) + message(FATAL_ERROR "BLAS library not found!. Please provide with a USER_LIB_PATH to CMake so it can be searched there") endif() -find_library(LIB_BLAS - NAMES blas - PATHS ${QASM_SIMULATOR_CPP_EXTERNAL_LIBS}) -if(NOT LIB_BLAS) - message(FATAL_ERROR "BLAS library not found!. Please provide with a USER_LIB_PATH to CMake so it can be searched there") -endif() - -find_library(LIB_THREADS - NAMES pthread - PATHS ${QASM_SIMULATOR_CPP_EXTERNAL_LIBS}) -if(NOT LIB_THREADS) - message(FATAL_ERROR "Pthreads library not found!. Please provide with a USER_LIB_PATH to CMake so it can be searched there") -endif() - -set(LIBRARIES PRIVATE ${LIB_BLAS} - ${LIB_LAPACK} - ${LIB_THREADS}) - +set(LIBRARIES PRIVATE ${BLAS_LIB}) + # Linking target_link_libraries(qasm_simulator_cpp ${LIBRARIES}) set(QASM_SIMULATOR_CPP_OUTPUT_DIR $ CACHE INTERNAL "Output directory for building QISKit C++ Simulator") -if(MINGW) +# TODO Windows 32 bits builds are not supported yet +set(ARCH_BITS "64") +if(ARCH32) + set(ARCH_BITS "32") +endif() + +# Copying necessary .dll files to output +# TODO look into "install()" CMake function +if(WIN32) # Windows 64 bits is also true here set(QASM_SIMULATOR_CPP_THIRD_PARTY_DLLS - "${QASM_SIMULATOR_CPP_SRC_DIR}/third-party/win64/dll/libblas.dll" - "${QASM_SIMULATOR_CPP_SRC_DIR}/third-party/win64/dll/libgfortran_64-3.dll" - "${QASM_SIMULATOR_CPP_SRC_DIR}/third-party/win64/dll/libquadmath_64-0.dll" + "${QASM_SIMULATOR_CPP_SRC_DIR}/third-party/win${ARCH_BITS}/dll/openblas.dll" CACHE INTERNAL "Third-party C++ Simulator DLLs") - foreach(dll_file ${QASM_SIMULATOR_CPP_THIRD_PARTY_DLLS}) add_custom_command( TARGET qasm_simulator_cpp @@ -146,7 +149,7 @@ if(MINGW) ${QASM_SIMULATOR_CPP_OUTPUT_DIR}/${FINAL_FILE}) endforeach() endif() - + # Tests # TODO: Enable them when ready #add_subdirectory(${QASM_SIMULATOR_CPP_DIR}/test) diff --git a/src/qasm-simulator-cpp/src/backends/ideal_backend.hpp b/src/qasm-simulator-cpp/src/backends/ideal_backend.hpp index 63583ecb7cf2..61d306240270 100644 --- a/src/qasm-simulator-cpp/src/backends/ideal_backend.hpp +++ b/src/qasm-simulator-cpp/src/backends/ideal_backend.hpp @@ -28,6 +28,8 @@ limitations under the License. #include #include #include +#define _USE_MATH_DEFINES +#include #include "base_backend.hpp" #include "qubit_vector.hpp" diff --git a/src/qasm-simulator-cpp/src/third-party/win64/dll/libblas.dll b/src/qasm-simulator-cpp/src/third-party/win64/dll/libblas.dll deleted file mode 100644 index 93f480579368..000000000000 Binary files a/src/qasm-simulator-cpp/src/third-party/win64/dll/libblas.dll and /dev/null differ diff --git a/src/qasm-simulator-cpp/src/third-party/win64/dll/libgcc_s_sjlj-1.dll b/src/qasm-simulator-cpp/src/third-party/win64/dll/libgcc_s_sjlj-1.dll deleted file mode 100644 index b1b6a545a0ab..000000000000 Binary files a/src/qasm-simulator-cpp/src/third-party/win64/dll/libgcc_s_sjlj-1.dll and /dev/null differ diff --git a/src/qasm-simulator-cpp/src/third-party/win64/dll/libgfortran_64-3.dll b/src/qasm-simulator-cpp/src/third-party/win64/dll/libgfortran_64-3.dll deleted file mode 100644 index adc19a7d5f4d..000000000000 Binary files a/src/qasm-simulator-cpp/src/third-party/win64/dll/libgfortran_64-3.dll and /dev/null differ diff --git a/src/qasm-simulator-cpp/src/third-party/win64/dll/libgomp-1.dll b/src/qasm-simulator-cpp/src/third-party/win64/dll/libgomp-1.dll deleted file mode 100644 index f03ff1a61281..000000000000 Binary files a/src/qasm-simulator-cpp/src/third-party/win64/dll/libgomp-1.dll and /dev/null differ diff --git a/src/qasm-simulator-cpp/src/third-party/win64/dll/liblapack.dll b/src/qasm-simulator-cpp/src/third-party/win64/dll/liblapack.dll deleted file mode 100644 index b4b53997e716..000000000000 Binary files a/src/qasm-simulator-cpp/src/third-party/win64/dll/liblapack.dll and /dev/null differ diff --git a/src/qasm-simulator-cpp/src/third-party/win64/dll/libquadmath_64-0.dll b/src/qasm-simulator-cpp/src/third-party/win64/dll/libquadmath_64-0.dll deleted file mode 100644 index 1c5df6168add..000000000000 Binary files a/src/qasm-simulator-cpp/src/third-party/win64/dll/libquadmath_64-0.dll and /dev/null differ diff --git a/src/qasm-simulator-cpp/src/third-party/win64/dll/libwinpthread-1.dll b/src/qasm-simulator-cpp/src/third-party/win64/dll/libwinpthread-1.dll deleted file mode 100644 index 5e56c5aa0830..000000000000 Binary files a/src/qasm-simulator-cpp/src/third-party/win64/dll/libwinpthread-1.dll and /dev/null differ diff --git a/src/qasm-simulator-cpp/src/third-party/win64/dll/openblas.dll b/src/qasm-simulator-cpp/src/third-party/win64/dll/openblas.dll new file mode 100644 index 000000000000..3c145d01d795 Binary files /dev/null and b/src/qasm-simulator-cpp/src/third-party/win64/dll/openblas.dll differ diff --git a/src/qasm-simulator-cpp/src/third-party/win64/lib/libblas.lib b/src/qasm-simulator-cpp/src/third-party/win64/lib/libblas.lib deleted file mode 100755 index 88344bd03268..000000000000 Binary files a/src/qasm-simulator-cpp/src/third-party/win64/lib/libblas.lib and /dev/null differ diff --git a/src/qasm-simulator-cpp/src/third-party/win64/lib/liblapack.lib b/src/qasm-simulator-cpp/src/third-party/win64/lib/liblapack.lib deleted file mode 100755 index 60cd33aeffdb..000000000000 Binary files a/src/qasm-simulator-cpp/src/third-party/win64/lib/liblapack.lib and /dev/null differ diff --git a/src/qasm-simulator-cpp/src/third-party/win64/lib/liblapacke.lib b/src/qasm-simulator-cpp/src/third-party/win64/lib/liblapacke.lib deleted file mode 100755 index a8c8eeb7952b..000000000000 Binary files a/src/qasm-simulator-cpp/src/third-party/win64/lib/liblapacke.lib and /dev/null differ diff --git a/src/qasm-simulator-cpp/src/third-party/win64/lib/openblas.lib b/src/qasm-simulator-cpp/src/third-party/win64/lib/openblas.lib new file mode 100644 index 000000000000..731c73853e56 Binary files /dev/null and b/src/qasm-simulator-cpp/src/third-party/win64/lib/openblas.lib differ