최근 수정 시각 : 2025-04-07 03:20:30

Q#


[include(틀:링크시 주의, 링크=Q\ 또는 # 또는 Q#)]
[[프로그래밍 언어|'''프로그래밍 언어
{{{#!wiki style="font-family: Times New Roman, serif; display: inline;"
]]
{{{#!wiki style="min-height: calc(1.5em + 5px); margin: 0 -10px -5px"
{{{#!wiki style="display: inline-table; min-width: 40%; min-height: calc(1.5em + 5px)"
{{{#!folding [ 목록 펼치기 · 접기 ]
{{{#!wiki style="margin: -5px -1px"
<colbgcolor=royalblue><colcolor=#fff> ※ 나무위키에 등재된 프로그래밍 언어 목록
AActionScript · Ada · Agda · ALGOL · APL · awk
BBASIC · Befunge · Brainfuck
CC · C# · C++ · Carbon · Chef · Clojure · COBOL · CoffeeScript · Coq · Crystal
DD · Dart
EElixir · Elm · emojicode · Erlang · ETA
FF# · Forth · Fortran
GGNU Octave · Go · Groovy
HHaskell · HolyC · HQ9+ · HRON
I
JJava · JavaScript · Julia
KKotlin · Krait
LLean · LISP · Lua
MMalbolge · MATLAB · Max · Mojo · Moonlight
NNim · Nix
OOberon · Objective-C · OCaml · Ook!
PPascal · Perl · PHP · Processing · Prolog · Python
QQ#
RR · Racket · Raku · ReasonML · Ruby · Rust
SScala · Scheme · Scratch · sed · Shakespeare · Shell Script · Smalltalk · Swift
TTypeScript
UUdon
VVisual Basic · Visual Basic .NET · Visual Basic for Applications · vvvv
WWave · Whitespace
X
Y
ZZenScript · Zig
한글누리 · 씨앗 · 아희 · 약속 · 엄랭 · 엔트리 · 창조}}}}}}}}}{{{#!wiki style="display: inline-table; min-width: 40%; min-height: calc(1.5em + 5px)"
{{{#!folding [ 순위 펼치기 · 접기 ]
{{{#!wiki style="margin: -5px -1px -10px"
{{{#!wiki style="min-height: calc(1.5em + 5px); margin: 0 -10px -5px"
{{{#!wiki style="display: inline-table; min-width: 25%; min-height: calc(1.5em + 5px)"
{{{#!folding [ IEEE Spectrum 2024 ]
{{{#!wiki style="margin: -5px -1px"
<tablewidth=100%><tablebgcolor=transparent><colbgcolor=#11a500><colcolor=#fff> 스펙트럼 부문 상위 10개 프로그래밍 언어 <colbgcolor=#ff1100><colcolor=#fff> 직업 부문 상위 10개 프로그래밍 언어
1 Python 1 SQL
2 Java 2 Python
3 JavaScript 3 Java
4 C++ 4 TypeScript
5 TypeScript 5 SAS
6 SQL 6 JavaScript
7 C# 7 C#
8 Go 8 HTML
9 C 9 Shell
10 HTML 10 C++ }}}}}}}}}{{{#!wiki style="display: inline-table; min-width: 25%; min-height: calc(1.5em + 5px)"
{{{#!folding [ Stack Overflow 2024 ]
{{{#!wiki style="margin: -5px -1px"
<colbgcolor=#ffa500><colcolor=#fff> 2024년 Stackoverflow 설문조사 상위 25개 프로그래밍 언어
1 JavaScript <colbgcolor=#ffa500><colcolor=#fff> 14 Rust
2 HTML & CSS 15 Kotlin
3 Python 16 Lua
4 SQL 17 Dart
5 TypeScript 18 어셈블리어
6 Bash 19 Ruby
7 Java 20 Swift
8 C# 21 R
9 C++ 22 Visual Basic
10 C 23 MATLAB
11 PHP 24 VBA
12 PowerShell 25 Groovy
13 Go }}}}}}}}}{{{#!wiki style="display: inline-table; min-width: 25%; min-height: calc(1.5em + 5px)"
{{{#!folding [ TIOBE 2025 ]
{{{#!wiki style="margin: -5px -1px"
<colbgcolor=#2777c2><colcolor=#fff> 2025년 2월 TIOBE 검색어 점유율 상위 20개 프로그래밍 언어
1 Python <colbgcolor=#2777c2><colcolor=#fff> 11 Fortran
2 C++ 12 Scratch
3 Java 13 Rust
4 C 14 PHP
5 C# 15 R
6 JavaScript 16 MATLAB
7 SQL 17 Assembly language
8 Go 18 COBOL
9 Delphi / Object Pascal 19 Ruby
10 Visual Basic 20 Prolog }}}}}}}}}{{{#!wiki style="display: inline-table; min-width: 25%; min-height: calc(1.5em + 5px)"
{{{#!folding [ PYPL 2025 ]
{{{#!wiki style="margin: -5px -1px -10px"
<colbgcolor=green><colcolor=#fff> 2025년 3월 PYPL 검색어 점유율 상위 20개 프로그래밍 언어
1 Python <colbgcolor=green><colcolor=#fff> 11 Swift
2 Java 12 Go
3 JavaScript 13 Kotlin
4 C/C++ 14 MATLAB
5 C# 15 Ada
6 R 16 Dart
7 PHP 17 Ruby
8 Rust 18 Lua
9 TypeScript 19 PowerShell
10 Objective-C 20 VBA }}}}}}}}}}}} }}}}}}}}}}}}
분류:프로그래밍 언어 · 프로그래밍 언어 목록 · 언어별 예제 · 틀:프로그래밍 언어 문법

파일:Microsoft 로고.svg파일:Microsoft 로고 화이트.svg
{{{#!wiki style="margin:0 -10px -5px; min-height:calc(1.5em + 5px); word-break:keep-all"
{{{#!folding [ 펼치기 · 접기 ]
{{{#!wiki style="margin:-6px -1px -11px"
<colbgcolor=#393939,#737373><colcolor=#fff>제품군
하드​웨어Surface · Xbox · HoloLens · PixelSense · Zune · Pluton · IVAS
소프트​웨어Windows · Office · Edge · Media Player · Hyper-V · Defender · Visual Studio Code · Visual Studio · Windows Terminal · Microsoft Store · Xbox App · PowerToys · Internet Explorer · MS-DOS · Windows Movie Maker · Autoruns · Clipchamp
서비스Microsoft Azure · OneDrive · Microsoft Copilot · Bing · LinkedIn · Microsoft Docs · Skype · MSN · 정품인증 · Xbox Game Pass · Xbox Cloud Gaming · Xbox network · SwiftKey
관련 기술ASF · ASP · Blazor · COM · DCOM · DirectX · 파일 시스템(FAT · NTFS · ReFS) · 언어 서버 프로토콜 · MFC · .NET(.NET Core · .NET Standard · C# · F# · Visual Basic .NET · #) · 라이브러리(Windows Forms · WPF · UWP · Xamarin · .NET MAUI · ASP.NET · ML.NET · XNA) · OLE · Silverlight · Visual Basic · VBA · WASAPI · Windows 커널 · Windows 디자인 · Windows API · Windows Runtime(UWP · WinUI) · WMA · WMV · 하복 엔진 · SAMI · PowerShell · Windows Modern Standby
산하 계열사 및 사업부GitHub · .NET Foundation · Microsoft Gaming · LinkedIn
관련 인물빌 게이츠(은퇴) · 폴 앨런(은퇴) · 스티브 발머(퇴사) · 게이브 뉴웰(퇴사) · 마이크 이바라(퇴사)
사티아 나델라 · 필 스펜서 · 브래드 스미스
기타제니맥스 미디어 인수 · 액티비전 블리자드 인수 · 시작 메뉴 · 빌 게이츠의 굴욕
관련 틀365 제품군 · 하드웨어 제품군 · Surface 제품군 · Windows 제품군}}}}}}}}}


1. 개요2. 역사3. 기능4. 특징
4.1. C#와의 비교4.2. F#와의 비교
5. 예제
5.1. 난수 생성기5.2. 그래프 색 지정 문제
6. 관련 문서7. 외부 링크

1. 개요

파일:QvK4uVpa8lr.jpg
Q#은 2017년에 발표된 양자컴퓨터의 양자 알고리즘을 개발하고 실행하기 위한 Microsoft의 오픈 소스 프로그래밍 언어이다.

2. 역사

2017년 9월 26일 Microsoft Ignite Keynote에서 Microsoft양자 컴퓨터를 위해 특별히 설계된 새로운 프로그래밍 언어를 출시할 것이라고 발표했다. 2017년 12월 11일에는 Microsoft는 .NET 프로젝트의 SDK인 Quantum Development Kit(QDK)의 일부로 Q#을 출시했다. 이후 Build 2019빌드에서 Microsoft는 Q# 컴파일러와 시뮬레이터를 포함한 Quantum Development Kit를 오픈소싱한다고 발표했다.

3. 기능

Q#의 주요 기능은 양자 알고리즘용 큐비트를 만들고 사용하는 기능이다. 결과적으로 Q#의 가장 두드러진 기능 중 일부는 각각 Controlled NOT 게이트 및 Hadamard 게이트를 통해 큐비트에 중첩 및 중첩제어를 도입 하는 기능과 Tofffoli Gates , Pauli X, Y, Z 게이트 등을 포함하는 기능이다.

결국 Q#과 함께 제공될 하드웨어 스택은 큐비트를 토폴로지 큐비트로 구현할 것으로 예상된다. 현재 Quantum Development Kit와 함께 제공되는 양자 시뮬레이터는 사용자 컴퓨터에서 최대 32큐비트를 처리하고 Azure에서는 최대 40큐비트를 처리할 수 있다.


Quantum Development Kit에서 제공하는 기능들은 다음과 같다.
  • Azure Quantum 서비스에 Qiskit[1] 및 Cirq 애플리케이션을 제출하는 Python 패키지
  • Q# 프로그래밍 언어 및 라이브러리
  • Jupyter Notebook에서 Q#을 실행하기 위한 IQ# 커널
  • Azure Quantum 서비스를 관리하고 Q# 애플리케이션을 제출하는 Azure CLI 확장
  • Q#을 포함하여 Python 및 .NET 언어용(C#, F#VB.NET) API
  • Visual Studio CodeVisual Studio용 확장

4. 특징

4.1. C#와의 비교

4.2. F#와의 비교

  • 변수는 let또는 mutable을 사용하여 선언
  • 1차 함수
  • open키워드를 사용하여 모듈 가져오기
  • 데이터 유형은 변수 이름 뒤에 선언
  • 범위 연산자 ..
  • for … in루프
  • 모든 작업/함수는 void가 아닌 빈 튜플 반환
  • 레코드 데이터 유형의 정의 (type대신 newtype 키워드 사용)

5. 예제

5.1. 난수 생성기

이 예제는 Microsoft의 공식 문서 중 연습-양자 난수 생성기 만들기에서 가져왔습니다.

namespace QuantumRNG {

    open Microsoft.Quantum.Canon;
    open Microsoft.Quantum.Intrinsic;
    open Microsoft.Quantum.Measurement;
    open Microsoft.Quantum.Math;
    open Microsoft.Quantum.Convert;

    operation GenerateRandomBit() : Result {
        // Allocate a qubit.
        use q = Qubit();
        // Put the qubit to superposition.
        H(q);
        // It now has a 50% chance of being measured 0 or 1.
        // Measure the qubit value.
        return M(q);
    }

    operation SampleRandomNumberInRange(max : Int) : Int {
        mutable output = 0; 
        repeat {
            mutable bits = []; 
            for idxBit in 1..BitSizeI(max) {
                set bits += [GenerateRandomBit()]; 
            }
            set output = ResultArrayAsInt(bits);
        } until (output <= max);
        return output;
    }

    @EntryPoint()
    operation SampleRandomNumber() : Int {
        let max = 50;
        Message($"Sampling a random number between 0 and {max}: ");
        return SampleRandomNumberInRange(max);
    }
}

5.2. 그래프 색 지정 문제

이 예제는 Microsoft의 공식 문서 중 연습 - Grover 알고리즘을 구현하여 그래프 색 지정 문제 해결에서 가져왔습니다.

namespace ExploringGroversSearchAlgorithm {
    open Microsoft.Quantum.Measurement;
    open Microsoft.Quantum.Math;
    open Microsoft.Quantum.Arrays;
    open Microsoft.Quantum.Canon;
    open Microsoft.Quantum.Convert;
    open Microsoft.Quantum.Diagnostics;
    open Microsoft.Quantum.Intrinsic;


    operation MarkColorEquality(c0 : Qubit[], c1 : Qubit[], target : Qubit) : Unit is Adj+Ctl {
        within {
            for (q0, q1) in Zipped(c0, c1) {
                CNOT(q0, q1);
            }
        } apply {
            (ControlledOnInt(0, X))(c1, target);
        }
    }


    operation MarkValidVertexColoring(
        edges : (Int, Int)[], 
        colorsRegister : Qubit[], 
        target : Qubit
    ) : Unit is Adj+Ctl {
        let nEdges = Length(edges);
        let colors = Chunks(2, colorsRegister);
        use conflictQubits = Qubit[nEdges];
        within {
            for ((start, end), conflictQubit) in Zipped(edges, conflictQubits) {
                MarkColorEquality(colors[start], colors[end], conflictQubit);
            }
        } apply {
            (ControlledOnInt(0, X))(conflictQubits, target);
        }
    }


    operation ApplyMarkingOracleAsPhaseOracle(
        markingOracle : ((Qubit[], Qubit) => Unit is Adj), 
        register : Qubit[]
    ) : Unit is Adj {
        use target = Qubit();
        within {
            X(target);
            H(target);
        } apply {
            markingOracle(register, target);
        }
    }


    operation RunGroversSearch(register : Qubit[], phaseOracle : ((Qubit[]) => Unit is Adj), iterations : Int) : Unit {
        ApplyToEach(H, register);
        
        for _ in 1 .. iterations {
            phaseOracle(register);
            within {
                ApplyToEachA(H, register);
                ApplyToEachA(X, register);
            } apply {
                Controlled Z(Most(register), Tail(register));
            }
        }
    }


    @EntryPoint()
    operation SolveGraphColoringProblem() : Unit {
        // Graph description: hardcoded from the example.
        let nVertices = 5;
        let edges = [(0, 1), (0, 2), (0, 3), (1, 2), (1, 3), (2, 3), (3, 4)];

        // Define the oracle that implements this graph coloring.
        let markingOracle = MarkValidVertexColoring(edges, _, _);
        let phaseOracle = ApplyMarkingOracleAsPhaseOracle(markingOracle, _);

        // Define the parameters of the search.
        
        // Each color is described using 2 bits (or qubits).
        let nQubits = 2 * nVertices;

        // The search space is all bit strings of length nQubits.
        let searchSpaceSize = 2 ^ (nQubits);

        // The number of solutions is the number of permutations of 4 colors (over the first four vertices) = 4!
        // multiplied by 3 colors that vertex 4 can take in each case.
        let nSolutions = 72;

        // The number of iterations can be computed using a formula.
        let nIterations = Round(PI() / 4.0 * Sqrt(IntAsDouble(searchSpaceSize) / IntAsDouble(nSolutions)));

        mutable answer = new Bool[nQubits];
        use (register, output) = (Qubit[nQubits], Qubit());
        mutable isCorrect = false;
        repeat {
            RunGroversSearch(register, phaseOracle, nIterations);
            let res = MultiM(register);
            // Check whether the result is correct.
            markingOracle(register, output);
            if (MResetZ(output) == One) {
                set isCorrect = true;
                set answer = ResultArrayAsBoolArray(res);
            }
            ResetAll(register);
        } until (isCorrect);
        // Convert the answer to readable format (actual graph coloring).
        let colorBits = Chunks(2, answer);
        Message("The resulting graph coloring:");
        for i in 0 .. nVertices - 1 {
            Message($"Vertex {i} - color {BoolArrayAsInt(colorBits[i])}");
        }
    }
}

6. 관련 문서

7. 외부 링크


[1] IBM에서 개발한 Python 기반 양자컴퓨팅 언어이다.