microsoft/qdk
Publicmirrored from https://github.com/microsoft/qdkAvailable
katas/content/deutsch_jozsa/examples/OracleImplementationDemo.qs
38lines · modecode
| 1 | namespace Kata { |
| 2 | open Microsoft.Quantum.Diagnostics; |
| 3 | open Microsoft.Quantum.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 | } |