This repository has been archived by the owner on Jan 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 923
/
Copy pathDriver.cs
46 lines (36 loc) · 1.61 KB
/
Driver.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using Microsoft.Quantum.Simulation.Simulators;
using Microsoft.Quantum.Extensions.Oracles;
namespace Microsoft.Quantum.Samples.OracleEmulation
{
class Driver
{
static void Main(string[] args)
{
// We begin by defining a quantum simulator to be our target machine
using (var qsim = new QuantumSimulator())
{
#region Simple oracles
// Create an oracle from a C# lambda.
// The result is an operation with signature
// (Qubit[], Qubit[]) => Unit
// that can be passed to Q#.
var oracle = EmulatedOracleFactory.Create(qsim, (x, y) => 42 ^ y);
// Provide the definition of an oracle that has been declared in
// Q#, replacing the stub body defined in Operations.qs. This
// way, the `HalfAnswer` oracle is accessible via the
// `OracleEmulation` namespace and does not have to be passed to
// operations depending on it (unlike the oracle created above).
EmulatedOracleFactory.Register<HalfAnswer>(qsim, (x, y) => 21 ^ y);
// Execute the simple oracles and print the results.
RunConstantOracles.Run(qsim, oracle).Wait();
#endregion
#region Emulated arithmetic
// Run the demo for emulated arithmetic.
RunAddOracle.Run(qsim).Wait();
#endregion
}
}
}
}