/// <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); }
/// <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); }
/// <summary> /// Creates a new driver for the entry point. /// </summary> /// <param name="settings">The driver settings.</param> /// <param name="entryPoint">The entry point.</param> public Driver(DriverSettings settings, IEntryPoint <TIn, TOut> entryPoint) { this.settings = settings; this.entryPoint = entryPoint; SimulatorOption = new OptionInfo <string>( settings.SimulatorOptionAliases, entryPoint.DefaultSimulatorName, "The name of the simulator to use.", suggestions: new[] { settings.QuantumSimulatorName, settings.ToffoliSimulatorName, settings.ResourcesEstimatorName, entryPoint.DefaultSimulatorName }); }
/// <summary> /// Creates a new driver for the entry point. /// </summary> /// <param name="settings">The driver settings.</param> /// <param name="entryPoint">The entry point.</param> public Driver(DriverSettings settings, IEntryPoint <TIn, TOut> entryPoint) { this.settings = settings; this.entryPoint = entryPoint; SimulatorOption = new OptionInfo <string>( settings.SimulatorOptionAliases, entryPoint.DefaultSimulatorName, "The name of the simulator to use.", suggestions: new[] { settings.QuantumSimulatorName, settings.ToffoliSimulatorName, settings.ResourcesEstimatorName, entryPoint.DefaultSimulatorName }); var targetAliases = ImmutableList.Create("--target"); const string targetDescription = "The target device ID."; TargetOption = string.IsNullOrWhiteSpace(entryPoint.DefaultExecutionTarget) ? new OptionInfo <string?>(targetAliases, targetDescription) : new OptionInfo <string?>(targetAliases, entryPoint.DefaultExecutionTarget, targetDescription); }