microsoft/qdk

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
billt/revert-mimalloc

Branches

Tags

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

Clone

HTTPS

Download ZIP

katas/content/oracles/examples/PhaseOracleAltBit.qs

30lines · modecode

1namespace Kata {
2 open Microsoft.Quantum.Diagnostics;
3
4 // This operation implements the oracle; we will learn how to implement oracles later in the kata
5 operation AlternatingBitPattern_PhaseOracle(x : Qubit[]) : Unit is Adj + Ctl {
6 use q = Qubit();
7 X(q);
8 ApplyControlledOnBitString([false, true, false], Z, x, q);
9 ApplyControlledOnBitString([true, false, true], Z, x, q);
10 X(q);
11 }
12
13 @EntryPoint()
14 operation PhaseOracle_Demo() : Unit {
15 use q = Qubit[3];
16 ApplyToEachA(H, q);
17
18 Message("Starting state (equal superposition of all basis states):");
19 DumpMachine();
20
21 // Apply the oracle
22 AlternatingBitPattern_PhaseOracle(q);
23
24 // Print the resulting state; notice which phases changed
25 Message("State after applying the phase oracle:");
26 DumpMachine();
27
28 ResetAll(q);
29 }
30}
31