Skip to content

Commit

Permalink
Implemented new XACCLogger and api functions for using it (#22)
Browse files Browse the repository at this point in the history
Signed-off-by: Alex McCaskey <mccaskeyaj@ornl.gov>
  • Loading branch information
Alex McCaskey committed Jan 23, 2018
1 parent 429fd55 commit f29fd47
Show file tree
Hide file tree
Showing 22 changed files with 184 additions and 98 deletions.
2 changes: 1 addition & 1 deletion quantum/aqc/compiler/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@
# *******************************************************************************/
# Gather tests
file (GLOB test_files tests/*.cpp)
add_tests("${test_files}" "${CMAKE_CURRENT_SOURCE_DIR}" "${LIBRARY_NAME};${Boost_LIBRARIES};dl;pthread;xacc-quantum-aqc")
add_tests("${test_files}" "${CMAKE_CURRENT_SOURCE_DIR}" "${LIBRARY_NAME};${Boost_LIBRARIES};dl;pthread;xacc-quantum-aqc;xacc")

4 changes: 2 additions & 2 deletions quantum/aqc/compiler/default/TrivialEmbeddingAlgorithm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ Embedding TrivialEmbeddingAlgorithm::embed(
if (i < j && i != j
&& (problem->edgeExists(i, j) && !hdware->edgeExists(i, j))) {
if (failHard) {
XACCError(
XACCLogger::instance()->error(
"Trivial Embedding not possible, there is no hardware edge corresponding to ("
+ std::to_string(i) + ", "
+ std::to_string(j) + ") problem edge.");
} else {
XACCInfo("This embedding failed, but user requested to not fail hard. Returning empty embedding.");
XACCLogger::instance()->info("This embedding failed, but user requested to not fail hard. Returning empty embedding.");
xaccEmbedding.clear();
return xaccEmbedding;
}
Expand Down
2 changes: 1 addition & 1 deletion quantum/aqc/ir/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@
# *******************************************************************************/
# Gather tests
file (GLOB test_files tests/*.cpp)
add_tests("${test_files}" "${CMAKE_CURRENT_SOURCE_DIR}" "${Boost_LIBRARIES}")
add_tests("${test_files}" "${CMAKE_CURRENT_SOURCE_DIR}" "${Boost_LIBRARIES};xacc")

2 changes: 1 addition & 1 deletion quantum/aqc/ir/DWIR.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class DWIR : public virtual IR {
return f;
}
}
XACCError("Invalid kernel name - " + name);
XACCLogger::instance()->error("Invalid kernel name - " + name);
}

virtual std::vector<std::shared_ptr<Function>> getKernels() {
Expand Down
12 changes: 6 additions & 6 deletions quantum/aqc/ir/DWKernel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class DWKernel: public virtual Function {
if (instructions.size() > idx) {
return *std::next(instructions.begin(), idx);
} else {
XACCError("Invalid instruction index.");
XACCLogger::instance()->error("Invalid instruction index.");
}
}

Expand Down Expand Up @@ -142,19 +142,19 @@ class DWKernel: public virtual Function {
}

virtual InstructionParameter getParameter(const int idx) const {
XACCError("DWKernel does not contain runtime parameters.");
XACCLogger::instance()->error("DWKernel does not contain runtime parameters.");
}

virtual void setParameter(const int idx, InstructionParameter& p) {
XACCError("DWKernel does not contain runtime parameters.");
XACCLogger::instance()->error("DWKernel does not contain runtime parameters.");
}

virtual std::vector<InstructionParameter> getParameters() {
XACCError("DWKernel does not contain runtime parameters.");
XACCLogger::instance()->error("DWKernel does not contain runtime parameters.");
}

virtual void addParameter(InstructionParameter instParam) {
XACCError("DWKernel does not contain runtime parameters.");
XACCLogger::instance()->error("DWKernel does not contain runtime parameters.");
}

virtual bool isParameterized() {
Expand All @@ -166,7 +166,7 @@ class DWKernel: public virtual Function {
}

virtual void evaluateVariableParameters(std::vector<InstructionParameter> parameters) {
XACCError("DWKernel does not contain runtime parameters.");
XACCLogger::instance()->error("DWKernel does not contain runtime parameters.");
}


Expand Down
2 changes: 1 addition & 1 deletion quantum/gate/compiler/KernelReplacementPreprocessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const std::string KernelReplacementPreprocessor::process(const std::string& sour
std::shared_ptr<Compiler> compiler,
std::shared_ptr<Accelerator> accelerator) {

XACCInfo("Running Kernel Replacement Preprocessor.\n");
XACCLogger::instance()->info("Running Kernel Replacement Preprocessor.\n");

// Find any occurrences of xacc::FUNCTION
// Get the first occurrence
Expand Down
2 changes: 1 addition & 1 deletion quantum/gate/ir/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@

# Gather tests
file (GLOB test_files tests/*.cpp)
add_tests("${test_files}" "${CMAKE_CURRENT_SOURCE_DIR}" "${LIBRARY_NAME};${Boost_LIBRARIES};xacc-quantum-gate")
add_tests("${test_files}" "${CMAKE_CURRENT_SOURCE_DIR}" "${LIBRARY_NAME};${Boost_LIBRARIES};xacc;xacc-quantum-gate")

6 changes: 3 additions & 3 deletions quantum/gate/ir/GateFunction.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class GateFunction: public virtual Function {
if (instructions.size() > idx) {
return *std::next(instructions.begin(), idx);
} else {
XACCError("Invalid instruction index.");
XACCLogger::instance()->error("Invalid instruction index.");
}
}

Expand Down Expand Up @@ -142,15 +142,15 @@ class GateFunction: public virtual Function {

virtual InstructionParameter getParameter(const int idx) const {
if (idx + 1 > parameters.size()) {
XACCError("Invalid Parameter requested.");
XACCLogger::instance()->error("Invalid Parameter requested.");
}

return parameters[idx];
}

virtual void setParameter(const int idx, InstructionParameter& p) {
if (idx + 1 > parameters.size()) {
XACCError("Invalid Parameter requested.");
XACCLogger::instance()->error("Invalid Parameter requested.");
}

parameters[idx] = p;
Expand Down
4 changes: 2 additions & 2 deletions quantum/gate/ir/GateInstruction.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,15 +130,15 @@ class GateInstruction: public virtual Instruction {

virtual InstructionParameter getParameter(const int idx) const {
if (idx + 1 > parameters.size()) {
XACCError("Invalid Parameter requested from Parameterized Gate Instruction.");
XACCLogger::instance()->error("Invalid Parameter requested from Parameterized Gate Instruction.");
}

return parameters[idx];
}

virtual void setParameter(const int idx, InstructionParameter& p) {
if (idx + 1 > parameters.size()) {
XACCError("Invalid Parameter requested from Parameterized Gate Instruction.");
XACCLogger::instance()->error("Invalid Parameter requested from Parameterized Gate Instruction.");
}

parameters[idx] = p;
Expand Down
2 changes: 1 addition & 1 deletion quantum/gate/ir/GateQIR.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class GateQIR: public xacc::IR, public Graph<CircuitNode> {
return f;
}
}
XACCError("Invalid kernel name.");
XACCLogger::instance()->error("Invalid kernel name.");
}

virtual bool kernelExists(const std::string& name) {
Expand Down
2 changes: 1 addition & 1 deletion quantum/gate/utils/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ include_directories(${CMAKE_SOURCE_DIR}/tpls/eigen)

# Gather tests
file (GLOB test_files tests/*.cpp)
add_tests("${test_files}" "${CMAKE_CURRENT_SOURCE_DIR}" "${Boost_LIBRARIES};xacc-quantum-gate")
add_tests("${test_files}" "${CMAKE_CURRENT_SOURCE_DIR}" "${Boost_LIBRARIES};xacc;xacc-quantum-gate")


20 changes: 10 additions & 10 deletions quantum/gate/utils/Registry.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,14 @@ class Registry : public Singleton<Registry<T, TArgs...>> {
bool add(const std::string& id,
CreatorFunctionPtr f) {
if (registry.find(id) != registry.end()) {
XACCInfo(id + " already exists in Registry. Ignoring and retaining previous Registry entry");
XACCLogger::instance()->info(id + " already exists in Registry. Ignoring and retaining previous Registry entry");
return true;
}

if (RuntimeOptions::instance()->exists("verbose-registry")) XACCInfo("Registry adding " + id);
if (RuntimeOptions::instance()->exists("verbose-registry")) XACCLogger::instance()->info("Registry adding " + id);
bool s = registry.emplace(std::make_pair(id, f)).second;
if (!s) {
XACCError("Could not add " + id + " to the Registry.");
XACCLogger::instance()->error("Could not add " + id + " to the Registry.");
} else {
return s;
}
Expand All @@ -81,14 +81,14 @@ class Registry : public Singleton<Registry<T, TArgs...>> {
bool add(const std::string& id,
CreatorFunctionPtr f, std::shared_ptr<options_description> options) {
if (registry.find(id) != registry.end()) {
XACCInfo(id + " already exists in Registry. Ignoring and retaining previous Registry entry");
XACCLogger::instance()->info(id + " already exists in Registry. Ignoring and retaining previous Registry entry");
return true;
}
if (RuntimeOptions::instance()->exists("verbose-registry")) XACCInfo("Registry adding " + id);
if (RuntimeOptions::instance()->exists("verbose-registry")) XACCLogger::instance()->info("Registry adding " + id);
bool s = registry.emplace(std::make_pair(id, f)).second;
bool s2 = registryOptions.insert(std::make_pair(id, std::move(options))).second;
if (!s || ! s2) {
XACCError("Could not add " + id + " to the Registry.");
XACCLogger::instance()->error("Could not add " + id + " to the Registry.");
} else {
return true;
}
Expand All @@ -98,19 +98,19 @@ class Registry : public Singleton<Registry<T, TArgs...>> {
std::shared_ptr<options_description> options,
std::function<bool(variables_map&)> optionsHandler) {
if (registry.find(id) != registry.end()) {
XACCInfo(
XACCLogger::instance()->info(
id
+ " already exists in Registry. Ignoring and retaining previous Registry entry");
return true;
}
if (RuntimeOptions::instance()->exists("verbose-registry"))
XACCInfo("Registry adding " + id);
XACCLogger::instance()->info("Registry adding " + id);
bool s = registry.emplace(std::make_pair(id, f)).second;
bool s2 =
registryOptions.insert(std::make_pair(id, std::move(options))).second;
bool s3 = registryOptionHandlers.insert(std::make_pair(id, std::move(optionsHandler))).second;
if (!s || !s2) {
XACCError("Could not add " + id + " to the Registry.");
XACCLogger::instance()->error("Could not add " + id + " to the Registry.");
} else {
return true;
}
Expand All @@ -128,7 +128,7 @@ class Registry : public Singleton<Registry<T, TArgs...>> {
if (search != registry.end()) {
return registry[id]->operator()(args...);
} else {
XACCError("Invalid Registry map id string - " + id);
XACCLogger::instance()->error("Invalid Registry map id string - " + id);
}
}

Expand Down
2 changes: 1 addition & 1 deletion quantum/gate/utils/SimulatedQubits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ class SimulatedQubits: public AcceleratorBuffer {

for (int i = 0; i < bufferState.size(); i++) {

XACCInfo(
XACCLogger::instance()->info(
bitStrings[i] + " -> ("
+ std::to_string(std::real(bufferState(i))) + ", "
+ std::to_string(std::imag(bufferState(i))) + ")");
Expand Down
2 changes: 1 addition & 1 deletion xacc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ target_link_libraries(${LIBRARY_NAME} ${Boost_LIBRARIES} ${CppUsLib})
file(GLOB test_files utils/tests/*Tester.cpp accelerator/tests/*Tester.cpp)

# Add the tests
add_tests("${test_files}" "${CMAKE_CURRENT_SOURCE_DIR}/utils" "${Boost_LIBRARIES}")
add_tests("${test_files}" "${CMAKE_CURRENT_SOURCE_DIR}/utils" "${Boost_LIBRARIES};xacc")

install(FILES ${HEADERS} DESTINATION include/xacc)
install(TARGETS ${LIBRARY_NAME} DESTINATION lib)
Loading

0 comments on commit f29fd47

Please sign in to comment.