Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Move OpenQL to modern CMake practices #460

Draft
wants to merge 2 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,5 @@ docs/_templates
docs/_templates

/.idea
.vscode
/cmake-build-*
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,6 @@
path = deps/json
url = https://github.com/nlohmann/json.git
shallow = true
[submodule "deps/googletest"]
path = deps/googletest
url = https://github.com/google/googletest.git
362 changes: 65 additions & 297 deletions CMakeLists.txt

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions RELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ secrets are configured correctly.
is to be released. For example, `release-0.0.1`, but the suffix doesn't
matter.

- Change the version in `include/ql/version.h` (this is the only functional
- Change the version in `src/ql/include/ql/version.h` (this is the only functional
place where the version is hardcoded) and change any other files where
applicable (changelog, etc) and update `CHANGELOG.md` accordingly, then
commit and make a PR for it.
Expand All @@ -35,7 +35,7 @@ secrets are configured correctly.
- If needed, also merge to `master`.

- Draft a new release through the GitHub interface. Set the "tag version"
to the same version you put in `include/ql/version.h`, the title to
to the same version you put in `src/ql/include/ql/version.h`, the title to
"Release `version`: `name`", and write release notes in the body. The
release notes should include at least:

Expand Down
1 change: 1 addition & 0 deletions deps/googletest
Submodule googletest added at 0e0d9f
4 changes: 2 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,14 +129,14 @@ def get_version(verbose=0):
""" Extract version information from source code """

matcher = re.compile('[\t ]*#define[\t ]+OPENQL_VERSION_STRING[\t ]+"(.*)"')
with open(os.path.join('..', 'include', 'ql', 'version.h'), 'r') as f:
with open(os.path.join('..', 'src', 'ql', 'include', 'ql', 'version.h'), 'r') as f:
for ln in f:
m = matcher.match(ln)
if m:
version = m.group(1)
break
else:
raise Exception('failed to parse version string from include/ql/version.h')
raise Exception('failed to parse version string from src/ql/include/ql/version.h')

return version

Expand Down
8 changes: 4 additions & 4 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.1 FATAL_ERROR)

add_openql_test(multi_qubits_randomized_benchmarking multi_qubits_randomized_benchmarking.cc ../tests)
add_openql_test(randomized_benchmarking randomized_benchmarking.cc ../tests)
add_openql_test(rb_single rb_single.cc ../tests)
add_openql_test(simple simple.cc ../tests)
add_openql_test(multi_qubits_randomized_benchmarking multi_qubits_randomized_benchmarking.cc)
add_openql_test(randomized_benchmarking randomized_benchmarking.cc)
add_openql_test(rb_single rb_single.cc)
add_openql_test(simple simple.cc)
2 changes: 1 addition & 1 deletion examples/multi_qubits_randomized_benchmarking.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#include <time.h>

#include <openql>
#include "openql.h"

// clifford inverse lookup table for grounded state
const size_t inv_clifford_lut_gs[] = {0, 2, 1, 3, 8, 10, 6, 11, 4, 9, 5, 7, 12, 16, 23, 21, 13, 17, 18, 19, 20, 15, 22, 14};
Expand Down
2 changes: 1 addition & 1 deletion examples/simple.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include <iostream>
#include <openql>
#include "openql.h"

int main(int argc, char **argv) {
// create platform
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

root_dir = os.getcwd() # root of the repository
src_dir = root_dir + os.sep + 'src' # C++ source directory
inc_dir = root_dir + os.sep + 'include' # C++ include directory
inc_dir = root_dir + os.sep + 'src' + os.sep + 'ql' + os.sep + 'include' # C++ include directory
pysrc_dir = root_dir + os.sep + 'python' # Python source files
target_dir = root_dir + os.sep + 'pybuild' # python-specific build directory
build_dir = target_dir + os.sep + 'build' # directory for setuptools to dump various files into
Expand Down
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add_subdirectory(ql)
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions src/openql.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "openql.h"
24 changes: 24 additions & 0 deletions src/ql/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Generate a header file with configuration options that cannot be compiled
# (entirely) into the shared/static library due to use of templates.
set(QL_CHECKED_VEC ${OPENQL_CHECKED_VEC})
set(QL_CHECKED_LIST ${OPENQL_CHECKED_LIST})
set(QL_CHECKED_MAP ${OPENQL_CHECKED_MAP})
set(QL_SHARED_LIB ${BUILD_SHARED_LIBS})
configure_file(
"include/ql/config.h.template"
"${CMAKE_CURRENT_BINARY_DIR}/include/ql/config.h"
)

add_library(config INTERFACE)
target_include_directories(config INTERFACE "include")
target_include_directories(config INTERFACE "${CMAKE_CURRENT_BINARY_DIR}/include/")

add_subdirectory(api)
add_subdirectory(arch)
add_subdirectory(com)
add_subdirectory(ir)
add_subdirectory(pass)
add_subdirectory(pmgr)
add_subdirectory(resource)
add_subdirectory(rmgr)
add_subdirectory(utils)
20 changes: 20 additions & 0 deletions src/ql/api/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
add_library(api
"misc.cc"
"pass.cc"
"compiler.cc"
"platform.cc"
"creg.cc"
"operation.cc"
"unitary.cc"
"kernel.cc"
"program.cc"
"cqasm_reader.cc"
)

target_include_directories(api PUBLIC include)

target_link_libraries(api PRIVATE config)
target_link_libraries(api PUBLIC ir_compat)
target_link_libraries(api PUBLIC pmgr)
target_link_libraries(api PUBLIC com_dec)
target_link_libraries(api PUBLIC arch_diamond_annotations)
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
23 changes: 23 additions & 0 deletions src/ql/arch/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
add_library(all_architectures OBJECT)

macro(add_arch_library name)
add_library("${name}" OBJECT "${ARGN}")
target_sources(all_architectures PUBLIC $<TARGET_OBJECTS:${name}>)
endmacro()

add_subdirectory(cc)
add_subdirectory(cc_light)
add_subdirectory(diamond)
add_subdirectory(none)

add_library(arch
"info_base.cc"
"architecture.cc"
"factory.cc"
)

target_include_directories(arch PUBLIC include)

target_link_libraries(arch PUBLIC utils)
target_link_libraries(arch PRIVATE ir_compat)
target_link_libraries(arch PRIVATE pmgr)
2 changes: 2 additions & 0 deletions src/ql/arch/architecture.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
*/

#include "ql/arch/architecture.h"
#include "ql/pmgr/declarations.h"
#include "ql/ir/compat/platform.h"

namespace ql {
namespace arch {
Expand Down
23 changes: 23 additions & 0 deletions src/ql/arch/cc/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
add_arch_library(arch_cc
"info.cc"
"pass/gen/vq1asm/detail/backend.cc"
"pass/gen/vq1asm/detail/codegen.cc"
"pass/gen/vq1asm/detail/codesection.cc"
"pass/gen/vq1asm/detail/datapath.cc"
"pass/gen/vq1asm/detail/functions.cc"
"pass/gen/vq1asm/detail/operands.cc"
"pass/gen/vq1asm/detail/settings.cc"
"pass/gen/vq1asm/detail/vcd.cc"
"pass/gen/vq1asm/vq1asm.cc"
)

create_resource(cc_hwconf_default "resources/hwconf_default.json" "${CMAKE_CURRENT_BINARY_DIR}/include/ql/arch/cc/resources/hwconf_default.inc")
add_dependencies(arch_cc cc_hwconf_default)

target_include_directories(arch_cc PUBLIC include)
target_include_directories(arch_cc PUBLIC "${CMAKE_CURRENT_BINARY_DIR}/include")

target_link_libraries(arch_cc PUBLIC utils)
target_link_libraries(arch_cc PUBLIC pmgr)
target_link_libraries(arch_cc PRIVATE ir)
target_link_libraries(arch_cc PUBLIC config)
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "ql/utils/json.h"
#include "ql/pmgr/manager.h"
#include "ql/arch/info_base.h"
#include "ql/arch/factory.h"

namespace ql {
namespace arch {
Expand All @@ -22,7 +23,8 @@ namespace cc {
*/
class Info : public InfoBase {
public:

static bool is_architecture_registered;

/**
* Writes the documentation for this architecture to the given output
* stream.
Expand Down Expand Up @@ -77,7 +79,6 @@ class Info : public InfoBase {
* is considered a backend pass.
*/
void populate_backend_passes(pmgr::Manager &manager, const utils::Str &variant) const override;

};

} // namespace cc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@

#pragma once

#include "types.h"
#include "options.h"
#include "codegen.h"
#include "ql/arch/cc/pass/gen/vq1asm/detail/types.h"
#include "ql/arch/cc/pass/gen/vq1asm/detail/options.h"
#include "ql/arch/cc/pass/gen/vq1asm/detail/codegen.h"

#include "ql/ir/ir.h"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

#pragma once

#include "types.h"
#include "options.h"
#include "settings.h"
#include "ql/arch/cc/pass/gen/vq1asm/detail/types.h"
#include "ql/arch/cc/pass/gen/vq1asm/detail/options.h"
#include "ql/arch/cc/pass/gen/vq1asm/detail/settings.h"

namespace ql {
namespace arch {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@

#include "ql/ir/ir.h"

#include "operands.h"
#include "types.h"
#include "options.h"
#include "bundle_info.h"
#include "codesection.h"
#include "functions.h"
#include "datapath.h"
#include "settings.h"
#include "vcd.h"
#include "ql/arch/cc/pass/gen/vq1asm/detail/operands.h"
#include "ql/arch/cc/pass/gen/vq1asm/detail/types.h"
#include "ql/arch/cc/pass/gen/vq1asm/detail/options.h"
#include "ql/arch/cc/pass/gen/vq1asm/detail/bundle_info.h"
#include "ql/arch/cc/pass/gen/vq1asm/detail/codesection.h"
#include "ql/arch/cc/pass/gen/vq1asm/detail/functions.h"
#include "ql/arch/cc/pass/gen/vq1asm/detail/datapath.h"
#include "ql/arch/cc/pass/gen/vq1asm/detail/settings.h"
#include "ql/arch/cc/pass/gen/vq1asm/detail/vcd.h"

namespace ql {
namespace arch {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

#include "ql/ir/ir.h"

#include "types.h"
#include "operands.h"
#include "ql/arch/cc/pass/gen/vq1asm/detail/types.h"
#include "ql/arch/cc/pass/gen/vq1asm/detail/operands.h"

// Constants
// FIXME: move out of .h
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

#include <iomanip>

#include "types.h"
#include "bundle_info.h"
#include "ql/arch/cc/pass/gen/vq1asm/detail/types.h"
#include "ql/arch/cc/pass/gen/vq1asm/detail/bundle_info.h"

#include "ql/utils/logger.h"
#include "ql/ir/compat/compat.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

#include "ql/ir/ir.h"

#include "types.h"
#include "operands.h"
#include "datapath.h"
#include "codesection.h"
#include "ql/arch/cc/pass/gen/vq1asm/detail/types.h"
#include "ql/arch/cc/pass/gen/vq1asm/detail/operands.h"
#include "ql/arch/cc/pass/gen/vq1asm/detail/datapath.h"
#include "ql/arch/cc/pass/gen/vq1asm/detail/codesection.h"

namespace ql {
namespace arch {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#include "ql/ir/ir.h"

#include "types.h"
#include "ql/arch/cc/pass/gen/vq1asm/detail/types.h"

/**
* Helper macro for QL_ICE() that throws when the given condition is not
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@

#pragma once

#include "types.h"
#include "ql/arch/cc/pass/gen/vq1asm/detail/types.h"
#include "ql/config.h"

// constants
#define CC_BACKEND_VERSION_STRING "0.4.0"
Expand All @@ -18,7 +19,7 @@
#define OPT_SUPPORT_STATIC_CODEWORDS 1 // support (currently: require) static codewords, instead of allocating them on demand
#define OPT_STATIC_CODEWORDS_ARRAYS 1 // JSON field static_codeword_override is an array with one element per qubit parameter
#define OPT_VECTOR_MODE 0 // 1=generate single code word for all output groups together (requires codewords allocated by backend)
#define OPT_CC_USER_FUNCTIONS 1 // 1=add support for some user functions (experimental)


// NOTE JvS: I added these to the documentation string for the backend pass, so
// you can see these values at runtime.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

#pragma once

#include "types.h"
#include "options.h"
#include "ql/arch/cc/pass/gen/vq1asm/detail/types.h"
#include "ql/arch/cc/pass/gen/vq1asm/detail/options.h"

#include "ql/ir/compat/platform.h" // FIXME
#include "ql/ir/ir.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

#include "ql/utils/vcd.h"

#include "types.h"
#include "settings.h"
#include "ql/arch/cc/pass/gen/vq1asm/detail/types.h"
#include "ql/arch/cc/pass/gen/vq1asm/detail/settings.h"

namespace ql {
namespace arch {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ namespace vq1asm {
* QuTech Central Controller Q1 processor assembly generator pass.
*/
class GenerateVQ1AsmPass : public pmgr::pass_types::Transformation {
static bool is_pass_registered;

protected:

/**
Expand Down
3 changes: 2 additions & 1 deletion src/ql/arch/cc/info.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ namespace ql {
namespace arch {
namespace cc {

bool Info::is_architecture_registered = Factory::register_architecture<Info>();

// local constants
const utils::Str predicateKeyInstructionType = "cc-desugar-instruction-type";
const utils::Str predicateValueMeas = "cc-desugar-meas";
Expand Down Expand Up @@ -655,7 +657,6 @@ void Info::post_process_platform(
* is considered a backend pass.
*/
void Info::populate_backend_passes(pmgr::Manager &manager, const utils::Str &variant) const {

// Remove prescheduler if enabled implicitly (pointless since we add our own scheduling).
// FIXME: bit of a hack, and invalidates https://openql.readthedocs.io/en/latest/gen/reference_architectures.html#default-pass-list
utils::Str ps_name = "prescheduler";
Expand Down
4 changes: 2 additions & 2 deletions src/ql/arch/cc/pass/gen/vq1asm/detail/backend.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
* @brief backend for the Central Controller
*/

#include "backend.h"
#include "operands.h"
#include "ql/arch/cc/pass/gen/vq1asm/detail/backend.h"
#include "ql/arch/cc/pass/gen/vq1asm/detail/operands.h"

#include "ql/utils/str.h"
#include "ql/utils/filesystem.h"
Expand Down
Loading