microsoft/qdk

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
copilot/replace-qsharp-with-qdk-python-tests

Branches

Tags

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

Clone

HTTPS

Download ZIP

katas/content/deutsch_jozsa/examples/OracleImplementationDemo.qs

38lines · modecode

1namespace Kata {
2 import Std.Diagnostics.*;
3 import Std.Math.*;
4
5 operation PhaseOracle_Zero(x : Qubit[]) : Unit {
6 // Do nothing...
7 }
8
9 operation PhaseOracle_One(x : Qubit[]) : Unit {
10 // Apply a global phase of -1
11 R(PauliI, 2.0 * PI(), x[0]);
12 }
13
14 operation PhaseOracle_Xmod2(x : Qubit[]) : Unit {
15 let N = Length(x);
16 // Array elements are indexed 0 through Length(x) - 1, inclusive.
17 Z(x[N - 1]);
18 }
19
20 @EntryPoint()
21 operation OracleImplementationDemo() : Unit {
22 use qs = Qubit[2];
23 Ry(2.0 * ArcCos(0.5), qs[0]);
24 Ry(2.0 * ArcCos(0.6), qs[1]);
25 Message("The state before oracle application:");
26 DumpMachine();
27
28 // Apply the oracle.
29 // Experiment with using other oracles to see their behavior!
30 // (Note that the -1 global phase might not show up in simulation)
31 PhaseOracle_Xmod2(qs);
32
33 Message("The state after oracle application:");
34 DumpMachine();
35
36 ResetAll(qs);
37 }
38}
39