[{"@context":"http:\/\/schema.org\/","@type":"BlogPosting","@id":"https:\/\/wiki.edu.vn\/en\/wiki41\/q-sharp-wikipedia\/#BlogPosting","mainEntityOfPage":"https:\/\/wiki.edu.vn\/en\/wiki41\/q-sharp-wikipedia\/","headline":"Q Sharp – Wikipedia","name":"Q Sharp – Wikipedia","description":"before-content-x4 Programming lang. for quantum algorithms after-content-x4 During a Microsoft Ignite Keynote on September 26, 2017, Microsoft announced that they","datePublished":"2019-06-19","dateModified":"2019-06-19","author":{"@type":"Person","@id":"https:\/\/wiki.edu.vn\/en\/wiki41\/author\/lordneo\/#Person","name":"lordneo","url":"https:\/\/wiki.edu.vn\/en\/wiki41\/author\/lordneo\/","image":{"@type":"ImageObject","@id":"https:\/\/secure.gravatar.com\/avatar\/c9645c498c9701c88b89b8537773dd7c?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/c9645c498c9701c88b89b8537773dd7c?s=96&d=mm&r=g","height":96,"width":96}},"publisher":{"@type":"Organization","name":"Enzyklop\u00e4die","logo":{"@type":"ImageObject","@id":"https:\/\/wiki.edu.vn\/wiki4\/wp-content\/uploads\/2023\/08\/download.jpg","url":"https:\/\/wiki.edu.vn\/wiki4\/wp-content\/uploads\/2023\/08\/download.jpg","width":600,"height":60}},"image":{"@type":"ImageObject","@id":"https:\/\/wiki.edu.vn\/wiki4\/wp-content\/uploads\/2023\/08\/download.jpg","url":"https:\/\/wiki.edu.vn\/wiki4\/wp-content\/uploads\/2023\/08\/download.jpg","width":100,"height":100},"url":"https:\/\/wiki.edu.vn\/en\/wiki41\/q-sharp-wikipedia\/","about":["Wiki"],"wordCount":7193,"articleBody":" (adsbygoogle = window.adsbygoogle || []).push({});before-content-x4Programming lang. for quantum algorithms (adsbygoogle = window.adsbygoogle || []).push({});after-content-x4During 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]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] (adsbygoogle = window.adsbygoogle || []).push({});after-content-x4In 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]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]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. (adsbygoogle = window.adsbygoogle || []).push({});after-content-x4Microsoft hosts a set of learning exercises to help learn Q# on GitHub: microsoft\/QuantumKatas with links to resources, and answers to the problems.Q# is syntactically related to both C# and F# yet also has some significant differences.The following source code is a multiplexer from the official Microsoft Q# library repository.\/\/ Copyright (c) Microsoft Corporation.\/\/ Licensed under the MIT License.namespace Microsoft.Quantum.Canon { open Microsoft.Quantum.Intrinsic; open Microsoft.Quantum.Arithmetic; open Microsoft.Quantum.Arrays; open Microsoft.Quantum.Diagnostics; open Microsoft.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) operation MultiplexOperationsFromGenerator Unit is Adj + Ctl))), index: LittleEndian, target: 'T) : Unit is Ctl + Adj { let (nUnitaries, unitaryFunction) = unitaryGenerator; let unitaryGeneratorWithOffset = (nUnitaries, 0, unitaryFunction); if Length(index!) == 0 { fail \"MultiplexOperations failed. Number of index qubits must be greater than 0.\"; } if nUnitaries > 0 { let auxiliary = []; Adjoint MultiplexOperationsFromGeneratorImpl(unitaryGeneratorWithOffset, auxiliary, index, target); } } \/\/\/ # Summary \/\/\/ Implementation step of `MultiplexOperationsFromGenerator`. \/\/\/ # See Also \/\/\/ - Microsoft.Quantum.Canon.MultiplexOperationsFromGenerator internal operation MultiplexOperationsFromGeneratorImpl Unit is Adj + Ctl))), auxiliary: Qubit[], index: LittleEndian, target: 'T) : Unit { body (...) { let nIndex = Length(index!); let nStates = 2^nIndex; let (nUnitaries, unitaryOffset, unitaryFunction) = unitaryGenerator; let nUnitariesLeft = MinI(nUnitaries, nStates \/ 2); let nUnitariesRight = MinI(nUnitaries, nStates); let leftUnitaries = (nUnitariesLeft, unitaryOffset, unitaryFunction); let rightUnitaries = (nUnitariesRight - nUnitariesLeft, unitaryOffset + nUnitariesLeft, unitaryFunction); let newControls = LittleEndian(Most(index!)); if nUnitaries > 0 { if Length(auxiliary) == 1 and nIndex == 0 { \/\/ Termination case (Controlled Adjoint (unitaryFunction(unitaryOffset)))(auxiliary, target); } elif Length(auxiliary) == 0 and nIndex >= 1 { \/\/ Start case let newauxiliary = Tail(index!); if nUnitariesRight > 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. let controls = [Tail(index!)] + auxiliary; use newauxiliary = Qubit(); use andauxiliary = Qubit[MaxI(0, Length(controls) - 2)]; within { ApplyAndChain(andauxiliary, controls, newauxiliary); } apply { if nUnitariesRight > 0 { MultiplexOperationsFromGeneratorImpl(rightUnitaries, [newauxiliary], newControls, target); } within { (Controlled X)(auxiliary, newauxiliary); } apply { MultiplexOperationsFromGeneratorImpl(leftUnitaries, [newauxiliary], newControls, target); } } } } } adjoint auto; controlled (controlRegister, ...) { MultiplexOperationsFromGeneratorImpl(unitaryGenerator, auxiliary + controlRegister, index, target); } adjoint controlled auto; } \/\/\/ # 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. operation MultiplexOperationsBruteForceFromGenerator Unit is Adj + Ctl))), index: LittleEndian, target: 'T) : Unit is Adj + Ctl { let nIndex = Length(index!); let nStates = 2^nIndex; let (nUnitaries, unitaryFunction) = unitaryGenerator; for idxOp in 0..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.MultiplexOperationsFromGenerator function MultiplexerFromGenerator(unitaryGenerator : (Int, (Int -> (Qubit[] => Unit is Adj + Ctl)))) : ((LittleEndian, Qubit[]) => Unit is Adj + Ctl) { return MultiplexOperationsFromGenerator(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.MultiplexOperationsBruteForceFromGenerator function MultiplexerBruteForceFromGenerator(unitaryGenerator : (Int, (Int -> (Qubit[] => Unit is Adj + Ctl)))) : ((LittleEndian, Qubit[]) => Unit is Adj + Ctl) { return MultiplexOperationsBruteForceFromGenerator(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. internal operation ApplyAndChain(auxRegister : Qubit[], ctrlRegister : Qubit[], target : Qubit) : Unit is Adj { if Length(ctrlRegister) == 0 { X(target); } elif Length(ctrlRegister) == 1 { CNOT(Head(ctrlRegister), target); } else { EqualityFactI(Length(auxRegister), Length(ctrlRegister)); let controls1 = ctrlRegister[0..0] + auxRegister; let controls2 = Rest(ctrlRegister); let targets = auxRegister + [target]; ApplyToEachA(ApplyAnd, Zipped3(controls1, controls2, targets)); } }} (adsbygoogle = window.adsbygoogle || []).push({});after-content-x4"},{"@context":"http:\/\/schema.org\/","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"item":{"@id":"https:\/\/wiki.edu.vn\/en\/wiki41\/#breadcrumbitem","name":"Enzyklop\u00e4die"}},{"@type":"ListItem","position":2,"item":{"@id":"https:\/\/wiki.edu.vn\/en\/wiki41\/q-sharp-wikipedia\/#breadcrumbitem","name":"Q Sharp – Wikipedia"}}]}]