예제 #1
0
 public async Task <ExecutionResult> ExecuteJobAsync(IChannel channel, AzureSubmissionContext submissionContext, CancellationToken?token)
 {
     LastAction = AzureClientAction.ExecuteJob;
     ExecutedJobs.Add(submissionContext.OperationName);
     JobParams = submissionContext.InputParams;
     return(ExecuteStatus.Ok.ToExecutionResult());
 }
예제 #2
0
        public void TestRuntimeCapabilities()
        {
            var services    = Startup.CreateServiceProvider("Workspace.QPRGen1");
            var azureClient = (AzureClient)services.GetService <IAzureClient>();

            // Choose an operation with measurement result comparison, which should
            // fail to compile on QPRGen0 targets but succeed on QPRGen1 targets
            var submissionContext = new AzureSubmissionContext()
            {
                OperationName = "Tests.qss.CompareMeasurementResult"
            };

            ExpectSuccess <IEnumerable <TargetStatusInfo> >(ConnectToWorkspaceAsync(azureClient));

            // Set up workspace with mock providers
            var azureWorkspace = azureClient.ActiveWorkspace as MockAzureWorkspace;

            Assert.IsNotNull(azureWorkspace);
            azureWorkspace?.AddProviders("ionq", "honeywell");

            // Verify that IonQ job fails to compile (QPRGen0)
            ExpectSuccess <TargetStatusInfo>(azureClient.SetActiveTargetAsync(new MockChannel(), "ionq.mock"));
            ExpectError(AzureClientError.InvalidEntryPoint, azureClient.SubmitJobAsync(new MockChannel(), submissionContext, CancellationToken.None));

            // Verify that Honeywell job can be successfully submitted (QPRGen1)
            ExpectSuccess <TargetStatusInfo>(azureClient.SetActiveTargetAsync(new MockChannel(), "honeywell.mock"));
            var job = ExpectSuccess <CloudJob>(azureClient.SubmitJobAsync(new MockChannel(), submissionContext, CancellationToken.None));

            Assert.IsNotNull(job);
        }
예제 #3
0
        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);
        }
예제 #4
0
        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 <TargetStatus> >(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?.AddMockTargets("ionq.simulator");

            // set the active target
            var target = ExpectSuccess <TargetStatus>(azureClient.SetActiveTargetAsync(new MockChannel(), "ionq.simulator"));

            Assert.AreEqual("ionq.simulator", target.Id);

            // 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 = new Dictionary <string, string>()
            {
                ["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);
        }
예제 #5
0
        public void TestJobExecution()
        {
            var services    = Startup.CreateServiceProvider("Workspace");
            var azureClient = (AzureClient)services.GetService <IAzureClient>();

            // connect
            var targets = ExpectSuccess <IEnumerable <TargetStatus> >(ConnectToWorkspaceAsync(azureClient));

            Assert.IsFalse(targets.Any());

            // add a target
            var azureWorkspace = azureClient.ActiveWorkspace as MockAzureWorkspace;

            Assert.IsNotNull(azureWorkspace);
            azureWorkspace?.AddMockTargets("ionq.simulator");

            // set the active target
            var target = ExpectSuccess <TargetStatus>(azureClient.SetActiveTargetAsync(new MockChannel(), "ionq.simulator"));

            Assert.AreEqual("ionq.simulator", target.Id);

            // execute the job and verify that the results are retrieved successfully
            var submissionContext = new AzureSubmissionContext()
            {
                OperationName   = "Tests.qss.HelloAgain",
                InputParameters = new Dictionary <string, string>()
                {
                    ["count"] = "3", ["name"] = "testing"
                },
                ExecutionTimeout         = 5,
                ExecutionPollingInterval = 1,
            };
            var histogram = ExpectSuccess <Histogram>(azureClient.ExecuteJobAsync(new MockChannel(), submissionContext, CancellationToken.None));

            Assert.IsNotNull(histogram);
        }