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

Function parseGateSpec

unittests/Optimizer/DecompositionPatternsTest.cpp:53–78  ·  view source on GitHub ↗

Helper to parse gate string like "x(1)", "z(2)", "rx ", "rx (1)"

Source from the content-addressed store, hash-verified

51
52// Helper to parse gate string like "x(1)", "z(2)", "rx<adj>", "rx<adj>(1)"
53GateSpec parseGateSpec(StringRef gateSpec) {
54 // Find the end of the gate name (before '<' or '(')
55 auto nameEnd = gateSpec.find_first_of("(<");
56 std::string gateName;
57 if (nameEnd == StringRef::npos) {
58 return {gateSpec.str(), 0, false};
59 }
60 gateName = gateSpec.substr(0, nameEnd).str();
61 gateSpec = gateSpec.drop_front(nameEnd);
62
63 // Check for <adj>
64 bool isAdj = gateSpec.consume_front("<adj>");
65
66 // Check for (N) control count
67 size_t numControls = 0;
68 if (gateSpec.consume_front("(")) {
69 gateSpec = gateSpec.ltrim();
70 if (gateSpec.starts_with("n")) {
71 numControls = std::numeric_limits<size_t>::max();
72 } else {
73 gateSpec.consumeInteger(10, numControls);
74 }
75 }
76
77 return {gateName, numControls, isAdj};
78}
79
80// Helper function to create a test module with a single gate operation
81ModuleOp createTestModule(MLIRContext *context, StringRef gateSpecStr) {

Callers 1

createTestModuleFunction · 0.85

Calls 1

strMethod · 0.45

Tested by

no test coverage detected