microsoft / qsharp

Azure Quantum Development Kit, including the Q# programming language, resource estimator, and Quantum Katas
https://microsoft.github.io/qsharp/
MIT License
366 stars 73 forks source link

Fuller QIR emission for runtime/optimization tools #1232

Open chemix-lunacy opened 3 months ago

chemix-lunacy commented 3 months ago

Describe the solution you'd like

I'd like the Q# compiler to be able to emit QIR that is not restricted to any particular profile so that it can then be fed into further tooling that can exploit the additional context and complexities of fully interwoven LLVM and QIR instructions

While doing full unrestricted QIR all at once is probably too big an ask, it may still be useful if support is slowly added in feature batches. Variables, pointers, method calls, forward branching, whatever isolated bits make sense to be built up incrementally that give more context to what's being executed.

Additional context

QIR is a very useful common IR for passing between tools, but conforming to a profile loses a huge amount of information that other tools could use for further processing.

Currently base profile (and adaptive) QIR is loosely viewed as a nearly direct-to-machine IR, only emitting structures and forms that are assumed to map directly onto QPU features. Useful if it gets fed directly into a driver, not so much as the beginning of a more complex processing pipeline.

Two easy examples in which passing unrestricted QIR on would have great benefit: a runtime which then performs execution and may deal with a multitude of instructions in ways which don't require low-level QPU support; an QIR optimizer/transpiler which replaces large swathes of unsupported instructions with intrinsics for custom hardware.

I have a project in the former camp. While it can execute the various profiles easily enough it's designed to be given QIR which represents the hybrid algorithm in its entireity - including all data and logic which affects the quantum aspects - to really shine. So I'd definintely love to be able to write heinously complex algorithms in Q# and feed them directly to it.

chemix-lunacy commented 3 months ago

The tool that I'd be using to run any QIR emitted by the Q# compiler has now been released: https://github.com/oqc-community/rasqal. So you could look there for anything I'd like to see at least.