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

Function mlirTypeFromAnnotation

python/cudaq/kernel/utils.py:380–593  ·  view source on GitHub ↗

Return the MLIR Type corresponding to the given kernel function argument type annotation. Throws an exception if the programmer did not annotate function argument types.

(annotation,
                           ctx,
                           raiseError=False,
                           cudaqAliases=None)

Source from the content-addressed store, hash-verified

378
379
380def mlirTypeFromAnnotation(annotation,
381 ctx,
382 raiseError=False,
383 cudaqAliases=None):
384 """
385 Return the MLIR Type corresponding to the given kernel function argument
386 type annotation. Throws an exception if the programmer did not annotate
387 function argument types.
388 """
389 _cudaq_names = cudaqAliases if cudaqAliases else {'cudaq'}
390
391 localEmitFatalError = emitFatalError
392 if raiseError:
393 # Client calling this will handle errors
394 def emitFatalErrorOverride(msg):
395 raise RuntimeError(msg)
396
397 localEmitFatalError = emitFatalErrorOverride
398
399 if annotation == None:
400 localEmitFatalError(
401 'cudaq.kernel functions must have argument type annotations.')
402
403 with ctx:
404
405 if hasattr(annotation, 'attr') and hasattr(annotation.value, 'id'):
406 if annotation.value.id in _cudaq_names:
407 if annotation.attr in ['qview', 'qvector']:
408 return quake.VeqType.get()
409 if annotation.attr in ['State']:
410 return cc.PointerType.get(cc.StateType.get())
411 if annotation.attr == 'qubit':
412 return quake.RefType.get()
413 if annotation.attr == 'pauli_word':
414 return cc.CharspanType.get()
415 if annotation.attr == 'measure_handle':
416 return cc.MeasureHandleType.get()
417
418 if annotation.value.id in ['numpy', 'np']:
419 if annotation.attr in ['array', 'ndarray']:
420 return cc.StdvecType.get(F64Type.get())
421 if annotation.attr == 'complex128':
422 return ComplexType.get(F64Type.get())
423 if annotation.attr == 'complex64':
424 return ComplexType.get(F32Type.get())
425 if annotation.attr == 'float64':
426 return F64Type.get()
427 if annotation.attr == 'float32':
428 return F32Type.get()
429 if annotation.attr == 'int64':
430 return IntegerType.get_signless(64)
431 if annotation.attr == 'int32':
432 return IntegerType.get_signless(32)
433 if annotation.attr == 'int16':
434 return IntegerType.get_signless(16)
435 if annotation.attr == 'int8':
436 return IntegerType.get_signless(8)
437

Callers 2

Calls 5

mlirTryCreateStructTypeFunction · 0.85
mlirTypeFromPyTypeFunction · 0.85
emitWarningFunction · 0.85
getClassAttributesMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected