Commit b9f9d1a3 authored by Amir Ebrahimi's avatar Amir Ebrahimi
Browse files

Re-add argparse directly to repo; Expose helper functions under qcor::arg

parent 97b96b98
Loading
Loading
Loading
Loading
+0 −18
Original line number Diff line number Diff line
@@ -49,24 +49,6 @@ if(GIT_FOUND)
  message( STATUS "QCOR Version / HEAD commit hash: ${QCOR_BUILD_VERSION}")
endif()

if(GIT_FOUND AND EXISTS "${CMAKE_SOURCE_DIR}/.git" AND NOT EXISTS "${CMAKE_SOURCE_DIR}/tpls/argparse/CMakeLists.txt")
    # Update submodules as needed
    option(GIT_SUBMODULE "Check submodules during build" ON)
    if(GIT_SUBMODULE)
        message(STATUS "Submodule update")
        execute_process(COMMAND ${GIT_EXECUTABLE} submodule update --init --recursive
                        WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
                        RESULT_VARIABLE GIT_SUBMOD_RESULT)
        if(NOT GIT_SUBMOD_RESULT EQUAL "0")
            message(FATAL_ERROR "git submodule update --init failed with ${GIT_SUBMOD_RESULT}, please checkout submodules")
        endif()
    endif()
endif()

if(NOT EXISTS "${CMAKE_SOURCE_DIR}/tpls/argparse/CMakeLists.txt")
    message(FATAL_ERROR "The submodules were not downloaded! GIT_SUBMODULE was turned off or failed. Please update submodules and try again.")
endif()

find_package(XACC REQUIRED)
find_package(Clang 10.0.0 REQUIRED)

+7 −2
Original line number Diff line number Diff line
@@ -4,9 +4,14 @@ file(GLOB SRC *.cpp)

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

target_include_directories(${LIBRARY_NAME} PUBLIC . ${CMAKE_BINARY_DIR} ${XACC_ROOT}/include/eigen ${XACC_ROOT}/include/argparse)
target_include_directories(${LIBRARY_NAME} 
                            PUBLIC 
                            . 
                            ${CMAKE_BINARY_DIR} 
                            ${XACC_ROOT}/include/eigen
                            ${CMAKE_SOURCE_DIR}/tpls/argparse)

target_link_libraries(${LIBRARY_NAME} PUBLIC xacc::xacc xacc::quantum_gate xacc::pauli argparse::argparse)
target_link_libraries(${LIBRARY_NAME} PUBLIC xacc::xacc xacc::quantum_gate xacc::pauli)

if(APPLE)
  set_target_properties(${LIBRARY_NAME}
+13 −0
Original line number Diff line number Diff line
@@ -5,6 +5,19 @@
#include "xacc_service.hpp"

namespace qcor {

namespace arg {
  static ArgumentParser _parser;
  
  ArgumentParser &get_parser() {
    return _parser;
  }

  void parse_args(int argc, const char *const argv[]) {
    get_parser().parse_args(argc, argv);
  }
}

void set_verbose(bool verbose) { xacc::set_verbose(verbose); }
bool get_verbose() { return xacc::verbose; }
void set_shots(const int shots) { ::quantum::set_shots(shots); }
+35 −3
Original line number Diff line number Diff line
@@ -22,9 +22,37 @@ namespace constants {
static constexpr double pi = 3.141592653589793238;
}

// Expose argparse
namespace arg {
  // Expose ArgumentParser for custom instantiation
  using ArgumentParser = argparse::ArgumentParser;

  // Default argument parser
  ArgumentParser &get_parser();

  // Parameter packing
  // Call add_argument with variadic number of string arguments
  template <typename... Targs> 
  argparse::Argument &add_argument(Targs... Fargs) {
    return get_parser().add_argument(Fargs...);
  }

  // Getter for options with default values.
  //  @throws std::logic_error if there is no such option
  //  @throws std::logic_error if the option has no value
  //  @throws std::bad_any_cast if the option is not of type T
  //
  template <typename T = std::string>
  T get_argument(std::string_view argument_name) {
    return get_parser().get<T>(argument_name);
  }
    
  // Main entry point for parsing command-line arguments using this
  //  ArgumentParser
  //  @throws std::runtime_error in case of any invalid argument
  //
  void parse_args(int argc, const char *const argv[]);
}

// Typedefs mapping xacc/Eigen types to qcor types
using CompositeInstruction = xacc::CompositeInstruction;
using HeterogeneousMap = xacc::HeterogeneousMap;
@@ -395,3 +423,7 @@ class KernelToUnitaryVisitor : public xacc::quantum::AllGateVisitor {
    }                                                                          \
  }
} // namespace qcor

namespace qcor_arg {

}
 No newline at end of file
+1 −2
Original line number Diff line number Diff line
@@ -54,8 +54,7 @@ std::unique_ptr<clang::CodeGenAction> emit_llvm_ir(
  std::vector<std::string> base_includes{
      "-I@XACC_ROOT@/include/xacc", "-I@XACC_ROOT@/include/pybind11/include",
      "-I@CMAKE_INSTALL_PREFIX@/include/qcor",
      "-I@XACC_ROOT@/include/quantum/gate", "-I@XACC_ROOT@/include/eigen",
      "-I@XACC_ROOT@/include/argparse"
      "-I@XACC_ROOT@/include/quantum/gate", "-I@XACC_ROOT@/include/eigen"
      };
  for (auto extra : extra_headers) {
    base_includes.push_back(extra);
Loading