Tech Blog
By Pranay Choudhary3 min read
← Back to blog

Q# is packaged with Microsoft Quantum Development Kit and is currently supported on 64-bit environments only. To begin with, you should have Visual Studio 2019 installed along with .NET core 3.1 SDK. Read my article on Getting started with Quantum Programming if you haven’t done that already.

Installing QDK

Install Microsoft Quantum Development Kit from Visual Studio Marketplace. Just download the extension and double click the file to open it in Visual Studio installer. Please note that this extension is currently compatible with Visual Studio 2019 only.

Creating Q# Project

Once QDK is installed, you are ready to write your first Q# program. Open Visual Studio 2019, click on Create a new Project. In the “Search for templates” bar type Q#. In search result you will see several options like Q# Application, Q# Library, Q# Test Project and so on. Select Q# Application.

Q# search

Once you create the project, By default, scaffolding feature in Visual Studio will generate a Hello World code for you.

Hello World

Your solution will look similar to this:

Solution Outline

Program.qs is the file were the actual Q# program is present.

namespace Quantum.QSharpApplication1 {

    //open Microsoft.Quantum.Canon;
    open Microsoft.Quantum.Intrinsic;

    
    @EntryPoint()
    operation HelloQ () : Unit {
        Message("Hello Q# World!");
    }
}

The csproj file will have the following content:

<Project Sdk="Microsoft.Quantum.Sdk/0.22.187631">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp3.1</TargetFramework>
  </PropertyGroup>
</Project>

Run the project using F5 or Ctrl+F5.

Hello World Output

Understanding the Hello World code

In earlier versions of QDK, you would need two projects or applications to run a Quantum Program – a Driver application and a Quantum application.

In the latest version of QDK, you can do it in one single application, using the @EntryPoint annotation. @EntryPoint() defines the first operation that must be invoked at application start up. It is equivalent to the Main method in C#. operation is nothing but what you would call a function in today’s programming languages. HelloQ is the name of the operation used in this program.

Unit is the return type of the operation HelloQ. Unit is equivalent to void, meaning the operation HelloQ does not return any value. Other return types present in Q# are Int, Double, BigInt, Bool, String, Range, Result, Qubit, etc.

open is equivalent to using keyword in C#. In the hello world example here, open Microsoft.Quantum.Intrinsic; imports the given library which contains the definition of the operation Message. Message is similar to the C# function Console.Write

Troubleshooting NuGet Packages

I have observed that Visual Studio struggles to download Microsoft.Quantum.* packages for the first time. You might see dependencies related errors in your Project

If you try to download the package using NuGet Package Manager Console, you might end up getting another error that says – Install-Package : The package is missing the required nuspec file. Path: C:\Users\the.user\.nuget\packages\fsharp.core\4.7.0 To resolve this problem, in your Visual Studio menu bar, goto Tools -> Options -> Nuget Package Manager and select Clear All NuGet Cache(s)

Next, right check on your project and select Rebuild. And Vola! NuGet will be able to restore the packages!

Conclusion

We have not invoked anything related to Quantum programming in this Hello World program. This program just ensures that your QuantumSimulator setup is ready to be explored.

Stay tuned for more complicated quantum programs and welcome to the Quantum World of programming

Keep reading

You may be interested in

Browse all articles →
How Angular is Different from AngularJS
September 27, 20227 min read

How Angular is Different from AngularJS

What is Angular? Angular is a popular open-source Typescript framework and free to use. Considered to be a JavaScript-based framework,TypeScript.is its primary programming language. TypeScript is Developed by Microsoft and its superset of JavaScript, which simply means that TypeScript has all the capabilities that JS has and more additional features. Angular is majorly used for […]

By Sachin DevadigaRead More →
Angular constructor vs ngOnInit
September 15, 20223 min read

Angular constructor vs ngOnInit

Overview: If you are new to angular or have been working with it for a while, you will have questions like: Is it necessary to inject dependencies in the constructor and bind data? When should we use ngOnInit ? What is the difference between constructor and OnInit?. So, in this blog we will answer all […]

By Priyanka SRead More →
Angular – Difference between ng-container and ng-template
July 13, 20222 min read

Angular – Difference between ng-container and ng-template

Overview: ng-container and ng-template, both are angular elements which will work like containers with HTML elements, but with different purpose/use cases. Lets see what is the use of ng-container and ng-template below: ng-container: In some cases when you do not want to add an extra HTML element to the DOM , for example like div […]

By Priyanka SRead More →