Book Image

Learn Q# Programming

By : Bhagvan Kommadi, Aneesh K Johny
Book Image

Learn Q# Programming

By: Bhagvan Kommadi, Aneesh K Johny

Overview of this book

<p>This book covers the fundamentals of quantum computing and programming with Microsoft’s Q# language. The reader will learn how to design, test and debug algorithms for different quantum applications.</p> <p>The primary focus of this book will be to give the audience an idea about how to get started with the concepts, different aspects, and theories of quantum computing operations, algorithms etc. Through this book, the developer will get a basic idea about the Microsoft Quantum Tool Kit and how to use the embedded Q# language. This will enable the reader to formalize and convert different real world problems to quantum algorithms and optimize them to use with a future quantum computer.</p> <p>By the end of the book, you would have successfully learned to create quantum programs of your own.</p>
Table of Contents (11 chapters)

First Quantum Program - Hello World


Q#  project  and solution is created using the following commands:

dotnet new console -lang Q# --output FirstQuantum

Visual Studio Code is used to open the project. The project will have two files Driver.cs (C# driver) and Operations.qs (Q#). The Operations.qs is renamed as Quantum.qs.

The code snippet below shows the Quantum.qs after adding the operation HelloWorld.

Code Snippet :Quantum  Q#Example

namespace FirstQuantum
{
    open Microsoft.Quantum.Canon;
    open Microsoft.Quantum.Primitive;

    /// HelloWorld Operation
    /// # Summary
    /// prints the message
    /// # Returns
    /// a Unit
    operation HelloWorld () : Unit {
        Message("Q# - Hello World");
    }

}

The Driver file will have the following code to execute HelloWorld.

Code Snippet :Driver C# Example

/////////////////////////////////////////////////////////////////////
// This file contains the driver class.
//////////////////////////////////////////////////////////////////////
using...