Commit d692ea78 authored by Nguyen, Thien Minh's avatar Nguyen, Thien Minh
Browse files

add a service registry for workflows



Signed-off-by: default avatarThien Nguyen <nguyentm@ornl.gov>
parent 5e2c9de9
Loading
Loading
Loading
Loading
+31 −4
Original line number Diff line number Diff line
set(LIBRARY_NAME qcor-qsim)
file(GLOB SRC *.cpp)
file(GLOB HEADERS *.hpp)

file(GLOB SRC *.cpp tests)
usfunctiongetresourcesource(TARGET ${LIBRARY_NAME} OUT SRC)
usfunctiongeneratebundleinit(TARGET ${LIBRARY_NAME} OUT SRC)

set(_bundle_name qcor_qsim)
add_library(${LIBRARY_NAME} SHARED ${SRC})

target_link_libraries(${LIBRARY_NAME} PUBLIC qcor)

xacc_configure_library_rpath(${LIBRARY_NAME})

file(GLOB HEADERS qcor_qsim.hpp)
set_target_properties(${LIBRARY_NAME}
                      PROPERTIES COMPILE_DEFINITIONS
                                 US_BUNDLE_NAME=${_bundle_name}
                                 US_BUNDLE_NAME
                                 ${_bundle_name})

usfunctionembedresources(TARGET
                         ${LIBRARY_NAME}
                         WORKING_DIRECTORY
                         ${CMAKE_CURRENT_SOURCE_DIR}
                         FILES
												 manifest.json)
												 
if(APPLE)
  set_target_properties(${LIBRARY_NAME}
                        PROPERTIES INSTALL_RPATH "@loader_path/../lib;${LLVM_INSTALL_PREFIX}/lib")
  set_target_properties(${LIBRARY_NAME}
                        PROPERTIES LINK_FLAGS "-undefined dynamic_lookup")
else()
  set_target_properties(${LIBRARY_NAME}
                        PROPERTIES INSTALL_RPATH "$ORIGIN/../lib:${LLVM_INSTALL_PREFIX}/lib")
  set_target_properties(${LIBRARY_NAME} PROPERTIES LINK_FLAGS "-shared")
endif()

install(TARGETS ${LIBRARY_NAME} DESTINATION ${CMAKE_INSTALL_PREFIX}/plugins)
install(FILES ${HEADERS} DESTINATION include/qcor)
install(TARGETS ${LIBRARY_NAME} DESTINATION lib)

if (QCOR_BUILD_TESTS)
	add_subdirectory(tests)

lib/qsim/manifest.json

0 → 100644
+6 −0
Original line number Diff line number Diff line
{
  "bundle.symbolic_name" : "qcor_qsim",
  "bundle.activator" : true,
  "bundle.name" : "Quantum Chemistry Simulation",
  "bundle.description" : ""
}
+25 −14
Original line number Diff line number Diff line
@@ -53,13 +53,6 @@ double CostFunctionEvaluator::evaluate(
  return 0.0;
}

QsimWorkflow *TimeDependentWorkflow::getInstance() {
  if (!instance) {
    instance = new TimeDependentWorkflow();
  }
  return instance;
}

QsimModel ModelBuilder::createModel(Observable *obs, TdObservable td_ham,
                                    const HeterogeneousMap &params) {
  QsimModel model;
@@ -135,15 +128,33 @@ QsimResult TimeDependentWorkflow::execute(const QsimModel &model) {
  return result;
}

QsimWorkflow *getWorkflow(WorkFlow type, const HeterogeneousMap &init_params) {
  // == TEMP-CODE
  // TODO: set-up service registry for workflow
  auto qsim_workflow = TimeDependentWorkflow::getInstance();
  if (qsim_workflow->initialize(init_params)) {
std::shared_ptr<QsimWorkflow> getWorkflow(const std::string &name, const HeterogeneousMap &init_params) {
  auto qsim_workflow = xacc::getService<QsimWorkflow>(name);
  if (qsim_workflow && qsim_workflow->initialize(init_params)) {
    return qsim_workflow;
  }

  // ERROR: unknown workflow or invalid initialization options.
  return nullptr;
}

} // namespace qcor

#include "cppmicroservices/BundleActivator.h"
#include "cppmicroservices/BundleContext.h"
#include "cppmicroservices/ServiceProperties.h"
namespace {
using namespace cppmicroservices;
class US_ABI_LOCAL QsimActivator : public BundleActivator {

public:
  QsimActivator() {}

  void Start(BundleContext context) {
    context.RegisterService<qcor::QsimWorkflow>(
        std::make_shared<qcor::TimeDependentWorkflow>());
  }

  void Stop(BundleContext) {}
};
} // namespace

CPPMICROSERVICES_EXPORT_BUNDLE_ACTIVATOR(QsimActivator)
 No newline at end of file
+0 −2
Original line number Diff line number Diff line
@@ -44,8 +44,6 @@ class TimeDependentWorkflow : public QsimWorkflow {
public:
  virtual bool initialize(const HeterogeneousMap &params) override;
  virtual QsimResult execute(const QsimModel &model) override;

  static QsimWorkflow *getInstance();
  virtual const std::string name() const override { return "td-evolution"; }
  virtual const std::string description() const override { return ""; }
private:
+14 −16
Original line number Diff line number Diff line
@@ -80,18 +80,19 @@ public:
  // Strongly-typed parameters/argument.
  // Build a simple Hamiltonian-based model: static Hamiltonian which is also
  // the observable of interest.
  static QsimModel createModel(Observable *obs, const HeterogeneousMap &params = {});
  static QsimModel createModel(Observable *obs,
                               const HeterogeneousMap &params = {});
  // Build a time-dependent problem model:
  //  -  obs: observable operator to measure.
  //  -  td_ham: time-dependent Hamiltonian to evolve the system.
  //     e.g. a function to map from time to Hamiltonian operator.
  static QsimModel createModel(Observable* obs, TdObservable td_ham,const HeterogeneousMap &params = {});
  static QsimModel createModel(Observable *obs, TdObservable td_ham,
                               const HeterogeneousMap &params = {});

  // ========  High-level model builder ==============
  // The idea here is to have contributed modules to translate problem descriptions
  // in various formats, e.g. PyScf, Psi4, broombridge, etc. 
  // into QCOR's Observable type.
  // Inputs:
  // The idea here is to have contributed modules to translate problem
  // descriptions in various formats, e.g. PyScf, Psi4, broombridge, etc. into
  // QCOR's Observable type. Inputs:
  //  - format: key to look up module/plugin to digest the input data.
  //  - data: model descriptions in plain-text format, e.g. load from file.
  static QsimModel createModel(const std::string &format,
@@ -105,7 +106,7 @@ public:
// Result is stored in a HetMap
using QsimResult = HeterogeneousMap;
// Abstract workflow:
class QsimWorkflow : Identifiable {
class QsimWorkflow : public Identifiable {
public:
  virtual bool initialize(const HeterogeneousMap &params) = 0;
  virtual QsimResult execute(const QsimModel &model) = 0;
@@ -114,10 +115,7 @@ protected:
  CostFunctionEvaluator *evaluator;
};

// Supported Workflow: to be defined and implemented
enum class WorkFlow { VQE, TD, PE };

// TODO: create a service registry for these.
QsimWorkflow* getWorkflow(WorkFlow type, const HeterogeneousMap &init_params); 

// Get workflow by name:
std::shared_ptr<QsimWorkflow> getWorkflow(const std::string &name,
                                          const HeterogeneousMap &init_params);
} // namespace qcor
 No newline at end of file
Loading