/// <summary> /// Simulates the entry point. /// </summary> /// <param name="settings">The driver settings.</param> /// <param name="entryPoint">The entry point.</param> /// <param name="parseResult">The command-line parsing result.</param> /// <param name="simulator">The simulator to use.</param> /// <returns>The exit code.</returns> internal static async Task <int> Simulate( DriverSettings settings, IEntryPoint <TIn, TOut> entryPoint, ParseResult parseResult, string simulator) { if (simulator == settings.ResourcesEstimatorName) { var resourcesEstimator = new ResourcesEstimator(); await resourcesEstimator.Run <TCallable, TIn, TOut>(entryPoint.CreateArgument(parseResult)); Console.WriteLine(resourcesEstimator.ToTSV()); } else { var(isCustom, createSimulator) = simulator == settings.QuantumSimulatorName ? (false, () => new QuantumSimulator()) : simulator == settings.ToffoliSimulatorName ? (false, new Func <IOperationFactory>(() => new ToffoliSimulator())) : (true, entryPoint.CreateDefaultCustomSimulator); if (isCustom && simulator != entryPoint.DefaultSimulatorName) { DisplayCustomSimulatorError(simulator); return(1); } await RunSimulator(entryPoint, parseResult, createSimulator); } return(0); }
static void Main(string[] args) { ResourcesEstimator estimator = new ResourcesEstimator(); Adder.Run(estimator).Wait(); Console.WriteLine(estimator.ToTSV()); }
static void _bellTestDoubleQubit() { using (var qsim = new QuantumSimulator()){ var estimator = new ResourcesEstimator(); BellTestTwoQubits.Run(estimator, 1000, Result.Zero).Wait(); System.Console.WriteLine(estimator.ToTSV()); System.Console.WriteLine("Press any key to continue..."); Console.ReadKey(); // Try initial values Result[] initials = new Result[] { Result.Zero, Result.One }; System.Console.WriteLine("** BELL TEST TWO QUBITS **"); foreach (Result initial in initials) { var res = BellTestTwoQubits.Run(qsim, 1000, initial).Result; var(numZeros, numOnes, agree) = res; System.Console.WriteLine( $"Init:{initial,-4} 0s={numZeros,-4} 1s={numOnes,-4} agree={agree, -4}"); } } }
/// <summary> /// Simulates the entry point. /// </summary> /// <param name="settings">The driver settings.</param> /// <param name="entryPoint">The entry point.</param> /// <param name="parseResult">The command-line parsing result.</param> /// <param name="simulator">The simulator to use.</param> /// <returns>The exit code.</returns> internal static async Task <int> Simulate( DriverSettings settings, IEntryPoint <TIn, TOut> entryPoint, ParseResult parseResult, string simulator) { if (simulator == settings.ResourcesEstimatorName) { // Force the explicit load of the QSharp.Core assembly so that the ResourcesEstimator // can discover it dynamically at runtime and override the defined callables. var coreAssemblyName = (from aName in entryPoint.GetType().Assembly.GetReferencedAssemblies() where aName.Name == "Microsoft.Quantum.QSharp.Core" select aName).First(); var coreAssembly = Assembly.Load(coreAssemblyName.FullName); var resourcesEstimator = new ResourcesEstimator(coreAssembly); await resourcesEstimator.Run <TCallable, TIn, TOut>(entryPoint.CreateArgument(parseResult)); Console.WriteLine(resourcesEstimator.ToTSV()); } else { var(isCustom, createSimulator) = simulator == settings.QuantumSimulatorName ? (false, () => new QuantumSimulator()) : simulator == settings.ToffoliSimulatorName ? (false, new Func <IOperationFactory>(() => new ToffoliSimulator())) : (true, entryPoint.CreateDefaultCustomSimulator); if (isCustom && simulator != entryPoint.DefaultSimulatorName) { DisplayCustomSimulatorError(simulator); return(1); } await RunSimulator(entryPoint, parseResult, createSimulator); } return(0); }
static void Main(string[] args) { // Estimate quantum resources. Console.WriteLine("Resource estimation"); Console.WriteLine("-------------------"); var estimator = new ResourcesEstimator(); BellTest.Run(estimator, 1000, Result.Zero).Wait(); Console.WriteLine(estimator.ToTSV()); // Actually run the experiment (assuming the resources are enough). Console.WriteLine(); Console.WriteLine("Experiment"); Console.WriteLine("----------"); using (var qsim = new QuantumSimulator()) { // Try initial values var initials = new Result[] { Result.Zero, Result.One }; foreach (var initial in initials) { var res = BellTest.Run(qsim, 1000, initial).Result; var(numZeros, numOnes, agree) = res; Console.WriteLine( $"Init:{initial,-4} 0s={numZeros,-4} 1s={numOnes,-4} agree={agree,-4}"); } } Console.WriteLine(); Console.WriteLine("Press any key to continue..."); Console.ReadKey(); }
/// <summary> /// Simulates the entry point. /// </summary> /// <param name="entryPoint">The entry point.</param> /// <param name="simulator">The simulator to use.</param> /// <returns>The exit code.</returns> private static async Task <int> Simulate(EntryPoint entryPoint, string simulator) { simulator = DefaultIfShadowed(Constants.SimulatorOptions.First(), simulator, EntryPoint.DefaultSimulator); switch (simulator) { case Constants.ResourcesEstimator: var resourcesEstimator = new ResourcesEstimator(); await entryPoint.Run(resourcesEstimator); Console.WriteLine(resourcesEstimator.ToTSV()); break; default: var(isCustom, createSimulator) = simulator switch { Constants.QuantumSimulator => (false, new Func <IOperationFactory>(() => new QuantumSimulator())), Constants.ToffoliSimulator => (false, new Func <IOperationFactory>(() => new ToffoliSimulator())), _ => (true, EntryPoint.CreateDefaultCustomSimulator) }; if (isCustom && simulator != EntryPoint.DefaultSimulator) { DisplayCustomSimulatorError(simulator); return(1); } await DisplayEntryPointResult(entryPoint, createSimulator); break; } return(0); }
static void estimate(int action) { var estimator = new ResourcesEstimator(); switch (action) { case 6: var res6 = MeasureQBit.Run(estimator, 1000, Result.Zero).Result; break; case 7: var res7 = FlipQBit.Run(estimator, 1000, Result.Zero).Result; break; case 8: var res8 = SuperposeQBit.Run(estimator, 1000, Result.Zero).Result; break; case 9: var res9 = EntangleQBits.Run(estimator, 1000, Result.Zero).Result; break; } System.Console.WriteLine(estimator.ToTSV()); System.Console.WriteLine(""); System.Console.WriteLine("CNOT: The count of CNOT(also known as the Controlled Pauli X gate) gates executed."); System.Console.WriteLine("QubitClifford: The count of any single qubit Clifford and Pauli gates executed."); System.Console.WriteLine("Measure: The count of any measurements executed."); System.Console.WriteLine("R: The count of any single qubit rotations executed, excluding T, Clifford and Pauli gates."); System.Console.WriteLine("T: The count of T gates and their conjugates, including the T gate, T_x = H.T.H, and T_y = Hy.T.Hy, executed."); System.Console.WriteLine("Depth: Depth of the quantum circuit executed by the Q# operation. By default, only T gates are counted in the depth, see depth counter for details."); System.Console.WriteLine("Width: Maximum number of qubits allocated during the execution of the Q# operation."); System.Console.WriteLine("BorrowedWidth: Maximum number of qubits borrowed inside the Q# operation."); }
static void Main(string[] args) { ResourcesEstimator estimator = new ResourcesEstimator(); RunDeutschJozsaAlgorithm.Run(estimator).Wait(); Console.WriteLine(estimator.ToTSV()); }
private static void RunResourcesEstimator() { var estimator = new ResourcesEstimator(); Run(estimator); Console.WriteLine(estimator.ToTSV()); }
public static void ResourceEstimator() { ResourcesEstimator sim = new ResourcesEstimator(); ResourceEstTrainModel.Run(sim).Wait(); var stats = sim.ToTSV(); System.Console.Write("\n" + stats + "\n"); }
static void Main(string[] args) { var estimator = new ResourcesEstimator(); BellTest.Run(estimator, 1000, Result.Zero).Wait(); System.Console.WriteLine(estimator.ToTSV()); System.Console.WriteLine("Press any key to continue..."); Console.ReadKey(); }
static async Task Main(string[] args) { var rng = new System.Random(); var queryAddress = rng.Next(0, 7); var estimator = new ResourcesEstimator(); var output = await TestImplicitQRAM.Run(estimator, queryAddress); // Print out a table of required resources, using the // ToTSV method of the ResourcesEstimator. Console.WriteLine(estimator.ToTSV()); }
static void Main(string[] args) { // using (var qsim = new QuantumSimulator()) // { // //HelloQ.Run(qsim, int.MaxValue, int.MaxValue).Wait(); // TooManyQubits.Run(qsim).Wait(); // } var tsim = new ToffoliSimulator(qubitCount: 500000); TooManyQubits.Run(tsim).Wait(); var estimator = new ResourcesEstimator(); TeleportClassicalMessage.Run(estimator, false).Wait(); var data = estimator.Data; Console.WriteLine(estimator.ToTSV()); }
static void Main(string[] args) { var estimator = new ResourcesEstimator(); BellTest.Run(estimator, 1000, Result.Zero).Wait(); System.Console.WriteLine(estimator.ToTSV()); /*using (var qsim = new QuantumSimulator()) * { * Result[] initials = new Result[] { Result.Zero, Result.One }; * foreach(Result initial in initials) * { * var res = BellTest.Run(qsim, 1000, initial).Result; * var (numZeros, numOnes, agree) = res; * System.Console.WriteLine( * $"Init:{initial,-4} 0s={numZeros,-4} 1s={numOnes,-4} agree={agree,-4}"); * } * }*/ System.Console.WriteLine("Press any key to continue..."); Console.ReadKey(); }
static void Main(string[] args) { var qsim = new ResourcesEstimator(); BellTest.Run(qsim, 1000, Result.Zero).Wait(); System.Console.WriteLine(qsim.ToTSV()); //using (var qsim = new QuantumSimulator()) //{ // //Try initial values // Result[] initials = new Result[] { Result.Zero, Result.One }; // foreach (Result initial in initials) // { // var res = BellTest.Run(qsim, 1000, initial).Result; // var (numZeroes, numOnes, agree) = res; // System.Console.WriteLine($"Init:{initial,-4} 0s={numZeroes,-4} 1s={numOnes,-4} agree={agree, -4}"); // } //} System.Console.WriteLine("Press any key to continue..."); Console.ReadKey(); }
static void Main(string[] args) { using (var qsim = new QuantumSimulator()) { Console.WriteLine($"Running Bell state experiment"); 100.Times(() => { BellStateExperiment.Run(qsim).Wait(); }); Console.WriteLine($"Running GHZ state experiment"); 100.Times(() => { GHZStateExperiment.Run(qsim, 5).Wait(); }); Console.WriteLine($"Running Teleport experiment"); var totalZeroes = 0; 500.Times(() => { var result = TeleportExperiment.Run(qsim).Result; Console.Write(result ? "1" : "0"); if (!result) { totalZeroes++; } }); Console.WriteLine(); Console.WriteLine($"Got {totalZeroes} zeroes."); Console.WriteLine($"Running Grover experiment"); var secret = GroverAND.Run(qsim).Result; Console.WriteLine($"Found element {secret}"); } var est = new ResourcesEstimator(); GroverAND.Run(est).Wait(); Console.WriteLine(est.ToTSV()); }
public void ToTSVTest() { var sim = new ResourcesEstimator(); VerySimpleEstimate.Run(sim).Wait(); var data = sim.ToTSV(); Console.WriteLine(data); Assert.NotNull(data); var rows = data.Split('\n'); Assert.Equal(10, rows.Length); var cols = rows[0].Split('\t'); Assert.Equal("Metric", cols[0].Trim()); Assert.Equal(3, cols.Length); var cliffords = rows.First(r => r.StartsWith("QubitClifford")).Split('\t'); Assert.Equal(3, cliffords.Length); Assert.Equal("2", cliffords[1]); }
static void Main(string[] args) { var sim = new ResourcesEstimator(); var evaluationPoints = new QArray <double>( new double[] { 0 } ); var polynomialCoefficients = new QArray <double>( new double[] { 0.9992759725166501, -0.16566707016968898, 0.007958079331694682, -0.0001450780334861007 } ); var odd = true; var even = false; Debug.Assert(!(odd && even)); System.Console.Write($"Resource counting for P(x) = {polynomialCoefficients[0]}"); if (odd) { System.Console.Write("*x"); } for (int d = 1; d < polynomialCoefficients.Length; ++d) { System.Console.Write($" + {polynomialCoefficients[d]}*" + $"x^{d + (odd ? d+1 : 0) + (even ? d : 0)}"); } System.Console.Write(".\n"); int pointPos = 3; int numBits = 32; var res = EvaluatePolynomial.Run(sim, polynomialCoefficients, evaluationPoints, numBits, pointPos, odd, even).Result; System.Console.WriteLine(sim.ToTSV()); }
static void Main(string[] args) { #region Parameters of Operation // filename of the molecule to be emulated // var FILENAME = "h2_2_sto6g_1.0au.yaml"; var FILENAME = "h4_sto6g_0.000.yaml"; // var FILENAME = "h20_nwchem.yaml"; // use this state provided in the YAML. var STATE = "|G>"; // the margin of error to use when approximating the expected value var MOE = 0.1; // precision to iterate over with the state preparation gate // the number of trials is directly proportional to this constant's inverse // the gate will be applying a transform of the form (2 pi i \phi) where \phi // varies by the precision specified below var ANGULAR_PRECISION = 0.01; Console.WriteLine($"STATE: {STATE} | MOE: {MOE} | PRECISION: {ANGULAR_PRECISION}"); #endregion #region Creating the Hamiltonian and JW Terms // create the first hamiltonian from the YAML File var hamiltonian = FermionHamiltonian.LoadFromYAML($@"{FILENAME}").First(); // convert the hamiltonian into it's JW Encoding var JWEncoding = JordanWignerEncoding.Create(hamiltonian); var data = JWEncoding.QSharpData(STATE); // Console.WriteLine("----- Print Hamiltonian"); // Console.Write(hamiltonian); // Console.WriteLine("----- End Print Hamiltonian \n"); #endregion #region Hybrid Quantum/Classical accelerator // Feed created state and hamiltonian terms to VQE Console.WriteLine("----- Begin VQE Simulation"); //var N = 10; // number of qubits, calculate from data??? //var oneReal = (1.0, 0.0); //var inputCoeffs = new ComplexPolar[N]; //for (int i = 0; i < Length(inputCoeffs) - 1; i++) // { // inputCoeffs[i] = oneReal; // } ResourcesEstimator estimator = new ResourcesEstimator(); Simulate.Run(estimator, data, 1.0, MOE).Wait(); //Aux.Run(estimator).Wait(); var configCNOT = new QCTraceSimulatorConfiguration(); configCNOT.useDepthCounter = true; configCNOT.gateTimes[PrimitiveOperationsGroups.CNOT] = 1.0; configCNOT.gateTimes[PrimitiveOperationsGroups.Measure] = 0.0; configCNOT.gateTimes[PrimitiveOperationsGroups.QubitClifford] = 0.0; configCNOT.gateTimes[PrimitiveOperationsGroups.R] = 0.0; configCNOT.gateTimes[PrimitiveOperationsGroups.T] = 0.0; var traceSimCNOT = new QCTraceSimulator(configCNOT); Simulate.Run(traceSimCNOT, data, 1.0, MOE).Wait(); double cnotDepth = traceSimCNOT.GetMetric <Simulate>(DepthCounter.Metrics.Depth); var configT = new QCTraceSimulatorConfiguration(); configT.useDepthCounter = true; configT.gateTimes[PrimitiveOperationsGroups.CNOT] = 0.0; configT.gateTimes[PrimitiveOperationsGroups.Measure] = 0.0; configT.gateTimes[PrimitiveOperationsGroups.QubitClifford] = 0.0; configT.gateTimes[PrimitiveOperationsGroups.R] = 0.0; configT.gateTimes[PrimitiveOperationsGroups.T] = 1.0; var traceSimT = new QCTraceSimulator(configT); Simulate.Run(traceSimT, data, 1.0, MOE).Wait(); double tDepth = traceSimT.GetMetric <Simulate>(DepthCounter.Metrics.Depth); var configClifford = new QCTraceSimulatorConfiguration(); configClifford.useDepthCounter = true; configClifford.gateTimes[PrimitiveOperationsGroups.CNOT] = 0.0; configClifford.gateTimes[PrimitiveOperationsGroups.Measure] = 0.0; configClifford.gateTimes[PrimitiveOperationsGroups.QubitClifford] = 1.0; configClifford.gateTimes[PrimitiveOperationsGroups.R] = 0.0; configClifford.gateTimes[PrimitiveOperationsGroups.T] = 0.0; var traceSimClifford = new QCTraceSimulator(configClifford); Simulate.Run(traceSimClifford, data, 1.0, MOE).Wait(); double cliffordDepth = traceSimClifford.GetMetric <Simulate>(DepthCounter.Metrics.Depth); Console.WriteLine(estimator.ToTSV()); Console.WriteLine($"CNOT depth is {cnotDepth}"); Console.WriteLine($"T depth is {tDepth}"); Console.WriteLine($"Clifford depth is {cliffordDepth}"); #endregion #region Classical update scheme // Determine how to update the starting state using classical methods #endregion }