@@ -105,77 +105,6 @@ void cudaq::RecordLogParser::handleOutput(
105105 const std::string &recValue = entries[2 ];
106106 std::string recLabel = (entries.size () == 4 ) ? entries[3 ] : " " ;
107107 cudaq::trim (recLabel);
108- if (recType == " RESULT" ) {
109- // Sample-type QIR output, where we have an array of `RESULT` per shot. For
110- // example,
111- // START
112- // OUTPUT RESULT 1 r00000
113- // ....
114- // OUTPUT RESULT 1 r00009
115- // END 0
116-
117- currentOutput = OutputType::RESULT;
118- const bool isUninitializedContainer =
119- (containerMeta.m_type == ContainerType::NONE) ||
120- (containerMeta.m_type == ContainerType::ARRAY &&
121- containerMeta.elementCount == 0 );
122- if (isUninitializedContainer) {
123- // NOTE: This is a temporary workaround until all backends consistently
124- // use the new transformation pass that wraps result records inside an
125- // array record output. For now, we permit "naked" RESULT records, i.e.,
126- // if the QIR produced by a sampled kernel emits a sequence of RESULT
127- // records without enclosing them in an ARRAY, we interpret them
128- // collectively as an array of results.
129- // NOTE: This assumption prevents us from correctly supporting `run` with
130- // `qir-base` profile.
131- containerMeta.m_type = ContainerType::ARRAY;
132- containerMeta.elementCount =
133- std::stoul (metadata[ResultCountMetadataName]);
134- containerMeta.arrayType = " i1" ;
135- preallocateArray ();
136- }
137-
138- // Note: For ordered schema, we expect the results are sequential in the
139- // same order that mz operations are called. This may include results in
140- // named registers (specified in kernel code) and other auto-generated
141- // register names. If index cannot be extracted from the label, we fall back
142- // to using this mechanism.
143- auto idxLabel = std::to_string (containerMeta.processedElements );
144-
145- // Get the index from the label, if feasible.
146- // / TODO: The `sample` API should be updated to not allow explicit
147- // / measurement operations in the kernel when targeting hardware backends.
148- // Until then, we handle both cases here - auto-generated labels like
149- // r00000, r00001, ... and named results like result%0, result%1, ...
150- if (!recLabel.empty ()) {
151- std::size_t percentPos = recLabel.find (' %' );
152- if (percentPos != std::string::npos) {
153- idxLabel = recLabel.substr (percentPos + 1 );
154- }
155- // This logic is fragile; for example user may have only one mz assigned
156- // to variable like r00001 and it will be interpreted as index 1, and
157- // cause `Array index out of bounds` error. The proper fix is to disallow
158- // explicit mz operations in sampled kernels. Also, `run` is appropriate
159- // for getting sub-register results.
160- else if (recLabel.size () == 6 && recLabel[0 ] == ' r' ) {
161- // check that the last 5 characters are all digits
162- bool allDigits = true ;
163- for (std::size_t i = 1 ; i < 6 ; ++i) {
164- if (recLabel[i] < ' 0' || recLabel[i] > ' 9' ) {
165- allDigits = false ;
166- break ;
167- }
168- }
169- if (allDigits) {
170- idxLabel = recLabel.substr (1 );
171- }
172- }
173- }
174-
175- processArrayEntry (recValue, fmt::format (" [{}]" , idxLabel));
176- containerMeta.processedElements ++;
177- return ;
178- }
179108 if (recType == " ARRAY" ) {
180109 containerMeta.m_type = ContainerType::ARRAY;
181110 containerMeta.elementCount = std::stoul (recValue);
@@ -196,6 +125,8 @@ void cudaq::RecordLogParser::handleOutput(
196125 }
197126 return ;
198127 }
128+ if (recType == " RESULT" )
129+ currentOutput = OutputType::RESULT;
199130 if (recType == " BOOL" )
200131 currentOutput = OutputType::BOOL;
201132 else if (recType == " INT" )
0 commit comments