최근 수정 시각 : 2025-04-15 21:41:24

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 · AdaT · AgdaTP · ALGOLT · ApexT · APL · awk · AssemblyT
BBASIC
C파일:C언어 로고.svg CT · 파일:C C#T · 파일:C++ 로고.svg C++T · CarbonT · 파일:clojure_logo.png ClojureS · COBOLT · CoffeeScript · Common LispS · CrystalT
D파일:external/upload.wikimedia.org/D_programming_language_logo.png DT · 파일:Dart 심볼.svg DartT
EElixir · 파일:Elm_logo.svg.png elmT · Erlang
F파일:fsharp-logo.png F#T · Factor · 파일:fennel-logo.svg FennelS · 파일:forth.png Forth · FortranT
GGNU Octave · 파일:Go 로고.svg GoT · Groovy
H파일:Haskell 로고 심볼.svg HaskellT · HolyCT
I
J파일:Java 로고.svg JavaT · 파일:JavaScript 로고.svg JavaScript · 파일:julia-dots.svg Julia
K파일:Kotlin 심볼.svg KotlinT · Krait
LLeanTP · 파일:LISP_logo.svg LISPS · 파일:Lua 로고.svg Lua
MMATLAB · MaxV · MojoT · Moonlight
N파일:Nim 왕관 로고.svg NimT · 파일:Nix 로고.svg Nix
OOberonT · Objective-CT · 파일:ocaml.svg OCamlT
PPascalT · Perl · 파일:PHP 로고.svg PHP · Processing · Prolog · 파일:Python 심볼.svg Python
QQ#T
R파일:R 로고.svg R · 파일:racket-logo.svg RacketS · Raku · ReasonMLT · RocqTP · 파일:Ruby 로고.svg Ruby · 파일:Rust 로고.svg파일:Rust 로고 화이트.svg RustT
SSAS · 파일:Scala 로고.png ScalaT · SchemeS · 파일:스크래치(교육 플랫폼) 로고.svg ScratchV · sed · Shell Script · Smalltalk · 파일:Swift 심볼 배경.svg SwiftT
T파일:Typescript_logo_2020.svg TypeScriptT
UUdon
VVisual Basic · Visual Basic .NET · Visual Basic for Applications · vvvvV
WWave
XXSharp
Y
ZZenScript · 파일:Zig 로고마크.svg ZigT
한글누리 · V · 씨앗 · 약속 · 파일:엔트리 아이콘.svg 엔트리V · 창조
T: 정적 타입 프로그래밍 언어 · P: 증명 보조 언어 · S: LISP 방언 및 S-표현식 기반 언어 · V: 시각적 프로그래밍 언어 }}}}}}}}}{{{#!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년 4월 TIOBE 검색어 점유율 상위 20개 프로그래밍 언어
1 Python <colbgcolor=#2777c2><colcolor=#fff> 11 Fortran
2 C++ 12 Scratch
3 C 13 PHP
4 Java 14 R
5 C# 15 Ada
6 JavaScript 16 MATLAB
7 Go 17 Assembly language
8 Visual Basic 18 Rust
9 Delphi / Object Pascal 19 Perl
10 SQL 20 COBOL }}}}}}}}}{{{#!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년 5월 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 Ruby
7 PHP 17 Dart
8 Rust 18 Lua
9 TypeScript 19 VBA
10 Objective-C 20 PowerShell }}}}}}}}}}}} }}}}}}}}}}}}
실행 방식 · 분류 · 언어 목록(분류:프로그래밍 언어 문법) · 언어별 예제 · 틀:프로그래밍 언어 문법 · 틀:난해한 프로그래밍 언어

파일: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 · Nearby Sharing
산하 계열사 및 사업부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 기반 양자컴퓨팅 언어이다.