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

Method __init__

python/cudaq/kernel/kernel_builder.py:248–296  ·  view source on GitHub ↗
(self, argTypeList)

Source from the content-addressed store, hash-verified

246 """
247
248 def __init__(self, argTypeList):
249 self.ctx = getMLIRContext()
250
251 self.conditionalOnMeasure = False
252 self.regCounter = 0
253 self.loc = Location.unknown(context=self.ctx)
254 self.module = Module.create(loc=self.loc)
255 self.uniqId = id(self)
256 self.uniqName = "PythonKernelBuilderInstance.." + hex(self.uniqId)
257 self.name = self.uniqName
258 self.funcName = nvqppPrefix + self.name
259 self.funcNameEntryPoint = self.uniqName + '.PyKernelFakeEntryPoint'
260 strAttr = StringAttr.get(self.funcNameEntryPoint, context=self.ctx)
261 attr = DictAttr.get({self.funcName: strAttr}, context=self.ctx)
262 self.module.operation.attributes.__setitem__('quake.mangled_name_map',
263 attr)
264
265 # List of in-place applied noise channels (rather than pre-registered
266 # noise classes)
267 self.appliedNoiseChannels = []
268
269 with self.ctx, InsertionPoint(self.module.body), self.loc:
270 self.mlirArgTypes = [
271 mlirTypeFromPyType(argType[0], self.ctx, argInstance=argType[1])
272 for argType in
273 [self.__processArgType(ty) for ty in argTypeList]
274 ]
275
276 # `cudaq.make_kernel(...)` produces an entry-point kernel by
277 # construction. Reject any handle-containing parameter type before
278 # tagging so the AST-bridge boundary check (which never runs on
279 # this path) cannot be sidestepped via `cudaq.make_kernel`.
280 for argTy in self.mlirArgTypes:
281 if containsMeasureHandle(argTy):
282 emitFatalError(boundaryDiagnostic)
283
284 self.funcOp = func.FuncOp(self.funcName, (self.mlirArgTypes, []),
285 loc=self.loc)
286 self.funcOp.attributes.__setitem__('cudaq-entrypoint',
287 UnitAttr.get())
288 self.funcOp.attributes.__setitem__('cudaq-kernel', UnitAttr.get())
289 e = self.funcOp.add_entry_block()
290 self.arguments = [self.__createQuakeValue(b) for b in e.arguments]
291 self.argument_count = len(self.arguments)
292
293 with InsertionPoint(e):
294 func.ReturnOp([])
295
296 self.insertPoint = InsertionPoint.at_block_begin(e)
297
298 def __processArgType(self, ty):
299 """

Callers 1

initSubClassMethod · 0.45

Calls 9

__processArgTypeMethod · 0.95
__createQuakeValueMethod · 0.95
getMLIRContextFunction · 0.85
mlirTypeFromPyTypeFunction · 0.85
__setitem__Method · 0.80
containsMeasureHandleFunction · 0.70
emitFatalErrorFunction · 0.70
createMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected