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

Method createMonotonicForLoop

python/cudaq/kernel/ast_bridge.py:1399–1419  ·  view source on GitHub ↗
(self,
                               bodyBuilder,
                               startVal,
                               stepVal,
                               endVal,
                               isDecrementing=False,
                               orElseBuilder=None)

Source from the content-addressed store, hash-verified

1397 return loop
1398
1399 def createMonotonicForLoop(self,
1400 bodyBuilder,
1401 startVal,
1402 stepVal,
1403 endVal,
1404 isDecrementing=False,
1405 orElseBuilder=None):
1406
1407 iTy = self.getIntegerType()
1408 assert startVal.type == iTy
1409 assert stepVal.type == iTy
1410 assert endVal.type == iTy
1411
1412 condPred = IntegerAttr.get(
1413 iTy, 4) if isDecrementing else IntegerAttr.get(iTy, 2)
1414 return self.createForLoop(
1415 [iTy], lambda args: bodyBuilder(args[0]), [startVal],
1416 lambda args: arith.CmpIOp(condPred, args[0], endVal).result,
1417 lambda args: [arith.AddIOp(args[0], stepVal).result],
1418 None if orElseBuilder is None else
1419 (lambda args: orElseBuilder(args[0])))
1420
1421 def createInvariantForLoop(self, bodyBuilder, endVal):
1422 """Create an invariant loop using the CC dialect."""

Callers 3

visit_CallMethod · 0.95
visit_ForMethod · 0.95

Calls 3

getIntegerTypeMethod · 0.95
createForLoopMethod · 0.95
getMethod · 0.45

Tested by

no test coverage detected