Skip to content

Commit

Permalink
handle qcs.delay_cycles
Browse files Browse the repository at this point in the history
  • Loading branch information
bcdonovan committed Apr 18, 2024
1 parent f235cce commit 9b272b6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
3 changes: 3 additions & 0 deletions lib/Conversion/QUIRToPulse/LoadPulseCals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#include "Dialect/Pulse/IR/PulseDialect.h"
#include "Dialect/Pulse/IR/PulseOps.h"
#include "Dialect/QCS/IR/QCSOps.h"
#include "Dialect/QUIR/IR/QUIROps.h"
#include "Dialect/QUIR/IR/QUIRTraits.h"
#include "Dialect/QUIR/Utils/Utils.h"
Expand Down Expand Up @@ -145,6 +146,8 @@ void LoadPulseCalsPass::loadPulseCals(CallCircuitOp callCircuitOp,
loadPulseCals(castOp, callCircuitOp, funcOp);
else if (auto castOp = dyn_cast<mlir::quir::ResetQubitOp>(op))
loadPulseCals(castOp, callCircuitOp, funcOp);
else if (isa<mlir::qcs::DelayCyclesOp>(op))
void; // no pulse call to load for a delay cycles op
else {
LLVM_DEBUG(llvm::dbgs() << "no pulse cal loading needed for " << op);
assert((!op->hasTrait<mlir::quir::UnitaryOp>() and
Expand Down
8 changes: 6 additions & 2 deletions lib/Conversion/QUIRToPulse/QUIRToPulse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,11 @@ QUIRToPulsePass::convertCircuitToSequence(CallCircuitOp &callCircuitOp,
PulseOpSchedulingInterface::setDuration(pulseCalCallSequenceOp,
durValue);
}
} else if (isa<qcs::DelayCyclesOp>(quirOp)) {
// a qcs.delay_cycles may be inserted into a quir.circuit and should be
// placed outside of the sequence at the call point
auto newDelayCyclesOp = builder.clone(*quirOp);
newDelayCyclesOp->moveAfter(callCircuitOp);
} else
assert(((isa<quir::ConstantOp>(quirOp) or isa<quir::ReturnOp>(quirOp) or
isa<quir::CircuitOp>(quirOp))) &&
Expand All @@ -234,7 +239,7 @@ QUIRToPulsePass::convertCircuitToSequence(CallCircuitOp &callCircuitOp,
convertedPulseSequenceOpReturnTypes.size()));
convertedPulseSequenceOp.setType(newFuncType);
entryBuilder.create<mlir::pulse::ReturnOp>(
convertedPulseSequenceOp.back().back().getLoc(),
convertedPulseSequenceOp.getLoc(),
mlir::ValueRange{convertedPulseSequenceOpReturnValues});
convertedPulseSequenceOp->moveBefore(mainFunc);

Expand All @@ -244,7 +249,6 @@ QUIRToPulsePass::convertCircuitToSequence(CallCircuitOp &callCircuitOp,
convertedPulseSequenceOp,
convertedPulseSequenceOpArgs);
convertedPulseCallSequenceOp->moveAfter(callCircuitOp);

return convertedPulseCallSequenceOp;
}

Expand Down

0 comments on commit 9b272b6

Please sign in to comment.