Skip to content
This repository has been archived by the owner on Jun 17, 2024. It is now read-only.

Commit

Permalink
feat: Add jobs function to PlanqkQuantumProvider to retrieve user jobs
Browse files Browse the repository at this point in the history
Implemented a new `jobs` function within the PlanqkQuantumProvider class.
This function enables users and orgs. to fetch a list of all their jobs.
  • Loading branch information
Sebastian Wagner committed Apr 26, 2024
1 parent c8898c4 commit f5aa304
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
5 changes: 5 additions & 0 deletions planqk/qiskit/client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@ def get_job(cls, job_id: str, provider: Optional[PROVIDER] = None) -> JobDto:
response = cls.perform_request(requests.get, f"{base_url()}/jobs/{job_id}", params=params)
return JobDto(**response)

@classmethod
def get_jobs(cls) -> List[JobDto]:
response = cls.perform_request(requests.get, f"{base_url()}/jobs")
return [JobDto(**job_info) for job_info in response]

@classmethod
def get_job_result(cls, job_id: str, provider: Optional[PROVIDER] = None) -> Dict[str, Any]:
params = {}
Expand Down
7 changes: 7 additions & 0 deletions planqk/qiskit/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,13 @@ def to_dict(self) -> dict:
"""
return {key: value for key, value in vars(self).items() if not key.startswith('_')}

def backend(self) -> Backend:
"""Return the backend where this job was executed."""
if self._backend is None:
from planqk.qiskit import PlanqkBackend
self._backend = PlanqkBackend(self._job_details.backend_id)
return self._backend

def queue_position(self):
"""
Return the position of the job in the server queue.
Expand Down
12 changes: 12 additions & 0 deletions planqk/qiskit/provider.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json
from typing import List

from qiskit.providers import ProviderV1 as Provider, QiskitBackendNotFoundError

Expand Down Expand Up @@ -124,3 +125,14 @@ def retrieve_job(self, backend: PlanqkBackend, job_id: str):
Job: the job from the backend with the given id.
"""
return PlanqkJob(backend=backend, job_id=job_id)

def jobs(self) -> List[PlanqkJob]:
"""
Returns all jobs of the user or organization.
Returns:
List[PlanqkJob]: a list of active jobs.
"""
print("Getting your jobs from PlanQK, this may take a few seconds...")
job_dtos = _PlanqkClient.get_jobs()
return [PlanqkJob(backend=None, job_id=job_dto.id, job_details=job_dto) for job_dto in job_dtos]

0 comments on commit f5aa304

Please sign in to comment.