Q Sharp

Last updated
Q#
Paradigm Quantum, functional, imperative
Designed by Microsoft Research (quantum architectures and computation group; QuArC)
Developer Microsoft
First appearedDecember 11, 2017 (2017-12-11)
Typing discipline Static, strong
Platform Common Language Infrastructure
License MIT License [1]
Filename extensions .qs
Website docs.microsoft.com/en-us/quantum
Influenced by
C#, F#, Python

Q# (pronounced as Q sharp) is a domain-specific programming language used for expressing quantum algorithms. [2] It was initially released to the public by Microsoft as part of the Quantum Development Kit. [3]

Contents

History

Historically, Microsoft Research had two teams interested in quantum computing: the QuArC team based in Redmond[ which? ], [4] directed by Krysta Svore, that explored the construction of quantum circuitry, and Station Q initially located in Santa Barbara and directed by Michael Freedman, that explored topological quantum computing. [5] [6]

During a Microsoft Ignite Keynote on September 26, 2017, Microsoft announced that they were going to release a new programming language geared specifically towards quantum computers. [7] On December 11, 2017, Microsoft released Q# as a part of the Quantum Development Kit. [3]

At Build 2019, Microsoft announced that it would be open-sourcing the Quantum Development Kit, including its Q# compilers and simulators. [8]

Bettina Heim currently leads the Q# language development effort. [9] [10]

Usage

Q# is available as a separately downloaded extension for Visual Studio, [11] but it can also be run as an independent tool from the command line or Visual Studio Code. The Quantum Development Kit ships with a quantum simulator which is capable of running Q#. [12]

In order to invoke the quantum simulator, another .NET programming language, usually C#, is used, which provides the (classical) input data for the simulator and reads the (classical) output data from the simulator. [13]

Features

A primary feature of Q# is the ability to create and use qubits for algorithms. As a consequence, some of the most prominent features of Q# are the ability to entangle and introduce superpositioning to qubits via Controlled NOT gates and Hadamard gates, respectively, as well as Toffoli Gates, Pauli X, Y, Z Gate, and many more which are used for a variety of operations; see the list at the article on quantum logic gates. [14]

The hardware stack that will eventually come together with Q# is expected to implement Qubits as topological qubits. The quantum simulator that is shipped with the Quantum Development Kit today is capable of processing up to 32 qubits on a user machine and up to 40 qubits on Azure. [15]

Documentation and resources

Currently, the resources available for Q# are scarce, but the official documentation is published: Microsoft Developer Network: Q#. Microsoft Quantum Github repository is also a large collection of sample programs implementing a variety of Quantum algorithms and their tests.

Microsoft has also hosted a Quantum Coding contest on Codeforces, called Microsoft Q# Coding Contest - Codeforces, and also provided related material to help answer the questions in the blog posts, plus the detailed solutions in the tutorials.

Microsoft hosts a set of learning exercises to help learn Q# on GitHub: microsoft/QuantumKatas with links to resources, and answers to the problems.

Syntax

Q# is syntactically related to both C# and F# yet also has some significant differences.

Similarities with C#

Similarities with F#

Differences

Example

The following source code is a multiplexer from the official Microsoft Q# library repository.

// Copyright (c) Microsoft Corporation.// Licensed under the MIT License.namespaceMicrosoft.Quantum.Canon{openMicrosoft.Quantum.Intrinsic;openMicrosoft.Quantum.Arithmetic;openMicrosoft.Quantum.Arrays;openMicrosoft.Quantum.Diagnostics;openMicrosoft.Quantum.Math;/// # Summary/// Applies a multiply-controlled unitary operation $U$ that applies a/// unitary $V_j$ when controlled by n-qubit number state $\ket{j}$.////// $U = \sum^{N-1}_{j=0}\ket{j}\bra{j}\otimes V_j$.////// # Input/// ## unitaryGenerator/// A tuple where the first element `Int` is the number of unitaries $N$,/// and the second element `(Int -> ('T => () is Adj + Ctl))`/// is a function that takes an integer $j$ in $[0,N-1]$ and outputs the unitary/// operation $V_j$.////// ## index/// $n$-qubit control register that encodes number states $\ket{j}$ in/// little-endian format.////// ## target/// Generic qubit register that $V_j$ acts on.////// # Remarks/// `coefficients` will be padded with identity elements if/// fewer than $2^n$ are specified. This implementation uses/// $n-1$ auxiliary qubits.////// # References/// - [ *Andrew M. Childs, Dmitri Maslov, Yunseong Nam, Neil J. Ross, Yuan Su*,///      arXiv:1711.10980](https://arxiv.org/abs/1711.10980)operationMultiplexOperationsFromGenerator<'T>(unitaryGenerator:(Int,(Int->('T=>UnitisAdj+Ctl))),index:LittleEndian,target:'T):UnitisCtl+Adj{let(nUnitaries,unitaryFunction)=unitaryGenerator;letunitaryGeneratorWithOffset=(nUnitaries,0,unitaryFunction);ifLength(index!)==0{fail"MultiplexOperations failed. Number of index qubits must be greater than 0.";}ifnUnitaries>0{letauxiliary=[];AdjointMultiplexOperationsFromGeneratorImpl(unitaryGeneratorWithOffset,auxiliary,index,target);}}/// # Summary/// Implementation step of `MultiplexOperationsFromGenerator`./// # See Also/// - Microsoft.Quantum.Canon.MultiplexOperationsFromGeneratorinternaloperationMultiplexOperationsFromGeneratorImpl<'T>(unitaryGenerator:(Int,Int,(Int->('T=>UnitisAdj+Ctl))),auxiliary:Qubit[],index:LittleEndian,target:'T):Unit{body(...){letnIndex=Length(index!);letnStates=2^nIndex;let(nUnitaries,unitaryOffset,unitaryFunction)=unitaryGenerator;letnUnitariesLeft=MinI(nUnitaries,nStates/2);letnUnitariesRight=MinI(nUnitaries,nStates);letleftUnitaries=(nUnitariesLeft,unitaryOffset,unitaryFunction);letrightUnitaries=(nUnitariesRight-nUnitariesLeft,unitaryOffset+nUnitariesLeft,unitaryFunction);letnewControls=LittleEndian(Most(index!));ifnUnitaries>0{ifLength(auxiliary)==1andnIndex==0{// Termination case(ControlledAdjoint(unitaryFunction(unitaryOffset)))(auxiliary,target);}elifLength(auxiliary)==0andnIndex>=1{// Start caseletnewauxiliary=Tail(index!);ifnUnitariesRight>0{MultiplexOperationsFromGeneratorImpl(rightUnitaries,[newauxiliary],newControls,target);}within{X(newauxiliary);}apply{MultiplexOperationsFromGeneratorImpl(leftUnitaries,[newauxiliary],newControls,target);}}else{// Recursion that reduces nIndex by 1 and sets Length(auxiliary) to 1.letcontrols=[Tail(index!)]+auxiliary;usenewauxiliary=Qubit();useandauxiliary=Qubit[MaxI(0,Length(controls)-2)];within{ApplyAndChain(andauxiliary,controls,newauxiliary);}apply{ifnUnitariesRight>0{MultiplexOperationsFromGeneratorImpl(rightUnitaries,[newauxiliary],newControls,target);}within{(ControlledX)(auxiliary,newauxiliary);}apply{MultiplexOperationsFromGeneratorImpl(leftUnitaries,[newauxiliary],newControls,target);}}}}}adjointauto;controlled(controlRegister,...){MultiplexOperationsFromGeneratorImpl(unitaryGenerator,auxiliary+controlRegister,index,target);}adjointcontrolledauto;}/// # Summary/// Applies multiply-controlled unitary operation $U$ that applies a/// unitary $V_j$ when controlled by n-qubit number state $\ket{j}$.////// $U = \sum^{N-1}_{j=0}\ket{j}\bra{j}\otimes V_j$.////// # Input/// ## unitaryGenerator/// A tuple where the first element `Int` is the number of unitaries $N$,/// and the second element `(Int -> ('T => () is Adj + Ctl))`/// is a function that takes an integer $j$ in $[0,N-1]$ and outputs the unitary/// operation $V_j$.////// ## index/// $n$-qubit control register that encodes number states $\ket{j}$ in/// little-endian format.////// ## target/// Generic qubit register that $V_j$ acts on.////// # Remarks/// `coefficients` will be padded with identity elements if/// fewer than $2^n$ are specified. This version is implemented/// directly by looping through n-controlled unitary operators.operationMultiplexOperationsBruteForceFromGenerator<'T>(unitaryGenerator:(Int,(Int->('T=>UnitisAdj+Ctl))),index:LittleEndian,target:'T):UnitisAdj+Ctl{letnIndex=Length(index!);letnStates=2^nIndex;let(nUnitaries,unitaryFunction)=unitaryGenerator;foridxOpin0..MinI(nStates,nUnitaries)-1{(ControlledOnInt(idxOp,unitaryFunction(idxOp)))(index!,target);}}/// # Summary/// Returns a multiply-controlled unitary operation $U$ that applies a/// unitary $V_j$ when controlled by n-qubit number state $\ket{j}$.////// $U = \sum^{2^n-1}_{j=0}\ket{j}\bra{j}\otimes V_j$.////// # Input/// ## unitaryGenerator/// A tuple where the first element `Int` is the number of unitaries $N$,/// and the second element `(Int -> ('T => () is Adj + Ctl))`/// is a function that takes an integer $j$ in $[0,N-1]$ and outputs the unitary/// operation $V_j$.////// # Output/// A multiply-controlled unitary operation $U$ that applies unitaries/// described by `unitaryGenerator`.////// # See Also/// - Microsoft.Quantum.Canon.MultiplexOperationsFromGeneratorfunctionMultiplexerFromGenerator(unitaryGenerator:(Int,(Int->(Qubit[]=>UnitisAdj+Ctl)))):((LittleEndian,Qubit[])=>UnitisAdj+Ctl){returnMultiplexOperationsFromGenerator(unitaryGenerator,_,_);}/// # Summary/// Returns a multiply-controlled unitary operation $U$ that applies a/// unitary $V_j$ when controlled by n-qubit number state $\ket{j}$.////// $U = \sum^{2^n-1}_{j=0}\ket{j}\bra{j}\otimes V_j$.////// # Input/// ## unitaryGenerator/// A tuple where the first element `Int` is the number of unitaries $N$,/// and the second element `(Int -> ('T => () is Adj + Ctl))`/// is a function that takes an integer $j$ in $[0,N-1]$ and outputs the unitary/// operation $V_j$.////// # Output/// A multiply-controlled unitary operation $U$ that applies unitaries/// described by `unitaryGenerator`.////// # See Also/// - Microsoft.Quantum.Canon.MultiplexOperationsBruteForceFromGeneratorfunctionMultiplexerBruteForceFromGenerator(unitaryGenerator:(Int,(Int->(Qubit[]=>UnitisAdj+Ctl)))):((LittleEndian,Qubit[])=>UnitisAdj+Ctl){returnMultiplexOperationsBruteForceFromGenerator(unitaryGenerator,_,_);}/// # Summary/// Computes a chain of AND gates////// # Description/// The auxiliary qubits to compute temporary results must be specified explicitly./// The length of that register is `Length(ctrlRegister) - 2`, if there are at least/// two controls, otherwise the length is 0.internaloperationApplyAndChain(auxRegister:Qubit[],ctrlRegister:Qubit[],target:Qubit):UnitisAdj{ifLength(ctrlRegister)==0{X(target);}elifLength(ctrlRegister)==1{CNOT(Head(ctrlRegister),target);}else{EqualityFactI(Length(auxRegister),Length(ctrlRegister));letcontrols1=ctrlRegister[0..0]+auxRegister;letcontrols2=Rest(ctrlRegister);lettargets=auxRegister+[target];ApplyToEachA(ApplyAnd,Zipped3(controls1,controls2,targets));}}}


Related Research Articles

<span class="mw-page-title-main">Quantum computing</span> Technology that uses quantum mechanics

A quantum computer is a computer that uses quantum mechanical phenomena to operate.

<span class="mw-page-title-main">Qubit</span> Basic unit of quantum information

In quantum computing, a qubit or quantum bit is a basic unit of quantum information—the quantum version of the classic binary bit physically realized with a two-state device. A qubit is a two-state quantum-mechanical system, one of the simplest quantum systems displaying the peculiarity of quantum mechanics. Examples include the spin of the electron in which the two levels can be taken as spin up and spin down; or the polarization of a single photon in which the two spin states can also be measured as horizontal and vertical linear polarization. In a classical system, a bit would have to be in one state or the other. However, quantum mechanics allows the qubit to be in a coherent superposition of multiple states simultaneously, a property that is fundamental to quantum mechanics and quantum computing.

Shor's algorithm is a quantum algorithm for finding the prime factors of an integer. It was developed in 1994 by the American mathematician Peter Shor. It is one of the few known quantum algorithms with compelling potential applications and strong evidence of superpolynomial speedup compared to best known classical algorithms. On the other hand, factoring numbers of practical significance requires far more qubits than available in the near future. Another concern is that noise in quantum circuits may undermine results, requiring additional qubits for quantum error correction.

<span class="mw-page-title-main">Quantum decoherence</span> Loss of quantum coherence

Quantum decoherence is the loss of quantum coherence, the process in which a system's behaviour changes from that which can be explained by quantum mechanics to that which can be explained by classical mechanics. Beginning out of attempts to extend the understanding of quantum mechanics, the theory has developed in several directions and experimental studies have confirmed some of the key issues. Quantum computing relies on quantum coherence and is the primary practical applications of the concept.

<span class="mw-page-title-main">Quantum circuit</span> Model of quantum computing

In quantum information theory, a quantum circuit is a model for quantum computation, similar to classical circuits, in which a computation is a sequence of quantum gates, measurements, initializations of qubits to known values, and possibly other actions. The minimum set of actions that a circuit needs to be able to perform on the qubits to enable quantum computation is known as DiVincenzo's criteria.

In quantum computing and specifically the quantum circuit model of computation, a quantum logic gate is a basic quantum circuit operating on a small number of qubits. Quantum logic gates are the building blocks of quantum circuits, like classical logic gates are for conventional digital circuits.

Superconducting quantum computing is a branch of solid state quantum computing that implements superconducting electronic circuits using superconducting qubits as artificial atoms, or quantum dots. For superconducting qubits, the two logic states are the ground state and the excited state, denoted respectively. Research in superconducting quantum computing is conducted by companies such as Google, IBM, IMEC, BBN Technologies, Rigetti, and Intel. Many recently developed QPUs use superconducting architecture.

Quantum programming is the process of designing or assembling sequences of instructions, called quantum circuits, using gates, switches, and operators to manipulate a quantum system for a desired outcome or results of a given experiment. Quantum circuit algorithms can be implemented on integrated circuits, conducted with instrumentation, or written in a programming language for use with a quantum computer or a quantum processor.

<span class="mw-page-title-main">Superdense coding</span> Two-bit quantum communication protocol

In quantum information theory, superdense coding is a quantum communication protocol to communicate a number of classical bits of information by only transmitting a smaller number of qubits, under the assumption of sender and receiver pre-sharing an entangled resource. In its simplest form, the protocol involves two parties, often referred to as Alice and Bob in this context, which share a pair of maximally entangled qubits, and allows Alice to transmit two bits to Bob by sending only one qubit. This protocol was first proposed by Charles H. Bennett and Stephen Wiesner in 1970 and experimentally actualized in 1996 by Klaus Mattle, Harald Weinfurter, Paul G. Kwiat and Anton Zeilinger using entangled photon pairs. Superdense coding can be thought of as the opposite of quantum teleportation, in which one transfers one qubit from Alice to Bob by communicating two classical bits, as long as Alice and Bob have a pre-shared Bell pair.

<span class="mw-page-title-main">Controlled NOT gate</span> Quantum logic gate

In computer science, the controlled NOT gate, controlled-X gate, controlled-bit-flip gate, Feynman gate or controlled Pauli-X is a quantum logic gate that is an essential component in the construction of a gate-based quantum computer. It can be used to entangle and disentangle Bell states. Any quantum circuit can be simulated to an arbitrary degree of accuracy using a combination of CNOT gates and single qubit rotations. The gate is sometimes named after Richard Feynman who developed an early notation for quantum gate diagrams in 1986.

<span class="mw-page-title-main">One-way quantum computer</span> Method of quantum computing

The one-way or measurement-based quantum computer (MBQC) is a method of quantum computing that first prepares an entangled resource state, usually a cluster state or graph state, then performs single qubit measurements on it. It is "one-way" because the resource state is destroyed by the measurements.

Entanglement distillation is the transformation of N copies of an arbitrary entangled state into some number of approximately pure Bell pairs, using only local operations and classical communication.

Quantum block codes are useful in quantum computing and in quantum communications. The encoding circuit for a large block code typically has a high complexity although those for modern codes do have lower complexity.

In quantum computing, the quantum phase estimation algorithm is a quantum algorithm to estimate the phase corresponding to an eigenvalue of a given unitary operator. Because the eigenvalues of a unitary operator always have unit modulus, they are characterized by their phase, and therefore the algorithm can be equivalently described as retrieving either the phase or the eigenvalue itself. The algorithm was initially introduced by Alexei Kitaev in 1995.

In quantum computing, the quantum Fourier transform (QFT) is a linear transformation on quantum bits, and is the quantum analogue of the discrete Fourier transform. The quantum Fourier transform is a part of many quantum algorithms, notably Shor's algorithm for factoring and computing the discrete logarithm, the quantum phase estimation algorithm for estimating the eigenvalues of a unitary operator, and algorithms for the hidden subgroup problem. The quantum Fourier transform was discovered by Don Coppersmith.

Linear optical quantum computing or linear optics quantum computation (LOQC), also photonic quantum computing (PQC), is a paradigm of quantum computation, allowing (under certain conditions, described below) universal quantum computation. LOQC uses photons as information carriers, mainly uses linear optical elements, or optical instruments (including reciprocal mirrors and waveplates) to process quantum information, and uses photon detectors and quantum memories to detect and store quantum information.

Quantum image processing (QIMP) is using quantum computing or quantum information processing to create and work with quantum images.

Quantum Computation Language (QCL) is one of the first implemented quantum programming languages. The most important feature of QCL is the support for user-defined operators and functions. Its syntax resembles the syntax of the C programming language and its classical data types are similar to primitive data types in C. One can combine classical code and quantum code in the same program.

In quantum information theory and operator theory, the Choi–Jamiołkowski isomorphism refers to the correspondence between quantum channels and quantum states, this is introduced by Man-Duen Choi and Andrzej Jamiołkowski. It is also called channel-state duality by some authors in the quantum information area, but mathematically, this is a more general correspondence between positive operators and the complete positive superoperators.

Parity measurement is a procedure in quantum information science used for error detection in quantum qubits. A parity measurement checks the equality of two qubits to return a true or false answer, which can be used to determine whether a correction needs to occur. Additional measurements can be made for a system greater than two qubits. Because parity measurement does not measure the state of singular bits but rather gets information about the whole state, it is considered an example of a joint measurement. Joint measurements do not have the consequence of destroying the original state of a qubit as normal quantum measurements do. Mathematically speaking, parity measurements are used to project a state into an eigenstate of an operator and to acquire its eigenvalue.

References

  1. "Introduction to Q#" (PDF). University of Washington.
  2. 1 2 QuantumWriter. "The Q# Programming Language". docs.microsoft.com. Retrieved 2017-12-11.
  3. 1 2 "Announcing the Microsoft Quantum Development Kit" . Retrieved 2017-12-11.
  4. "Solving the quantum many-body problem with artificial neural networks". Microsoft Azure Quantum. 15 February 2017.
  5. Scott Aaronson's blog, 2013, 'Microsoft: From QDOS to QMA in less than 35 years', https://scottaaronson.blog/?p=1471
  6. "What are the Q# programming language & QDK? - Azure Quantum". learn.microsoft.com.
  7. "Microsoft announces quantum computing programming language" . Retrieved 2017-12-14.
  8. Microsoft is open-sourcing its Quantum Development Kit
  9. "The Women of QuArC". 30 March 2019.
  10. "Intro to Q# - Intro to Quantum Software Development". stem.mitre.org.
  11. QuantumWriter. "Setting up the Q# development environment". docs.microsoft.com. Retrieved 2017-12-14.
  12. Akdogan, Erman (23 October 2022). "Quantum computing is coming for finance & crypto". Medium.
  13. "This Week in Programming: Get Quantum with Q Sharp". The New Stack. 16 December 2017.
  14. "Qubit Gate - an overview". www.sciencedirect.com.
  15. "Microsoft previews quantum computing development kit". CIO.
  16. "Types in Q# - Microsoft Quantum". docs.microsoft.com.