C++ API¶
If you’re more of a C++ than a Python person, the same API exposed to Python can also be used from within C++.
There is currently no supported way to install OpenQL as a system library. Instead, you can use CMake to include OpenQL as a dependency of your program. This is pretty straight-forward:
cmake_minimum_required(VERSION 3.1 FATAL_ERROR)
# This would be just add_subdirectory(OpenQL) for your program, or perhaps
# add_subdirectory(deps/OpenQL) if you prefer; wherever your OpenQL git
# submodule is.
add_subdirectory(../.. OpenQL)
# Use whatever CMake magic you need to build your program, but linking
# something against OpenQL should be as easy as the second line. This should
# take care of both the libraries and header file include directories.
add_executable(example example.cc)
target_link_libraries(example ql)
With that configuration, #include <openql>
becomes available, which places the OpenQL API in the ql
namespace. Here’s a basic example of what a program might look like:
#include <iostream>
#include <openql>
int main(int argc, char **argv) {
// create platform
auto platf = ql::Platform("seven_qubits_chip", "cc_light");
// create program
auto prog = ql::Program("aProgram", platf, 2);
// create kernel
auto k = ql::Kernel("aKernel", platf, 2);
k.gate("prepz", 0);
k.gate("prepz", 1);
k.gate("x", 0);
k.gate("y", 1);
k.measure(0);
k.measure(1);
// add kernel to program
prog.add_kernel(k);
// compile the program
prog.compile();
std::cout << "Seems good to me!" << std::endl;
return 0;
}
The API is documented here.
Note
The API classes are merely wrappers of the classes used internally by OpenQL. You can of course also use the internal classes, but their interfaces should not be assumed to be stable from version to version.