microsoft/qdk

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
billti/copilot

Branches

Tags

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

Clone

HTTPS

Download ZIP

samples/testing/operations/src/BellState.qs

35lines · modecode

1// Copyright (c) Microsoft Corporation. All rights reserved.
2// Licensed under the MIT License.
3
4namespace BellState {
5 /// # Summary
6 /// Operation that generates all bell states for testing with `dump_operation.py`.
7 ///
8 /// # Input
9 /// ## qs
10 /// Input qubit register
11 ///
12 /// ## choice
13 /// Bell state to construct.
14 /// 0: |Φ+〉(PhiPlus)
15 /// 1: |Φ-〉(PhiMinus)
16 /// 2: |Ψ+〉(PsiPlus)
17 /// 3: |Ψ-〉(PsiMinus)
18
19 operation AllBellStates(qs : Qubit[], choice : Int) : Unit is Ctl + Adj {
20 open Microsoft.Quantum.Convert;
21
22 H(qs[0]);
23 CNOT(qs[0], qs[1]);
24
25 let bitmask = IntAsBoolArray(choice, 2);
26 if bitmask[1] {
27 X(qs[1]);
28 }
29
30 if bitmask[0] {
31 Z(qs[0]);
32 }
33
34 }
35}
36