Skip to content

Job

Bases: BaseJob

Source code in q3as/api.py
class Job(BaseJob):
    client: Client

    def __init__(self, client: Client, info: JobInfo, request: JobRequest):
        super().__init__(info, request)
        self.client = client

    def result(
        self, polling_interval: float = 1.0, max_wait: Optional[float] = None
    ) -> VQEResult:
        """
        Wait for the job to finish and return result
        If the job is not finished, return None. If the Job finished with an error, raise an exception.
        """
        if self.status is not JobStatus.STARTED:
            vqe_result = self.result_now()
            if vqe_result is not None:
                return vqe_result
        info, result = self.client._wait_for_job(
            self.info.slug, polling_interval, max_wait
        )
        self.info = info
        vqe_result = result.as_vqe_result()
        if vqe_result is None:
            raise ValueError("Expected result to not be None")
        return vqe_result

    def result_now(self) -> Optional[VQEResult]:
        """
        Get the result of the job now without waiting for it to finish.
        If the job is not finished, return None. If the Job finished with an error, raise an exception.
        """
        self.client._get_job_result(self.info.slug).as_vqe_result()

    def refetch(self) -> Job:
        """
        Refetch the job from the server.
        """
        info = self.client._get_job_info(self.info.slug)
        self.info = info
        return self

    def pause(self) -> Job:
        """
        Pause the job.
        """
        info = self.client._pause_job(self.info.slug)
        self.info = info
        return self

    def resume(self) -> Job:
        """
        Resume the job.
        """
        info = self.client._resume_job(self.info.slug)
        self.info = info
        return self

    def delete(self) -> Job:
        """
        Delete the job.
        """
        info = self.client._delete_job(self.info.slug)
        self.info = info
        return self

delete()

Delete the job.

Source code in q3as/api.py
def delete(self) -> Job:
    """
    Delete the job.
    """
    info = self.client._delete_job(self.info.slug)
    self.info = info
    return self

pause()

Pause the job.

Source code in q3as/api.py
def pause(self) -> Job:
    """
    Pause the job.
    """
    info = self.client._pause_job(self.info.slug)
    self.info = info
    return self

refetch()

Refetch the job from the server.

Source code in q3as/api.py
def refetch(self) -> Job:
    """
    Refetch the job from the server.
    """
    info = self.client._get_job_info(self.info.slug)
    self.info = info
    return self

result(polling_interval=1.0, max_wait=None)

Wait for the job to finish and return result If the job is not finished, return None. If the Job finished with an error, raise an exception.

Source code in q3as/api.py
def result(
    self, polling_interval: float = 1.0, max_wait: Optional[float] = None
) -> VQEResult:
    """
    Wait for the job to finish and return result
    If the job is not finished, return None. If the Job finished with an error, raise an exception.
    """
    if self.status is not JobStatus.STARTED:
        vqe_result = self.result_now()
        if vqe_result is not None:
            return vqe_result
    info, result = self.client._wait_for_job(
        self.info.slug, polling_interval, max_wait
    )
    self.info = info
    vqe_result = result.as_vqe_result()
    if vqe_result is None:
        raise ValueError("Expected result to not be None")
    return vqe_result

result_now()

Get the result of the job now without waiting for it to finish. If the job is not finished, return None. If the Job finished with an error, raise an exception.

Source code in q3as/api.py
def result_now(self) -> Optional[VQEResult]:
    """
    Get the result of the job now without waiting for it to finish.
    If the job is not finished, return None. If the Job finished with an error, raise an exception.
    """
    self.client._get_job_result(self.info.slug).as_vqe_result()

resume()

Resume the job.

Source code in q3as/api.py
def resume(self) -> Job:
    """
    Resume the job.
    """
    info = self.client._resume_job(self.info.slug)
    self.info = info
    return self