Loading lib/qsim/impls/CMakeLists.txt +3 −5 Original line number Diff line number Diff line set(LIBRARY_NAME qcor-quantum-simulation) file(GLOB SRC *.cpp modules/*.cpp) file(GLOB HEADERS *.hpp) file(GLOB SRC *.cpp ansatz_generator/*.cpp cost_evaluator/*.cpp utils/*.cpp workflow/*.cpp) usfunctiongetresourcesource(TARGET ${LIBRARY_NAME} OUT SRC) usfunctiongeneratebundleinit(TARGET ${LIBRARY_NAME} OUT SRC) Loading @@ -9,7 +8,7 @@ set(_bundle_name qcor_qsim) add_library(${LIBRARY_NAME} SHARED ${SRC}) target_link_libraries(${LIBRARY_NAME} PUBLIC qcor qcor-qsim) target_include_directories(${LIBRARY_NAME} PUBLIC . ../base ${XACC_ROOT}/include/eigen) target_include_directories(${LIBRARY_NAME} PUBLIC . ./utils ../base ${XACC_ROOT}/include/eigen) xacc_configure_library_rpath(${LIBRARY_NAME}) set_target_properties(${LIBRARY_NAME} Loading Loading @@ -37,8 +36,7 @@ else() endif() install(TARGETS ${LIBRARY_NAME} DESTINATION ${CMAKE_INSTALL_PREFIX}/plugins) install(FILES ${HEADERS} DESTINATION include/qcor) if (QCOR_BUILD_TESTS) add_subdirectory(modules/tests) add_subdirectory(cost_evaluator/tests) endif() No newline at end of file lib/qsim/impls/ansatz_generator/trotter.cpp 0 → 100644 +26 −0 Original line number Diff line number Diff line #include "trotter.hpp" #include "xacc_service.hpp" namespace qcor { namespace qsim { Ansatz TrotterEvolution::create_ansatz(Observable *obs, const HeterogeneousMap ¶ms) { Ansatz result; // This ansatz generator requires an observable. assert(obs != nullptr); double dt = 1.0; if (params.keyExists<double>("dt")) { dt = params.get<double>("dt"); } // Just use exp_i_theta for now // TODO: formalize a standard library kernel for this. auto expCirc = std::dynamic_pointer_cast<xacc::quantum::Circuit>( xacc::getService<xacc::Instruction>("exp_i_theta")); expCirc->expand({{"pauli", obs->toString()}}); result.circuit = expCirc->operator()({dt}); result.nb_qubits = expCirc->nRequiredBits(); return result; } } // namespace qsim } // namespace qcor No newline at end of file lib/qsim/impls/ansatz_generator/trotter.hpp 0 → 100644 +15 −0 Original line number Diff line number Diff line #pragma once #include "qcor_qsim.hpp" namespace qcor { namespace qsim { // 1st-order Trotterization class TrotterEvolution : public AnsatzGenerator { public: Ansatz create_ansatz(Observable *obs, const HeterogeneousMap ¶ms) override; virtual const std::string name() const override { return "trotter"; } virtual const std::string description() const override { return ""; } }; } // namespace qsim } // namespace qcor No newline at end of file lib/qsim/impls/cost_evaluator/partial_tomography.cpp 0 → 100644 +18 −0 Original line number Diff line number Diff line #include "partial_tomography.hpp" #include "qsim_utils.hpp" namespace qcor { namespace qsim { double PartialTomoObjFuncEval::evaluate( std::shared_ptr<CompositeInstruction> state_prep) { auto subKernels = qcor::__internal__::observe( xacc::as_shared_ptr(target_operator), state_prep); // Run the pass manager (optimization + placement) executePassManager(subKernels); auto tmp_buffer = qalloc(state_prep->nPhysicalBits()); xacc::internal_compiler::execute(tmp_buffer.results(), subKernels); const double energy = tmp_buffer.weighted_sum(target_operator); return energy; } } // namespace qsim } // namespace qcor No newline at end of file lib/qsim/impls/cost_evaluator/partial_tomography.hpp 0 → 100644 +16 −0 Original line number Diff line number Diff line #pragma once #include "qcor_qsim.hpp" namespace qcor { namespace qsim { class PartialTomoObjFuncEval : public CostFunctionEvaluator { public: // Evaluate the cost virtual double evaluate(std::shared_ptr<CompositeInstruction> state_prep) override; virtual const std::string name() const override { return "default"; } virtual const std::string description() const override { return ""; } }; } // namespace qsim } // namespace qcor No newline at end of file Loading
lib/qsim/impls/CMakeLists.txt +3 −5 Original line number Diff line number Diff line set(LIBRARY_NAME qcor-quantum-simulation) file(GLOB SRC *.cpp modules/*.cpp) file(GLOB HEADERS *.hpp) file(GLOB SRC *.cpp ansatz_generator/*.cpp cost_evaluator/*.cpp utils/*.cpp workflow/*.cpp) usfunctiongetresourcesource(TARGET ${LIBRARY_NAME} OUT SRC) usfunctiongeneratebundleinit(TARGET ${LIBRARY_NAME} OUT SRC) Loading @@ -9,7 +8,7 @@ set(_bundle_name qcor_qsim) add_library(${LIBRARY_NAME} SHARED ${SRC}) target_link_libraries(${LIBRARY_NAME} PUBLIC qcor qcor-qsim) target_include_directories(${LIBRARY_NAME} PUBLIC . ../base ${XACC_ROOT}/include/eigen) target_include_directories(${LIBRARY_NAME} PUBLIC . ./utils ../base ${XACC_ROOT}/include/eigen) xacc_configure_library_rpath(${LIBRARY_NAME}) set_target_properties(${LIBRARY_NAME} Loading Loading @@ -37,8 +36,7 @@ else() endif() install(TARGETS ${LIBRARY_NAME} DESTINATION ${CMAKE_INSTALL_PREFIX}/plugins) install(FILES ${HEADERS} DESTINATION include/qcor) if (QCOR_BUILD_TESTS) add_subdirectory(modules/tests) add_subdirectory(cost_evaluator/tests) endif() No newline at end of file
lib/qsim/impls/ansatz_generator/trotter.cpp 0 → 100644 +26 −0 Original line number Diff line number Diff line #include "trotter.hpp" #include "xacc_service.hpp" namespace qcor { namespace qsim { Ansatz TrotterEvolution::create_ansatz(Observable *obs, const HeterogeneousMap ¶ms) { Ansatz result; // This ansatz generator requires an observable. assert(obs != nullptr); double dt = 1.0; if (params.keyExists<double>("dt")) { dt = params.get<double>("dt"); } // Just use exp_i_theta for now // TODO: formalize a standard library kernel for this. auto expCirc = std::dynamic_pointer_cast<xacc::quantum::Circuit>( xacc::getService<xacc::Instruction>("exp_i_theta")); expCirc->expand({{"pauli", obs->toString()}}); result.circuit = expCirc->operator()({dt}); result.nb_qubits = expCirc->nRequiredBits(); return result; } } // namespace qsim } // namespace qcor No newline at end of file
lib/qsim/impls/ansatz_generator/trotter.hpp 0 → 100644 +15 −0 Original line number Diff line number Diff line #pragma once #include "qcor_qsim.hpp" namespace qcor { namespace qsim { // 1st-order Trotterization class TrotterEvolution : public AnsatzGenerator { public: Ansatz create_ansatz(Observable *obs, const HeterogeneousMap ¶ms) override; virtual const std::string name() const override { return "trotter"; } virtual const std::string description() const override { return ""; } }; } // namespace qsim } // namespace qcor No newline at end of file
lib/qsim/impls/cost_evaluator/partial_tomography.cpp 0 → 100644 +18 −0 Original line number Diff line number Diff line #include "partial_tomography.hpp" #include "qsim_utils.hpp" namespace qcor { namespace qsim { double PartialTomoObjFuncEval::evaluate( std::shared_ptr<CompositeInstruction> state_prep) { auto subKernels = qcor::__internal__::observe( xacc::as_shared_ptr(target_operator), state_prep); // Run the pass manager (optimization + placement) executePassManager(subKernels); auto tmp_buffer = qalloc(state_prep->nPhysicalBits()); xacc::internal_compiler::execute(tmp_buffer.results(), subKernels); const double energy = tmp_buffer.weighted_sum(target_operator); return energy; } } // namespace qsim } // namespace qcor No newline at end of file
lib/qsim/impls/cost_evaluator/partial_tomography.hpp 0 → 100644 +16 −0 Original line number Diff line number Diff line #pragma once #include "qcor_qsim.hpp" namespace qcor { namespace qsim { class PartialTomoObjFuncEval : public CostFunctionEvaluator { public: // Evaluate the cost virtual double evaluate(std::shared_ptr<CompositeInstruction> state_prep) override; virtual const std::string name() const override { return "default"; } virtual const std::string description() const override { return ""; } }; } // namespace qsim } // namespace qcor No newline at end of file