Commit fff39506 authored by Mccaskey, Alex's avatar Mccaskey, Alex
Browse files

Updates to readme, removing old source, getting ready for conversion to clang syntax handler

parent 8a8fd3d8
Loading
Loading
Loading
Loading
+8 −5
Original line number Diff line number Diff line
@@ -3,6 +3,10 @@ if(${CMAKE_VERSION} VERSION_LESS 3.12)
    cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION})
endif()

if (NOT XACC_DIR)
  set(XACC_DIR "$ENV{HOME}/.xacc")
endif()

set(CMAKE_STANDARD_REQUIRED ON)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_DISABLE_IN_SOURCE_BUILDS ON)
@@ -10,21 +14,20 @@ set(CMAKE_DISABLE_SOURCE_CHANGES ON)
set(CMAKE_POSITION_INDEPENDENT_CODE TRUE)
set(CMAKE_EXPORT_COMPILE_COMMANDS TRUE)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/cmake/Modules)
set(CLANG_COMPILER /usr/bin/clang++-9)

project(qcor LANGUAGES CXX)

option(QCOR_BUILD_TESTS "Build qcor tests" OFF)

find_package(Clang 9.0.0 REQUIRED)
find_package(Clang 10.0.0 REQUIRED)
find_package(XACC REQUIRED)

configure_file(${CMAKE_SOURCE_DIR}/scripts/qcor.in
               ${CMAKE_BINARY_DIR}/qcor)
include_directories(/home/cades/dev/llvm-project-csp/build/xacc_llvm_install/include)

#include_directories(/home/cades/dev/llvm-project-csp/build/xacc_llvm_install/include)

add_subdirectory(handlers)
add_subdirectory(runtime)
#add_subdirectory(compiler)
#add_subdirectory(ir)

install(PROGRAMS ${CMAKE_BINARY_DIR}/qcor DESTINATION bin)
+40 −49
Original line number Diff line number Diff line
@@ -6,7 +6,7 @@
# QCOR

QCOR is a C++ language extension and associated compiler implementation
for variational quantum computation on near-term, noisy devices.
for hybrid quantum-classical programming.


## Dependencies
@@ -14,24 +14,30 @@ for variational quantum computation on near-term, noisy devices.
Compiler (C++14): GNU 6.1+, Clang 3.4+
CMake 3.9+ (for build)
XACC: see https://xacc.readthedocs.io/en/latest/install.html#building-xacc
clang-dev version 8+
LLVM/Clang [Syntax Handler Fork](https://github.com/hfinkel/llvm-project-csp).
```

## Linux Build Instructions
Easiest way to install CMake - do not use the package manager,
instead use `pip`, and ensure that `/usr/local/bin` is in your PATH:
```bash
$ python -m pip install --upgrade cmake
$ python3 -m pip install --upgrade cmake
$ export PATH=$PATH:/usr/local/bin
```

On Ubuntu 16.04 (for others, replace xenial with Ubuntu release name),
install latest clang and llvm libraries and headers (you may need sudo)
For now we require our users build a specific fork of LLVM/Clang that 
provides Syntax Handler plugin support. We expect this fork to be upstreamed 
in a future release of LLVM and Clang, and at that point users will only 
need to download the appropriate LLVM/Clang binaries (via `apt-get` for instance).

To build this fork of LLVM/Clang (be aware this step takes up a good amount of RAM):
```bash
$ wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add -
$ echo "deb http://apt.llvm.org/xenial/ llvm-toolchain-xenial-9 main" > /etc/apt/sources.list.d/llvm.list
$ apt-get update && apt-get install -y libclang-9-dev llvm-9-dev clangd-9
$ ln -s /usr/bin/llvm-config-9 /usr/bin/llvm-config
$ (for theia ide) ls -s /usr/bin/clangd-9 /usr/bin/clangd
$ apt-get install ninja-build [if you dont have ninja]
$ git clone https://github.com/hfinkel/llvm-project-csp llvm
$ cd llvm && mkdir build && cd build
$ cmake -G Ninja ../llvm -DCMAKE_INSTALL_PREFIX=$HOME/.llvm -DBUILD_SHARED_LIBS=TRUE -DLLVM_TARGETS_TO_BUILD="X86" -DLLVM_ENABLE_PROJECTS=clang
$ cmake --build . --target install
$ sudo ln -s $HOME/.llvm/bin/llvm-config /usr/bin
```

Note that, for now, developers must clone QCOR manually:
@@ -39,9 +45,9 @@ Note that, for now, developers must clone QCOR manually:
$ git clone https://github.com/ornl-qci/qcor
$ cd qcor
$ mkdir build && cd build
$ cmake .. -DXACC_DIR=~/.xacc (or wherever you installed XACC)
$ [with tests] cmake .. -DXACC_DIR=~/.xacc -DQCOR_BUILD_TESTS=TRUE
$ make install
$ cmake .. 
$ [with tests] cmake .. -DQCOR_BUILD_TESTS=TRUE
$ make -j$(nproc) install
```
Update your PATH to ensure that the ```qcor``` compiler is available.
```bash
@@ -56,48 +62,33 @@ the following file
```cpp
#include "qcor.hpp"

int main(int argc, char **argv) {

  // Initialize QCOR
  qcor::Initialize(argc, argv);

  // Define your quantum kernel, here as a
  // standard C++ lambda containing quantum code
  auto ansatz = [&](qbit q, std::vector<double> t) {
[[clang::syntax(xasm)]] void ansatz(qreg q, double t) {
  X(q[0]);
    Ry(q[1], t[0]);
    CNOT(q[1], q[0]);
  };

  // Get a valid Optimizer
  auto optimizer =
      qcor::getOptimizer("nlopt", {std::make_pair("nlopt-optimizer", "cobyla"),
                                   std::make_pair("nlopt-maxeval", 20)});

  // Define the Observable
  auto observable =
      qcor::getObservable("pauli", std::string("5.907 - 2.1433 X0X1 "
                                               "- 2.1433 Y0Y1"
                                               "+ .21829 Z0 - 6.125 Z1"));
  Ry(q[1], t);
  CX(q[1], q[0]);
}

  // Call qcor::taskInitiate to kick off asynchronous execution of
  // VQE with given ansatz, optimizer, and observable, and initial params 0.0
  auto handle = qcor::taskInitiate(ansatz, "vqe", optimizer, observable,
                                   std::vector<double>{0.0});
int main(int argc, char **argv) {

  // Go do other work, task is running asynchronously
  auto opt = qcor::getOptimizer();
  auto obs = qcor::getObservable(
      "5.907 - 2.1433 X0X1 - 2.1433 Y0Y1 + .21829 Z0 - 6.125 Z1");

  // Now request the results, this will wait
  // until the task finishes.
  auto results = qcor::sync(handle);
  // Schedule an asynchronous VQE execution
  // with the given quantum kernel ansatz
  auto handle = qcor::taskInitiateWithSyntax(ansatz, "vqe", opt, obs, 0.45);

  // Get the results...
  std::cout << results->getInformation("opt-val").as<double>() << "\n";
  auto results_buffer = handle.get();
  auto energy = qcor::extract_results<double>(results_buffer, "opt-val");
  auto angles =
      qcor::extract_results<std::vector<double>>(results_buffer, "opt-params");

  // Finalize the framework.
  qcor::Finalize();
  printf("energy = %f\n", energy);
  printf("angles = [");
  for (int i = 0; i < 1; i++)
    printf("%f ", angles[i]);
  printf("]\n");
}

```
To compile this with QCOR targeting a Rigetti QCS QPU, run the following

+2 −1
Original line number Diff line number Diff line
#include "qcor_version2.hpp"
#include <vector> 

[[clang::syntax(xasm)]] void ansatz(qreg q, double t) {
  X(q[0]);
@@ -14,7 +15,7 @@ int main(int argc, char **argv) {

  // Schedule an asynchronous VQE execution
  // with the given quantum kernel ansatz
  auto handle = qcor::taskInitiateWithSyntax(ansatz, "vqe", opt, obs, 0.45);
  auto handle = qcor::taskInitiate(ansatz, "vqe", opt, obs, 0.45);

  auto results_buffer = handle.get();
  auto energy = qcor::extract_results<double>(results_buffer, "opt-val");
+1 −1
Original line number Diff line number Diff line
@@ -22,7 +22,7 @@ using namespace clang;

namespace {

std::string qpu_name = "local-ibm";
std::string qpu_name = "qpp";

class XasmHandler : public SyntaxHandler {
public:

instructions/CMakeLists.txt

deleted100644 → 0
+0 −50
Original line number Diff line number Diff line
set (PACKAGE_NAME "QCor Analog Instructions")
set (PACKAGE_DESCRIPTION "QCor Analog Instruction Bundle")
set (LIBRARY_NAME qcor-instructions)

file (GLOB_RECURSE HEADERS *.hpp)
file (GLOB SRC *.cpp ypulse/*.cpp ameas/*.cpp hwe/*.cpp)

# Set up dependencies to resources to track changes
usFunctionGetResourceSource(TARGET ${LIBRARY_NAME} OUT SRC)
# Generate bundle initialization code
usFunctionGenerateBundleInit(TARGET ${LIBRARY_NAME} OUT SRC)

include_directories(${CMAKE_CURRENT_SOURCE_DIR}/ypulse)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/ameas)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/hwe)

add_library(${LIBRARY_NAME} SHARED ${SRC})

set(_bundle_name qcor_instructions)

set_target_properties(${LIBRARY_NAME} PROPERTIES
    # This is required for every bundle
    COMPILE_DEFINITIONS US_BUNDLE_NAME=${_bundle_name}
    # This is for convenience, used by other CMake functions
    US_BUNDLE_NAME ${_bundle_name}
    )

# Embed meta-data from a manifest.json file
usFunctionEmbedResources(TARGET ${LIBRARY_NAME}
    WORKING_DIRECTORY
    ${CMAKE_CURRENT_SOURCE_DIR}
    FILES
    manifest.json
    )

target_link_libraries(${LIBRARY_NAME} xacc xacc-quantum-gate xacc-pauli)

if(APPLE)
   set_target_properties(${LIBRARY_NAME} PROPERTIES INSTALL_RPATH "@loader_path/../lib")
   set_target_properties(${LIBRARY_NAME} PROPERTIES LINK_FLAGS "-undefined dynamic_lookup")
else()
   set_target_properties(${LIBRARY_NAME} PROPERTIES INSTALL_RPATH "$ORIGIN/../lib")
   set_target_properties(${LIBRARY_NAME} PROPERTIES LINK_FLAGS "-shared")
endif()

install(TARGETS ${LIBRARY_NAME} DESTINATION ${CMAKE_INSTALL_PREFIX}/plugins)

if(QCOR_BUILD_TESTS)
   add_subdirectory(tests)
endif()
 No newline at end of file
Loading