Unverified Commit 086de9fc authored by Thien Nguyen's avatar Thien Nguyen Committed by GitHub
Browse files

Merge pull request #117 from ORNL-QCI/tnguyen/develop

Merging development branch
parents 52148127 beef52c9
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -29,7 +29,7 @@ usFunctionEmbedResources(TARGET ${LIBRARY_NAME}
    manifest.json
    )

target_include_directories(${LIBRARY_NAME} PUBLIC . visitors)
target_include_directories(${LIBRARY_NAME} PUBLIC . visitors utils)

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

+11 −3
Original line number Diff line number Diff line
@@ -56,6 +56,13 @@ void TNQVM::execute(
    options.insert("vqe-execution-context", kernelDecomposed);
    visitor->setOptions(options);

    // Nearest neighbor transform:
    if (visitor->name() == "itensor-mps" || visitor->name() == "exatn-mps" ||
        visitor->name() == "exatn-pmps") {
      auto opt = xacc::getService<xacc::IRTransformation>("nnizer");
      opt->apply(kernelDecomposed.getBase(), nullptr,
                 {std::make_pair("max-distance", 1)});
    }
    // Initialize the visitor
    visitor->initialize(buffer, getShotCountOption(options));
    visitor->setKernelName(kernelDecomposed.getBase()->name());
@@ -105,12 +112,13 @@ void TNQVM::execute(std::shared_ptr<xacc::AcceleratorBuffer> buffer,
  // Initialize the visitor
  visitor->initialize(buffer, getShotCountOption(options));
  visitor->setKernelName(kernel->name());
  // If this is an Exatn-MPS visitor, transform the kernel to nearest-neighbor
  // If this is an MPS visitor, transform the kernel to nearest-neighbor
  // Note: currently, we don't support MPS aggregated blocks (multiple qubit MPS
  // tensors in one block). Hence, the circuit must always be transformed into
  // *nearest* neighbor only (distance = 1 for two-qubit gates).
  if (visitor->name() == "exatn-mps" || visitor->name() == "exatn-pmps") {
    auto opt = xacc::getService<xacc::IRTransformation>("lnn-transform");
  if (visitor->name() == "itensor-mps" || visitor->name() == "exatn-mps" ||
      visitor->name() == "exatn-pmps") {
    auto opt = xacc::getService<xacc::IRTransformation>("nnizer");
    opt->apply(kernel, nullptr, {std::make_pair("max-distance", 1)});
    // std::cout << "After LNN transform: \n" << kernel->toString() << "\n";
  }
+6 −0
Original line number Diff line number Diff line
@@ -34,6 +34,7 @@
#include "xacc.hpp"
#include "xacc_service.hpp"
#include "TNQVMVisitor.hpp"
#include "RandomEngine.hpp"
#include <cassert>

// Documentation: https://xacc.readthedocs.io/en/latest/extensions.html#tnqvm
@@ -110,6 +111,11 @@ public:
      }
    }

    if (config.keyExists<int>("seed")) {
      const auto seed = config.get<int>("seed");
      randomEngine::setSeed(seed);
    }

    // Updated the cached configurations (to be sent on to visitor)
    // Note: Accelerator-level configs (visitor name, shots, vqe mode, etc.)
    // have been handled here, i.e. retrieving from the new config map. The rest
+3 −5
Original line number Diff line number Diff line
@@ -34,10 +34,9 @@
#include<complex>
#include<vector>
#include <assert.h>
#include <random>
#include <chrono>
#include <functional>

#include "RandomEngine.hpp"
typedef std::vector<std::complex<double>> StateVectorType;
typedef std::vector<std::vector<std::complex<double>>> GateMatrixType;

@@ -57,9 +56,8 @@ std::vector<T> linspace(T a, T b, size_t N) {

inline double generateRandomProbability()
{
  auto randFunc = std::bind(std::uniform_real_distribution<double>(0, 1),
                            std::mt19937(std::chrono::high_resolution_clock::now().time_since_epoch().count()));
  return randFunc();
  auto& rng = tnqvm::randomEngine::get_instance();
  return rng.randProb();
}

void ApplySingleQubitGate(StateVectorType& io_psi, size_t in_index, const GateMatrixType& in_gateMatrix)
+31 −0
Original line number Diff line number Diff line
#pragma once
#include <random>
namespace tnqvm {
struct randomEngine {
  randomEngine(const randomEngine &) = delete;
  randomEngine &operator=(const randomEngine &) = delete;
  double randProb() {
    const auto val = std::uniform_real_distribution<double>(0.0, 1.0)(m_engine);
    return val;
  }

  thread_local static randomEngine &get_instance() {
    thread_local static randomEngine instance;
    thread_local static size_t seed = 0;
    if (seed != globalSeed) {
      instance.m_engine.seed(globalSeed);
      seed = globalSeed;
    }
    return instance;
  }
  std::mt19937_64 m_engine;
  static inline size_t globalSeed = []() {
    std::random_device rd;
    return rd();
  }();
  static void setSeed(size_t seed) { globalSeed = seed; }

private:
  randomEngine() = default;
};
} // namespace tnqvm
 No newline at end of file
Loading