/// <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);
        }
Exemple #2
0
        /// <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);
        }