MCPcopy Create free account
hub / github.com/QuEST-Kit/QuEST / assertStringIsValidPauliStrSum

Function assertStringIsValidPauliStrSum

quest/src/core/parser.cpp:396–430  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

394
395
396void assertStringIsValidPauliStrSum(string lines, const char* caller) {
397
398 int numPaulis = 0;
399 bool nonEmptyLine = false;
400 qindex lineIndex = 0;
401
402 // parse each line in-turn
403 stringstream stream(lines);
404
405 for (string line; getline(stream, line); lineIndex++) {
406
407 // permit and skip empty lines
408 if (isOnlyWhiteSpace(line))
409 continue;
410 else
411 nonEmptyLine = true;
412
413 // assert the line is interpretable
414 bool validLine = isInterpretablePauliStrSumLine(line);
415 validate_parsedPauliStrSumLineIsInterpretable(validLine, line, lineIndex, caller);
416
417 // assert the coeff is parsable (e.g. doesn't exceed valid number range)
418 bool validCoeff = isPauliStrSumCoeffWithinQcompRange(line);
419 validate_parsedPauliStrSumCoeffWithinQcompRange(validCoeff, line, lineIndex, caller);
420
421 // assert the line has a consistent number of Paulis as previous
422 int numLinePaulis = getNumPaulisInLine(line);
423 if (!numPaulis)
424 numPaulis = numLinePaulis;
425 validate_parsedPauliStrSumLineHasConsistentNumPaulis(numPaulis, numLinePaulis, line, lineIndex, caller);
426 }
427
428 // ensure we parsed at least 1 Pauli string
429 validate_parsedStringIsNotEmpty(nonEmptyLine, caller);
430}
431
432
433

Callers 1

Tested by

no test coverage detected