Skip to content

Commit 0c30f6b

Browse files
IsFairySarah Schneiderburgholzer
authored
✨ Integrate LogicBlocks (#79)
This PR adds the https://github.com/IsFairy/LogicBlocks submodule as a drop-in replacement for the existing Z3 code. It effectively replaces all existing Z3 code with a corresponding wrapper that allows for higher levels of abstraction and (in the future) for employing different solvers in QMAP. Co-authored-by: Sarah Schneider <sarah.schneider@jku.at> Co-authored-by: burgholzer <burgholzer@me.com>
1 parent c1b13f9 commit 0c30f6b

File tree

17 files changed

+280
-562
lines changed

17 files changed

+280
-562
lines changed

.github/workflows/codeql-analysis.yml

Lines changed: 47 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,58 @@ on:
99
- cron: '15 21 * * 6'
1010

1111
jobs:
12-
analyze:
13-
name: Analyze
12+
analyze-cpp:
13+
name: Analyze C++
1414
runs-on: ubuntu-latest
1515
permissions:
1616
actions: read
1717
contents: read
1818
security-events: write
1919

20-
strategy:
21-
fail-fast: false
22-
matrix:
23-
language: [ 'cpp', 'python' ]
20+
steps:
21+
- name: Checkout repository
22+
uses: actions/checkout@v3
23+
with:
24+
submodules: recursive
25+
26+
# Initializes the CodeQL tools for scanning.
27+
- name: Initialize CodeQL
28+
uses: github/codeql-action/init@v2
29+
with:
30+
languages: 'cpp'
31+
32+
- uses: actions/setup-python@v4
33+
name: Install Python
34+
with:
35+
python-version: '3.10'
36+
37+
- name: Installing boost
38+
run: sudo apt-get install -y libboost-program-options-dev
39+
40+
- name: Install Z3
41+
run: python -m pip install z3-solver
42+
43+
- name: Configure CMake
44+
run: |
45+
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$pythonLocation/lib/python3.10/site-packages/z3/lib
46+
export Z3_ROOT=$pythonLocation/lib/python3.10/site-packages/z3
47+
export Z3_DIR=$pythonLocation/lib/python3.10/site-packages/z3
48+
cmake -S "${{github.workspace}}" -B "${{github.workspace}}/build" -DCMAKE_BUILD_TYPE=Release -DBUILD_QMAP_TESTS=ON -DBINDINGS=ON
49+
50+
- name: Build
51+
run: cmake --build "${{github.workspace}}/build" --parallel 4
52+
53+
54+
- name: Perform CodeQL Analysis
55+
uses: github/codeql-action/analyze@v2
56+
57+
analyze-python:
58+
name: Analyze Python
59+
runs-on: ubuntu-latest
60+
permissions:
61+
actions: read
62+
contents: read
63+
security-events: write
2464

2565
steps:
2666
- name: Checkout repository
@@ -32,9 +72,8 @@ jobs:
3272
- name: Initialize CodeQL
3373
uses: github/codeql-action/init@v2
3474
with:
35-
languages: ${{ matrix.language }}
75+
languages: 'python'
3676

37-
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
3877
- name: Autobuild
3978
uses: github/codeql-action/autobuild@v2
4079

.gitmodules

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,8 @@
33
url = https://github.com/cda-tum/qfr.git
44
branch = main
55
shallow = true
6+
[submodule "extern/LogicBlocks"]
7+
path = extern/LogicBlocks
8+
url = https://github.com/IsFairy/LogicBlocks.git
9+
branch = main
10+
shallow = true

.lgtm.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,15 @@ extraction:
1010
packages:
1111
- python-pip
1212
after_prepare:
13-
- export PATH=~/.local/bin:$PATH
13+
- export PATH=~/.local/bin:~/.local/lib:$PATH
1414
- pip3 install cmake --user
15+
- pip3 install z3-solver --user
1516
- cmake --version
17+
- pip3 show z3-solver
1618
configure:
1719
command:
20+
- export Z3_ROOT=~/.local/lib/python3.8/site-packages/z3
21+
- export Z3_DIR=~/.local/lib/python3.8/site-packages/z3
1822
- cmake -S . -B build -DBUILD_QMAP_TESTS=ON -DBUILD_QFR_TESTS=ON -DBUILD_DD_PACKAGE_TESTS=ON -DBINDINGS=ON
1923
index:
2024
build_command:

CMakeLists.txt

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,26 +35,29 @@ if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
3535
endif ()
3636

3737
macro(check_submodule_present MODULENAME)
38-
if(NOT EXISTS "${PROJECT_SOURCE_DIR}/extern/${MODULENAME}/CMakeLists.txt")
38+
if (NOT EXISTS "${PROJECT_SOURCE_DIR}/extern/${MODULENAME}/CMakeLists.txt")
3939
message(FATAL_ERROR "${MODULENAME} submodule not cloned properly. Please run `git submodule update --init --recursive` from the main project directory")
40-
endif()
40+
endif ()
4141
endmacro()
4242

4343
check_submodule_present(qfr)
4444

45+
check_submodule_present(LogicBlocks)
46+
4547
# Add path for custom modules
46-
list (APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
48+
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
4749

4850
# search for Z3
4951
find_package(Z3)
50-
if(Z3_FOUND AND NOT TARGET z3::z3lib)
52+
if (Z3_FOUND AND NOT TARGET z3::z3lib)
5153
message(STATUS "Found Z3 with version ${Z3_VERSION_STRING}")
5254
add_library(z3::z3lib IMPORTED INTERFACE)
5355
set_property(TARGET z3::z3lib PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${Z3_CXX_INCLUDE_DIRS})
5456
set_property(TARGET z3::z3lib PROPERTY INTERFACE_LINK_LIBRARIES ${Z3_LIBRARIES})
55-
else()
57+
add_definitions(-DZ3_FOUND)
58+
else ()
5659
message(WARNING "Did not find Z3. Exact library and other depending target will not be available")
57-
endif()
60+
endif ()
5861

5962
# add main library code
6063
add_subdirectory(src)
@@ -72,6 +75,6 @@ if (CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
7275
endif ()
7376

7477
# add Python binding code
75-
if(BINDINGS)
78+
if (BINDINGS)
7679
add_subdirectory(mqt/qmap)
77-
endif()
80+
endif ()

MANIFEST.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,5 @@ prune extern/qfr/extern/dd_package/extern
1515
prune extern/qfr/extern/zx/extern/googletest
1616

1717
graft apps
18+
19+
graft extern/LogicBlocks

cmake/FindZ3.cmake

Lines changed: 49 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ INCLUDE(CheckCXXSourceRuns)
33

44
# Function to check Z3's version
55
function(check_z3_version z3_include z3_lib)
6-
# The program that will be executed to print Z3's version.
7-
file(WRITE ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/testz3.cpp
8-
"#include <assert.h>
6+
# The program that will be executed to print Z3's version.
7+
file(WRITE ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/testz3.cpp
8+
"#include <assert.h>
99
#include <z3.h>
1010
int main() {
1111
unsigned int major, minor, build, rev;
@@ -14,70 +14,70 @@ function(check_z3_version z3_include z3_lib)
1414
return 0;
1515
}")
1616

17-
# Get lib path
18-
get_filename_component(z3_lib_path ${z3_lib} PATH)
17+
# Get lib path
18+
get_filename_component(z3_lib_path ${z3_lib} PATH)
1919

20-
try_run(
21-
Z3_RETURNCODE
22-
Z3_COMPILED
23-
${CMAKE_BINARY_DIR}
24-
${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/testz3.cpp
25-
COMPILE_DEFINITIONS -I"${z3_include}"
26-
LINK_LIBRARIES -L${z3_lib_path} -lz3
27-
RUN_OUTPUT_VARIABLE SRC_OUTPUT
28-
)
20+
try_run(
21+
Z3_RETURNCODE
22+
Z3_COMPILED
23+
${CMAKE_BINARY_DIR}
24+
${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/testz3.cpp
25+
COMPILE_DEFINITIONS -I"${z3_include}"
26+
LINK_LIBRARIES -L${z3_lib_path} -lz3
27+
RUN_OUTPUT_VARIABLE SRC_OUTPUT
28+
)
2929

30-
if(Z3_COMPILED)
31-
string(REGEX REPLACE "([0-9]*\\.[0-9]*\\.[0-9]*)" "\\1"
32-
z3_version "${SRC_OUTPUT}")
33-
set(Z3_VERSION_STRING ${z3_version} PARENT_SCOPE)
34-
endif()
30+
if (Z3_COMPILED)
31+
string(REGEX REPLACE "([0-9]*\\.[0-9]*\\.[0-9]*)" "\\1"
32+
z3_version "${SRC_OUTPUT}")
33+
set(Z3_VERSION_STRING ${z3_version} PARENT_SCOPE)
34+
endif ()
3535
endfunction(check_z3_version)
3636

3737
# if Z3_ROOT is provided, check there first
3838
set(Z3_ROOT "" CACHE PATH "Root of Z3 distribution.")
3939
if (DEFINED ENV{Z3_ROOT})
40-
set(Z3_ROOT $ENV{Z3_ROOT})
41-
message("Z3_ROOT: ${Z3_ROOT}")
40+
set(Z3_ROOT $ENV{Z3_ROOT})
41+
message("Z3_ROOT: ${Z3_ROOT}")
4242
endif ()
4343
if (NOT ${Z3_ROOT} STREQUAL "")
44-
find_path(Z3_CXX_INCLUDE_DIRS NAMES z3.h z3++.h
45-
NO_DEFAULT_PATH
46-
PATHS ${Z3_ROOT}/include
47-
PATH_SUFFIXES libz3 z3)
44+
find_path(Z3_CXX_INCLUDE_DIRS NAMES z3.h z3++.h
45+
NO_DEFAULT_PATH
46+
PATHS ${Z3_ROOT}/include
47+
PATH_SUFFIXES libz3 z3)
4848

49-
find_library(Z3_LIBRARIES NAMES z3 libz3
50-
NO_DEFAULT_PATH
51-
PATHS ${Z3_ROOT}
52-
PATH_SUFFIXES lib bin)
49+
find_library(Z3_LIBRARIES NAMES z3 libz3
50+
NO_DEFAULT_PATH
51+
PATHS ${Z3_ROOT}
52+
PATH_SUFFIXES lib bin)
5353
endif ()
5454

5555
# see if a config file is available
5656
if (NOT Z3_CXX_INCLUDE_DIRS OR NOT Z3_LIBRARIES)
57-
find_package(Z3 CONFIG)
58-
endif()
57+
find_package(Z3 CONFIG)
58+
endif ()
5959

6060
# try default paths as a last hope
6161
if (NOT Z3_FOUND)
62-
find_path(Z3_CXX_INCLUDE_DIRS NAMES z3.h z3++.h
63-
PATH_SUFFIXES libz3 z3)
64-
find_library(Z3_LIBRARIES NAMES z3 libz3
65-
PATH_SUFFIXES lib bin)
62+
find_path(Z3_CXX_INCLUDE_DIRS NAMES z3.h z3++.h
63+
PATH_SUFFIXES libz3 z3)
64+
find_library(Z3_LIBRARIES NAMES z3 libz3
65+
PATH_SUFFIXES lib bin)
6666

67-
unset(Z3_VERSION_STRING)
67+
unset(Z3_VERSION_STRING)
6868

69-
# Try to check version by compiling a small program that prints Z3's version
70-
if(Z3_CXX_INCLUDE_DIRS AND Z3_LIBRARIES)
71-
check_z3_version(${Z3_CXX_INCLUDE_DIRS} ${Z3_LIBRARIES})
72-
endif()
69+
# Try to check version by compiling a small program that prints Z3's version
70+
if (Z3_CXX_INCLUDE_DIRS AND Z3_LIBRARIES)
71+
check_z3_version(${Z3_CXX_INCLUDE_DIRS} ${Z3_LIBRARIES})
72+
endif ()
7373

74-
if(NOT Z3_VERSION_STRING)
75-
set(Z3_VERSION_STRING "0.0.0")
76-
endif()
74+
if (NOT Z3_VERSION_STRING)
75+
set(Z3_VERSION_STRING "0.0.0")
76+
endif ()
7777

78-
include (FindPackageHandleStandardArgs)
79-
find_package_handle_standard_args(Z3
80-
REQUIRED_VARS Z3_LIBRARIES Z3_CXX_INCLUDE_DIRS
81-
VERSION_VAR Z3_VERSION_STRING)
82-
mark_as_advanced(Z3_CXX_INCLUDE_DIRS Z3_LIBRARIES)
83-
endif ()
78+
include(FindPackageHandleStandardArgs)
79+
find_package_handle_standard_args(Z3
80+
REQUIRED_VARS Z3_LIBRARIES Z3_CXX_INCLUDE_DIRS
81+
VERSION_VAR Z3_VERSION_STRING)
82+
mark_as_advanced(Z3_CXX_INCLUDE_DIRS Z3_LIBRARIES)
83+
endif ()

extern/LogicBlocks

Submodule LogicBlocks added at 6c848ac

include/Encodings.hpp

Lines changed: 0 additions & 85 deletions
This file was deleted.

include/exact/ExactMapper.hpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
#ifndef EXACT_MAPPER_hpp
77
#define EXACT_MAPPER_hpp
88

9-
#include "Encodings.hpp"
109
#include "Mapper.hpp"
1110

1211
#include <algorithm>
@@ -16,10 +15,7 @@
1615
#include <functional>
1716
#include <set>
1817
#include <unordered_set>
19-
#include <z3++.h>
2018

21-
using namespace z3;
22-
using matrix = std::vector<expr_vector>;
2319
using Swaps = std::vector<std::pair<unsigned short, unsigned short>>;
2420
using QubitChoice = std::set<unsigned short>;
2521

0 commit comments

Comments
 (0)