Skip to content

Commit

Permalink
first draft
Browse files Browse the repository at this point in the history
  • Loading branch information
reza-j committed Jul 26, 2023
1 parent be964f3 commit 12a516a
Show file tree
Hide file tree
Showing 3 changed files with 596 additions and 0 deletions.
106 changes: 106 additions & 0 deletions include/Conversion/QUIRToPulse/LoadPulseCals.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
//===- LoadPulseCals.h ------------------------------------------*- C++ -*-===//
//
// (C) Copyright IBM 2023.
//
// This code is part of Qiskit.
//
// This code is licensed under the Apache License, Version 2.0 with LLVM
// Exceptions. You may obtain a copy of this license in the LICENSE.txt
// file in the root directory of this source tree.
//
// Any modifications or derivative works of this code must retain this
// copyright notice, and modified files need to carry a notice indicating
// that they have been altered from the originals.
//
//===----------------------------------------------------------------------===//
///
/// This file declares the pass to load the pulse calibrations.
///
//===----------------------------------------------------------------------===//

#ifndef LOAD_PULSE_CALS_H
#define LOAD_PULSE_CALS_H

#include "Dialect/Pulse/IR/PulseOps.h"

#include "mlir/IR/MLIRContext.h"
#include "mlir/Pass/Pass.h"

namespace mlir::pulse {

struct LoadPulseCalsPass
: public PassWrapper<LoadPulseCalsPass, OperationPass<ModuleOp>> {
std::string DEFAULT_PULSE_CALS = "";
std::string ADDITIONAL_PULSE_CALS = "";

// this pass receives the path to default pulse calibrations file as input.
// optionally, it can also receive a path to additional pulse calibrations,
// which can be used to (a) override the pulse calibration that will be used
// for some quantum gates. e.g., one might be interested to study the impact
// of changing the pulse sequence corresponding to cx quantum gate on qubits
// 4 and 5, then they can specify the desired pulse sequence in an additional
// file; and/or (b) add additional pulse calibrations
LoadPulseCalsPass() = default;
LoadPulseCalsPass(const LoadPulseCalsPass &pass) : PassWrapper(pass) {}
LoadPulseCalsPass(std::string inDefaultPulseCals) {
DEFAULT_PULSE_CALS = inDefaultPulseCals;
}
LoadPulseCalsPass(std::string inDefaultPulseCals,
std::string inAdditionalPulseCals) {
DEFAULT_PULSE_CALS = inDefaultPulseCals;
ADDITIONAL_PULSE_CALS = inAdditionalPulseCals;
}

void runOnOperation() override;

llvm::StringRef getArgument() const override;
llvm::StringRef getDescription() const override;

// optionally, one can override the path to default pulse calibrations with
// this option; e.g., to write a LIT test one can invoke this pass with
// --load-pulse-cals=default-pulse-cals=<path-to-pulse-cals-file>
Option<std::string> defaultPulseCals{
*this, "default-pulse-cals",
llvm::cl::desc("default pulse calibrations MLIR file"),
llvm::cl::value_desc("filename"), llvm::cl::init("")};

void loadPulseCals(mlir::quir::CallCircuitOp callCircuitOp, FuncOp funcOp);
void loadPulseCals(mlir::quir::CallGateOp callGateOp,
mlir::quir::CallCircuitOp callCircuitOp, FuncOp funcOp);
void loadPulseCals(mlir::quir::BuiltinCXOp CXOp,
mlir::quir::CallCircuitOp callCircuitOp, FuncOp funcOp);
void loadPulseCals(mlir::quir::Builtin_UOp UOp,
mlir::quir::CallCircuitOp callCircuitOp, FuncOp funcOp);
void loadPulseCals(mlir::quir::MeasureOp measureOp,
mlir::quir::CallCircuitOp callCircuitOp, FuncOp funcOp);
void loadPulseCals(mlir::quir::BarrierOp barrierOp,
mlir::quir::CallCircuitOp callCircuitOp, FuncOp funcOp);
void loadPulseCals(mlir::quir::DelayOp delayOp,
mlir::quir::CallCircuitOp callCircuitOp, FuncOp funcOp);
void loadPulseCals(mlir::quir::ResetQubitOp resetOp,
mlir::quir::CallCircuitOp callCircuitOp, FuncOp funcOp);

void addPulseCalToModule(FuncOp funcOp, mlir::pulse::SequenceOp sequenceOp);

// parse the pulse cals and add them to pulseCalsNameToSequenceMap
void parsePulseCalsSequenceOps(std::string &pulseCalsPath);
std::map<std::string, SequenceOp> pulseCalsNameToSequenceMap;

mlir::pulse::SequenceOp
mergePulseSequenceOps(std::vector<mlir::pulse::SequenceOp> &sequenceOps,
std::string mergedSequenceOpName);
bool mergeAttributes(std::vector<mlir::pulse::SequenceOp> &sequenceOps,
std::string attrName,
std::vector<mlir::Attribute> &attrVector);
std::string getMangledName(std::string &gateName, std::set<uint32_t> &qubits);
std::string getMangledName(std::string &gateName, uint32_t qubit);
std::set<uint32_t> getQubitOperands(std::vector<Value> qubitOperands,
mlir::quir::CallCircuitOp callCircuitOp);

// TODO: move this function to Utils; it's used here and MergeCircuitsPass
static mlir::quir::CircuitOp
getCircuitOp(mlir::quir::CallCircuitOp callCircuitOp);
};
} // namespace mlir::pulse

#endif // LOAD_PULSE_CALS_H
2 changes: 2 additions & 0 deletions lib/Conversion/QUIRToPulse/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

add_mlir_conversion_library(QUIRToPulse

LoadPulseCals.cpp

detail/TypeConversion.cpp

ADDITIONAL_HEADER_DIRS
Expand Down
Loading

0 comments on commit 12a516a

Please sign in to comment.