Exemplo n.º 1
0
        public async Task <ExecutionResult> SetActiveTargetAsync(IChannel channel, string targetId, CancellationToken?cancellationToken = default)
        {
            if (ActiveWorkspace == null || AvailableProviders == null)
            {
                channel?.Stderr($"Please call {GetCommandDisplayName("connect")} before setting an execution target.");
                return(AzureClientError.NotConnected.ToExecutionResult());
            }

            var connectionResult = await RefreshConnectionAsync(channel);

            if (connectionResult.Status != ExecuteStatus.Ok)
            {
                return(connectionResult);
            }

            // Validate that this target is valid in the workspace.
            var target = AvailableTargets.FirstOrDefault(t => targetId == t.TargetId);

            if (target == null)
            {
                channel?.Stderr($"Target {targetId} is not available in the current Azure Quantum workspace.");
                channel?.Stdout($"Available execution targets: {ValidExecutionTargetsDisplayText}");
                return(AzureClientError.InvalidTarget.ToExecutionResult());
            }

            // Validate that we know which package to load for this target.
            var executionTarget = AzureExecutionTarget.Create(target);

            if (executionTarget == null)
            {
                channel?.Stderr($"Target {targetId} does not support executing Q# jobs.");
                channel?.Stdout($"Available execution targets: {ValidExecutionTargetsDisplayText}");
                return(AzureClientError.InvalidTarget.ToExecutionResult());
            }

            // Set the active target and load the package.
            ActiveTarget = executionTarget;

            channel?.Stdout($"Loading package {ActiveTarget.PackageName} and dependencies...");
            await References.AddPackage(ActiveTarget.PackageName);

            channel?.Stdout($"Active target is now {ActiveTarget.TargetId}");

            return(AvailableTargets.First(target => target.TargetId == ActiveTarget.TargetId).ToExecutionResult());
        }
Exemplo n.º 2
0
 public AzureExecutionTarget?CreateExecutionTarget(string targetId) =>
 AzureExecutionTarget.Create(targetId);