Exemple #1
0
    def submit(self, problem: Union[str, Problem]) -> Job:
        """Submits a job to execution to the associated Azure Quantum Workspace.

       :param problem: 
            The Problem to solve. It can be an instance of a Problem, 
            or the URL of an Azure Storage Blob where the serialized version
            of a Problem has been uploaded.
        """
        ## Create a container URL:
        job_id = Job.create_job_id()
        logger.info(f"Submitting job with id: {job_id}")

        container_name = f"job-{job_id}"

        if not self.workspace.storage:
            # No storage account is passed, in this case, get linked account from the service
            container_uri = self.workspace._get_linked_storage_sas_uri(
                container_name)
            container_client = ContainerClient.from_container_url(
                container_uri)
            create_container_using_client(container_client)
            container_uri = azure.quantum.storage.remove_sas_token(
                container_uri)
        else:
            # Storage account is passed, use it to generate a container_uri
            container_uri = azure.quantum.storage.get_container_uri(
                self.workspace.storage, container_name)

        logger.debug(f"Container URI: {container_uri}")

        if isinstance(problem, str):
            name = "Optimization problem"
            problem_uri = problem
        else:
            name = problem.name
            problem_uri = problem.upload(self.workspace,
                                         compress=True,
                                         container_name=container_name,
                                         blob_name="inputData")

        logger.info(
            f"Submitting problem '{name}'. Using payload from: '{problem_uri}'"
        )

        details = JobDetails(id=job_id,
                             name=name,
                             container_uri=container_uri,
                             input_data_format=self.input_data_format,
                             output_data_format=self.output_data_format,
                             input_data_uri=problem_uri,
                             provider_id=self.provider,
                             target=self.target,
                             input_params=self.params)

        logger.debug(f"==> submitting: {details}")
        job = self.workspace.submit_job(Job(self.workspace, details))
        return job
Exemple #2
0
    def list_jobs(self) -> List[Job]:
        client = self._create_jobs_client()
        jobs = client.list()

        result = []
        for j in jobs:
            result.append(Job(self, j))

        return result
Exemple #3
0
    def submit(self,
               problem: Union[str, "Problem"],
               compress: bool = True) -> Job:
        """Submits a job to execution to the associated
        Azure Quantum Workspace.

        :param problem:
            The Problem to solve. It can be an instance of a Problem,
            or the URL of an Azure Storage Blob where the serialized version
            of a Problem has been uploaded.
        :param compress:
            Whether or not to compress the problem when uploading it
            the Blob Storage. This input param is not used and will be
            deprecated.
        """
        if compress == False:
            import warnings
            warnings.warn("The service no longer accepts payloads that \
are not compressed with gzip encoding. Ignoring compress flag.")

        from azure.quantum.optimization import Problem
        if isinstance(problem, Problem):
            self.check_valid_problem(problem)
            return super().submit(input_data=problem,
                                  name=problem.name,
                                  input_params=self.params,
                                  blob_name="inputData",
                                  content_type=problem.content_type)

        else:
            if hasattr(problem, "uploaded_blob_uri"):
                name = problem.name
                problem_uri = problem.uploaded_blob_uri

            elif isinstance(problem, str):
                name = "Optimization problem"
                problem_uri = problem

            else:
                raise ValueError(
                    "Cannot submit problem: should be of type str, Problem or have uploaded_blob_uri attribute."
                )

            # Create job from storage URI
            job = Job.from_storage_uri(
                workspace=self.workspace,
                name=name,
                target=self.name,
                input_data_uri=problem_uri,
                provider_id=self.provider_id,
                input_data_format=self.input_data_format,
                output_data_format=self.output_data_format,
                input_params=self.params)

        return job
Exemple #4
0
    def list_jobs(self,
                  name_match: str = None,
                  status: Optional[JobStatus] = None,
                  created_after: Optional[datetime] = None) -> List[Job]:
        """Returns list of jobs that meet optional (limited) filter criteria. 
            :param name_match: regex expression for job name matching
            :param status: filter by job status
            :param created_after: filter jobs after time of job creation
        """
        client = self._create_jobs_client()
        jobs = client.list()

        result = []
        for j in jobs:
            deserialized_job = Job(self, j)
            if deserialized_job.matches_filter(name_match, status,
                                               created_after):
                result.append(deserialized_job)

        return result
Exemple #5
0
    def __init__(self, backend, azure_job=None, **kwargs) -> None:
        """
            A Job running on Azure Quantum
        """
        if azure_job is None:
            azure_job = Job.from_input_data(
                workspace=backend.provider().get_workspace(), **kwargs)

        self._azure_job = azure_job
        self._workspace = backend.provider().get_workspace()

        super().__init__(backend, self._azure_job.id, **kwargs)
Exemple #6
0
 def get_job(self, job_id: str) -> Job:
     """Returns the job corresponding to the given id."""
     client = self._create_jobs_client()
     details = client.get(job_id)
     return Job(self, details)
Exemple #7
0
 def cancel_job(self, job: Job) -> Job:
     client = self._create_jobs_client()
     client.cancel(job.details.id)
     details = client.get(job.id)
     return Job(self, details)
Exemple #8
0
 def submit_job(self, job: Job) -> Job:
     client = self._create_jobs_client()
     details = client.create(job.details.id, job.details)
     return Job(self, details)
Exemple #9
0
 def get_test_job_id(self):
     return ZERO_UID if self.is_playback \
            else Job.create_job_id()
Exemple #10
0
 def cancel_job(self, job: Job) -> Job:
     client = self._create_jobs_client()
     client.cancel(job.details.id, custom_headers=self._custom_headers())
     details = client.get(job.id, custom_headers=self._custom_headers())
     return Job(self, details)
Exemple #11
0
 def submit_job(self, job: Job) -> Job:
     client = self._create_jobs_client()
     details = client.create(job.details.id,
                             job.details,
                             custom_headers=self._custom_headers())
     return Job(self, details)
Exemple #12
0
    def get_dummy_job_id(self):
        if self.in_recording or self.is_live:
            return Job.create_job_id()

        return self.dummy_uid