diff --git a/python/utils/OpaqueArguments.h b/python/utils/OpaqueArguments.h index 75a3cd33e57..68be7edc246 100644 --- a/python/utils/OpaqueArguments.h +++ b/python/utils/OpaqueArguments.h @@ -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" diff --git a/runtime/common/AnalogHamiltonian.h b/runtime/common/AnalogHamiltonian.h index 0294cb64dde..9b9adf0502a 100644 --- a/runtime/common/AnalogHamiltonian.h +++ b/runtime/common/AnalogHamiltonian.h @@ -8,7 +8,7 @@ #pragma once -#include "common/FmtCore.h" +#include "common/cudaq_fmt.h" #include "nlohmann/json.hpp" #include #include @@ -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; } diff --git a/runtime/common/BaseRemoteRESTQPU.h b/runtime/common/BaseRemoteRESTQPU.h index cd96ed9a411..96ac870bc08 100644 --- a/runtime/common/BaseRemoteRESTQPU.h +++ b/runtime/common/BaseRemoteRESTQPU.h @@ -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" @@ -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(); }); diff --git a/runtime/common/BraketExecutor.h b/runtime/common/BraketExecutor.h index afab27275b3..98bfe5d7c17 100644 --- a/runtime/common/BraketExecutor.h +++ b/runtime/common/BraketExecutor.h @@ -10,7 +10,6 @@ #include "common/BraketServerHelper.h" #include "common/Executor.h" -#include "common/FmtCore.h" #include "common/Logger.h" #include "common/SampleResult.h" #include "cudaq.h" diff --git a/runtime/common/JsonConvert.h b/runtime/common/JsonConvert.h index 0e0bbcbccc6..f549a20a77b 100644 --- a/runtime/common/JsonConvert.h +++ b/runtime/common/JsonConvert.h @@ -9,7 +9,6 @@ #pragma once #include "GPUInfo.h" #include "common/ExecutionContext.h" -#include "common/FmtCore.h" #include "cudaq/Support/Version.h" #include "cudaq/gradients.h" #include "cudaq/optimizers.h" diff --git a/runtime/common/Logger.cpp b/runtime/common/Logger.cpp index 18037ff70f7..bf3d90bb65d 100644 --- a/runtime/common/Logger.cpp +++ b/runtime/common/Logger.cpp @@ -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, @@ -151,4 +153,4 @@ std::string format_packed(const std::string_view fmt_str, } } // namespace details -} // namespace cudaq +} // namespace cudaq_fmt diff --git a/runtime/common/Logger.h b/runtime/common/Logger.h index 55990ec77f6..8b6ba299619 100644 --- a/runtime/common/Logger.h +++ b/runtime/common/Logger.h @@ -8,17 +8,7 @@ #pragma once -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include "common/cudaq_fmt.h" namespace cudaq { @@ -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 -concept one_of = ((std::same_as || - std::same_as, Types>) || - ...); - -template -struct is_variant_member; - -template -struct is_variant_member> - : std::bool_constant> {}; - -template -concept variant_alternative = - is_variant_member, 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, std::complex, std::string_view, const char *, - char *, void *, std::chrono::milliseconds, - std::chrono::system_clock::time_point, - std::reference_wrapper>, - std::reference_wrapper, - std::reference_wrapper>, - std::reference_wrapper>, - std::reference_wrapper>, - std::reference_wrapper>, - std::reference_wrapper>, - std::reference_wrapper>, - std::reference_wrapper>>, - std::reference_wrapper>>>; - storage_t value; - - template - requires variant_alternative - 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 &arr); - -void print_packed(const std::string_view message, - const std::span &arr); - -// -// Functions substitutes for fmt::format and fmt::print -// -template -std::string format(const std::string_view message, Args &&...args) { - auto array = std::array{ - fmt_arg(std::forward(args))...}; - return format_packed(message, array); -} - -template -void print(const std::string_view message, Args &&...args) { - auto array = std::array{ - fmt_arg(std::forward(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 @@ -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); \ @@ -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( - 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( + timestamp.time_since_epoch()), + cudaq_fmt::format(message, args...)); } /// @brief Context information (function, file, and line) of a caller @@ -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++; } } @@ -289,7 +202,7 @@ class ScopedTrace { argsMsg += (i != nArgs - 1) ? "{}, " : "{}}})"; } } - argsMsg = cudaq::details::format(argsMsg, args...); + argsMsg = cudaq_fmt::format(argsMsg, args...); globalTraceStack++; } } @@ -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); diff --git a/runtime/common/PluginUtils.h b/runtime/common/PluginUtils.h index 9bbb79e1a36..0ebdc4f5f64 100644 --- a/runtime/common/PluginUtils.h +++ b/runtime/common/PluginUtils.h @@ -7,8 +7,8 @@ ******************************************************************************/ #pragma once -#include "FmtCore.h" #include "Logger.h" +#include "cudaq_fmt.h" #include #include #include @@ -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(); diff --git a/runtime/common/RuntimeMLIRCommonImpl.h b/runtime/common/RuntimeMLIRCommonImpl.h index f7def4386d8..6cf7b09a549 100644 --- a/runtime/common/RuntimeMLIRCommonImpl.h +++ b/runtime/common/RuntimeMLIRCommonImpl.h @@ -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); diff --git a/runtime/common/cudaq_fmt.h b/runtime/common/cudaq_fmt.h new file mode 100644 index 00000000000..912377aefd6 --- /dev/null +++ b/runtime/common/cudaq_fmt.h @@ -0,0 +1,124 @@ +/****************************************************************-*- C++ -*-**** + * Copyright (c) 2022 - 2026 NVIDIA Corporation & Affiliates. * + * All rights reserved. * + * * + * This source code and the accompanying materials are made available under * + * the terms of the Apache License 2.0 which accompanies this distribution. * + ******************************************************************************/ + +#pragma once + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +// +// This header provides a wrapper around some of the fmtlib functions, so that +// fmtlib headers, which are not distributed, do not bleed into user code. +// +// It introduces a cudaq_fmt namespace to make it easy to distinguish between +// what would otherwise be fmt::format and cudaq::fmt::format. +// + +namespace cudaq_fmt { +struct fmt_arg; +namespace details { +// +// Concepts to check if T is in the variant +// +template +concept one_of = ((std::same_as || + std::same_as, Types>) || + ...); + +template +struct is_variant_member; + +template +struct is_variant_member> + : std::bool_constant> {}; + +template +concept variant_alternative = + is_variant_member, Variant>::value; + +// +// Packed versions of format and print, implemented in Logger.cpp +// +std::string format_packed(const std::string_view message, + const std::span &arr); + +void print_packed(const std::string_view message, + const std::span &arr); +} // namespace details + +// +// 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, std::complex, std::string_view, const char *, + char *, void *, std::chrono::milliseconds, + std::chrono::system_clock::time_point, + std::reference_wrapper>, + std::reference_wrapper, + std::reference_wrapper>, + std::reference_wrapper>, + std::reference_wrapper>, + std::reference_wrapper>, + std::reference_wrapper>, + std::reference_wrapper>, + std::reference_wrapper>>, + std::reference_wrapper>>>; + storage_t value; + + template + requires details::variant_alternative + fmt_arg(const T &v) : value(std::cref(v)) {} +}; + +// +// Functions substitutes for fmt::format and fmt::print +// +template +std::string format(const std::string_view message, Args &&...args) { + auto array = std::array{ + fmt_arg(std::forward(args))...}; + return details::format_packed(message, array); +} + +template +void print(const std::string_view message, Args &&...args) { + auto array = std::array{ + fmt_arg(std::forward(args))...}; + return details::print_packed(message, array); +} + +// +// Substitute for fmt::underlying +// +// Converts `e` to the underlying type. +// +// Example: +// +// enum class color { red, green, blue }; +// auto s = cudaq_fmt::format("{}", cudaq_fmt::underlying(color::red)); // +// s == "0" +// +template +constexpr auto underlying(Enum e) noexcept -> std::underlying_type_t { + return static_cast>(e); +} + +} // namespace cudaq_fmt diff --git a/runtime/cudaq/platform/default/rest/helpers/braket/BraketExecutor.cpp b/runtime/cudaq/platform/default/rest/helpers/braket/BraketExecutor.cpp index 0efa9c8f5ef..2cf623c6dcc 100644 --- a/runtime/cudaq/platform/default/rest/helpers/braket/BraketExecutor.cpp +++ b/runtime/cudaq/platform/default/rest/helpers/braket/BraketExecutor.cpp @@ -8,6 +8,7 @@ #include "common/BraketExecutor.h" #include "common/BraketServerHelper.h" +#include "common/FmtCore.h" #include #include diff --git a/runtime/cudaq/platform/fermioniq/FermioniqBaseQPU.h b/runtime/cudaq/platform/fermioniq/FermioniqBaseQPU.h index fa9e639e022..bd4128c0b9a 100644 --- a/runtime/cudaq/platform/fermioniq/FermioniqBaseQPU.h +++ b/runtime/cudaq/platform/fermioniq/FermioniqBaseQPU.h @@ -88,9 +88,9 @@ class FermioniqBaseQPU : public BaseRemoteRESTQPU { terms.push_back(termStr); auto coeff = term.evaluate_coefficient(); - auto coeff_str = - fmt::format("{}{}{}j", coeff.real(), coeff.imag() < 0.0 ? "-" : "+", - std::fabs(coeff.imag())); + auto coeff_str = cudaq_fmt::format("{}{}{}j", coeff.real(), + coeff.imag() < 0.0 ? "-" : "+", + std::fabs(coeff.imag())); terms.push_back(coeff_str); diff --git a/runtime/nvqir/cudensitymat/CuDensityMatErrorHandling.h b/runtime/nvqir/cudensitymat/CuDensityMatErrorHandling.h index 2e08977376c..c75f80e761d 100644 --- a/runtime/nvqir/cudensitymat/CuDensityMatErrorHandling.h +++ b/runtime/nvqir/cudensitymat/CuDensityMatErrorHandling.h @@ -7,18 +7,18 @@ ******************************************************************************/ #pragma once +#include "common/cudaq_fmt.h" #include #include -#include #include #define HANDLE_CUDM_ERROR(x) \ { \ const auto err = x; \ if (err != CUDENSITYMAT_STATUS_SUCCESS) { \ - throw std::runtime_error(fmt::format("[cudaq] %{} in {} (line {})", \ - fmt::underlying(err), __FUNCTION__, \ - __LINE__)); \ + throw std::runtime_error(cudaq_fmt::format( \ + "[cudaq] %{} in {} (line {})", cudaq_fmt::underlying(err), \ + __FUNCTION__, __LINE__)); \ } \ } @@ -26,9 +26,9 @@ { \ const auto err = x; \ if (err != cudaSuccess) { \ - throw std::runtime_error(fmt::format("[cuda] %{} in {} (line {})", \ - fmt::underlying(err), __FUNCTION__, \ - __LINE__)); \ + throw std::runtime_error(cudaq_fmt::format("[cuda] %{} in {} (line {})", \ + cudaq_fmt::underlying(err), \ + __FUNCTION__, __LINE__)); \ } \ } @@ -36,7 +36,7 @@ do { \ cublasStatus_t err_ = (err); \ if (err_ != CUBLAS_STATUS_SUCCESS) { \ - std::printf("[cublas] error %d at %s:%d\n", fmt::underlying(err_), \ + std::printf("[cublas] error %d at %s:%d\n", cudaq_fmt::underlying(err_), \ __FILE__, __LINE__); \ throw std::runtime_error("cublas error"); \ } \ diff --git a/runtime/nvqir/custatevec/CuStateVecState.h b/runtime/nvqir/custatevec/CuStateVecState.h index dbb84e4a268..10d69e9744f 100644 --- a/runtime/nvqir/custatevec/CuStateVecState.h +++ b/runtime/nvqir/custatevec/CuStateVecState.h @@ -7,8 +7,9 @@ ******************************************************************************/ #pragma once -#include "common/FmtCore.h" +#include "common/Logger.h" #include "common/SimulationState.h" +#include "common/cudaq_fmt.h" #include #include @@ -20,9 +21,9 @@ { \ const auto err = x; \ if (err != CUSTATEVEC_STATUS_SUCCESS) { \ - throw std::runtime_error(fmt::format("[custatevec] %{} in {} (line {})", \ - custatevecGetErrorString(err), \ - __FUNCTION__, __LINE__)); \ + throw std::runtime_error(cudaq_fmt::format( \ + "[custatevec] %{} in {} (line {})", custatevecGetErrorString(err), \ + __FUNCTION__, __LINE__)); \ } \ }; @@ -30,9 +31,9 @@ { \ const auto err = x; \ if (err != cudaSuccess) { \ - throw std::runtime_error(fmt::format("[custatevec] %{} in {} (line {})", \ - cudaGetErrorString(err), \ - __FUNCTION__, __LINE__)); \ + throw std::runtime_error( \ + cudaq_fmt::format("[custatevec] %{} in {} (line {})", \ + cudaGetErrorString(err), __FUNCTION__, __LINE__)); \ } \ }; @@ -160,11 +161,11 @@ class CusvState : public cudaq::SimulationState { std::complex getAmplitude(const std::vector &basisState) override { if (getNumQubits() != basisState.size()) - throw std::runtime_error( - fmt::format("[custatevec-state] getAmplitude with an invalid number " - "of bits in the " - "basis state: expected {}, provided {}.", - getNumQubits(), basisState.size())); + throw std::runtime_error(cudaq_fmt::format( + "[custatevec-state] getAmplitude with an invalid number " + "of bits in the " + "basis state: expected {}, provided {}.", + getNumQubits(), basisState.size())); if (std::any_of(basisState.begin(), basisState.end(), [](int x) { return x != 0 && x != 1; })) throw std::runtime_error( diff --git a/runtime/nvqir/cutensornet/mps_simulation_state.inc b/runtime/nvqir/cutensornet/mps_simulation_state.inc index b569f5041a4..d38491f8256 100644 --- a/runtime/nvqir/cutensornet/mps_simulation_state.inc +++ b/runtime/nvqir/cutensornet/mps_simulation_state.inc @@ -274,7 +274,7 @@ std::complex MPSSimulationState::getAmplitude( const std::vector &basisState) { if (getNumQubits() != basisState.size()) throw std::runtime_error( - fmt::format("[tensornet-state] getAmplitude with an invalid number " + cudaq_fmt::format("[tensornet-state] getAmplitude with an invalid number " "of bits in the " "basis state: expected {}, provided {}.", getNumQubits(), basisState.size())); @@ -646,7 +646,7 @@ MPSSettings::MPSSettings() { } svdAlgo = iter->second; CUDAQ_INFO("Setting MPS SVD algorithm to {} ({}).", - fmt::underlying(svdAlgo), iter->first); + cudaq_fmt::underlying(svdAlgo), iter->first); } using GaugePair = @@ -673,7 +673,7 @@ MPSSettings::MPSSettings() { } gaugeOption = iter->second; CUDAQ_INFO("Setting MPS GAUGE option to {} ({}).", iter->first, - fmt::underlying(iter->second)); + cudaq_fmt::underlying(iter->second)); } } @@ -684,7 +684,7 @@ void MPSSimulationState::toHostImpl( auto stateVec = state->getStateVector(); if (stateVec.size() != numElements) throw std::runtime_error( - fmt::format("[MPSSimulationState] Dimension mismatch: expecting {} " + cudaq_fmt::format("[MPSSimulationState] Dimension mismatch: expecting {} " "elements but providing an array of size {}.", stateVec.size(), numElements)); if (std::is_same_v) { diff --git a/runtime/nvqir/cutensornet/simulator_cutensornet.inc b/runtime/nvqir/cutensornet/simulator_cutensornet.inc index 4ced7885bf3..eb6569631e2 100644 --- a/runtime/nvqir/cutensornet/simulator_cutensornet.inc +++ b/runtime/nvqir/cutensornet/simulator_cutensornet.inc @@ -219,7 +219,7 @@ void SimulatorTensorNetBase::applyKrausChannel( const auto targetPrecision = std::is_same_v ? cudaq::simulation_precision::fp32 : cudaq::simulation_precision::fp64; - const std::string cacheKey = fmt::format( + const std::string cacheKey = cudaq_fmt::format( "GeneralKrausMat_{}", std::to_string(vecComplexHash(op.data))); if (op.precision == targetPrecision) return getOrCacheMat(cacheKey, op.data, m_gateDeviceMemCache); diff --git a/runtime/nvqir/cutensornet/simulator_tensornet.h b/runtime/nvqir/cutensornet/simulator_tensornet.h index 6d47fb1d7b9..b20fe1cc34e 100644 --- a/runtime/nvqir/cutensornet/simulator_tensornet.h +++ b/runtime/nvqir/cutensornet/simulator_tensornet.h @@ -47,11 +47,11 @@ class SimulatorTensorNet : public SimulatorTensorNetBase { std::getenv("CUDAQ_TENSORNET_CONTROLLED_RANK")) { auto maxControlledRank = std::atoi(maxControlledRankEnvVar); if (maxControlledRank <= 0) - throw std::runtime_error( - fmt::format("Invalid CUDAQ_TENSORNET_CONTROLLED_RANK environment " - "variable setting. Expecting a " - "positive integer value, got '{}'.", - maxControlledRank)); + throw std::runtime_error(cudaq_fmt::format( + "Invalid CUDAQ_TENSORNET_CONTROLLED_RANK environment " + "variable setting. Expecting a " + "positive integer value, got '{}'.", + maxControlledRank)); CUDAQ_INFO("Setting max controlled rank for full tensor expansion from " "{} to {}.", diff --git a/runtime/nvqir/cutensornet/tensornet_state.inc b/runtime/nvqir/cutensornet/tensornet_state.inc index 9da45d06420..98c3bae3e2b 100644 --- a/runtime/nvqir/cutensornet/tensornet_state.inc +++ b/runtime/nvqir/cutensornet/tensornet_state.inc @@ -484,7 +484,7 @@ TensorNetState::contractStateVectorInternal( std::complex stateNorm{0.0, 0.0}; if (!in_projectedModeValues.empty() && in_projectedModeValues.size() != projectedModes.size()) - throw std::invalid_argument(fmt::format( + throw std::invalid_argument(cudaq_fmt::format( "The number of projected modes ({}) must equal the number of " "projected values ({}).", projectedModes.size(), in_projectedModeValues.size())); diff --git a/runtime/nvqir/cutensornet/timing_utils.h b/runtime/nvqir/cutensornet/timing_utils.h index b7495c0d298..805cecbd6cc 100644 --- a/runtime/nvqir/cutensornet/timing_utils.h +++ b/runtime/nvqir/cutensornet/timing_utils.h @@ -7,7 +7,6 @@ ******************************************************************************/ #pragma once -#include "common/FmtCore.h" #include "common/Logger.h" #ifndef NTIMING @@ -15,24 +14,3 @@ #else #define LOG_API_TIME() #endif - -namespace nvqir { -template -std::string containerToString(ItTy begin, ItTy end) { - fmt::basic_memory_buffer buffer; - fmt::format_to(std::back_inserter(buffer), "["); - for (ItTy itr = begin; itr != end; ++itr) { - fmt::format_to(std::back_inserter(buffer), "{}", *itr); - if (std::next(itr) != end) { - fmt::format_to(std::back_inserter(buffer), ","); - } - } - fmt::format_to(std::back_inserter(buffer), "]"); - return fmt::to_string(buffer); -} - -template -static inline std::string containerToString(const ContainerTy &container) { - return containerToString(container.begin(), container.end()); -} -} // namespace nvqir diff --git a/runtime/nvqir/cutensornet/tn_simulation_state.inc b/runtime/nvqir/cutensornet/tn_simulation_state.inc index 43fa7ffb21c..21b62f7c266 100644 --- a/runtime/nvqir/cutensornet/tn_simulation_state.inc +++ b/runtime/nvqir/cutensornet/tn_simulation_state.inc @@ -213,7 +213,7 @@ std::complex TensorNetSimulationState::getAmplitude( const std::vector &basisState) { if (getNumQubits() != basisState.size()) throw std::runtime_error( - fmt::format("[tensornet-state] getAmplitude with an invalid number " + cudaq_fmt::format("[tensornet-state] getAmplitude with an invalid number " "of bits in the " "basis state: expected {}, provided {}.", getNumQubits(), basisState.size())); @@ -315,7 +315,7 @@ void TensorNetSimulationState::toHostImpl( std::complex *clientAllocatedData, std::size_t numElements) const { auto stateVec = m_state->getStateVector(); if (stateVec.size() != numElements) - throw std::runtime_error(fmt::format( + throw std::runtime_error(cudaq_fmt::format( "[TensorNetSimulationState] Dimension mismatch: expecting {} " "elements but providing an array of size {}.", stateVec.size(), numElements));