microsoft/qdk

Public

mirrored fromhttps://github.com/microsoft/qdkAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
copilot/add-link-to-qsharp-application

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

library/core/qir.qs

50lines · modecode

1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4namespace QIR.Runtime {
5 operation __quantum__rt__qubit_allocate() : Qubit {
6 body intrinsic;
7 }
8
9 operation __quantum__rt__qubit_borrow() : Qubit {
10 body intrinsic;
11 }
12
13 operation __quantum__rt__qubit_release(q : Qubit) : Unit {
14 body intrinsic;
15 }
16
17 operation AllocateQubitArray(size : Int) : Qubit[] {
18 if size < 0 {
19 fail "Cannot allocate qubit array with a negative length";
20 }
21 mutable qs = [];
22 for _ in 0..size - 1 {
23 set qs += [__quantum__rt__qubit_allocate()];
24 }
25 qs
26 }
27
28 operation BorrowQubitArray(size : Int) : Qubit[] {
29 if size < 0 {
30 fail "Cannot borrow qubit array with a negative length";
31 }
32 mutable qs = [];
33 for _ in 0..size - 1 {
34 set qs += [__quantum__rt__qubit_borrow()];
35 }
36 qs
37 }
38
39 operation ReleaseQubitArray(qs : Qubit[]) : Unit {
40 for q in qs {
41 __quantum__rt__qubit_release(q);
42 }
43 }
44
45 function __quantum__rt__read_loss(r : Result) : Bool {
46 body intrinsic;
47 }
48
49 export __quantum__rt__qubit_allocate, __quantum__rt__qubit_borrow, __quantum__rt__qubit_release, AllocateQubitArray, BorrowQubitArray, ReleaseQubitArray, __quantum__rt__read_loss;
50}
51