-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature proposal: Provide standalone QIR passes #88
Comments
Thanks for this proposal. QAT already includes a number of custom written LLVM passes. Each of these passes are standalone and could, in theory at least, be used as standalone passes that could be loaded by To clarify what you are proposing:
|
Hi @troelsfr and thanks for your feedback! First, I have to admit that, despite looking into it for a while, I am not too familiar yet with the whole architecture of QAT. 😁 I noticed QAT indeed uses LLVM passes but:
The core of the discussions was to provide some standalone LLVM/QIR passes, independently from QAT. These standalone passes would provide many features, some of them potentially not being in the scope of QAT, falling into these categories: Analyses, Checks, Optimizations, Backend-conversions... Hence, they could be used as part of an LLVM toolchain and selected according to the needs of the compiler. This set could be enriched by users, OS project maintainers or hardware vendors. To the point where, when a need arises, one can pick from the available passes. A bit in the way that LLVM already provides dozens of standard passes, these would become "QIR standard passes" that deal specifically with quantum stuff. Note : QAT would clearly still be an important and useful tool. And it could also rely on some of these passes. Maybe a first step would be to extract the existing ones from QAT and provide them as a first subset of this "ever-growing set" I mentioned. I hope I manage to express the need a bit more clearly. 😊 Maybe this is a duplicate with what QAT intends to achieve in the end, but I'm not sure about it. This is why, during the community calls, we agreed we should start a discussion about it here. 😉 |
Starting on a high level: The purpose of QAT is to 1) transform generic QIR into a profile specific QIR (i.e. specific to a given set of capabilities - machine or simulator specific), and 2) validate that a QIR satisfy the requirements of a specific profile. Note that rather than taking about hardware specificity we are using a similar concept which is "profile" that may cover either a QPU, a simulator or a hybrid CPU-QPU setup. Both of the steps are achieved using LLVM passes and therefore the majority of the codebase consists of pure LLVM passes. The passes for transformation are set up in the component setup function. As you will see, all custom written passes are nearly free of dependencies (if you disregard the logger and the configuration component). This means that they could without much effort be made into an The passes follow the standard for the new pass manager meaning that you will either have analysis passes or transformation passes - I think this is well aligned with what you are writing. If you compile and run QAT, you will note that each component (a collection of LLVM passes) are configurable from the command-line, meaning that the end-user can pick and choose as the like, and create a profile transformation in accordance to their need. And yes, hopefully, QAT will eventually contain a large set of passes for users and hardware providers to pick and choose from. I think of all of the above is in line with your suggestions and the only thing needed would be some one writing the dynamic libraries. To give a concrete example, in order to create a PassPluginLibraryInfo getGroupingPlugin() {
return {LLVM_PLUGIN_API_VERSION, PluginName, LLVM_VERSION_STRING,
[](PassBuilder &pass_builder) {
auto logger = std::make_shared<CommentLogger>();
pass_builder.registerAnalysisRegistrationCallback(
[logger](ModuleAnalysisManager &mam) {
mam.registerPass([&] { return GroupingAnalysisPass({}, logger); });
});
pass_builder.registerPipelineParsingCallback(
[&](StringRef name, ModulePassManager &mpm,
ArrayRef<PassBuilder::PipelineElement>) {
if (name.equals("group-quantum-instructions")) {
auto pass = GroupingPass({});
pass.setLogger(logger);
mpm.addPass(std::move(pass));
return true;
}
return false;
});
}};
}
extern "C" LLVM_ATTRIBUTE_WEAK ::llvm::PassPluginLibraryInfo
llvmGetPassPluginInfo() {
return getGroupingPlugin();
} which would make it loadable in Could your proposal be summarised as adding |
Thanks again @troelsfr for this very detailed reply! It helps me A LOT in better understanding the goals and ambitions of QAT. This is probably what we missed the most during the community calls. I agree my initial proposal has lots to do with what you write. Once again, reaching this conclusion (or not) was the whole point of starting this conversation. 😁
This is where I wonder the most. It seems to me that "profiles" are monolithic. I'm not sure whether QAT allows something like "I want to use JUST the atomic pass that" (or a combination of these passes), for instance:
Talking about the Configuration component, is this related to what you wrote in the docs : "The downsides to opt is that we cannot pass a configuration to the individual passes" ? Isn't
Totally agreed. Except when they rely on some configuration?
Indeed. I've been using something quite similar to make passes available to
Beyond that, I'd say. On an architectural standpoint and even in terms of repo organization, the idea was to provide each pass as an independent "package" (not only for And then to have documentation that describes each one of them, just like here. I hope this all makes sense... |
A small update to this proposal: Passes are getting separated into separate folders which is the preliminary work to have them as stand-alone/opt compatible entities in PR #137 . |
This follows:
QAT includes/mimics/relies on LLVM passes but embeds them inside QAT-specific components.
LLVM passes can be provided as standalone libraries that can be applied with the
opt
tool.Proposal: Initiate an ever-growing set of genuine and standalone LLVM passes dedicated to QIR analysis and transformation.
Notes:
The text was updated successfully, but these errors were encountered: