Skip to content

Getting cppsim to compile from sources alongside the MindQuantum sources#23

Open
dmikushin wants to merge 82 commits into
Takishima:feature/cppsimfrom
dmikushin:feature/cppsim
Open

Getting cppsim to compile from sources alongside the MindQuantum sources#23
dmikushin wants to merge 82 commits into
Takishima:feature/cppsimfrom
dmikushin:feature/cppsim

Conversation

@dmikushin
Copy link
Copy Markdown

In principle, cppsim source is now integrated into MQ, and compiles together with it. There are several items to be addressed yet:

  1. The cmake and cmake/commands modules folder should not be reached with ../../.., this is ugly. But I was not able to find an example of a better way to do it in other subfolders.
include("${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/compiler_has_std_filesystem.cmake")

Accessing ../../include/cppsim include directory is also ugly, maybe there is a good environment variable to use instead?

  1. CppSim still deals with dlfcn-win32 by itself, while all other dependencies are brought in globally, by MQ. I guess we should move this dependency out on MQ likewise, but before that maybe it's better to use cross-platform dynalo instead?

  2. There is an issue with std::allocator, compiler complains about max_size(). Even though throw() version is not deprecated, it fails either way. Maybe we disable exceptions?

    // class std::allocator<std::complex<double> >’ has no member named ‘max_size’; did you mean ‘_M_max_size’?
    size_type max_size() const noexcept
    {
        std::allocator<T> a;
        return a.max_size();
    }

…to automatic arrays type deduction for v and tmp
…ng string of source code. We intentionally keep the generator in Python, in order to let the people to customize it more easily.
…generated kernel to the correctness test. Breaking compatibility with the original kernels API, in order to be able to supply psi and m as plain pointers
…pilation. On the other hand, we could possibly use arrays for matrix operations?
…should be able to generated vectorized matrix multiplies (given that the compiler options are set). Matrix-vector itself is not yet efficient though, moreover the gaps in 'psi' elements are bad for memory efficiency
… The compilation times with eigen are an order of magnitude faster now, feels like the time is flat
Takishima and others added 27 commits December 20, 2022 07:39
Add a check to make sure the kernelgen.py script does exists based on
the input to the kernelgen() function.

Also make kernelgen() a function instead of a macro and add a
`COMBINATIONS` arguments
…nfigs, which somehow fail to advertise themselves as MSYS or MINGW environments
@Takishima
Copy link
Copy Markdown
Owner

1. The `cmake` and `cmake/commands` modules folder should not be reached with `../../..`, this is ugly. But I was not able to find an example of a better way to do it in other subfolders.

This is easily fixed. As long as the corresponding folders are inside the CMAKE_MODULE_PATH you can include them without using a path:

include(compiler_has_std_filesystem)
2. CppSim still deals with `dlfcn-win32` by itself, while all other dependencies are brought in globally, by MQ. I guess we should move this dependency out on MQ likewise, but before that maybe it's better to use cross-platform dynalo instead?

Sure we could do that. Otherwise, we can just add dlfcn-win32 to the list of third parties in MindQuantum and only load it when necessary.

3. There is an issue with std::allocator, compiler complains about max_size(). Even though throw() version is not deprecated, it fails either way. Maybe we disable exceptions?

As discussed yesterday, look at the version included in HiQ-ProjectQ.

Copy link
Copy Markdown
Owner

@Takishima Takishima left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's a preliminary review of the code with some comments. More work is needed before we can propose this for a merge.

Also, the source code is missing the license information which might trigger some tools once we do perform the actual merge on Gitee.

Comment on lines +1 to +16
cmake_minimum_required(VERSION 3.20 FATAL_ERROR)

project(
cppsim
VERSION 1.0.0
LANGUAGES C CXX)

# Minimum required Python version (used both in this file and in the installed CMake configuration)
set(CPPSIM_PYTHON_VERSION_MIN 3.7.0)

option(BUILD_TESTING "Build the test suite?" OFF)

if(NOT DEFINED ITERATOR_DEBUG_VALUE)
set(ITERATOR_DEBUG_VALUE 0)
endif()
option(MSVC_ITERATOR_DEBUG "Define _ITERATOR_DEBUG_LEVEL (defaults to 0, can be set using ITERATOR_DEBUG_VALUE)" OFF)
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To match with the rest of MindQuantum, remove these lines. The CMake options and variables should be already defined by MindQuantum

Comment on lines +20 to +30
include(GNUInstallDirs)

set(CPPSIM_INSTALL_BINDIR "${CMAKE_INSTALL_BINDIR}")
set(CPPSIM_INSTALL_SBINDIR "${CMAKE_INSTALL_SBINDIR}")
set(CPPSIM_INSTALL_SYSCONFDIR "${CMAKE_INSTALL_SYSCONFDIR}")
set(CPPSIM_INSTALL_INCLUDEDIR "${CMAKE_INSTALL_INCLUDEDIR}/cppsim")
set(CPPSIM_INSTALL_DATADIR "${CMAKE_INSTALL_DATADIR}/cppsim")
set(CPPSIM_INSTALL_LIBDIR "${CMAKE_INSTALL_LIBDIR}/cppsim")
set(CPPSIM_INSTALL_DOCDIR "${CMAKE_INSTALL_DATADIR}/doc/cppsim")
set(CPPSIM_INSTALL_CMAKEDIR "${CPPSIM_INSTALL_DATADIR}/cmake")
set(CPPSIM_INSTALL_3RDPARTYDIR "${CPPSIM_INSTALL_LIBDIR}/third_party")
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Modify those so that they are using the MQ_INSTALL_XXX CMake variables.

You may redefined the CPPSIM_INSTALL_XXX to be relative to MQ_INSTALL_3RDPARTYDIR for example

# ==============================================================================

# TODO
include("${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/compiler_has_std_filesystem.cmake")
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As explained in another comment, you should be able to simply write

include(compiler_has_std_filesystem)

This should work since MindQuantum modifies the CMAKE_MODULE_PATH variables elsewhere for this exact purpose.

Comment on lines +53 to +61
if(NOT DEFINED Eigen3_DIR)
FetchContent_Declare(
Eigen3
GIT_REPOSITORY https://gitlab.com/libeigen/eigen.git
GIT_TAG 3147391d946bb4b6c68edd901f2add6ac1f31f8c)
FetchContent_MakeAvailable(googletest Eigen3)
else()
find_package(Eigen3 CONFIG REQUIRED)
endif()
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be removed since Eigen3 is found by MindQuantum in its third-party libraries directory.

You can add a short comment saying that one could want to look for Eigen3 here if it was not before.

@@ -0,0 +1,43 @@
#include <algorithm>
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test code should go under tests

@@ -0,0 +1,142 @@
// Ensure hand-written and generated kernels give equal results.
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test code should go under tests

@@ -0,0 +1,271 @@
#include <algorithm>
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test code should go under tests

Comment on lines +88 to +97
find_package(res_embed QUIET CONFIG)
if(NOT res_embed_FOUND)
FetchContent_Declare(
res_embed
GIT_REPOSITORY https://github.com/dmikushin/res_embed.git
GIT_TAG 93b5711070086dea53c3b535018ff34e68479242)
FetchContent_MakeAvailable(res_embed)
else()
message(STATUS "Found res_embed at ${res_embed_DIR}")
endif()
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like for Eigen3 these lines are not required since ResEmbed is a third-party of MindQuantum.

You can add a short comment saying that one could want to look for ResEmbed here if it was not before.

@Takishima
Copy link
Copy Markdown
Owner

Also ensure that the versions of the third-party specified in the third_party folders are the same you are specifying (e.g. for ResEmbed)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants