ORNL-QCI / tnqvm

Tensor Network QPU Simulator for Eclipse XACC
43 stars 10 forks source link

ITensor error for 1 qubit program #14

Closed amccaskey closed 3 years ago

amccaskey commented 7 years ago

Running the following 1 qubit test program

#include "XACC.hpp"

const std::string src = R"src(__qpu__ statePrep(qbit qreg, double theta) {
    Rx(qreg[0], theta);
    Rz(qreg[0], theta);
}

// H = X_0
__qpu__ term0(qbit qreg, double theta) {
    statePrep(qreg, theta);
    cbit creg[1];
    H(qreg[0]);
    creg[0] = MeasZ(qreg[0]);
})src";

int main(int argc, char** argv) {

   // Initialize XACC - find all available
   // compilers and accelerators, parse command line.
   xacc::Initialize(argc, argv);

   auto qpu = xacc::getAccelerator("tnqvm");

   auto qubitReg = qpu->createBuffer("qreg", 1);

// Create a Program
   xacc::Program program(qpu, src);
   program.build();

   auto kernels = program.getRuntimeKernels();

   std::vector<xacc::InstructionParameter> params {1.0};

   kernels[1](qubitReg, params);

   // Finalize the framework.
   xacc::Finalize();
}

Here's the CMakeLists.txt file

# Start a CMake project
project(test-xacc-jupyter CXX)

# Set the minimum version to 3.2
cmake_minimum_required(VERSION 3.2)

# Find XACC
find_package(XACC REQUIRED)

set(CppMicroServicesConfig_DIR "${XACC_ROOT}/share/cppmicroservices3/cmake")
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${XACC_ROOT}/share/xacc")
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CppMicroServicesConfig_DIR}")
include(tests)
include(CppMicroServicesConfig)

# Find Boost
find_package(Boost COMPONENTS system program_options filesystem chrono thread REQUIRED)
include_directories(${Boost_INCLUDE_DIRS})

# Include all XACC Include Directories
include_directories(${XACC_INCLUDE_DIRS})

# Link to the XACC Library Directory,
link_directories(${XACC_LIBRARY_DIR})

# Create the executabe
add_executable(test-xacc-jupyter test-xacc-jupyter.cpp)

# Like the necessary libaries
target_link_libraries(test-xacc-jupyter ${XACC_LIBRARIES} ${Boost_LIBRARIES} dl pthread)
#0  0x00007fffef6bd19e in itensor::InfArray<itensor::IndStr<itensor::Index>, 11ul>::empty (this=0x0)
    at /projects/tnqvm-install/build/tnqvm-prefix/src/tnqvm/ITensor/itensor/util/infarray.h:345
#1  0x00007fffef6b8522 in itensor::RangeT<itensor::Index, 0ul>::empty (this=0x0)
    at /projects/tnqvm-install/build/tnqvm-prefix/src/tnqvm/ITensor/itensor/tensor/range.h:154
#2  0x00007fffef6b1b20 in itensor::IndexSetT<itensor::Index>::operator bool (this=0x0)
    at /projects/tnqvm-install/build/tnqvm-prefix/src/tnqvm/ITensor/itensor/indexset.h:90
#3  0x00007fffef6a98a0 in itensor::ITensorT<itensor::Index>::operator bool (this=0x0)
    at /projects/tnqvm-install/build/tnqvm-prefix/src/tnqvm/ITensor/itensor/itensor_interface.h:91
#4  0x00007fffef79658f in itensor::ITensorT<itensor::Index>::operator*= (this=0x7fffffff8110, R=...)
    at itensor_operators.cc:101
#5  0x00007fffef6a1e34 in itensor::operator*<itensor::Index> (A=..., B=...)
    at /projects/tnqvm-install/build/tnqvm-prefix/src/tnqvm/ITensor/itensor/itensor_interface.ih:373
#6  0x00007fffef68ecf0 in xacc::quantum::ITensorMPSVisitor::averZs(std::set<int, std::less<int>, std::allocator<int> >) () from /usr/local/xacc/lib/plugins/accelerators/libtnqvm.so
#7  0x00007fffef68fe1c in xacc::quantum::ITensorMPSVisitor::visit(xacc::quantum::Measure&) ()
   from /usr/local/xacc/lib/plugins/accelerators/libtnqvm.so
#8  0x00007ffff77e869b in void xacc::BaseInstructionVisitable::acceptImpl<xacc::quantum::Measure>(xacc::quantum::Measure&, std::shared_ptr<xacc::BaseInstructionVisitor>) () from /usr/local/xacc/lib/libxacc-quantum-gate.so
#9  0x00007ffff77e85a5 in xacc::quantum::Measure::accept(std::shared_ptr<xacc::BaseInstructionVisitor>) ()
   from /usr/local/xacc/lib/libxacc-quantum-gate.so
#10 0x00007fffef6e4405 in xacc::tnqvm::TNQVM::execute(std::shared_ptr<xacc::AcceleratorBuffer>, std::shared_ptr<xacc::Function>) () at /usr/include/c++/7/ext/new_allocator.h:136
#11 0x0000000000468006 in xacc::Kernel<>::operator()(std::shared_ptr<xacc::AcceleratorBuffer>, std::vector<boost::variant<int, double, float, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::complex<double> >, std::allocator<boost::variant<int, double, float, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::complex<double> > > >) ()
#12 0x0000000000459fa0 in main ()

For 2+ qubits, this code works.

amccaskey commented 6 years ago

Added a test for this in mccaskey/updateArch. Couldn't figure out how to fix it since I don't know enough about ITensor, will have to wait for @mileschen360 to fix it.

DmitryLyakh commented 4 years ago

Should this be closed as ancient?