From f235cceb1bb973aa10a6bb3dea0c63056051f8c2 Mon Sep 17 00:00:00 2001 From: Brian Donovan Date: Wed, 17 Apr 2024 17:07:22 -0400 Subject: [PATCH 1/5] remove qubits from SynchronizeOp --- lib/Conversion/QUIRToPulse/QUIRToPulse.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/Conversion/QUIRToPulse/QUIRToPulse.cpp b/lib/Conversion/QUIRToPulse/QUIRToPulse.cpp index 6bfd4e7b3..be558a353 100644 --- a/lib/Conversion/QUIRToPulse/QUIRToPulse.cpp +++ b/lib/Conversion/QUIRToPulse/QUIRToPulse.cpp @@ -110,6 +110,11 @@ void QUIRToPulsePass::runOnOperation() { // erase circuit ops moduleOp->walk([&](CircuitOp circOp) { circOp->erase(); }); + // Remove all arguments from synchronization ops + moduleOp->walk([](qcs::SynchronizeOp synchOp) { + synchOp.getQubitsMutable().assign(ValueRange({})); + }); + // erase qubit ops and constant angle ops moduleOp->walk([&](Operation *op) { if (isa(op)) From 9b272b62f7ad90e66e41706b4a1cc73efe0a09ec Mon Sep 17 00:00:00 2001 From: Brian Donovan Date: Thu, 18 Apr 2024 15:07:59 -0400 Subject: [PATCH 2/5] handle qcs.delay_cycles --- lib/Conversion/QUIRToPulse/LoadPulseCals.cpp | 3 +++ lib/Conversion/QUIRToPulse/QUIRToPulse.cpp | 8 ++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/Conversion/QUIRToPulse/LoadPulseCals.cpp b/lib/Conversion/QUIRToPulse/LoadPulseCals.cpp index 0ae5b2fee..e08fb0871 100644 --- a/lib/Conversion/QUIRToPulse/LoadPulseCals.cpp +++ b/lib/Conversion/QUIRToPulse/LoadPulseCals.cpp @@ -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" @@ -145,6 +146,8 @@ void LoadPulseCalsPass::loadPulseCals(CallCircuitOp callCircuitOp, loadPulseCals(castOp, callCircuitOp, funcOp); else if (auto castOp = dyn_cast(op)) loadPulseCals(castOp, callCircuitOp, funcOp); + else if (isa(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() and diff --git a/lib/Conversion/QUIRToPulse/QUIRToPulse.cpp b/lib/Conversion/QUIRToPulse/QUIRToPulse.cpp index be558a353..c67be5674 100644 --- a/lib/Conversion/QUIRToPulse/QUIRToPulse.cpp +++ b/lib/Conversion/QUIRToPulse/QUIRToPulse.cpp @@ -221,6 +221,11 @@ QUIRToPulsePass::convertCircuitToSequence(CallCircuitOp &callCircuitOp, PulseOpSchedulingInterface::setDuration(pulseCalCallSequenceOp, durValue); } + } else if (isa(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(quirOp) or isa(quirOp) or isa(quirOp))) && @@ -234,7 +239,7 @@ QUIRToPulsePass::convertCircuitToSequence(CallCircuitOp &callCircuitOp, convertedPulseSequenceOpReturnTypes.size())); convertedPulseSequenceOp.setType(newFuncType); entryBuilder.create( - convertedPulseSequenceOp.back().back().getLoc(), + convertedPulseSequenceOp.getLoc(), mlir::ValueRange{convertedPulseSequenceOpReturnValues}); convertedPulseSequenceOp->moveBefore(mainFunc); @@ -244,7 +249,6 @@ QUIRToPulsePass::convertCircuitToSequence(CallCircuitOp &callCircuitOp, convertedPulseSequenceOp, convertedPulseSequenceOpArgs); convertedPulseCallSequenceOp->moveAfter(callCircuitOp); - return convertedPulseCallSequenceOp; } From 9147d94d1b9bc21df3af7495408aeadca42a5300 Mon Sep 17 00:00:00 2001 From: Brian Donovan Date: Thu, 18 Apr 2024 15:20:26 -0400 Subject: [PATCH 3/5] modify for gcc compile --- lib/Conversion/QUIRToPulse/LoadPulseCals.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Conversion/QUIRToPulse/LoadPulseCals.cpp b/lib/Conversion/QUIRToPulse/LoadPulseCals.cpp index e08fb0871..64d634aef 100644 --- a/lib/Conversion/QUIRToPulse/LoadPulseCals.cpp +++ b/lib/Conversion/QUIRToPulse/LoadPulseCals.cpp @@ -147,7 +147,7 @@ void LoadPulseCalsPass::loadPulseCals(CallCircuitOp callCircuitOp, else if (auto castOp = dyn_cast(op)) loadPulseCals(castOp, callCircuitOp, funcOp); else if (isa(op)) - void; // no pulse call to load for a delay cycles op + (void) 0; // 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() and From b780dff747caee643817688ae7ce534d16545e56 Mon Sep 17 00:00:00 2001 From: Brian Donovan Date: Thu, 18 Apr 2024 16:08:08 -0400 Subject: [PATCH 4/5] review suggestions --- lib/Conversion/QUIRToPulse/LoadPulseCals.cpp | 6 +++--- lib/Conversion/QUIRToPulse/QUIRToPulse.cpp | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/Conversion/QUIRToPulse/LoadPulseCals.cpp b/lib/Conversion/QUIRToPulse/LoadPulseCals.cpp index 64d634aef..e6d7d33b4 100644 --- a/lib/Conversion/QUIRToPulse/LoadPulseCals.cpp +++ b/lib/Conversion/QUIRToPulse/LoadPulseCals.cpp @@ -146,9 +146,9 @@ void LoadPulseCalsPass::loadPulseCals(CallCircuitOp callCircuitOp, loadPulseCals(castOp, callCircuitOp, funcOp); else if (auto castOp = dyn_cast(op)) loadPulseCals(castOp, callCircuitOp, funcOp); - else if (isa(op)) - (void) 0; // no pulse call to load for a delay cycles op - else { + else if (isa(op)) { + // 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() and !op->hasTrait()) && diff --git a/lib/Conversion/QUIRToPulse/QUIRToPulse.cpp b/lib/Conversion/QUIRToPulse/QUIRToPulse.cpp index c67be5674..b01fd5d9a 100644 --- a/lib/Conversion/QUIRToPulse/QUIRToPulse.cpp +++ b/lib/Conversion/QUIRToPulse/QUIRToPulse.cpp @@ -224,7 +224,7 @@ QUIRToPulsePass::convertCircuitToSequence(CallCircuitOp &callCircuitOp, } else if (isa(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); + auto *newDelayCyclesOp = builder.clone(*quirOp); newDelayCyclesOp->moveAfter(callCircuitOp); } else assert(((isa(quirOp) or isa(quirOp) or From 76d94863c089ab1ff6d742e63f69598421a85b0e Mon Sep 17 00:00:00 2001 From: Brian Donovan Date: Wed, 24 Apr 2024 16:18:49 -0400 Subject: [PATCH 5/5] add getMixFrameName --- include/Dialect/Pulse/Utils/Utils.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/include/Dialect/Pulse/Utils/Utils.h b/include/Dialect/Pulse/Utils/Utils.h index 2cdea100c..ec2cf8e9e 100644 --- a/include/Dialect/Pulse/Utils/Utils.h +++ b/include/Dialect/Pulse/Utils/Utils.h @@ -82,4 +82,21 @@ MixFrameOp getMixFrameOp(PulseOpTy pulseOp, return mixFrameOp; } +template +llvm::StringRef getMixFrameName(PulseOpTy pulseOp, SequenceOp sequenceOp) { + + auto frameArgIndex = + pulseOp.getTarget().template cast().getArgNumber(); + + assert(sequenceOp->hasAttrOfType("pulse.args") and + "no pulse.args found for the pulse cal sequence."); + + auto argAttr = sequenceOp->getAttrOfType("pulse.args"); + + llvm::StringRef frameName = + argAttr[frameArgIndex].template dyn_cast().getValue(); + + return frameName; +} + } // end namespace mlir::pulse