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

adding initial ypulse and analog measure (ameas) instruction

parent 612b6599
Loading
Loading
Loading
Loading
Loading
+4 −3
Original line number Diff line number Diff line
@@ -31,10 +31,11 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CppMicroServicesConfig_DIR}")
include(tests)
include(CppMicroServicesConfig)

#include_directories(${XACC_INCLUDE_DIRS})
include_directories(${XACC_INCLUDE_DIRS})

#link_directories(${XACC_LIBRARY_DIR})
link_directories(${XACC_LIBRARY_DIR})

message(STATUS "${CLANG_INCLUDE_DIRS}")

add_subdirectory(compiler)
add_subdirectory(instructions)
+49 −0
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-analog)

file (GLOB_RECURSE HEADERS *.hpp)
file (GLOB SRC *.cpp ypulse/*.cpp ameas/*.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)

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

set(_bundle_name qcor_analog)

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_LIBRARIES})

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
+26 −0
Original line number Diff line number Diff line
#include "YPulse.hpp"
#include "AMeas.hpp"

#include "cppmicroservices/BundleActivator.h"
#include "cppmicroservices/BundleContext.h"
#include "cppmicroservices/ServiceProperties.h"

using namespace cppmicroservices;

class US_ABI_LOCAL QcorInstructionActivator : public BundleActivator {
public:
  QcorInstructionActivator() {}

  void Start(BundleContext context) {
    auto inst = std::make_shared<xacc::quantum::YPulse>();
    auto inst2 = std::make_shared<xacc::quantum::AMeas>();

    context.RegisterService<xacc::quantum::GateInstruction>(inst);
    context.RegisterService<xacc::quantum::GateInstruction>(inst2);

  }

  void Stop(BundleContext context) {}
};

CPPMICROSERVICES_EXPORT_BUNDLE_ACTIVATOR(QcorInstructionActivator)
+76 −0
Original line number Diff line number Diff line
#include "AMeas.hpp"
#include "XACC.hpp"

namespace xacc {
namespace quantum {
AMeas::AMeas() : GateInstruction(name()) {}

AMeas::AMeas(std::vector<int> qbs) : GateInstruction(name(), qbs) {}

const std::string AMeas::name() const {
  // Name used to construct IR instances,
  return "ameas";
}

const std::string AMeas::description() const {
  // Pulse waveform
  return "";
}

const bool AMeas::isAnalog() const { return true; }
const int AMeas::nRequiredBits() const { return 1; }

void AMeas::customVisitAction(BaseInstructionVisitor &iv) {

  // CACHING IMPLEMENTED, need to create qcor::getPulseLibrary function
  std::map<std::string, InstructionParameter> pulseLibrary =
      xacc::getCache("qcor_pulse_library.json"); //= qcor::getPulseLibrary();

  // Set the channel
  if (!options.count("t0")) {
    options.insert({"t0", InstructionParameter(64)});
  }

  if (options["pulse_id"].toString() == "null") {
    // No samples provided, but we have an angle
    // so generate them based on angle

    // GENERATE SAMPLES FROM THETA
    xacc::error("Currently invalid pulse_id (null). We do not generate pulses "
                "from angles yet.");
    //   auto theta = getParameter(0).as<double>();
    // FIXME GENERATE new_name_we_create samples
    //   options.insert({"pulse_id",
    //   InstructionParameter("new_name_we_create")});

    // qcor::appendPulse(new_name_we_create_samples);

  } else {
    // user did provide pulse id, so just make
    // sure it exists in the pulseLibrary
    auto pulseId = options["pulse_id"].as<std::string>();
    if (!pulseLibrary.count(pulseId)) {
      xacc::error("This pulse_id (" + pulseId +
                  ") is not in the pulse library cache.");
    }
  }

  // We now have valid ch, t0, and pulse_id,
  // so build up instruction json
  std::stringstream ss;
  ss << "\"ch\": \"m" << bits()[0] << "\", \"name\": \""
     << options["pulse_id"].as<std::string>()
     << "\", \"t0\":" << options["t0"].toString();
  iv.getNativeAssembly() += "{ " + ss.str() + " },";
  iv.getNativeAssembly() +=
      "{\"name\": \"acquire\", \"qubits\": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, "
      "11, 12, 13, 14, 15, 16, 17, 18, 19], \"memory_slot\": [0, 1, 2, 3, 4, "
      "5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19], "
      "\"register_slot\": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, "
      "15, 16, 17, 18, 19], \"duration\": 512, \"kernels\": [{\"name\": "
      "\"boxcar\", \"params\": {\"start_window\": 0, \"stop_window\": 512}}], "
      "\"t0\": 64},";
}

} // namespace quantum
} // namespace xacc
+29 −0
Original line number Diff line number Diff line
#ifndef IMPLS_AMEAS_HPP
#define IMPLS_AMEAS_HPP

#include "GateInstruction.hpp"

namespace xacc {
namespace quantum {
class AMeas : public GateInstruction {

public:
  AMeas();
  AMeas(std::vector<int> qbs);

  DEFINE_CLONE(AMeas)
  DEFINE_VISITABLE()

  const std::string name() const override;
  const std::string description() const override;

  const bool isAnalog() const override;
  const int nRequiredBits() const override;

  void customVisitAction(BaseInstructionVisitor &iv) override;
  virtual ~AMeas() {}
};
} // namespace quantum
} // namespace xacc

#endif
Loading