Skip to content

Commit

Permalink
Improvements (#176)
Browse files Browse the repository at this point in the history
* WIP

* Simplified MATLAB detection

* Update CHANGES.md

* Formatting

* Minor update

POSIX-compliance

Signed-off-by: Vlad Gheorghiu <vsoftco@gmail.com>

* Update

Signed-off-by: Vlad Gheorghiu <vsoftco@gmail.com>

* add .txt extension

VERSION conflicts with cpp20 <version> on macOS, hence renamed to
VERSION.txt

Signed-off-by: Vlad Gheorghiu <vsoftco@gmail.com>

* Update

Signed-off-by: Vlad Gheorghiu <vsoftco@gmail.com>

* Update

Signed-off-by: Vlad Gheorghiu <vsoftco@gmail.com>

* fix

Signed-off-by: Vlad Gheorghiu <vsoftco@gmail.com>

* Minor update

Signed-off-by: Vlad Gheorghiu <vsoftco@gmail.com>

* improve performance of multiidx2n (#173)

* improve performance of multiidx2n

* minor cleanup

* minor fix

* CCNOT example (#175)

* add toffoli example

* fix typo

* Updated CCNOT example

Signed-off-by: Vlad Gheorghiu <vsoftco@gmail.com>

* Minor typos

Signed-off-by: Vlad Gheorghiu <vsoftco@gmail.com>

---------

Signed-off-by: Vlad Gheorghiu <vsoftco@gmail.com>
Co-authored-by: Saman <100295082+enum-class@users.noreply.github.com>
  • Loading branch information
vsoftco and enum-class committed Jul 29, 2024
1 parent 0753d9e commit 46c8c98
Show file tree
Hide file tree
Showing 19 changed files with 146 additions and 174 deletions.
13 changes: 10 additions & 3 deletions .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Configure Quantum++
run: cmake -B build
Expand Down Expand Up @@ -55,7 +55,7 @@ jobs:
- name: Run unit tests
run: ctest --test-dir build -E qpp_Timer

- name: Uninstall
- name: Uninstall Quantum++
shell: bash
run: |
if [ "$RUNNER_OS" == "Windows" ]; then
Expand All @@ -65,5 +65,12 @@ jobs:
fi
- name: Install pyqpp
shell: bash
run: |
pip3 install --user .
python3 -m venv venv
if [ "$RUNNER_OS" == "Windows" ]; then
venv/Scripts/activate
else
. venv/bin/activate
fi
pip3 install .
14 changes: 10 additions & 4 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# Pre-release

- Simplified MATLAB detection via CMake `find_package()` function. Users should
only use `-DQPP_MATLAB=ON` when building with MATLAB support, all other
MATLAB-related CMake flags have been removed.

# Version 5.1 - 1 March 2024

- Replaced ["CHANGES"] by ["CHANGES.md"],
Expand Down Expand Up @@ -308,7 +314,7 @@
attribute `[[qpp::parallel]]`. Since C++17, unknown attributes are supposed
to be ignored by the compiler (and one can use this technique to define
custom attributes). Warnings are explicitly disabled for
clang/gcc/MSVC/icc. If your compiler emits a warning, please disable it
Clang/GCC/MSVC/Intel. If your compiler emits a warning, please disable it
with the corresponding `#pragma` directive at the beginning of ["qpp.h"]
- Added from-string constructor for `qpp::Bit_circuit` and
`qpp::Dynamic_bitset`
Expand Down Expand Up @@ -911,13 +917,13 @@
as using traits over-complicated the design and it was not worth it.
- Marked final all classes that are not intended to be used as base classes.
- Modified the `CMakeLists.txt`, which now:
- supports only GNU gcc and LLVM/Apple clang; otherwise, emits an error
during the CMake running phase
- supports only GCC and LLVM/Apple clang; otherwise, emits an error during
the CMake running phase
- adds `-D_NO_THREAD_LOCAL` definition for conditional compiling the
source code without support for `std::thread_local` (if using e.g.,
LLVM/Apple clang with libc++, as libc++ does not yet support
`std::thread_local`)
- uses OpenMP only if the compiler is detected as GNU gcc
- uses OpenMP only if the compiler is detected as GCC

# Version 0.7 - 22 April 2015

Expand Down
8 changes: 4 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,21 +52,21 @@ if(${Python3_FOUND})
endif()

# BEGIN LOCAL stuff, you don't need those in standalone projects
option(SANITIZE "Enable code sanitizing (only for gcc/clang)" OFF)
option(SANITIZE "Enable code sanitizing (only for GCC/Clang)" OFF)

# Dependencies, do not modify unless you know what you're doing
include(cmake/qpp_eigen3.cmake)

# Dependencies, do not modify unless you know what you're doing
include(cmake/qpp_dependencies.cmake)
include(cmake/qpp_MATLAB.cmake)

# Dependencies, do not modify unless you know what you're doing
include(cmake/qpp_MATLAB.cmake)
include(cmake/qpp_dependencies.cmake)

# Unit testing
add_subdirectory(${CMAKE_SOURCE_DIR}/unit_tests/ EXCLUDE_FROM_ALL SYSTEM)

# Enable all warnings for GNU gcc and Clang/AppleClang
# Enable all warnings for GCC and Clang/AppleClang
if(${CMAKE_CXX_COMPILER_ID} MATCHES "Clang" OR ${CMAKE_CXX_COMPILER_ID}
STREQUAL "GNU")
add_compile_options("-pedantic" "-Wall" "-Wextra" "-Weffc++")
Expand Down
40 changes: 11 additions & 29 deletions INSTALL.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
# Installation instructions

**Quantum++** is a header-only library that uses [CMake](https://cmake.org/) as
its build/install system. **Quantum++** is platform-independent,
supporting [UNIX](https://www.opengroup.org/membership/forums/platform/unix)
(including
[macOS](https://www.apple.com/macos/)) and UNIX-like operating systems
(e.g., [Linux](https://www.linux.org)), as well
as [Windows](https://www.microsoft.com/en-us/windows).
its build/install system. **Quantum++** is platform-independent, supporting
[UNIX](https://www.opengroup.org/membership/forums/platform/unix) (including
[macOS](https://www.apple.com/macos/)) and UNIX-like operating systems (e.g.,
[Linux](https://www.linux.org)), as well as
[Windows](https://www.microsoft.com/en-us/windows).

---

## Pre-requisites

- C++17 compliant compiler, e.g., [gcc](https://gcc.gnu.org/)
, [clang](https://clang.llvm.org)
- C++17 compliant compiler, e.g., [GCC](https://gcc.gnu.org/)
, [Clang](https://clang.llvm.org)
, [MSVC](https://visualstudio.microsoft.com/vs/) etc.
- [CMake](https://cmake.org/)
- [Eigen 3](https://eigen.tuxfamily.org) linear algebra library. If missing, it
Expand All @@ -25,13 +24,8 @@ as [Windows](https://www.microsoft.com/en-us/windows).
Python 3 wrapper
- [MATLAB](https://www.mathworks.com/products/matlab/) compiler shared
libraries and include header files, in case you want to enable
interoperability with MATLAB. If enabled, allows applications build with
interoperability with MATLAB. If enabled, allows applications built with
**Quantum++** to save/load **Quantum++** matrices and vectors to/from MATLAB.
The locations of the MATLAB compiler shared libraries and header files are
platform-specific, e.g., under Linux, they may be located under
`/usr/local/MATLAB/R2021a/bin/glnxa64` and
`/usr/local/MATLAB/R2021a/extern/include`, respectively. On your platform the
locations may of course differ.

---

Expand Down Expand Up @@ -103,19 +97,7 @@ their corresponding `CMakeLists.txt` via `findpackage(qpp ...)`.
| `QPP_FP` | `default`, etc. [`default` by default] | Floating-point type (`qpp::realT`) |
| `QPP_IDX` | `default`, etc. [`default` by default] | Integer index type (`qpp::idx`) |
| | | |
| `SANITIZE` | `ON/OFF` [`OFF` by default] | Enable code sanitizing (only for gcc/clang) |

If `QPP_MATLAB=ON` and the system could not detect your MATLAB installation,
you can manually specify the path to MATLAB's installation directory via the
additional CMake argument

MATLAB_INSTALL_DIR=/path/to/MATLAB

If you are still receiving errors, you can manually specify the path to
MATLAB's required libraries and header files via the additional arguments

MATLAB_LIB_DIR=/path/to/MATLAB/libs
MATLAB_INCLUDE_DIR=/path/to/MATLAB/headers
| `SANITIZE` | `ON/OFF` [`OFF` by default] | Enable code sanitizing (only for GCC/Clang) |

---

Expand Down Expand Up @@ -273,8 +255,8 @@ If building under Windows
with [MATLAB](https://www.mathworks.com/products/matlab/) support, please add
the
location of
`libmx.dll` and `libmat.dll` (the `.dll` **and not** the `.lib` files) to
your `PATH` environment variable. In our case they are located
`libmx.dll` and `libmat.dll` (the `.dll` **and not** the `.lib` files) to your
`PATH` environment variable. For example, on our platform they are located
under `C:\Program Files\MATLAB\R2021a\bin\win64`.

---
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ Copyright (c) 2017 - 2024 softwareQ Inc. All rights reserved.

[Quantum++](https://github.com/softwareQinc/qpp) is distributed under the MIT
license. Please see the
[`LICENSE`](https://github.com/softwareQinc/qpp/blob/main/LICENSE) file for
more details.
[`LICENSE.txt`](https://github.com/softwareQinc/qpp/blob/main/LICENSE.txt)
file for more details.

---

Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion cmake/examples.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ add_custom_target(examples COMMENT "Examples")
foreach(file ${EXAMPLE_FILES})
get_filename_component(TARGET_NAME ${file} NAME_WE)
# Do not build "examples/matlab_io.cpp" if there's no MATLAB support
if(${TARGET_NAME} STREQUAL "matlab_io" AND NOT BUILD_WITH_MATLAB)
if(${TARGET_NAME} STREQUAL "matlab_io" AND NOT MATLAB_FOUND)
continue()
endif()
add_executable(${TARGET_NAME} EXCLUDE_FROM_ALL ${file})
Expand Down
106 changes: 6 additions & 100 deletions cmake/qpp_MATLAB.cmake
Original file line number Diff line number Diff line change
@@ -1,107 +1,13 @@
# MATLAB support, disabled by default
option(QPP_MATLAB "MATLAB support" OFF)
if(${QPP_MATLAB})
message(STATUS "Detecting MATLAB")
# Try to find it automatically
find_package(
Matlab
OPTIONAL_COMPONENTS MX_LIBRARY MAT_LIBRARY
QUIET)
message(STATUS "Detecting MATLAB...")
find_package(Matlab REQUIRED COMPONENTS MX_LIBRARY MAT_LIBRARY)
if(MATLAB_FOUND)
message(STATUS "Detecting MATLAB - done (in ${Matlab_ROOT_DIR})")
include_directories(SYSTEM ${Matlab_INCLUDE_DIRS})
if(WIN32)
if(MSVC)
set(MATLAB_LIB_DIR
"${Matlab_ROOT_DIR}/extern/lib/win64/microsoft"
CACHE PATH "Custom path to MATLAB lib directory")
elseif(MINGW)
set(MATLAB_LIB_DIR
"${Matlab_ROOT_DIR}/extern/lib/win64/mingw64"
CACHE PATH "Custom path to MATLAB lib directory")
else()
message(FATAL_ERROR "Platform not supported, aborting.")
endif()
elseif(UNIX AND NOT APPLE)
set(MATLAB_LIB_DIR
"${Matlab_ROOT_DIR}/bin/glnxa64"
CACHE PATH "Custom path to MATLAB lib directory")
elseif(APPLE)
if(${CMAKE_HOST_SYSTEM_PROCESSOR} MATCHES "arm64")
message(
FATAL_ERROR
"arm64 architecture is not (yet) supported by MATLAB, aborting.")
endif()
set(MATLAB_LIB_DIR
"${Matlab_ROOT_DIR}/bin/maci64"
CACHE PATH "Custom path to MATLAB lib directory")
else()
message(FATAL_ERROR "Platform not supported, aborting.")
endif()
link_directories(${MATLAB_LIB_DIR})
add_compile_definitions(QPP_MATLAB)
set(BUILD_WITH_MATLAB TRUE)
else() # Location manually specified
set(MATLAB_INSTALL_DIR
""
CACHE PATH "Custom path to MATLAB installation")
if(IS_DIRECTORY ${MATLAB_INSTALL_DIR})
# MATLAB include files
set(MATLAB_INCLUDE_DIR
"${MATLAB_INSTALL_DIR}/extern/include"
CACHE PATH "Custom path to MATLAB include directory")
if(IS_DIRECTORY ${MATLAB_INCLUDE_DIR})
include_directories(SYSTEM ${MATLAB_INCLUDE_DIR})
else()
message(FATAL_ERROR "Possibly corrupted MATLAB include headers")
endif()
# MATLAB linker files
if(WIN32)
if(MSVC)
set(MATLAB_LIB_DIR
"${MATLAB_INSTALL_DIR}/extern/lib/win64/microsoft"
CACHE PATH "Custom path to MATLAB lib directory")
elseif(MINGW64)
set(MATLAB_LIB_DIR
"${MATLAB_INSTALL_DIR}/extern/lib/win64/mingw64"
CACHE PATH "Custom path to MATLAB lib directory")
else()
message(FATAL_ERROR "Platform not supported, aborting.")
endif()
elseif(UNIX AND NOT APPLE)
set(MATLAB_LIB_DIR
"${MATLAB_INSTALL_DIR}/bin/glnxa64"
CACHE PATH "Custom path to MATLAB lib directory")
elseif(APPLE)
set(MATLAB_LIB_DIR
"${MATLAB_INSTALL_DIR}/bin/maci64"
CACHE PATH "Custom path to MATLAB lib directory")
else()
message(FATAL_ERROR "Platform not supported, aborting.")
endif()
if(IS_DIRECTORY ${MATLAB_LIB_DIR})
link_directories(${MATLAB_LIB_DIR})
else()
message(FATAL_ERROR "Possibly corrupted MATLAB compiler libraries")
endif()
# Everything is OK, inject definition (as #define) in the source
message(STATUS "Detecting MATLAB - done (in ${MATLAB_INSTALL_DIR})")
add_compile_definitions(QPP_MATLAB)
set(BUILD_WITH_MATLAB TRUE)
else()
message(FATAL_ERROR "Could not detect MATLAB, aborting")
endif()
endif()
# MATLAB linking dependencies to be injected in the main CMakeLists.txt
if(${BUILD_WITH_MATLAB})
if(WIN32)
if(MSVC)
set(QPP_MATLAB_LINK_DEPS libmx libmat)
elseif(MINGW)
set(QPP_MATLAB_LINK_DEPS mx mat)
endif()
else()
set(QPP_MATLAB_LINK_DEPS mx mat)
endif()
set(QPP_MATLAB_LINK_DEPS Matlab::mat Matlab::mx)
message(STATUS "Detected MATLAB in: ${Matlab_ROOT_DIR}")
else()
message(FATAL_ERROR "Could not detect MATLAB, aborting")
endif()
endif()
2 changes: 1 addition & 1 deletion cmake/qpp_dependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ if(${CMAKE_CXX_COMPILER_ID} MATCHES "Clang")
add_compile_options(-stdlib=libc++)
endif()

# GNU gcc additional debug settings
# GCC additional debug settings
if(${CMAKE_CXX_COMPILER_ID} MATCHES "GNU")
# if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin") ## use the "no-weak" debugging
# flag only when debugging under OS X, ## as gdb cannot step in template
Expand Down
14 changes: 7 additions & 7 deletions cmake/qpp_uninstall.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@ endif()
file(READ "@CMAKE_BINARY_DIR@/install_manifest.txt" files)
string(REGEX REPLACE "\n" ";" files "${files}")
foreach(file ${files})
message(STATUS "Uninstalling $ENV{DESTDIR}${file}")
if(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}")
message(STATUS "Uninstalling ${file}")
if(IS_SYMLINK "${file}" OR EXISTS "${file}")
execute_process(
COMMAND @CMAKE_COMMAND@ -E rm $ENV{DESTDIR}${file}
COMMAND @CMAKE_COMMAND@ -E rm -f "${file}"
OUTPUT_VARIABLE rm_out
RESULT_VARIABLE rm_retval)
if(NOT "${rm_retval}" STREQUAL 0)
message(FATAL_ERROR "Problem when removing $ENV{DESTDIR}${file}")
if(${rm_retval})
message(FATAL_ERROR "Problem when removing ${file}")
endif()
else(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}")
message(STATUS "File $ENV{DESTDIR}${file} does not exist.")
else()
message(STATUS "File ${file} does not exist.")
endif()
endforeach()

Expand Down
Loading

0 comments on commit 46c8c98

Please sign in to comment.