Skip to content

Commit

Permalink
Ensure an ion.yield operation is returning an region output to all pa…
Browse files Browse the repository at this point in the history
…rallal protocol ops
  • Loading branch information
paul0403 committed Jan 20, 2025
1 parent 78c7251 commit 82cabb8
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
9 changes: 7 additions & 2 deletions mlir/lib/Ion/IR/IonOps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,23 @@ void ParallelProtocolOp::build(OpBuilder &builder, OperationState &result, Value
BodyBuilderFn bodyBuilder)
{
OpBuilder::InsertionGuard guard(builder);
Location loc = result.location;

result.addOperands(inQubits);
for (Value v : inQubits)
result.addTypes(v.getType());

Region *bodyRegion = result.addRegion();
Block *bodyBlock = builder.createBlock(bodyRegion);
for (Value v : inQubits)
for (Value v : inQubits) {
bodyBlock->addArgument(v.getType(), v.getLoc());
}

builder.setInsertionPointToStart(bodyBlock);
bodyBuilder(builder, result.location, bodyBlock->getArguments());
bodyBuilder(builder, loc, bodyBlock->getArguments());

builder.setInsertionPointToEnd(bodyBlock);
builder.create<ion::YieldOp>(loc, bodyBlock->getArguments());
}

//===----------------------------------------------------------------------===//
Expand Down
3 changes: 0 additions & 3 deletions mlir/lib/Ion/Transforms/QuantumToIonPatterns.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,6 @@ mlir::LogicalResult oneQubitGateToPulse(CustomOp op, mlir::PatternRewriter &rewr
auto qubit = qubits.front();
builder.create<ion::PulseOp>(loc, time, qubit, beam0toEAttr, phase1Attr);
builder.create<ion::PulseOp>(loc, time, qubit, beam1toEAttr, phase2Attr);
builder.create<ion::YieldOp>(loc);
});
rewriter.replaceOp(op, ppOp);
return success();
Expand Down Expand Up @@ -408,8 +407,6 @@ mlir::LogicalResult MSGateToPulse(CustomOp op, mlir::PatternRewriter &rewriter,
rewriter.getI64VectorAttr(beam.polarization),
rewriter.getI64VectorAttr(flipSign(beam.wavevector)));
builder.create<ion::PulseOp>(loc, time, qubit1, beam6Attr, phase0Attr);

builder.create<ion::YieldOp>(loc);
});
rewriter.replaceOp(op, ppOp);
return success();
Expand Down
7 changes: 7 additions & 0 deletions mlir/test/Ion/QuantumToIon.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ func.func @example_ion_two_qubit(%arg0: f64) -> !quantum.bit {
// CHECK-SAME: polarization = dense<[0, 1]> : vector<2xi64>,
// CHECK-SAME: wavevector = dense<[-2, 3]> : vector<2xi64>>,
// CHECK-SAME: phase = 0.000000e+00 : f64}
// CHECK-NEXT: ion.yield %arg1 : !quantum.bit
// CHECK-NEXT: }
%4 = quantum.custom "RX"(%arg0) %2 : !quantum.bit

Expand All @@ -186,6 +187,7 @@ func.func @example_ion_two_qubit(%arg0: f64) -> !quantum.bit {
// CHECK-SAME: polarization = dense<[0, 1]> : vector<2xi64>,
// CHECK-SAME: wavevector = dense<[-2, 3]> : vector<2xi64>>,
// CHECK-SAME: phase = 3.1415926535{{[0-9]*}} : f64}
// CHECK-NEXT: ion.yield %arg1 : !quantum.bit
// CHECK-NEXT: }
%5 = quantum.custom "RY"(%arg0) %4 : !quantum.bit

Expand All @@ -209,6 +211,7 @@ func.func @example_ion_two_qubit(%arg0: f64) -> !quantum.bit {
// CHECK-SAME: polarization = dense<[0, 1]> : vector<2xi64>,
// CHECK-SAME: wavevector = dense<[-2, 3]> : vector<2xi64>>,
// CHECK-SAME: phase = 0.000000e+00 : f64}
// CHECK-NEXT: ion.yield %arg1 : !quantum.bit
// CHECK-NEXT: }
%6 = quantum.custom "RX"(%arg0) %5 : !quantum.bit

Expand Down Expand Up @@ -264,6 +267,7 @@ func.func @example_ion_two_qubit(%arg0: f64) -> !quantum.bit {
// CHECK-SAME: polarization = dense<[7, 8]> : vector<2xi64>,
// CHECK-SAME: wavevector = dense<[-9, -10]> : vector<2xi64>>,
// CHECK-SAME: phase = 0.000000e+00 : f64}
// CHECK-NEXT: ion.yield %arg1, %arg2 : !quantum.bit, !quantum.bit
// CHECK-NEXT: }
%7:2 = quantum.custom "MS"(%arg0) %6, %3 : !quantum.bit, !quantum.bit
return %7#0: !quantum.bit
Expand Down Expand Up @@ -340,6 +344,7 @@ func.func @example_ion_three_qubit(%arg0: f64) -> (!quantum.bit, !quantum.bit, !
// CHECK-SAME: polarization = dense<[7, 8]> : vector<2xi64>,
// CHECK-SAME: wavevector = dense<[-9, -10]> : vector<2xi64>>,
// CHECK-SAME: phase = 0.000000e+00 : f64}
// CHECK-NEXT: ion.yield %arg1, %arg2 : !quantum.bit, !quantum.bit
// CHECK-NEXT: }
%5:2 = quantum.custom "MS"(%arg0) %2, %3 : !quantum.bit, !quantum.bit

Expand Down Expand Up @@ -395,6 +400,7 @@ func.func @example_ion_three_qubit(%arg0: f64) -> (!quantum.bit, !quantum.bit, !
// CHECK-SAME: polarization = dense<[1, 2]> : vector<2xi64>,
// CHECK-SAME: wavevector = dense<[3, -4]> : vector<2xi64>>,
// CHECK-SAME: phase = 0.000000e+00 : f64}
// CHECK-NEXT: ion.yield %arg1, %arg2 : !quantum.bit, !quantum.bit
// CHECK-NEXT: }
%6:2 = quantum.custom "MS"(%arg0) %5#0, %4 : !quantum.bit, !quantum.bit

Expand Down Expand Up @@ -450,6 +456,7 @@ func.func @example_ion_three_qubit(%arg0: f64) -> (!quantum.bit, !quantum.bit, !
// CHECK-SAME: polarization = dense<[37, 42]> : vector<2xi64>,
// CHECK-SAME: wavevector = dense<[42, 37]> : vector<2xi64>>,
// CHECK-SAME: phase = 0.000000e+00 : f64}
// CHECK-NEXT: ion.yield %arg1, %arg2 : !quantum.bit, !quantum.bit
// CHECK-NEXT: }
%7:2 = quantum.custom "MS"(%arg0) %5#1, %6#1 : !quantum.bit, !quantum.bit
return %6#0, %7#0, %7#1: !quantum.bit, !quantum.bit, !quantum.bit
Expand Down

0 comments on commit 82cabb8

Please sign in to comment.