Skip to content

Commit be0781f

Browse files
arcondellomarshall-dwJun CaiKarthika Raghavanvpapish
committed
Initial Commit
Co-authored-by: Marshall Drew-Brook <[email protected]> Co-authored-by: Jun Cai <[email protected]> Co-authored-by: Karthika Raghavan <[email protected]> Co-authored-by: Vlad Papish <[email protected]> Co-authored-by: fzieba <[email protected]> Co-authored-by: Fiona Hanington <[email protected]> Co-authored-by: Tony Leung <[email protected]> Co-authored-by: Filip Zieba <[email protected]> Co-authored-by: Charles Chan <[email protected]> Co-authored-by: Mohsinul Jahid <[email protected]> Co-authored-by: David Johnson <[email protected]> Co-authored-by: Tomas Cirip <[email protected]> Co-authored-by: Alexander Condello <[email protected]>
0 parents  commit be0781f

File tree

413 files changed

+63825
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

413 files changed

+63825
-0
lines changed

LICENSE

+349
Large diffs are not rendered by default.

c-client/.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/.idea/
2+
/Build*/

c-client/CMakeLists.txt

+248
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,248 @@
1+
cmake_minimum_required(VERSION 2.8)
2+
set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/../cmake-modules)
3+
project(sapi-c-client CXX C)
4+
include(ExternalProject)
5+
6+
file(STRINGS ../version.txt SAPI_VERSION LIMIT_COUNT 1)
7+
if(${CMAKE_SIZEOF_VOID_P} EQUAL 8)
8+
set(BITS 64)
9+
else()
10+
set(BITS 32)
11+
endif()
12+
if(CMAKE_HOST_WIN32)
13+
set(SAPI_ARCH "win${BITS}")
14+
elseif(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
15+
set(SAPI_ARCH "linux${BITS}")
16+
elseif(CMAKE_HOST_APPLE)
17+
set(SAPI_ARCH "osx") # No more 32-bit OSX
18+
else()
19+
message(SEND_ERROR "Unknown system type")
20+
endif()
21+
set(SAPI_CLIENT C)
22+
configure_file("${CMAKE_SOURCE_DIR}/../remote/src/user-agent.cpp.in"
23+
user-agent.cpp @ONLY ESCAPE_QUOTES)
24+
25+
set(PRODUCT_NAME "D-WAVE C PACK")
26+
27+
if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
28+
set(README_LINUX_NSS "
29+
Linux users: if you see an error message like this:
30+
31+
libssl3.so: cannot open shared object file: No such file or directory
32+
33+
your system is likely missing NSS libraries. Install the libnss3 (Ubuntu,
34+
Debian) or nss (Fedora, Red Hat) package.")
35+
else()
36+
set(README_LINUX_NSS)
37+
endif()
38+
configure_file(README.txt.in README.txt @ONLY)
39+
configure_file(${CMAKE_SOURCE_DIR}/licenses/eula.txt.in
40+
${CMAKE_CURRENT_BINARY_DIR}/licenses/eula.txt @ONLY)
41+
42+
set(DOWNLOAD_DIR ${CMAKE_CURRENT_BINARY_DIR}/download)
43+
44+
# Enable C++11 support
45+
# requires g++ >=4.4 on Linux
46+
if(CMAKE_COMPILER_IS_GNUCXX)
47+
execute_process(COMMAND ${CMAKE_CXX_COMPILER} -dumpversion
48+
OUTPUT_VARIABLE GXX_VERSION OUTPUT_STRIP_TRAILING_WHITESPACE
49+
ERROR_QUIET)
50+
if(GXX_VERSION VERSION_LESS 4.4)
51+
message(SEND_ERROR "g++ >= 4.4 required")
52+
elseif(GXX_VERSION VERSION_LESS 4.7)
53+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
54+
else()
55+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
56+
endif()
57+
elseif(CMAKE_CXX_COMPILER_ID STREQUAL Clang)
58+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -stdlib=libc++")
59+
elseif(MSVC)
60+
add_definitions(/D_WIN32_WINNT=0x501)
61+
if(MSVC_VERSION EQUAL 1700)
62+
add_definitions(/D_VARIADIC_MAX=10)
63+
endif()
64+
endif()
65+
66+
configure_file(src/version.c.in version.c @ONLY ESCAPE_QUOTES)
67+
68+
# Boost
69+
find_package(Boost 1.53 REQUIRED COMPONENTS system)
70+
add_definitions(-DBOOST_ALL_NO_LIB)
71+
include_directories(SYSTEM ${Boost_INCLUDE_DIR})
72+
73+
# coin-or
74+
include(coinor)
75+
include_directories(${COINOR_INCLUDE_DIR})
76+
77+
# External: orang
78+
ExternalProject_Add(orang
79+
GIT_REPOSITORY "http://git.dwavesys.local/scm/~marshall/orang.git"
80+
GIT_TAG "v1.1"
81+
UPDATE_COMMAND ""
82+
CONFIGURE_COMMAND ""
83+
CMAKE_COMMAND ""
84+
BUILD_COMMAND ""
85+
INSTALL_COMMAND "")
86+
87+
set(FIND_EMBEDDING_SOURCES
88+
${CMAKE_SOURCE_DIR}/../find-embedding/src/find_embedding.cpp)
89+
90+
set(FIX_VARIABLES_SOURCES
91+
${CMAKE_SOURCE_DIR}/../fix-variables/src/fix_variables.cpp)
92+
93+
set(SAPI_LOCAL_SOURCES
94+
${CMAKE_SOURCE_DIR}/../local-solvers/src/orang-heuristic.cpp
95+
${CMAKE_SOURCE_DIR}/../local-solvers/src/orang-solvers.cpp
96+
${CMAKE_SOURCE_DIR}/../local-solvers/src/problems.cpp)
97+
98+
set(QSAGE_SOURCES
99+
${CMAKE_SOURCE_DIR}/../qsage/src/blackbox.cpp)
100+
101+
set(SAPI_REMOTE_SOURCES
102+
${CMAKE_SOURCE_DIR}/../remote/src/answer-service.cpp
103+
${CMAKE_SOURCE_DIR}/../remote/src/await.cpp
104+
${CMAKE_SOURCE_DIR}/../remote/src/base64.cpp
105+
${CMAKE_SOURCE_DIR}/../remote/src/decode-answer.cpp
106+
${CMAKE_SOURCE_DIR}/../remote/src/decode-qp.cpp
107+
${CMAKE_SOURCE_DIR}/../remote/src/encode-qp.cpp
108+
${CMAKE_SOURCE_DIR}/../remote/src/http-service.cpp
109+
${CMAKE_SOURCE_DIR}/../remote/src/json.cpp
110+
${CMAKE_SOURCE_DIR}/../remote/src/problem-manager.cpp
111+
${CMAKE_SOURCE_DIR}/../remote/src/retry-service.cpp
112+
${CMAKE_SOURCE_DIR}/../remote/src/sapi-service.cpp
113+
${CMAKE_SOURCE_DIR}/../remote/src/threadpool.cpp
114+
${CMAKE_CURRENT_BINARY_DIR}/user-agent.cpp)
115+
116+
include_directories(${CMAKE_SOURCE_DIR}/include
117+
${CMAKE_SOURCE_DIR}/../find-embedding/include
118+
${CMAKE_SOURCE_DIR}/../fix-variables/include
119+
${CMAKE_SOURCE_DIR}/../local-solvers/include
120+
${CMAKE_SOURCE_DIR}/../qsage/include
121+
${CMAKE_SOURCE_DIR}/../remote/include
122+
${CMAKE_CURRENT_BINARY_DIR}/orang-prefix/src/orang/src)
123+
124+
125+
option(ENABLE_LIBRARY "Build client library" ON)
126+
if(ENABLE_LIBRARY)
127+
# libcurl
128+
find_package(CURL 7.28 REQUIRED)
129+
include_directories(SYSTEM ${CURL_INCLUDE_DIRS})
130+
131+
add_library(dwave_sapi SHARED
132+
src/dwave_sapi.cpp
133+
src/embed-problem.cpp
134+
src/unembed-answer.cpp
135+
src/fix-variables.cpp
136+
src/conversions.cpp
137+
src/internal.cpp
138+
src/global.cpp
139+
src/remote.cpp
140+
src/local.cpp
141+
src/freefuncs.cpp
142+
src/defaults.cpp
143+
src/sapi-impl.cpp
144+
${CMAKE_BINARY_DIR}/version.c
145+
${FIND_EMBEDDING_SOURCES}
146+
${FIX_VARIABLES_SOURCES}
147+
${SAPI_LOCAL_SOURCES}
148+
${QSAGE_SOURCES}
149+
${SAPI_REMOTE_SOURCES})
150+
151+
target_link_libraries(dwave_sapi
152+
${Boost_SYSTEM_LIBRARY}
153+
${CURL_LIBRARY}
154+
${COINOR_LIBRARIES})
155+
156+
add_dependencies(dwave_sapi orang)
157+
158+
get_target_property(DWAVE_SAPI_LINK_FLAGS dwave_sapi LINK_FLAGS)
159+
160+
if(NOT DWAVE_SAPI_LINK_FLAGS)
161+
set(DWAVE_SAPI_LINK_FLAGS)
162+
endif()
163+
164+
if(CMAKE_HOST_APPLE)
165+
list(APPEND DWAVE_SAPI_LINK_FLAGS
166+
"-Wl,-exported_symbols_list,${CMAKE_SOURCE_DIR}/exported-symbols-osx.map")
167+
elseif(CMAKE_HOST_UNIX)
168+
list(APPEND DWAVE_SAPI_LINK_FLAGS
169+
"-Wl,--version-script=${CMAKE_SOURCE_DIR}/version.map")
170+
endif()
171+
172+
set_target_properties(dwave_sapi PROPERTIES
173+
COMPILE_DEFINITIONS DWAVE_SAPI_BUILD
174+
LINK_FLAGS "${DWAVE_SAPI_LINK_FLAGS}")
175+
176+
if(CMAKE_BUILD_TYPE MATCHES "Release|MinSizeRel")
177+
set(STRIP_ARGS)
178+
if(CMAKE_HOST_APPLE)
179+
set(STRIP_ARGS "-x")
180+
endif()
181+
182+
if(CMAKE_STRIP)
183+
get_target_property(DWAVE_SAPI_OUTPUT_NAME dwave_sapi LOCATION)
184+
add_custom_command(TARGET dwave_sapi POST_BUILD
185+
COMMAND ${CMAKE_STRIP} ${STRIP_ARGS} ${DWAVE_SAPI_OUTPUT_NAME}
186+
COMMENT "Stripping dwave_sapi c library"
187+
VERBATIM)
188+
endif()
189+
endif()
190+
191+
install(FILES
192+
${CMAKE_BINARY_DIR}/README.txt
193+
${CMAKE_CURRENT_SOURCE_DIR}/include/dwave_sapi.h
194+
DESTINATION .)
195+
196+
install(TARGETS dwave_sapi DESTINATION .)
197+
198+
install(DIRECTORY examples DESTINATION .)
199+
200+
install(FILES
201+
${CMAKE_CURRENT_BINARY_DIR}/licenses/eula.txt
202+
../licenses.txt
203+
DESTINATION licenses)
204+
205+
# Packaging
206+
207+
if(${CMAKE_SIZEOF_VOID_P} EQUAL 8)
208+
set(BITS 64)
209+
else()
210+
set(BITS 32)
211+
endif()
212+
213+
if(CMAKE_HOST_WIN32)
214+
set(CPACK_SYSTEM_NAME "win${BITS}")
215+
elseif(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
216+
set(CPACK_SYSTEM_NAME "linux${BITS}")
217+
elseif(CMAKE_HOST_APPLE)
218+
set(CPACK_SYSTEM_NAME "osx") # No more 32-bit OSX
219+
else()
220+
message(SEND_ERROR "Unknown system type")
221+
endif()
222+
223+
set(CPACK_PACKAGE_NAME sapi-c-client)
224+
set(CPACK_PACKAGE_VERSION "${SAPI_VERSION}")
225+
include(CPack)
226+
endif()
227+
228+
option(ENABLE_TESTS "Enable sapi c client tests" OFF)
229+
if(ENABLE_TESTS)
230+
# Google Mock
231+
set(GMOCK_INCLUDEDIR "" CACHE PATH "Google Mock header file directory")
232+
set(GMOCK_LIBRARYDIR "" CACHE PATH "Google Mock library directory")
233+
find_path(GMock_INCLUDE_DIRS gmock/gmock.h HINTS ${GMOCK_INCLUDEDIR})
234+
find_library(GMock_LIBRARY gmock HINTS ${GMOCK_LIBRARYDIR})
235+
236+
# Google Test
237+
set(GTEST_INCLUDEDIR "" CACHE PATH "GTest header file directory")
238+
set(GTEST_LIBRARYDIR "" CACHE PATH "GTest library directory")
239+
set(GTEST_LIBRARYDIRS ${GTEST_LIBRARYDIR})
240+
if(GMOCK_LIBRARYDIR)
241+
list(APPEND GTEST_LIBRARYDIRS ${GMOCK_LIBRARYDIR}/gtest)
242+
endif()
243+
244+
find_path(GTest_INCLUDE_DIRS gtest/gtest.h PATHS ${GTEST_INCLUDEDIR})
245+
find_library(GTest_LIBRARY gtest HINTS ${GTEST_LIBRARYDIRS})
246+
247+
add_subdirectory(test)
248+
endif()

c-client/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# C Core Library

c-client/README.txt.in

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Getting started with the D-Wave(TM) Quantum Computer Solver API C Package
2+
=========================================================================
3+
4+
Version @SAPI_VERSION@
5+
6+
This package includes a header file (dwave_sapi.h) and a shared library:
7+
* Linux: libdwave_sapi.so
8+
* OSX: libdwave_sapi.dylib
9+
* Windows: dwave_sapi.dll (and import library dwave_sapi.lib)
10+
11+
In order to connect to the D-Wave(TM) Quantum Computer Solver API, you will
12+
need two pieces of information: the SAPI URL and an authentication token.
13+
The SAPI URL is listed on the "Solver API" page of the web user interface.
14+
Authentication tokens are also obtained from the web user interface: click
15+
on "API Tokens" in the menu under your user name.
16+
17+
You can find some example code in the examples subdirectory.
18+
19+
@README_LINUX_NSS@
+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
//Copyright © 2019 D-Wave Systems Inc.
2+
//The software is licensed to authorized users only under the applicable license agreement. See License.txt.
3+
4+
#include <stdlib.h>
5+
#include <dwave_sapi.h>
6+
#include "make_anneal_schedule.h"
7+
8+
sapi_AnnealSchedule *make_anneal_schedule(
9+
double nominal_anneal_time, double feature_start_frac,
10+
double hold_time, double fast_ramp_slope) {
11+
12+
sapi_AnnealSchedule *schedule;
13+
sapi_AnnealSchedulePoint *points;
14+
15+
if (nominal_anneal_time <= 0.0
16+
|| feature_start_frac < 0.0 || feature_start_frac > 1.0
17+
|| hold_time < 0.0 || fast_ramp_slope < 0.0) {
18+
19+
return NULL;
20+
}
21+
22+
/* allocate memory. At most 4 points will be created. */
23+
schedule = malloc(sizeof(sapi_AnnealSchedule));
24+
points = malloc(4 * sizeof(sapi_AnnealSchedulePoint));
25+
if (schedule == NULL || points == NULL) {
26+
free(schedule);
27+
free(points);
28+
return NULL;
29+
}
30+
schedule->elements = points;
31+
32+
/* schedule always starts at (0,0) */
33+
points[0].time = 0.0;
34+
points[0].relative_current = 0.0;
35+
schedule->len = 1;
36+
#define LAST_POINT (points[schedule->len - 1])
37+
38+
/* do we have a feature?
39+
* check on feature_start_frac avoids duplicating (0,0) */
40+
if ((hold_time > 0 || fast_ramp_slope > 0) && feature_start_frac > 0) {
41+
points[schedule->len].time = feature_start_frac * nominal_anneal_time;
42+
points[schedule->len].relative_current = feature_start_frac;
43+
schedule->len++;
44+
}
45+
46+
/* do we have a hold? */
47+
if (hold_time > 0) {
48+
points[schedule->len].time = LAST_POINT.time + hold_time;
49+
points[schedule->len].relative_current = LAST_POINT.relative_current;
50+
schedule->len++;
51+
}
52+
53+
/* add fast ramp or rest of linear anneal
54+
* check that we aren't already at end of anneal */
55+
if (feature_start_frac < 1.0) {
56+
if (fast_ramp_slope > 0) {
57+
double ramp_time = (1.0 - LAST_POINT.relative_current) / fast_ramp_slope;
58+
points[schedule->len].time = LAST_POINT.time + ramp_time;
59+
points[schedule->len].relative_current = 1.0;
60+
schedule->len++;
61+
} else {
62+
points[schedule->len].time = nominal_anneal_time + hold_time;
63+
points[schedule->len].relative_current = 1.0;
64+
schedule->len++;
65+
}
66+
}
67+
#undef LAST_POINT
68+
69+
return schedule;
70+
}
+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//Copyright © 2019 D-Wave Systems Inc.
2+
//The software is licensed to authorized users only under the applicable license agreement. See License.txt.
3+
4+
#ifndef MAKEANNEALSCHEDULE_H_INCLUDED
5+
#define MAKEANNEALSCHEDULE_H_INCLUDED
6+
7+
#include <dwave_sapi.h>
8+
9+
/*
10+
Build annealing waveform pattern. Supports pause and fast_ramp features.
11+
12+
nominal_anneal_time: specify length of regular linear anneal
13+
feature_start_frac: fraction through regular anneal to begin hold
14+
and/or fast ramp
15+
hold_time: amount of time to hold at constant value starting at
16+
feature_start_frac*nominal_anneal_time
17+
fast_ramp_slope: if > 0.0, apply fast-ramp with given slope
18+
(in 1/us) following hold
19+
20+
Returns an anneal schedule s that can be used as a solver parameter. To free
21+
memory, call free(s->elements) and free(s);
22+
23+
Returns NULL if any parameter is out of range or if memory allocation fails.
24+
*/
25+
sapi_AnnealSchedule *make_anneal_schedule(
26+
double nominal_anneal_time, double feature_start_frac,
27+
double hold_time, double fast_ramp_slope);
28+
29+
#endif

0 commit comments

Comments
 (0)