Controlled swap of the states of the provided qubits. The controls parameter is expected to be a list of QuakeValue. ```python # Example: kernel = cudaq.make_kernel() # Allocate qubit/s to the `kernel`. qubits = kernel.qalloc
(self, controls, qubitA, qubitB)
| 1055 | fwdControls, [target.mlirValue]) |
| 1056 | |
| 1057 | def cswap(self, controls, qubitA, qubitB): |
| 1058 | """ |
| 1059 | Controlled swap of the states of the provided qubits. The controls |
| 1060 | parameter is expected to be a list of QuakeValue. |
| 1061 | |
| 1062 | ```python |
| 1063 | # Example: |
| 1064 | kernel = cudaq.make_kernel() |
| 1065 | # Allocate qubit/s to the `kernel`. |
| 1066 | qubits = kernel.qalloc(2) |
| 1067 | # Place the 0th qubit in the 1-state. |
| 1068 | kernel.x(qubits[0]) |
| 1069 | # Swap their states. |
| 1070 | kernel.swap(qubits[0], qubits[1])) |
| 1071 | ``` |
| 1072 | """ |
| 1073 | fwdControls = None |
| 1074 | if isinstance(controls, list): |
| 1075 | fwdControls = [c.mlirValue for c in controls] |
| 1076 | elif quake.RefType.isinstance( |
| 1077 | controls.mlirValue.type) or quake.VeqType.isinstance( |
| 1078 | controls.mlirValue.type): |
| 1079 | fwdControls = [controls.mlirValue] |
| 1080 | else: |
| 1081 | emitFatalError( |
| 1082 | f"Invalid control type for cswap ({type(controls)}).") |
| 1083 | |
| 1084 | with self.insertPoint, self.loc: |
| 1085 | quake.SwapOp([], [], fwdControls, |
| 1086 | [qubitA.mlirValue, qubitB.mlirValue]) |
| 1087 | |
| 1088 | def swap(self, qubitA, qubitB): |
| 1089 | """ |