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

Method visit_If

python/cudaq/kernel/ast_bridge.py:5214–5245  ·  view source on GitHub ↗

Map a Python `ast.If` node to an if statement operation in the CC dialect.

(self, node)

Source from the content-addressed store, hash-verified

5212 "CUDA-Q does not currently support Assert expressions", node)
5213
5214 def visit_If(self, node):
5215 """Map a Python `ast.If` node to an if statement operation in the CC
5216 dialect."""
5217
5218 # Visit the conditional node, retain
5219 # measurement results by assigning a dummy variable name
5220 self.currentAssignVariableName = ''
5221 self.visit(node.test)
5222 self.currentAssignVariableName = None
5223 condition = self.__arithmetic_to_bool(self.popValue())
5224
5225 ifOp = cc.IfOp([], condition, [])
5226 thenBlock = Block.create_at_start(ifOp.thenRegion, [])
5227 with InsertionPoint(thenBlock):
5228 self.symbolTable.beginBlock()
5229 self.pushIfStmtBlockStack()
5230 [self.visit(b) for b in node.body]
5231 if not self.hasTerminator(thenBlock):
5232 cc.ContinueOp([])
5233 self.popIfStmtBlockStack()
5234 self.symbolTable.endBlock()
5235
5236 if len(node.orelse) > 0:
5237 elseBlock = Block.create_at_start(ifOp.elseRegion, [])
5238 with InsertionPoint(elseBlock):
5239 self.symbolTable.beginBlock()
5240 self.pushIfStmtBlockStack()
5241 [self.visit(b) for b in node.orelse]
5242 if not self.hasTerminator(elseBlock):
5243 cc.ContinueOp([])
5244 self.popIfStmtBlockStack()
5245 self.symbolTable.endBlock()
5246
5247 def visit_Return(self, node):
5248

Callers

nothing calls this directly

Calls 8

visitMethod · 0.95
__arithmetic_to_boolMethod · 0.95
popValueMethod · 0.95
pushIfStmtBlockStackMethod · 0.95
hasTerminatorMethod · 0.95
popIfStmtBlockStackMethod · 0.95
beginBlockMethod · 0.45
endBlockMethod · 0.45

Tested by

no test coverage detected