Home Application-development Learn Q# Programming

Learn Q# Programming

By Bhagvan Kommadi , Aneesh K Johny
books-svg-icon Book
Subscription
$10 p/m for first 3 months. $15.99 p/m after that. Cancel Anytime!
What do you get with a Packt Subscription?
This book & 7000+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook + Subscription?
Download this book in EPUB and PDF formats, plus a monthly download credit
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook?
Download this book in EPUB and PDF formats
Access this title in our online reader
DRM FREE - Read whenever, wherever and however you want
Online reader with customised display settings for better reading experience
What do you get with video?
Download this video in MP4 format
Access this title in our online reader
DRM FREE - Watch whenever, wherever and however you want
Online reader with customised display settings for better learning experience
What do you get with video?
Stream this video
Access this title in our online reader
DRM FREE - Watch whenever, wherever and however you want
Online reader with customised display settings for better learning experience
What do you get with Audiobook?
Download a zip folder consisting of audio files (in MP3 Format) along with supplementary PDF
What do you get with Exam Trainer?
Flashcards, Mock exams, Exam Tips, Practice Questions
Access these resources with our interactive certification platform
Mobile compatible-Practice whenever, wherever, however you want
BUY NOW $10 p/m for first 3 months. $15.99 p/m after that. Cancel Anytime!
Subscription
What do you get with a Packt Subscription?
This book & 7000+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook + Subscription?
Download this book in EPUB and PDF formats, plus a monthly download credit
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook?
Download this book in EPUB and PDF formats
Access this title in our online reader
DRM FREE - Read whenever, wherever and however you want
Online reader with customised display settings for better reading experience
What do you get with video?
Download this video in MP4 format
Access this title in our online reader
DRM FREE - Watch whenever, wherever and however you want
Online reader with customised display settings for better learning experience
What do you get with video?
Stream this video
Access this title in our online reader
DRM FREE - Watch whenever, wherever and however you want
Online reader with customised display settings for better learning experience
What do you get with Audiobook?
Download a zip folder consisting of audio files (in MP3 Format) along with supplementary PDF
What do you get with Exam Trainer?
Flashcards, Mock exams, Exam Tips, Practice Questions
Access these resources with our interactive certification platform
Mobile compatible-Practice whenever, wherever, however you want
About this book

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.

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.

By the end of the book, you would have successfully learned to create quantum programs of your own.

Publication date:
March 2020
Publisher
Packt
Pages
325
ISBN
9781788991889

 

Chapter 1. Fundamentals of Quantum Computing

The inter-disciplinary science and technology development on the twenty-first century enabled us to combine the aspects of different disciplines and make excellent results, application and solutions to real life problems. The exciting development that we are sure to see in the coming future is quantum computation. Merger of computer science with physics, quantum mechanics opens a large opportunity in the computing space. In today's information driven world, quantum computation is about to redefine the way we think about information technology and computer science world. This book will give you a fundamental idea about quantum computations, theories, application, physical interpretation, programming a quantum computer and programming language Q#.

This chapter emphasizes on the historical aspect of quantum computation. A brief history of origin of the idea of quantum computation will be given in this chapter apart from the basic physical interpretation, representation and quantum mechanics of quantum computation systems. The following topics will be covered in this chapter:

  • Quantum Computing: The Origin
  • Why Quantum Computing?
  • The Qubit
  • Quantum Mechanics of Qubit
  • Quantum Mechanics to Quantum Logic
 

Quantum Computation: The Origin


The beginning of the twentieth century was a mile stone in the history of science which redirect all the fundamental understanding. Beginning with the change in the perspective of how we think of the physical reality was changed by the theory of relativity and the understanding of universe by the introduction of quantum mechanics, which tells us the behavior of particles. Then there comes the Uncertainty principle, which turn around the understanding of elemental particle theories and measurements. Richard Feynman in the 1960s  proposed many aspects of quantum electrodynamics, the study of the way in which electrons behave in presence of electromagnetic radiation, through photons. Feynman along with others began to investigate the possibility of handling information using the simple quantum mechanical processes, considering the representation of binary numbers in accordance with the quantum states of two-state quantum system. This was a giant undertaking, in the scene that the scientists actually trying to emulate quantum mechanical process using a quantum computation device rather than a normal classical computer. During a conference co-hosted by IBM and MIT, Feynman challenged the computer science community to develop a computing device using the principles of quantum mechanics.

 First ever practical and commercially available computing device "ENIAC" (Wikipedia)

In 1985, David Deutsch from Oxford university published an article describing the possibility of a universal quantum computing device. He explained and proved that if a two-state quantum system could be made to evolve by means of a set of simple yet powerful operations, it can be used to simulate any physical system. This operation was called quantum gates because of its similarity with binary logic gates. Then in 1994, Peter Shor, currently a professor at Massachusetts Institute of Technology (MIT), Cambridge, Massachusetts, USA, proposed and developed an algorithm using quantum gates to find the prime factors of large number, which used to take enormous amount of time by  classical computer. This algorithm was a valuable leap in quantum computing, because many of the normal encryption schemes uses large number, of which, finding factors is extremely difficult. This opened an enormous opportunity in the scientific community in the field of computing. There were so many problems associated with the creation of quantum states. In 1995 a group of researchers from Caltech and The National Institute of Standard and Technology (NIST) jointly developed methods to create quantum states using magnetic fields, which allow ions or particles to isolate from environmental influences. This was a giant leap in the quantum technology even though the states are very unstable.

Richard Feynman (Wikipedia)

In early 2000s a group of scientists demonstrated the Shor's algorithm with a time span of 48 hrs using a quantum computer. As the time continues more and more technological and algorithmic developments have been made which eventually made better understanding of how to build a real quantum system. Then a group of researchers lead by Robert J. Schoelkopf invented a way to create superconducting qubits called transom qubits. It is a charged qubits and most of the todays research is focused on technology related to transom qubits. Major changes happened in the last few years, companies like IBM, Microsoft, Google and startups like rigeti, D-wave developing state-of-the-art quantum computers for commercial applications. In 2019 January, IBM released its first quantum computer for commercial applications. The efforts are still on to remove all the hurdles in quantum computing and researchers are pushing the limits to make a universal quantum machine to fulfill all the needs of the masses.

 

Why Quantum Computing?


Today's computers are very good at fulfilling our needs. We are enjoying the benefits of today's classical computers. It is entertaining us, connecting us and even help us in each and every moment of life in one way or another. Classical computers are helping us to process huge amount of data in this data driven world and make the world is a better place. From medicine to finance, engineering and so many other areas, computers and computer knowledge is an essential for a human being to survive. The power of the computers are increasing day by day and it will continue to increase as we develop further. 

However, there are limitations to the classical computers. There are problems that cannot be addressed with classical computers. In other words, there are problems that cannot be addressed using a classical computer. There are many complex system in science which are so complex and massive that we cannot do it with even the powerful supercomputers using classical computing technology. This leads the scientists to seek new methods and approaches to tackle with this limitation of classical computers.

We need systems with computational power with the size and the complexity of the system itself. The best example we can choose is the simulation of atoms and molecules. Everyone knows that simulating an atom or a molecule is very complex due to the complex quantum mechanical calculation involved. The behavior of an electron inside an atom or molecule is very complex to compute, which is very essential in understanding the inner mechanism of that molecule.

The simulation of chemistry and simulation of even small scale macro molecules which are essential for life on earth is very complex for a classical computer. Nature is quantum mechanical and classical computer is very limited in simulating quantum mechanical aspects. So it is essential to use the object which obeys the same natural laws to simulate or understand the nature. A quantum computer can easily simulate these complex systems so that we can understand it. The implications this leads to is immense, opportunities in new drugs, new materials, understanding catalytic interaction in chemical reactions complex molecular interactions which are impossible to calculate using today's computing technology.

 

The Qubit


In this digital age, as we all know the information is digitally handled as bits, that is zeros and ones. Each of this information chunks are called "bit". For last five decades, we have been playing with this so called bit and today all of our digital life, even real life is connected to these two numbers, 0 and,1 called bits. Each of this bit can be intimated to the states of an electric switch. The on state of the switch can be considered as 1 and off state is 0. Analogs to this classical approach, we can materialize the representation of information in quantum computing using units called quantum bits or abbreviated as qubits. The quantum version of classical bits. Qubit is a two-state or two-level quantum mechanical representation of information. The fundamental difference between a qubit and classical bit is that, classical bit can only be in either one of its states or level whereas qubit can be in coherent superposition of both states/levels. The term qubit was originally introduced by Benjamin Schumacher, an American theoretical physicist working in the area of quantum information theory, in his 1995 paper, Quantum Coding published in Physical Review A. The paper deals with the compression of quantum information created by a qubit, and it is called Schumacher compression.

Qubit Vs Bit

The classical information processed as bits using a CPU is implemented by one of the two levels of a low  DC voltage.  This binary logic is represented by two voltage states in different logic families, for example, the voltage level for TTL family for logical 0 is

and for logical 1 is

. Similarly, for CMOS family of logic, 0 is 0.5 V and 1 is 2 Vcc. For all these logic families, information is represented by either 0 or 1 or a combination of both. A qubit or quantum bit is used in quantum computing and it is different from normal bits. Consider representing data using an atom. The ground state of electron in the atom can be taken as state 

and the excited state of the atom to another energy level can be taken as 

.  In this format, a qubit can simultaneously represent the states 

and

. Using this property, if we use 4 qubits to represent information, the qubit can represent all the data simultaneously and it is 16 times faster than a normal computer. Table 1—the table represents quantum equivalent of classical computers. A quantum computer with 300 qubit can replace all the supercomputers on the planet

Quantum Bits

Equivalent Classical Bit

1

1

10

1024

50

1.125899907E17

300

2.037035976E90

Qubit Realization Techniques

There are various proposals that have been made to physically implement a qubit. Many researches are going on to find a good method to realize qubit. A quantum mechanical system with two-levels can be used as a qubit.  We can also use multilevel systems provided if they have two levels that can be decouple  from other levels. Researchers are successfully implemented systems that can be approximated two-levels with various degrees of accuracy. The various technologies and techniques to produce a qubit is will serve various purposes in a practical quantum machine. The following list will be an incomplete set of technologies practically implemented by researchers:

Physics

Terminology

Information

Coherent state of light

Squeezed Light

Quadrature

Early

Late

Photon

Number of Photons

Fock State

Vacuum

Single Photon State

Electron

Spin/Number

Spin/Charge

Up/No Charge

Down/Charge

Josephson Junction

Superconducting Charge/Flux/Phase Qubit

Charge/Current/Energy

Uncharged Island/Clockwise Current/Ground State

Charged Island/Counter Clockwise Current/First Excited State

 

Quantum Mechanics of Qubit


Quantum mechanics deals with the smallest elementary particles and their interactions. Quantum computing is utilizes two special quantum mechanical phenomena called superposition and entanglement.

Superposition

The quantum mechanical super position is much like the classical wave superposition. Any two or more quantum sates can be added or superposed together to form a valid quantum states. In other words, a quantum state can be represented by the sum of another two or more different states. This is a property of the solutions of Schrödinger equation (Equation 1). Schrödinger equation is linear in nature and any combination of the solutions of a linear equation is also a solution.

We can observe superposition phenomena in nature, the interference pattern observed from electron double-slit experiment is similar to that of observed by diffraction of classical waves. This pattern is the result of superposition.

Entanglement

This is an exciting phenomenon for physicists. This is attributed to the dependencies of a particle and it's properties on another particle or a set of particle in its spacial proximity.  In an elaborated way we can define that, quantum entanglement is a phenomenon for which the quantum states of two or more particles or quantum objects have to be described with reference to each other. This leads to correlations between observation between physical properties of the system. The physical properties can be position, momentum, spin and polarization.

These aforementioned two phenomenons are the basis for quantum computing.

Quantum Mechanical Representation of Qubit

A quantum mechanical state is generally represented by Dirac notations also known as "bra-ket" notations.  There are infinitely many states are possible for a qubit, but we represent these states by two basis vectors or states. The vectors are

and

, pronounced as "ket-1" and "ket-0". These vectors are called orthonormal basis states,

, together they called computational basis. These vectors are span the two-dimensional linear vector or Hilbert space of qubit.

A pure qubit can be represented by the linear combination of basis states

as

Where 

and 

are the probability amplitude in complex numbers. The probability of outcome "0" is 

and probability of outcome "1" is

and will be constrained by

. We use Bloch sphere to represent a qubit graphically, Fig. 2.

Figure 2: Bloch Sphere representation of qubit

A qubit have four degrees of freedom due to the involvement of complex numbers in probability  amplitudes. This will be reduced to three due to constraint

. Further we reduce the degrees of freedom by using changing the coordinates. Probability amplitudes are rewritten into the following form using coordinate change,

For a single qubit,  due to the  insignificance of

, and we can choose

to be real, the general state is further reduced to,

Where the term

is the physically significant relative phase. On the Bloch sphere, the north and south poles represents the classical bits and any point on the sphere will represent the concurrent state of a qubit. This polar axis is arbitrarily chosen.

Quantum Mechanics to Quantum Logic

We have discussed all the basics related to quantum computing and qubits. For making use of this qubit, we need to form quantum logic circuits. We utilize the basic principles of qubits and its operation to create quantum computing circuits. The circuits are very similar to that of classical computing circuits, called logic gates. These quantum circuits are called quantum logic gates or simply quantum gates. This quantum circuits are built using few qubits, using a single qubit to many numbers of qubits depending upon the complexity and requirements of algorithms. Quantum gates are reversible in nature and using quantum logic gates we can perform classical computing operations.  A typical example can be a CCNOT gate or reversible Toffoli gate. Using this gate we can implement all the Boolean functions.

A detailed representation and mathematical formulation of qubit and its operation is given in chapter 4 :The Fundamentals of Qubit Representation and Computation.

 

Summary


This chapter gives an idea about the historical background about quantum computing and related technologies. An attempt is made to explain the benefits of using quantum computer and how it is going to reshape our future. This chapter will help us to explore about the building block of quantum computer - qubit, the origin of the word, meaning, and  brief mathematical representation.

The next chapter will give a detailed idea about Q# language. The aspects discussed in detail will be Q# Constructs, Q# Control flow, I/O conventions and basic setup for visual studio for programming in Q#.

 

Review Questions


  • Prepare a brief note on the history of quantum computing
  • Prepare a brief note about the technologies related to qubits realization
 

Reference


About the Authors
  • Bhagvan Kommadi

    Bhagvan Kommadi, Founder, Architect Corner has around 18 years experience in the industry ranging from large-scale enterprise development to incubating software product startups. He has done Masters in Industrial Systems Engineering at Georgia Institute of Technology (1997) and Bachelors in Aerospace Engineering from Indian Institute of Technology, Madras (1993). He is currently working as CTO of Crystal Delta Solutions. He is the member of IFX forum and an Individual member of Oracle JCP. He has developed Go language based blockchain solutions in retail, education, banking, and financial services sectors. These blockchain solutions were based on Chain Core (Go language based), Ethereum and Hyperledger blockchain platforms. He has experience in building high transactional applications using Java, C, C++, C#, Python, Go, Ruby and JavaScript frameworks. He has reviewed books such as Beyond Software Architecture-Creating and sustaining winning solutions by Luke Hohmann and Algorithms of the intelligent Web by Dr. Haralambos (Babis) Marmanis.

    Browse publications by this author
  • Aneesh K Johny

    Aneesh K Johnny is a PhD scholar in the Department of Applied Mechanics, Indian Institute of Technology, Madras. He is a part of Micro and Nanoscale Transport Laboratory, doing research in nanofluidic transport. He did his masters from APJ Abdhul Kalam Technological University, Kerala in Thermal Power Engineering and Bachelors from Mahatma Gandhi University, Kerala in Mechanical Engineering. Aneesh is the co-founder and Product Manager of Quantica Computacao. His area of interests are Molecular Dynamics, Quantum Computing and Statistical Mechanics. He is one of the architects of Alchemy, an in-development quantum computing simulator from Quantica Computacao, and involved in developing algorithms for quantum cryptography.

    Browse publications by this author
Learn Q# Programming
Unlock this book and the full library FREE for 7 days
Start now