Commit 4b5eb758 authored by Mccaskey, Alex's avatar Mccaskey, Alex
Browse files

updating with xacc::quantum::getObservable()

parent 65614ce9
Loading
Loading
Loading
Loading
+8 −25
Original line number Diff line number Diff line
@@ -4,9 +4,9 @@
#include "IRProvider.hpp"
#include "xacc.hpp"
#include "xacc_service.hpp"
#include "xacc_observable.hpp"

#include "FermionOperator.hpp"
#include "PauliOperator.hpp"
// #include "PauliOperator.hpp"
#include "CountGatesOfTypeVisitor.hpp"
#include "CommonGates.hpp"

@@ -68,7 +68,6 @@ void Finalize() { xacc::Finalize(); }

ResultBuffer qalloc(const std::size_t nBits) { return xacc::qalloc(nBits); }
ResultBuffer qalloc() { return xacc::qalloc(); }

ResultBuffer sync(Handle &handle) { return handle.get(); }

Handle submit(HandlerLambda &&totalJob) {
@@ -91,44 +90,28 @@ Handle submit(HandlerLambda &&totalJob,
}

std::shared_ptr<Optimizer> getOptimizer(const std::string &name) {
  return xacc::getService<xacc::Optimizer>(name);
  return xacc::getOptimizer(name);
}
std::shared_ptr<Optimizer> getOptimizer(const std::string &name,
                                        const HeterogeneousMap &&options) {
  auto opt = getOptimizer(name);
  opt->setOptions(options);
  return opt;
  return xacc::getOptimizer(name, options);
}

std::shared_ptr<Observable> getObservable(const std::string &type,
                                          const std::string &representation) {
  using namespace xacc::quantum;
  if (type == "pauli") {
    return representation.empty()
               ? std::make_shared<PauliOperator>()
               : std::make_shared<PauliOperator>(representation);
  } else if (type == "fermion") {
    return representation.empty()
               ? std::make_shared<FermionOperator>()
               : std::make_shared<FermionOperator>(representation);
  } else {
    xacc::error("Invalid observable type");
    return std::make_shared<PauliOperator>();
  }
  return xacc::quantum::getObservable(type, representation);
}

std::shared_ptr<Observable> getObservable() {
  return getObservable("pauli", std::string(""));
  return xacc::quantum::getObservable();
}
std::shared_ptr<Observable> getObservable(const std::string &representation) {
  return getObservable("pauli", representation);
  return xacc::quantum::getObservable("pauli", representation);
}

std::shared_ptr<Observable> getObservable(const std::string &type,
                                          const HeterogeneousMap &&options) {
  auto observable = xacc::getService<Observable>(type);
  observable->fromOptions(options);
  return observable;
  return xacc::quantum::getObservable(type, options);
}

} // namespace qcor
+9 −14
Original line number Diff line number Diff line
@@ -19,15 +19,13 @@ using namespace xacc;
//                  its plugin/service registry system.
//
// (2) Finalize - Finalize the QCOR runtime library. This should be called at
// the
//                end of a QCOR-enabled program to cleanup and finalize QCOR.
//                the end of a QCOR-enabled program to cleanup and finalize QCOR.
//                Specifically, this Finalizes the XACC framework which cleans
//                up the provided service pointers.
//
// (3) submit - This function enables job or task submission to QCOR for
// asynchronous
//              execution. Tasks are functor-like objects (lambdas for example)
//              that take a single argument - a reference to a
//              asynchronous execution. Tasks are functor-like objects (lambdas
//              for example) that take a single argument - a reference to a
//              qcor::qpu_handler. Tasks can use this qpu_handler to execute
//              desired objective functions or hybrid algorithms. This function
//              returns a C++ future object wrapping the to-be-populated
@@ -36,22 +34,19 @@ using namespace xacc;
//              to accept an already created AcceleratorBuffer.
//
// (4) getOptimizer - This function returns a concrete Optimizer implementation
// (such as the nlopt
//                    optimizer). It is overloaded to optionally take a
//                    heterogeneous map of optimizer options. This method
//                    leverages the XACC service registry to get reference to
//                    the desired optimizer service implementation.
//                    (such as the nlopt optimizer). It is overloaded to
//                    optionally take a heterogeneous map of optimizer options.
//                    This method leverages the XACC service registry to get
//                    reference to the desired optimizer service implementation.
//
// (5) getObservable - This function returns a concrete Observable
// implementation instance.
//                     This Observable dictates measurements on an unmeasured
//                     implementation instance. This Observable dictates measurements on an unmeasured
//                     quantum kernel. It is overloaded to enable creation of an
//                     Observable from a particular string representation or a
//                     heterogeneous map of options.
//
// (6) add - This function adds to quantum kernels together, i.e. appends the
// instructions
//           of the second one to the first. This returns a new quantum kernel
//           instructions of the second one to the first. This returns a new quantum kernel
//           representing this addition.
//
// QCOR C++ Quantum Kernels: