Exemple #1
0
        // This method computes the gate count of simulation a single configuration passed to it.
        internal static async Task <GateCountResults> RunGateCount(JordanWignerEncodingData qSharpData, HamiltonianSimulationConfig config)
        {
            // Creates and configures Trace simulator for accumulating gate counts.
            QCTraceSimulator sim = CreateAndConfigureTraceSim();

            // Create stop-watch to measure the execution time
            Stopwatch stopWatch = new Stopwatch();

            var gateCountResults = new GateCountResults();

            #region Trace Simulator on Trotter step
            if (config.hamiltonianSimulationAlgorithm == HamiltonianSimulationConfig.HamiltonianSimulationAlgorithm.ProductFormula)
            {
                stopWatch.Reset();
                stopWatch.Start();
                var res = await RunTrotterStep.Run(sim, qSharpData);

                stopWatch.Stop();

                gateCountResults = new GateCountResults {
                    Method = "Trotter",
                    ElapsedMilliseconds = stopWatch.ElapsedMilliseconds,
                    RotationsCount      = sim.GetMetric <RunTrotterStep>(PrimitiveOperationsGroupsNames.R),
                    TCount               = sim.GetMetric <RunTrotterStep>(PrimitiveOperationsGroupsNames.T),
                    CNOTCount            = sim.GetMetric <RunTrotterStep>(PrimitiveOperationsGroupsNames.CNOT),
                    TraceSimulationStats = sim.ToCSV()
                };

                // Dump all the statistics to CSV files, one file per statistics collector
                // FIXME: the names here aren't varied, and so the CSVs will get overwritten when running many
                //        different Hamiltonians.
                var gateStats = sim.ToCSV();
                foreach (var x in gateStats)
                {
                    System.IO.File.WriteAllLines($"TrotterGateCountEstimates.{x.Key}.csv", new string[] { x.Value });
                }
            }
            #endregion

            #region Trace Simulator on Qubitization step
            if (config.hamiltonianSimulationAlgorithm == HamiltonianSimulationConfig.HamiltonianSimulationAlgorithm.Qubitization)
            {
                if (config.qubitizationConfig.qubitizationStatePrep == HamiltonianSimulationConfig.QubitizationConfig.QubitizationStatePrep.MinimizeQubitCount)
                {
                    stopWatch.Reset();
                    stopWatch.Start();
                    var res = await RunQubitizationStep.Run(sim, qSharpData);

                    stopWatch.Stop();

                    gateCountResults = new GateCountResults
                    {
                        Method = "Qubitization",
                        ElapsedMilliseconds = stopWatch.ElapsedMilliseconds,
                        RotationsCount      = sim.GetMetric <RunQubitizationStep>(PrimitiveOperationsGroupsNames.R),
                        TCount               = sim.GetMetric <RunQubitizationStep>(PrimitiveOperationsGroupsNames.T),
                        CNOTCount            = sim.GetMetric <RunQubitizationStep>(PrimitiveOperationsGroupsNames.CNOT),
                        TraceSimulationStats = sim.ToCSV()
                    };

                    // Dump all the statistics to CSV files, one file per statistics collector
                    // FIXME: the names here aren't varied, and so the CSVs will get overwritten when running many
                    //        different Hamiltonians.
                    var gateStats = sim.ToCSV();
                    foreach (var x in gateStats)
                    {
                        System.IO.File.WriteAllLines($"QubitizationGateCountEstimates.{x.Key}.csv", new string[] { x.Value });
                    }
                }
            }
            #endregion

            #region Trace Simulator on Optimized Qubitization step
            if (config.hamiltonianSimulationAlgorithm == HamiltonianSimulationConfig.HamiltonianSimulationAlgorithm.Qubitization)
            {
                if (config.qubitizationConfig.qubitizationStatePrep == HamiltonianSimulationConfig.QubitizationConfig.QubitizationStatePrep.MinimizeTGateCount)
                {
                    stopWatch.Reset();
                    stopWatch.Start();

                    // This primarily affects the Qubit count and CNOT count.
                    // The T-count only has a logarithmic dependence on this parameter.
                    var targetError = 0.001;

                    var res = await RunOptimizedQubitizationStep.Run(sim, qSharpData, targetError);

                    stopWatch.Stop();

                    gateCountResults = new GateCountResults
                    {
                        Method = "Optimized Qubitization",
                        ElapsedMilliseconds = stopWatch.ElapsedMilliseconds,
                        RotationsCount      = sim.GetMetric <RunOptimizedQubitizationStep>(PrimitiveOperationsGroupsNames.R),
                        TCount               = sim.GetMetric <RunOptimizedQubitizationStep>(PrimitiveOperationsGroupsNames.T),
                        CNOTCount            = sim.GetMetric <RunOptimizedQubitizationStep>(PrimitiveOperationsGroupsNames.CNOT),
                        TraceSimulationStats = sim.ToCSV()
                    };

                    // Dump all the statistics to CSV files, one file per statistics collector
                    // FIXME: the names here aren't varied, and so the CSVs will get overwritten when running many
                    //        different Hamiltonians.
                    var gateStats = sim.ToCSV();
                    foreach (var x in gateStats)
                    {
                        System.IO.File.WriteAllLines($"OptimizedQubitizationGateCountEstimates.{x.Key}.csv", new string[] { x.Value });
                    }
                }
            }
            #endregion

            return(gateCountResults);
        }
Exemple #2
0
        // This method computes the gate count of simulation a single configuration passed to it.
        internal static async Task <GateCountResults> RunGateCount(
            JordanWignerEncodingData qSharpData, HamiltonianSimulationConfig config,
            string outputFolder = null
            )
        {
            // Creates and configures Trace simulator for accumulating gate counts.
            var sim = CreateAndConfigureTraceSim();

            // Create stop-watch to measure the execution time
            var stopWatch = new Stopwatch();

            var gateCountResults = new GateCountResults();

            #region Trace Simulator on Trotter step
            if (config.HamiltonianSimulationAlgorithm == HamiltonianSimulationAlgorithm.ProductFormula)
            {
                var res = await stopWatch.Measure(async() => await RunTrotterStep.Run(sim, qSharpData));

                gateCountResults = new GateCountResults
                {
                    Method = "Trotter",
                    ElapsedMilliseconds = stopWatch.ElapsedMilliseconds,
                    RotationsCount      = sim.GetMetric <RunTrotterStep>(PrimitiveOperationsGroupsNames.R),
                    TCount               = sim.GetMetric <RunTrotterStep>(PrimitiveOperationsGroupsNames.T),
                    CNOTCount            = sim.GetMetric <RunTrotterStep>(PrimitiveOperationsGroupsNames.CNOT),
                    TraceSimulationStats = sim.ToCSV()
                };

                // Dump all the statistics to CSV files, one file per statistics collector
                // FIXME: the names here aren't varied, and so the CSVs will get overwritten when running many
                //        different Hamiltonians.
                if (outputFolder != null)
                {
                    sim.WriteResultsToFolder(outputFolder, "TrotterGateCountEstimates");
                }
            }
            #endregion

            #region Trace Simulator on Qubitization step
            if (config.HamiltonianSimulationAlgorithm == HamiltonianSimulationAlgorithm.Qubitization)
            {
                if (config.QubitizationConfig.QubitizationStatePrep == QubitizationStatePrep.MinimizeQubitCount)
                {
                    var res = await stopWatch.Measure(async() => await RunQubitizationStep.Run(sim, qSharpData));

                    gateCountResults = new GateCountResults
                    {
                        Method = "Qubitization",
                        ElapsedMilliseconds = stopWatch.ElapsedMilliseconds,
                        RotationsCount      = sim.GetMetric <RunQubitizationStep>(PrimitiveOperationsGroupsNames.R),
                        TCount               = sim.GetMetric <RunQubitizationStep>(PrimitiveOperationsGroupsNames.T),
                        CNOTCount            = sim.GetMetric <RunQubitizationStep>(PrimitiveOperationsGroupsNames.CNOT),
                        TraceSimulationStats = sim.ToCSV(),
                        NormMultipler        = res
                    };

                    // Dump all the statistics to CSV files, one file per statistics collector
                    // FIXME: the names here aren't varied, and so the CSVs will get overwritten when running many
                    //        different Hamiltonians.
                    if (outputFolder != null)
                    {
                        sim.WriteResultsToFolder(outputFolder, "QubitizationGateCountEstimates");
                    }
                }
            }
            #endregion

            #region Trace Simulator on Optimized Qubitization step
            if (config.HamiltonianSimulationAlgorithm == HamiltonianSimulationAlgorithm.Qubitization)
            {
                if (config.QubitizationConfig.QubitizationStatePrep == QubitizationStatePrep.MinimizeTGateCount)
                {
                    // This primarily affects the Qubit count and CNOT count.
                    // The T-count only has a logarithmic dependence on this parameter.
                    var targetError = 0.001;
                    var res         = await stopWatch.Measure(async() => await RunOptimizedQubitizationStep.Run(sim, qSharpData, targetError));

                    stopWatch.Stop();

                    gateCountResults = new GateCountResults
                    {
                        Method = "Optimized Qubitization",
                        ElapsedMilliseconds = stopWatch.ElapsedMilliseconds,
                        RotationsCount      = sim.GetMetric <RunOptimizedQubitizationStep>(PrimitiveOperationsGroupsNames.R),
                        TCount               = sim.GetMetric <RunOptimizedQubitizationStep>(PrimitiveOperationsGroupsNames.T),
                        CNOTCount            = sim.GetMetric <RunOptimizedQubitizationStep>(PrimitiveOperationsGroupsNames.CNOT),
                        TraceSimulationStats = sim.ToCSV(),
                        NormMultipler        = res
                    };

                    // Dump all the statistics to CSV files, one file per statistics collector
                    // FIXME: the names here aren't varied, and so the CSVs will get overwritten when running many
                    //        different Hamiltonians.
                    if (outputFolder != null)
                    {
                        sim.WriteResultsToFolder(outputFolder, "OptimizedQubitizationGateCountEstimates");
                    }
                }
            }
            #endregion

            return(gateCountResults);
        }