MCPcopy Create free account
hub / github.com/NVIDIA/cuda-quantum / parse

Method parse

runtime/common/RecordLogParser.cpp:15–65  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

13#include "cudaq/runtime/logger/logger.h"
14
15void cudaq::RecordLogParser::parse(const std::string &outputLog) {
16 ScopedTraceWithContext(cudaq::TIMING_RUN, "RecordLogParser::parse");
17 CUDAQ_DBG("Parsing log:\n{}", outputLog);
18 std::vector<std::string> lines = cudaq::split(outputLog, '\n');
19 if (lines.empty())
20 return;
21
22 // Collect log from a single shot and process it only if it is successful.
23 bool processingShot = false;
24 // Maintain the starting index of each shot's data
25 std::size_t shotStart = 0;
26
27 for (std::size_t idx = 0; idx < lines.size(); ++idx) {
28 const auto &line = lines[idx];
29 std::vector<std::string> entries = cudaq::split(line, '\t');
30 if (entries.empty())
31 continue;
32
33 const std::string &recordType = entries[0];
34 if (recordType == "HEADER")
35 handleHeader(entries);
36 else if (recordType == "METADATA")
37 handleMetadata(entries);
38 else if (recordType == "START") {
39 processingShot = true;
40 shotStart = 0;
41 } else if (recordType == "OUTPUT") {
42 if (processingShot)
43 shotStart = shotStart == 0 ? idx : shotStart;
44 else
45 handleOutput(entries);
46 } else if (recordType == "END") {
47 if (entries.size() < 2)
48 throw std::runtime_error("Missing shot status");
49 if (entries[1] == "0") {
50 if (processingShot) {
51 // Successful shot, process it
52 for (std::size_t j = shotStart; j < idx; ++j)
53 handleOutput(cudaq::split(lines[j], '\t'));
54 }
55 } else {
56 CUDAQ_DBG("Discarding shot data due to non-zero END status.");
57 }
58 processingShot = false;
59 shotStart = 0;
60 containerMeta.reset();
61 } else {
62 throw std::runtime_error("Invalid record type: " + recordType);
63 }
64 }
65}
66
67void cudaq::RecordLogParser::handleHeader(
68 const std::vector<std::string> &entries) {

Callers 15

_getChildFuncNamesMethod · 0.45
__str__Method · 0.45
compileMethod · 0.45
visit_CallMethod · 0.45
compile_to_mlirFunction · 0.45
initializeMethod · 0.45
_parse_astFunction · 0.45
_get_ast_from_callableFunction · 0.45
_make_kernel_astFunction · 0.45
bindExecutionContextFunction · 0.45
CUDAQ_TESTFunction · 0.45

Calls 4

splitFunction · 0.50
emptyMethod · 0.45
sizeMethod · 0.45
resetMethod · 0.45

Tested by 3

_get_ast_from_callableFunction · 0.36
_make_kernel_astFunction · 0.36
CUDAQ_TESTFunction · 0.36