...
 
Commits (2)
......@@ -71,6 +71,7 @@ private:
class HPCVirtTearDown : public xacc::TearDown {
public:
virtual void tearDown() override;
virtual std::string name() const override { return "xacc-hpc-virt"; }
};
} // namespace quantum
} // namespace xacc
......
......@@ -13,14 +13,15 @@
*******************************************************************************/
#pragma once
// TearDown interface: all registered TearDown services
#include <string>
// TearDown interface: all registered TearDown services
// will have its tearDown() method called once xacc is about to Finalize().
// Contributing services (e.g. plugins) can use this to clean up any global resources
// that they instantiated.
// Contributing services (e.g. plugins) can use this to clean up any global
// resources that they instantiated.
namespace xacc {
class TearDown {
public:
virtual void tearDown() = 0;
virtual void tearDown() = 0;
virtual std::string name() const { return ""; }
};
} //namespace
\ No newline at end of file
} // namespace xacc
\ No newline at end of file
......@@ -112,7 +112,9 @@ void setGlobalLoggerPredicate(MessagePredicate predicate) {
XACCLogger::instance()->dumpQueue();
}
void logToFile(bool enable, const std::string &fileNamePrefix) { XACCLogger::instance()->logToFile(enable, fileNamePrefix); }
void logToFile(bool enable, const std::string &fileNamePrefix) {
XACCLogger::instance()->logToFile(enable, fileNamePrefix);
}
void setLoggingLevel(int level) {
XACCLogger::instance()->setLoggingLevel(level);
......@@ -771,14 +773,26 @@ void Finalize() {
auto tearDowns = xacc::getServices<TearDown>();
debug("Tearing down " + std::to_string(tearDowns.size()) +
" registered TearDown services..");
std::vector<std::shared_ptr<TearDown>> frameworkTearDowns;
for (auto &td : tearDowns) {
try {
td->tearDown();
// If this is XACC HPC TearDown,
// add it to the list of XACC internal TearDown services to be executed
// after all plugins' TearDowns.
if (td->name() == "xacc-hpc-virt") {
frameworkTearDowns.emplace_back(td);
} else {
td->tearDown();
}
} catch (int exception) {
xacc::error("Error while tearing down a service. Code: " +
std::to_string(exception));
}
}
// Runs XACC internal TearDowns
for (auto &td : frameworkTearDowns) {
td->tearDown();
}
xacc::xaccFrameworkInitialized = false;
compilation_database.clear();
......