70 int nTgtsOp1,
int nCtrlsOp2,
int nTgtsOp2) {
71 auto currentGate = dyn_cast_or_null<T2>(*currentOp);
76 if (currentGate.getControls().size() != nCtrlsOp2 ||
77 currentGate.getTargets().size() != nTgtsOp2)
84 auto previousGate = dyn_cast_or_null<T1>(prevOp);
89 if (previousGate.getControls().size() != nCtrlsOp1 ||
90 previousGate.getTargets().size() != nTgtsOp1)
94 if (currentGate.getControls().size() == previousGate.getControls().size()) {
95 std::vector<int> controlsCurr =
97 std::vector<int> controlsPrev =
100 std::sort(controlsCurr.begin(), controlsCurr.end(), std::greater<int>());
101 std::sort(controlsPrev.begin(), controlsPrev.end(), std::greater<int>());
103 if (!(std::equal(controlsCurr.begin(), controlsCurr.end(),
104 controlsPrev.begin())))
109 if (currentGate.getTargets().size() == previousGate.getTargets().size()) {
110 std::vector<int> targetsCurr =
112 std::vector<int> targetsPrev =
115 std::sort(targetsCurr.begin(), targetsCurr.end(), std::greater<int>());
116 std::sort(targetsPrev.begin(), targetsPrev.end(), std::greater<int>());
118 if (!(std::equal(targetsCurr.begin(), targetsCurr.end(),
119 targetsPrev.begin())))
124 llvm::outs() <<
"Current Operation: ";
125 currentGate->print(llvm::outs());
126 llvm::outs() <<
"\n";
127 llvm::outs() <<
"Previous Operation: ";
128 previousGate->print(llvm::outs());
129 llvm::outs() <<
"\n";
132 mlir::IRRewriter rewriter(currentGate->getContext());
134 rewriter.eraseOp(currentGate);
135 rewriter.eraseOp(previousGate);
void patternCancellation(mlir::Operation *currentOp, int nCtrlsOp1, int nTgtsOp1, int nCtrlsOp2, int nTgtsOp2)
Function that removes (cancel) a pattern of two quantum operations under specific constraints.
Definition CancellationOperations.hpp:69