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

Function __generalOperation

python/cudaq/kernel/kernel_builder.py:47–75  ·  view source on GitHub ↗

This is a utility function that applies a general quantum operation to the internal PyKernel MLIR ModuleOp.

(self,
                       opName,
                       parameters,
                       controls,
                       target,
                       isAdj=False,
                       context=None)

Source from the content-addressed store, hash-verified

45
46
47def __generalOperation(self,
48 opName,
49 parameters,
50 controls,
51 target,
52 isAdj=False,
53 context=None):
54 """
55 This is a utility function that applies a general quantum operation to the
56 internal PyKernel MLIR ModuleOp.
57 """
58 opCtor = getattr(quake, '{}Op'.format(opName.title()))
59 self.clearCache()
60
61 if quake.RefType.isinstance(target.mlirValue.type):
62 opCtor([], parameters, controls, [target.mlirValue], is_adj=isAdj)
63 return
64
65 # Must be a `veq`, get the size
66 size = quake.VeqSizeOp(self.getIntegerType(), target.mlirValue)
67
68 def body(idx):
69 extracted = quake.ExtractRefOp(quake.RefType.get(context),
70 target.mlirValue,
71 -1,
72 index=idx).result
73 opCtor([], parameters, controls, [extracted], is_adj=isAdj)
74
75 self.createInvariantForLoop(size, body)
76
77
78def get_parameter_value(self, parameter):

Calls 4

formatMethod · 0.80
clearCacheMethod · 0.80
getIntegerTypeMethod · 0.45

Tested by

no test coverage detected