Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
ORNL Quantum Computing Institute
xacc
Commits
eadbe4ef
Commit
eadbe4ef
authored
Feb 08, 2018
by
Mccaskey, Alex
Browse files
minor cleanup
Signed-off-by:
Alex McCaskey
<
mccaskeyaj@ornl.gov
>
parent
8a541136
Changes
6
Hide whitespace changes
Inline
Side-by-side
xacc/XACC.cpp
View file @
eadbe4ef
...
...
@@ -51,11 +51,11 @@ void Initialize(int arc, char** arv) {
argc
=
arc
;
argv
=
arv
;
XACCLogger
::
instance
()
->
info
(
"Creating XACC ServiceRegistry"
);
XACCLogger
::
instance
()
->
enqueueLog
(
"Creating XACC ServiceRegistry"
);
// Get reference to the service registry
auto
serviceRegistry
=
xacc
::
ServiceRegistry
::
instance
();
try
{
XACCLogger
::
instance
()
->
info
(
"Initializing the ServiceRegistry"
);
XACCLogger
::
instance
()
->
enqueueLog
(
"Initializing the ServiceRegistry"
);
serviceRegistry
->
initialize
();
}
catch
(
std
::
exception
&
e
)
{
XACCLogger
::
instance
()
->
error
(
"Failure initializing XACC Plugin Registry - "
+
...
...
@@ -65,16 +65,16 @@ void Initialize(int arc, char** arv) {
// Parse any user-supplied command line options
xaccCLParser
->
parse
(
argc
,
argv
);
info
(
"[xacc] Initializing XACC Framework."
);
XACCLogger
::
instance
()
->
enqueueLog
(
"[xacc] Initializing XACC Framework."
);
// Check that we have some
auto
s
=
serviceRegistry
->
getServices
<
Compiler
>
().
size
();
auto
a
=
serviceRegistry
->
getServices
<
Accelerator
>
().
size
();
info
(
XACCLogger
::
instance
()
->
enqueueLog
(
"[xacc::plugins] XACC has "
+
std
::
to_string
(
s
)
+
" Compiler"
+
((
s
==
1
||
s
==
0
)
?
""
:
"s"
)
+
" available."
);
info
(
XACCLogger
::
instance
()
->
enqueueLog
(
"[xacc::plugins] XACC has "
+
std
::
to_string
(
a
)
+
" Accelerator"
+
((
s
==
0
||
s
==
1
)
?
""
:
"s"
)
+
" available."
);
...
...
@@ -83,8 +83,16 @@ void Initialize(int arc, char** arv) {
// We're good if we make it here, so indicate that we've been
// initialized
xacc
::
xaccFrameworkInitialized
=
true
;
if
(
!
optionExists
(
"queue-preamble"
))
{
XACCLogger
::
instance
()
->
dumpQueue
();
}
}
void
setGlobalLoggerPredicate
(
MessagePredicate
predicate
)
{
XACCLogger
::
instance
()
->
setGlobalLoggerPredicate
(
predicate
);
XACCLogger
::
instance
()
->
dumpQueue
();
}
void
info
(
const
std
::
string
&
msg
,
MessagePredicate
predicate
)
{
XACCLogger
::
instance
()
->
info
(
msg
,
predicate
);
...
...
xacc/XACC.hpp
View file @
eadbe4ef
...
...
@@ -67,6 +67,7 @@ void addCommandLineOptions(const std::string& category, const std::map<std::stri
void
addCommandLineOptions
(
std
::
shared_ptr
<
options_description
>
options
);
void
setGlobalLoggerPredicate
(
MessagePredicate
predicate
);
void
info
(
const
std
::
string
&
msg
,
MessagePredicate
predicate
=
std
::
function
<
bool
(
void
)
>
([]()
{
return
true
;}));
void
debug
(
const
std
::
string
&
msg
,
MessagePredicate
predicate
=
std
::
function
<
bool
(
void
)
>
([]()
{
return
true
;}));
void
error
(
const
std
::
string
&
msg
,
MessagePredicate
predicate
=
std
::
function
<
bool
(
void
)
>
([]()
{
return
true
;}));
...
...
xacc/utils/CLIParser.hpp
View file @
eadbe4ef
...
...
@@ -57,7 +57,10 @@ public:
(
"list-compilers"
,
"List all available XACC Compilers"
)
(
"list-accelerators"
,
"List all available XACC Accelerators"
)
(
"no-color"
,
"Turn off colored logger output (blue for INFO, red for ERROR, etc.)."
)
(
"use-cout"
,
"Use std::cout for logs instead of SPDLOG Logger."
);
(
"use-cout"
,
"Use std::cout for logs instead of SPDLOG Logger."
)
(
"queue-preamble"
,
"Pass this option to xacc::Initialize() if you would "
"like all startup messages to be queued until after a "
"global logger predicate has been passed."
);
}
void
addOptionsDescription
(
std
::
shared_ptr
<
options_description
>
options
)
{
...
...
xacc/utils/ServiceRegistry.cpp
View file @
eadbe4ef
...
...
@@ -22,12 +22,15 @@ void ServiceRegistry::initialize() {
const
std
::
string
xaccLibDir
=
std
::
string
(
XACC_INSTALL_DIR
)
+
std
::
string
(
"/lib"
);
XACCLogger
::
instance
()
->
info
(
"XACC Library Directory: "
+
xaccLibDir
);
XACCLogger
::
instance
()
->
enqueueLog
(
"XACC Library Directory: "
+
xaccLibDir
);
for
(
auto
&
entry
:
boost
::
filesystem
::
directory_iterator
(
xaccLibDir
))
{
// We want the gate and aqc bundles that come with XACC
if
(
boost
::
contains
(
entry
.
path
().
filename
().
string
(),
"libxacc-quantum"
))
{
XACCLogger
::
instance
()
->
info
(
"Installing base plugin "
+
entry
.
path
().
filename
().
string
());
auto
name
=
entry
.
path
().
filename
().
string
();
boost
::
replace_all
(
name
,
"lib"
,
""
);
boost
::
replace_all
(
name
,
".so"
,
""
);
XACCLogger
::
instance
()
->
enqueueLog
(
"Installing base plugin "
+
name
);
context
.
InstallBundles
(
entry
.
path
().
string
());
}
}
...
...
@@ -41,7 +44,10 @@ void ServiceRegistry::initialize() {
auto
p
=
entry
.
path
();
if
(
boost
::
filesystem
::
is_directory
(
p
))
{
for
(
auto
&
subentry
:
boost
::
filesystem
::
directory_iterator
(
p
))
{
XACCLogger
::
instance
()
->
info
(
"Installing 3rd party plugin "
+
subentry
.
path
().
filename
().
string
());
auto
name
=
subentry
.
path
().
filename
().
string
();
boost
::
replace_all
(
name
,
"lib"
,
""
);
boost
::
replace_all
(
name
,
".so"
,
""
);
XACCLogger
::
instance
()
->
enqueueLog
(
"Installing 3rd party plugin "
+
name
);
context
.
InstallBundles
(
subentry
.
path
().
string
());
}
}
...
...
@@ -53,7 +59,7 @@ void ServiceRegistry::initialize() {
"There are no plugins. Install plugins to begin working with XACC."
);
}
XACCLogger
::
instance
()
->
info
(
"Starting the C
ppU
s Framework."
);
XACCLogger
::
instance
()
->
enqueueLog
(
"Starting the C
++ Microservice
s Framework."
);
// Start the framework itself.
framework
.
Start
();
...
...
xacc/utils/Utils.cpp
View file @
eadbe4ef
...
...
@@ -81,7 +81,7 @@ XACCLogger::XACCLogger() :
void
XACCLogger
::
info
(
const
std
::
string
&
msg
,
MessagePredicate
predicate
)
{
if
(
useCout
)
{
if
(
predicate
())
{
if
(
predicate
()
&&
globalPredicate
()
)
{
if
(
useColor
)
{
std
::
cout
<<
"
\033
[1;34m[XACC Info] "
+
msg
+
"
\033
[0m
\n
"
;
}
else
{
...
...
@@ -89,7 +89,7 @@ void XACCLogger::info(const std::string& msg, MessagePredicate predicate) {
}
}
}
else
{
if
(
predicate
())
{
if
(
predicate
()
&&
globalPredicate
()
)
{
if
(
useColor
)
{
logger
->
info
(
"
\033
[1;34m"
+
msg
+
"
\033
[0m"
);
}
else
{
...
...
@@ -100,7 +100,7 @@ void XACCLogger::info(const std::string& msg, MessagePredicate predicate) {
}
void
XACCLogger
::
debug
(
const
std
::
string
&
msg
,
MessagePredicate
predicate
)
{
if
(
useCout
)
{
if
(
predicate
())
{
if
(
predicate
()
&&
globalPredicate
()
)
{
if
(
useColor
)
{
std
::
cout
<<
"
\033
[1;33m[XACC Debug] "
+
msg
+
"
\033
[0m
\n
"
;
}
else
{
...
...
@@ -108,7 +108,7 @@ void XACCLogger::debug(const std::string& msg, MessagePredicate predicate) {
}
}
}
else
{
if
(
predicate
())
{
if
(
predicate
()
&&
globalPredicate
()
)
{
if
(
useColor
)
{
logger
->
info
(
"
\033
[1;33m"
+
msg
+
"
\033
[0m"
);
}
else
{
...
...
@@ -119,10 +119,10 @@ void XACCLogger::debug(const std::string& msg, MessagePredicate predicate) {
}
void
XACCLogger
::
error
(
const
std
::
string
&
msg
,
MessagePredicate
predicate
)
{
if
(
useCout
)
{
if
(
predicate
())
if
(
predicate
()
&&
globalPredicate
()
)
XACCError
(
msg
);
}
else
{
if
(
predicate
())
{
if
(
predicate
()
&&
globalPredicate
()
)
{
logger
->
error
(
msg
);
}
}
...
...
xacc/utils/Utils.hpp
View file @
eadbe4ef
...
...
@@ -19,6 +19,7 @@
#include
"RuntimeOptions.hpp"
#include
"spdlog/spdlog.h"
#include
<iostream>
#include
<queue>
namespace
xacc
{
...
...
@@ -103,49 +104,6 @@ public:
using
MessagePredicate
=
std
::
function
<
bool
(
void
)
>
;
//class LoggerImpl {
//public:
//
// virtual void info(const std::string& msg) = 0;
// virtual void error(const std::string& msg) = 0;
//
//};
//
//class SpdlogImpl : public LoggerImpl {
//
//protected:
//
// std::shared_ptr<spdlog::logger> logger;
//
// bool useColor = true;
//
//public:
//
// SpdlogImpl() : useColor(
// !RuntimeOptions::instance()->exists("no-color")) {
// logger = spdlog::stdout_logger_mt("xacc-logger");
// }
//
// virtual void info(const std::string& msg) {
// logger->info(useColor ? "\033[1;34m" + msg + "\033[0m" : msg);
// }
//
// virtual void error(const std::string& msg) {
// logger->error(useColor ? );
// }
//};
//
//class CoutImpl : public LoggerImpl {
//
//public:
//
// virtual void info(const std::string& msg) {
// }
//
// virtual void error(const std::string& msg) {
// }
//};
class
XACCLogger
:
public
Singleton
<
XACCLogger
>
{
protected:
...
...
@@ -156,6 +114,10 @@ protected:
bool
useColor
=
true
;
MessagePredicate
globalPredicate
=
[]()
{
return
true
;};
std
::
queue
<
std
::
string
>
logQueue
;
XACCLogger
();
public:
...
...
@@ -168,6 +130,17 @@ public:
return
instance_
;
}
void
enqueueLog
(
const
std
::
string
log
)
{
logQueue
.
push
(
log
);
}
void
dumpQueue
()
{
while
(
!
logQueue
.
empty
())
{
info
(
logQueue
.
front
());
logQueue
.
pop
();
}
}
void
setGlobalLoggerPredicate
(
MessagePredicate
pred
)
{
globalPredicate
=
pred
;}
void
info
(
const
std
::
string
&
msg
,
MessagePredicate
predicate
=
std
::
function
<
bool
(
void
)
>
([]()
{
return
true
;}));
void
debug
(
const
std
::
string
&
msg
,
MessagePredicate
predicate
=
std
::
function
<
bool
(
void
)
>
([]()
{
return
true
;}));
void
error
(
const
std
::
string
&
msg
,
MessagePredicate
predicate
=
std
::
function
<
bool
(
void
)
>
([]()
{
return
true
;}));
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment