Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion python/utils/OpaqueArguments.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#pragma once

#include "PyTypes.h"
#include "common/FmtCore.h"
#include "cudaq/Optimizer/Builder/Runtime.h"
#include "cudaq/Optimizer/CodeGen/QIRFunctionNames.h"
#include "cudaq/Optimizer/CodeGen/QIROpaqueStructTypes.h"
Expand Down
4 changes: 2 additions & 2 deletions runtime/common/AnalogHamiltonian.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#pragma once

#include "common/FmtCore.h"
#include "common/cudaq_fmt.h"
#include "nlohmann/json.hpp"
#include <optional>
#include <string>
Expand Down Expand Up @@ -37,7 +37,7 @@ using json = nlohmann::json;

/// @brief Convert a double to a JSON string.
inline std::string doubleAsJsonString(double d) {
std::string s = fmt::format("{:.8f}", d);
std::string s = cudaq_fmt::format("{:.8f}", d);
return s;
}

Expand Down
6 changes: 3 additions & 3 deletions runtime/common/BaseRemoteRESTQPU.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
#include "common/ExecutionContext.h"
#include "common/Executor.h"
#include "common/ExtraPayloadProvider.h"
#include "common/FmtCore.h"
#include "common/Logger.h"
#include "common/Resources.h"
#include "common/RestClient.h"
#include "common/RuntimeMLIR.h"
#include "common/cudaq_fmt.h"
#include "cudaq.h"
#include "cudaq/Frontend/nvqpp/AttributeNames.h"
#include "cudaq/Optimizer/Builder/Intrinsics.h"
Expand Down Expand Up @@ -526,8 +526,8 @@ class BaseRemoteRESTQPU : public QPU {
if (failed(mlir::SymbolTable::replaceAllSymbolUses(
funcOp.getOperation(), newNameAttr, m_module.getOperation()))) {
throw std::runtime_error(
fmt::format("Failed to replace symbol uses for function {}",
fullFuncName.str()));
cudaq_fmt::format("Failed to replace symbol uses for function {}",
fullFuncName.str()));
}
return mlir::WalkResult::advance();
});
Expand Down
2 changes: 1 addition & 1 deletion runtime/common/BraketExecutor.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@

#include "common/BraketServerHelper.h"
#include "common/Executor.h"
#include "common/FmtCore.h"
#include "common/Logger.h"
#include "common/SampleResult.h"
#include "common/cudaq_fmt.h"
#include "cudaq.h"
#include <aws/braket/BraketClient.h>
#include <aws/core/Aws.h>
Expand Down
2 changes: 1 addition & 1 deletion runtime/common/JsonConvert.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#pragma once
#include "GPUInfo.h"
#include "common/ExecutionContext.h"
#include "common/FmtCore.h"
#include "common/cudaq_fmt.h"
#include "cudaq/Support/Version.h"
#include "cudaq/gradients.h"
#include "cudaq/optimizers.h"
Expand Down
4 changes: 3 additions & 1 deletion runtime/common/Logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,9 @@ std::string pathToFileName(const std::string_view fullFilePath) {
return file.filename().string();
}
} // namespace details
} // namespace cudaq

namespace cudaq_fmt {
namespace details {

void print_packed(const std::string_view message,
Expand Down Expand Up @@ -151,4 +153,4 @@ std::string format_packed(const std::string_view fmt_str,
}

} // namespace details
} // namespace cudaq
} // namespace cudaq_fmt
118 changes: 15 additions & 103 deletions runtime/common/Logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,7 @@

#pragma once

#include <chrono>
#include <complex>
#include <cstddef>
#include <cstdint>
#include <functional>
#include <map>
#include <span>
#include <string>
#include <type_traits>
#include <variant>
#include <vector>
#include "common/cudaq_fmt.h"

namespace cudaq {

Expand All @@ -39,83 +29,6 @@ void warn(const std::string_view msg);
std::string pathToFileName(const std::string_view fullFilePath);
} // namespace details

namespace details {

//
// Concepts to check if T is in the variant
//
template <typename T, typename... Types>
concept one_of = ((std::same_as<T, Types> ||
std::same_as<std::reference_wrapper<const T>, Types>) ||
...);

template <typename T, typename Variant>
struct is_variant_member;

template <typename T, typename... Types>
struct is_variant_member<T, std::variant<Types...>>
: std::bool_constant<one_of<T, Types...>> {};

template <typename T, typename Variant>
concept variant_alternative =
is_variant_member<std::decay_t<T>, Variant>::value;

//
// Packed parameter type passing arguments to fmt
// Built-in types need to be passed by value.
// Please store large types (like vectors, strings) as reference_wrappers
//
struct fmt_arg {
using storage_t = std::variant<
bool, char, uint32_t, int32_t, uint64_t, int64_t, float, double,
std::complex<float>, std::complex<double>, std::string_view, const char *,
char *, void *, std::chrono::milliseconds,
std::chrono::system_clock::time_point,
std::reference_wrapper<const std::vector<int32_t>>,
std::reference_wrapper<const std::string>,
std::reference_wrapper<const std::vector<uint32_t>>,
std::reference_wrapper<const std::vector<uint64_t>>,
std::reference_wrapper<const std::vector<float>>,
std::reference_wrapper<const std::vector<double>>,
std::reference_wrapper<const std::vector<std::string>>,
std::reference_wrapper<const std::map<std::string, std::string>>,
std::reference_wrapper<const std::vector<std::complex<float>>>,
std::reference_wrapper<const std::vector<std::complex<double>>>>;
storage_t value;

template <typename T>
requires variant_alternative<T, storage_t>
fmt_arg(const T &v) : value(std::cref(v)) {}
};

//
// Packed versions of format and print, implemented in Logger.cpp
//
std::string format_packed(const std::string_view message,
const std::span<fmt_arg> &arr);

void print_packed(const std::string_view message,
const std::span<fmt_arg> &arr);

//
// Functions substitutes for fmt::format and fmt::print
//
template <typename... Args>
std::string format(const std::string_view message, Args &&...args) {
auto array = std::array<fmt_arg, sizeof...(Args)>{
fmt_arg(std::forward<Args>(args))...};
return format_packed(message, array);
}

template <typename... Args>
void print(const std::string_view message, Args &&...args) {
auto array = std::array<fmt_arg, sizeof...(Args)>{
fmt_arg(std::forward<Args>(args))...};
return print_packed(message, array);
}

} // namespace details

/// This type seeks to enable automated injection of the
/// source location of the `cudaq::info()` or `debug()` call.
/// We do this via a struct of the same name (info), which
Expand All @@ -134,7 +47,7 @@ void print(const std::string_view message, Args &&...args) {
const char *fileName = __builtin_FILE(), \
int lineNo = __builtin_LINE()) { \
if (details::should_log(details::LogLevel::NAME)) { \
auto msg = cudaq::details::format(message, args...); \
auto msg = cudaq_fmt::format(message, args...); \
std::string name = funcName; \
auto start = name.find_first_of(" "); \
name = name.substr(start + 1, name.find_first_of("(") - start - 1); \
Expand Down Expand Up @@ -166,12 +79,12 @@ void log(const std::string_view message, Args &&...args) {
const auto timestamp = std::chrono::system_clock::now();
const auto now_c = std::chrono::system_clock::to_time_t(timestamp);
std::tm now_tm = *std::localtime(&now_c);
cudaq::details::print("[{:04}-{:02}-{:02} {:02}:{:02}:{:%S}] {}\n",
now_tm.tm_year + 1900, now_tm.tm_mon + 1,
now_tm.tm_mday, now_tm.tm_hour, now_tm.tm_min,
std::chrono::round<std::chrono::milliseconds>(
timestamp.time_since_epoch()),
cudaq::details::format(message, args...));
cudaq_fmt::print("[{:04}-{:02}-{:02} {:02}:{:02}:{:%S}] {}\n",
now_tm.tm_year + 1900, now_tm.tm_mon + 1, now_tm.tm_mday,
now_tm.tm_hour, now_tm.tm_min,
std::chrono::round<std::chrono::milliseconds>(
timestamp.time_since_epoch()),
cudaq_fmt::format(message, args...));
}

/// @brief Context information (function, file, and line) of a caller
Expand Down Expand Up @@ -256,7 +169,7 @@ class ScopedTrace {
for (std::size_t i = 0; i < nArgs; i++) {
argsMsg += (i != nArgs - 1) ? "{}, " : "{}}})";
}
argsMsg = cudaq::details::format(argsMsg, args...);
argsMsg = cudaq_fmt::format(argsMsg, args...);
globalTraceStack++;
}
}
Expand Down Expand Up @@ -289,7 +202,7 @@ class ScopedTrace {
argsMsg += (i != nArgs - 1) ? "{}, " : "{}}})";
}
}
argsMsg = cudaq::details::format(argsMsg, args...);
argsMsg = cudaq_fmt::format(argsMsg, args...);
globalTraceStack++;
}
}
Expand Down Expand Up @@ -336,15 +249,14 @@ class ScopedTrace {
.count() /
1000.0);
// If we're printing because the tag was found, then add that tag info
std::string tagStr =
tagFound ? cudaq::details::format("[tag={}] ", tag) : "";
std::string tagStr = tagFound ? cudaq_fmt::format("[tag={}] ", tag) : "";
std::string sourceInfo =
context.fileName
? cudaq::details::format(
"[{}:{}] ", details::pathToFileName(context.fileName),
context.lineNo)
? cudaq_fmt::format("[{}:{}] ",
details::pathToFileName(context.fileName),
context.lineNo)
: "";
auto str = cudaq::details::format(
auto str = cudaq_fmt::format(
"{}{}{}{} executed in {} ms.{}",
globalTraceStack > 0 ? std::string(globalTraceStack, '-') + " " : "",
tagStr, sourceInfo, traceName, duration, argsMsg);
Expand Down
6 changes: 3 additions & 3 deletions runtime/common/PluginUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
******************************************************************************/

#pragma once
#include "FmtCore.h"
#include "Logger.h"
#include "cudaq_fmt.h"
#include <dlfcn.h>
#include <mutex>
#include <string_view>
Expand All @@ -31,8 +31,8 @@ PluginPointerType *getUniquePluginInstance(const std::string_view symbolName,
GetPluginFunction fcn =
(GetPluginFunction)(intptr_t)dlsym(handle, symbolName.data());
if (!fcn)
throw std::runtime_error(
fmt::format("Could not load the requested plugin. \n{}\n", dlerror()));
throw std::runtime_error(cudaq_fmt::format(
"Could not load the requested plugin. \n{}\n", dlerror()));

CUDAQ_INFO("Successfully loaded the plugin.");
return fcn();
Expand Down
6 changes: 3 additions & 3 deletions runtime/common/RuntimeMLIRCommonImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -489,9 +489,9 @@ mlir::LogicalResult qirProfileTranslationFunction(

auto config = parseCodeGenTranslation(qirProfile);
if (!config.isQIRProfile)
throw std::runtime_error(
fmt::format("Unexpected codegen profile while translating to QIR: {}",
config.profile));
throw std::runtime_error(cudaq_fmt::format(
"Unexpected codegen profile while translating to QIR: {}",
config.profile));

auto context = op->getContext();
mlir::PassManager pm(context);
Expand Down
Loading
Loading