microsoft/qdk

Public

mirrored from https://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/OracleConverterDemo.qs

50lines · modecode

1namespace Kata {
2 open Microsoft.Quantum.Diagnostics;
3 open Microsoft.Quantum.Arrays;
4
5 @EntryPoint()
6 operation OracleConverterDemo () : Unit {
7 use register = Qubit[3];
8 ApplyToEachA(H, register);
9
10 Message("The equal superposition state:");
11 DumpMachine();
12
13 // Apply the phase oracle `IsSeven_PhaseOracle`
14 IsSeven_PhaseOracle(register);
15
16 Message("The state after applying the phase oracle IsSeven_PhaseOracle:");
17 DumpMachine();
18 ResetAll(register);
19
20 ApplyToEachA(H, register);
21
22 // Apply the marking oracle `IsSeven_MarkingOracle` as a phase oracle
23 ApplyMarkingOracleAsPhaseOracle(IsSeven_MarkingOracle, register);
24
25 Message("The state after applying the converted marking oracle IsSeven_MarkingOracle:");
26 DumpMachine();
27 ResetAll(register);
28 }
29
30 operation IsSeven_PhaseOracle(x : Qubit[]) : Unit is Adj + Ctl {
31 Controlled Z(Most(x), Tail(x));
32 }
33
34 operation IsSeven_MarkingOracle(x : Qubit[], y : Qubit) : Unit is Adj + Ctl {
35 Controlled X(x, y);
36 }
37
38 operation ApplyMarkingOracleAsPhaseOracle(
39 markingOracle : ((Qubit[], Qubit) => Unit is Adj + Ctl),
40 qubits : Qubit[])
41 : Unit is Adj + Ctl {
42 use minus = Qubit();
43 within {
44 X(minus);
45 H(minus);
46 } apply {
47 markingOracle(qubits, minus);
48 }
49 }
50}
51