Commit 254208e8 authored by Nguyen, Thien's avatar Nguyen, Thien

Added an example to load QASM example

Signed-off-by: Nguyen, Thien's avatarThien Nguyen <nguyentm@ornl.gov>
parent 0cb51886
......@@ -38,3 +38,7 @@ target_link_libraries(qaoa_qubo PRIVATE xacc xacc-quantum-gate)
add_executable(quantum_phase_estimation quantum_phase_estimation.cpp)
target_link_libraries(quantum_phase_estimation PRIVATE xacc xacc-quantum-gate)
add_executable(phase_estimation_qasm phase_estimation_10q.cpp)
target_link_libraries(phase_estimation_qasm PRIVATE xacc xacc-quantum-gate)
target_compile_definitions(phase_estimation_qasm PRIVATE QASM_SOURCE_DIR="${CMAKE_CURRENT_SOURCE_DIR}/resources")
#include "xacc.hpp"
int main(int argc, char **argv) {
xacc::Initialize(argc, argv);
// State-vector simulator: "aer", "qpp"
auto accelerator = xacc::getAccelerator("aer");
auto compiler = xacc::getCompiler("staq");
const std::string QASM_SRC_FILE = std::string(QASM_SOURCE_DIR) + "/qasm_src.txt";
// Read source file:
std::ifstream inFile;
inFile.open(QASM_SRC_FILE);
std::stringstream strStream;
strStream << inFile.rdbuf();
const std::string qasmSrcStr = strStream.str();
// Compile:
auto IR = compiler->compile(qasmSrcStr);
auto program = IR->getComposites()[0];
std::cout << "Number of instructions: " << program->nInstructions() << "\n";
// Allocate some qubits and execute:
auto buffer = xacc::qalloc(10);
accelerator->execute(buffer, program);
buffer->print();
xacc::Finalize();
}
\ No newline at end of file
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment