public void TestJobExecutionWithArrayInput() { var services = Startup.CreateServiceProvider("Workspace"); var azureClient = (AzureClient)services.GetService <IAzureClient>(); // connect var targets = ExpectSuccess <IEnumerable <TargetStatusInfo> >(ConnectToWorkspaceAsync(azureClient)); Assert.IsFalse(targets.Any()); // add a target var azureWorkspace = azureClient.ActiveWorkspace as MockAzureWorkspace; Assert.IsNotNull(azureWorkspace); azureWorkspace?.AddProviders("ionq"); // set the active target var target = ExpectSuccess <TargetStatusInfo>(azureClient.SetActiveTargetAsync(new MockChannel(), "ionq.simulator")); Assert.AreEqual("ionq.simulator", target.TargetId); // execute the job and verify that the results are retrieved successfully var submissionContext = new AzureSubmissionContext() { OperationName = "Tests.qss.SayHelloWithArray", InputParameters = AbstractMagic.ParseInputParameters("{\"names\": [\"foo\", \"bar\"]}"), ExecutionTimeout = 5, ExecutionPollingInterval = 1, }; var histogram = ExpectSuccess <Histogram>(azureClient.ExecuteJobAsync(new MockChannel(), submissionContext, CancellationToken.None)); Assert.IsNotNull(histogram); }
public async Task FromWorkspace() { var entryPointGenerator = Init("Workspace"); var entryPoint = entryPointGenerator.Generate("Tests.qss.HelloAgain", null); Assert.IsNotNull(entryPoint); var job = await entryPoint.SubmitAsync( new MockQuantumMachine(), new AzureSubmissionContext() { InputParameters = AbstractMagic.ParseInputParameters("count=2 name=\"test\"") } ); Assert.IsNotNull(job); }
public static AzureSubmissionContext Parse(string inputCommand) { var inputParameters = AbstractMagic.ParseInputParameters(inputCommand, firstParameterInferredName: ParameterNameOperationName); var operationName = inputParameters.DecodeParameter <string>(ParameterNameOperationName); var jobName = inputParameters.DecodeParameter <string>(ParameterNameJobName, defaultValue: operationName); var shots = inputParameters.DecodeParameter <int>(ParameterNameShots, defaultValue: DefaultShots); var timeout = inputParameters.DecodeParameter <int>(ParameterNameTimeout, defaultValue: DefaultExecutionTimeoutInSeconds); var pollingInterval = inputParameters.DecodeParameter <int>(ParameterNamePollingInterval, defaultValue: DefaultExecutionPollingIntervalInSeconds); return(new AzureSubmissionContext() { FriendlyName = jobName, Shots = shots, OperationName = operationName, InputParameters = inputParameters, ExecutionTimeout = timeout, ExecutionPollingInterval = pollingInterval, }); }
public void TestJobSubmission() { var services = Startup.CreateServiceProvider("Workspace"); var azureClient = (AzureClient)services.GetService <IAzureClient>(); var submissionContext = new AzureSubmissionContext(); // not yet connected ExpectError(AzureClientError.NotConnected, azureClient.SubmitJobAsync(new MockChannel(), submissionContext, CancellationToken.None)); // connect var targets = ExpectSuccess <IEnumerable <TargetStatusInfo> >(ConnectToWorkspaceAsync(azureClient)); Assert.IsFalse(targets.Any()); // no target yet ExpectError(AzureClientError.NoTarget, azureClient.SubmitJobAsync(new MockChannel(), submissionContext, CancellationToken.None)); // add a target var azureWorkspace = azureClient.ActiveWorkspace as MockAzureWorkspace; Assert.IsNotNull(azureWorkspace); azureWorkspace?.AddProviders("ionq"); // set the active target var target = ExpectSuccess <TargetStatusInfo>(azureClient.SetActiveTargetAsync(new MockChannel(), "ionq.simulator")); Assert.AreEqual("ionq.simulator", target.TargetId); // no operation name specified ExpectError(AzureClientError.NoOperationName, azureClient.SubmitJobAsync(new MockChannel(), submissionContext, CancellationToken.None)); // specify an operation name, but have missing parameters submissionContext.OperationName = "Tests.qss.HelloAgain"; ExpectError(AzureClientError.JobSubmissionFailed, azureClient.SubmitJobAsync(new MockChannel(), submissionContext, CancellationToken.None)); // specify input parameters and verify that the job was submitted submissionContext.InputParameters = AbstractMagic.ParseInputParameters("count=3 name=\"testing\""); var job = ExpectSuccess <CloudJob>(azureClient.SubmitJobAsync(new MockChannel(), submissionContext, CancellationToken.None)); var retrievedJob = ExpectSuccess <CloudJob>(azureClient.GetJobStatusAsync(new MockChannel(), job.Id)); Assert.AreEqual(job.Id, retrievedJob.Id); }