microsoft / qsharp-compiler

Q# compiler, command line tool, and Q# language server
https://docs.microsoft.com/quantum
MIT License
682 stars 171 forks source link

Q# - Preview feature: Compilation to QIR (issue 3) #1034

Closed bettinaheim closed 2 years ago

bettinaheim commented 3 years ago

Project Overview

We are working on adding support for compiling Q# to QIR and executing it. QIR is a convention for how to represent quantum programs in LLVM. We aim to ultimately move the Q# compiler to be fully LLVM-based.

While the support and integration is not yet complete, we have set up an example for how to compile a Q# project to QIR and execute it on our full state simulator for early adventurers who are excited to give it a try!

This GitHub issue is one of two tasks that we have defined for Unitary Hack 2021.

Task

Find a Q# program that doesn't compile correctly into QIR or unexpectedly fails when executing the QIR on the full state simulator due to an issue with the generated QIR that hasn't been filed yet, and file the issue. Then create a PR to add a link to the created issue to the readme.

Instructions

Clone this repo and check out the unitaryhack branch. Make sure you have Clang 11 and dotnet 3.1 installed. Open the folder examples/QIR/Development in VS Code, and install the QDK extension if you have not already. Navigate to Terminal -> New Terminal and enter the command dotnet build. It may take a while until the command finishes since it will be downloading the LLVM libraries. After that, type dotnet run; you should now see the text "Executed successfully!".

Now you are all set to get started! Open Program.qs and experiment with all sorts of language constructs and patterns in Q# and see if you can get the compiler to fail. If the command dotnet run no longer succeeds, you have achieved your mission to beat the compiler!

Note: The project has been set up to be compiled using the source code version of the compiler and QIR emission; if you make edits to the QIR generation capability, you will see those reflected in how the Development project is compiled.

Avhijit-Nair commented 3 years ago

This seems like so much fun! Will give this a try for sure!

bettinaheim commented 3 years ago

@Avhijit-codeboy Awesome! Let me know how it goes, and if you have any questions or issues with the setup; happy to help. :)

Avhijit-Nair commented 3 years ago

Thanks @bettinaheim!