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

Function containsMeasureHandle

python/cudaq/kernel/utils.py:48–70  ·  view source on GitHub ↗

Return True iff ``ty`` is ``!cc.measure_handle`` or transitively contains one. The walk stops at callable / function-type boundaries: a callable parameter's signature is a device-side type contract for the body of the callable, not a slot for a handle value.

(ty, _seen=None)

Source from the content-addressed store, hash-verified

46
47
48def containsMeasureHandle(ty, _seen=None):
49 """Return True iff ``ty`` is ``!cc.measure_handle`` or transitively
50 contains one. The walk stops at callable / function-type boundaries: a
51 callable parameter's signature is a device-side type contract for the
52 body of the callable, not a slot for a handle value.
53 """
54 if _seen is None:
55 _seen = set()
56 if ty is None or id(ty) in _seen:
57 return False
58 _seen.add(id(ty))
59 if cc.MeasureHandleType.isinstance(ty):
60 return True
61 if cc.PointerType.isinstance(ty):
62 return containsMeasureHandle(cc.PointerType.getElementType(ty), _seen)
63 if cc.ArrayType.isinstance(ty):
64 return containsMeasureHandle(cc.ArrayType.getElementType(ty), _seen)
65 if cc.StdvecType.isinstance(ty):
66 return containsMeasureHandle(cc.StdvecType.getElementType(ty), _seen)
67 if cc.StructType.isinstance(ty):
68 return any(
69 containsMeasureHandle(t, _seen) for t in cc.StructType.getTypes(ty))
70 return False
71
72
73def getMLIRContext():

Callers 2

__init__Method · 0.70
visit_FunctionDefMethod · 0.70

Calls 2

getElementTypeMethod · 0.80
addMethod · 0.45

Tested by

no test coverage detected