Skip to content

Commit

Permalink
Fix failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
annagrin committed Jul 13, 2024
1 parent 5fb7354 commit 1381456
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lib/Optimizer/Transforms/StatePreparation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,13 @@ readConstantArray(mlir::OpBuilder &builder, cudaq::cc::GlobalOp &global) {
LogicalResult transform(ModuleOp module, func::FuncOp funcOp) {
auto builder = OpBuilder::atBlockBegin(&funcOp.getBody().front());
auto toErase = std::vector<mlir::Operation *>();
auto succeeded = false;
auto hasInitState = false;
auto replacedInitState = false;

funcOp->walk([&](Operation *op) {
if (auto initOp = dyn_cast<quake::InitializeStateOp>(op)) {
toErase.push_back(initOp);
hasInitState = true;
auto loc = op->getLoc();
builder.setInsertionPointAfter(initOp);
// Find the qvector alloc.
Expand Down Expand Up @@ -153,14 +155,14 @@ LogicalResult transform(ModuleOp module, func::FuncOp funcOp) {
initOp.replaceAllUsesWith(qubits);
toErase.push_back(addr);
toErase.push_back(global);
succeeded = true;
replacedInitState = true;
}
}
}
}
});

if (!succeeded) {
if (hasInitState && !replacedInitState) {
funcOp.emitOpError("StatePreparation failed to replace quake.init_state");
return failure();
}
Expand Down

0 comments on commit 1381456

Please sign in to comment.