Skip to content

Commit ce1e6a2

Browse files
committed
deleting old stuff is so much fun
1 parent 6bf9d8c commit ce1e6a2

1 file changed

Lines changed: 7 additions & 38 deletions

File tree

mlir/lib/Dialect/QCO/Transforms/QuaternionMergeRotationGates.cpp

Lines changed: 7 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -88,34 +88,19 @@ struct MergeRotationGatesPattern final
8888
return mlir::failure();
8989
}
9090
auto user = mlir::dyn_cast<UnitaryOpInterface>(userOP);
91+
// QCU operations cannot contain control qubits so we dont need to check for
92+
// these
93+
94+
// Check if consecutive operations are connected and feed into on another
9195
if (op.getOutputQubit(0) != user.getInputQubit(0)) {
92-
// if (op.getAllOutQubits() != unitaryUser.getAllInQubits()) {
9396
return mlir::failure();
9497
}
95-
// TODO maybe check for size of ctrl qubits - we only merge gates without
96-
// control
97-
// rewriteAdditiveAngle(op, rewriter, quaternionFolding);
98-
auto const type = op->getName().stripDialect().str();
9998

10099
UnitaryOpInterface newUser =
101100
createOpQuaternionMergedAngle(op, user, rewriter);
102101

103-
// Prepare erasure of op
104-
const auto& opAllInQubits = op.getAllInQubits();
105-
const auto& newUserAllInQubits = newUser.getAllInQubits();
106-
for (size_t i = 0; i < newUser->getOperands().size(); i++) {
107-
const auto& operand = newUser->getOperand(i);
108-
const auto found = llvm::find(newUserAllInQubits, operand);
109-
if (found == newUserAllInQubits.end()) {
110-
continue;
111-
}
112-
const auto idx = std::distance(newUserAllInQubits.begin(), found);
113-
rewriter.modifyOpInPlace(
114-
newUser, [&] { newUser->setOperand(i, opAllInQubits[idx]); });
115-
}
116-
117102
// Replace user with newUser
118-
rewriter.replaceOp(user, newUser);
103+
rewriter.replaceOp(user, newUser->getResults());
119104

120105
// Erase op
121106
rewriter.eraseOp(op);
@@ -166,15 +151,12 @@ struct MergeRotationGatesPattern final
166151

167152
if (type == "rx") {
168153
return createAxisQuaternion(angle, 'x', loc, rewriter);
169-
// return {.w = cos, .x = sin, .y = zero, .z = zero};
170154
}
171155
if (type == "ry") {
172156
return createAxisQuaternion(angle, 'y', loc, rewriter);
173-
// return {.w = cos, .x = zero, .y = sin, .z = zero};
174157
}
175158
if (type == "rz") {
176159
return createAxisQuaternion(angle, 'z', loc, rewriter);
177-
// return {.w = cos, .x = zero, .y = zero, .z = sin};
178160
}
179161
throw std::runtime_error("Unsupported operation type: " + type);
180162
}
@@ -241,11 +223,6 @@ struct MergeRotationGatesPattern final
241223
uGateFromQuaternion(Quaternion q, UnitaryOpInterface op,
242224
mlir::PatternRewriter& rewriter) {
243225
auto loc = op->getLoc();
244-
auto user = mlir::dyn_cast<UnitaryOpInterface>(*op->getUsers().begin());
245-
246-
auto userInQubits = user.getInQubits();
247-
auto userPosCtrlInQubits = user.getPosCtrlInQubits();
248-
auto userNegCtrlInQubits = user.getNegCtrlInQubits();
249226

250227
// convert back to zyz euler angles
251228
auto floatType = op.getParameter(0).getType();
@@ -280,15 +257,8 @@ struct MergeRotationGatesPattern final
280257
auto gamma =
281258
rewriter.create<mlir::arith::AddFOp>(loc, thetaPlus, thetaMinus);
282259

283-
const llvm::SmallVector<mlir::Value, 3> newParamsVec{
284-
alpha.getResult(), beta.getResult(), gamma.getResult()};
285-
const mlir::ValueRange newParams(newParamsVec);
286-
287-
return rewriter.create<UOp>(
288-
loc, userInQubits.getType(), userPosCtrlInQubits.getType(),
289-
userNegCtrlInQubits.getType(), mlir::DenseF64ArrayAttr{},
290-
mlir::DenseBoolArrayAttr{}, newParams, userInQubits,
291-
userPosCtrlInQubits, userNegCtrlInQubits);
260+
return rewriter.create<UOp>(loc, op.getInputQubit(0), alpha.getResult(),
261+
beta.getResult(), gamma.getResult());
292262
}
293263

294264
/**
@@ -353,7 +323,6 @@ struct MergeRotationGates final
353323
if (mlir::failed(mlir::applyPatternsGreedily(op, std::move(patterns)))) {
354324
signalPassFailure();
355325
}
356-
// TODO implement pass here
357326
}
358327
};
359328

0 commit comments

Comments
 (0)