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

Function mlirTypeFromPyType

python/cudaq/kernel/utils.py:627–764  ·  view source on GitHub ↗
(argType, ctx, **kwargs)

Source from the content-addressed store, hash-verified

625
626
627def mlirTypeFromPyType(argType, ctx, **kwargs):
628 if argType in [int, np.int64]:
629 return IntegerType.get_signless(64, ctx)
630 if argType == np.int32:
631 return IntegerType.get_signless(32, ctx)
632 if argType == np.int16:
633 return IntegerType.get_signless(16, ctx)
634 if argType == np.int8:
635 return IntegerType.get_signless(8, ctx)
636 if argType in [float, np.float64]:
637 return F64Type.get(ctx)
638 if argType == np.float32:
639 return F32Type.get(ctx)
640 if argType == bool:
641 return IntegerType.get_signless(1, ctx)
642 if argType == complex:
643 return ComplexType.get(mlirTypeFromPyType(float, ctx))
644 if argType == np.complex128:
645 return ComplexType.get(mlirTypeFromPyType(np.float64, ctx))
646 if argType == np.complex64:
647 return ComplexType.get(mlirTypeFromPyType(np.float32, ctx))
648 if argType == pauli_word:
649 return cc.CharspanType.get(ctx)
650 if argType == State:
651 return cc.PointerType.get(cc.StateType.get(ctx), ctx)
652
653 if get_origin(argType) == list:
654 pyEleTy = get_args(argType)
655 if len(pyEleTy) == 1:
656 eleTy = mlirTypeFromPyType(pyEleTy[0], ctx)
657 return cc.StdvecType.get(eleTy, ctx)
658 argType = list
659
660 if argType in [list, np.ndarray, List]:
661 if 'argInstance' not in kwargs:
662 return cc.StdvecType.get(mlirTypeFromPyType(float, ctx), ctx)
663 if argType != np.ndarray:
664 if kwargs['argInstance'] == None:
665 return cc.StdvecType.get(mlirTypeFromPyType(float, ctx), ctx)
666
667 argInstance = kwargs['argInstance']
668 argTypeToCompareTo = kwargs[
669 'argTypeToCompareTo'] if 'argTypeToCompareTo' in kwargs else None
670
671 if len(argInstance) == 0:
672 if argTypeToCompareTo == None:
673 emitFatalError('Cannot infer runtime argument type')
674
675 eleTy = cc.StdvecType.getElementType(argTypeToCompareTo)
676 return cc.StdvecType.get(eleTy, ctx)
677
678 if isinstance(argInstance[0], list):
679 return cc.StdvecType.get(
680 mlirTypeFromPyType(
681 type(argInstance[0]),
682 ctx,
683 argInstance=argInstance[0],
684 argTypeToCompareTo=cc.StdvecType.getElementType(

Callers 14

MlirTypesClass · 0.90
get_parameter_valueFunction · 0.85
__init__Method · 0.85
exp_pauliMethod · 0.85
for_loopMethod · 0.85
__call__Method · 0.85
getStructMemberIdxMethod · 0.85
visit_CallMethod · 0.85
get_item_typeMethod · 0.85
visit_NameMethod · 0.85
mlirTypeFromAnnotationFunction · 0.85

Calls 8

typeFunction · 0.85
mlirTryCreateStructTypeFunction · 0.85
sumFunction · 0.85
getElementTypeMethod · 0.80
getClassAttributesMethod · 0.80
emitFatalErrorFunction · 0.70
getMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected