Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename function.get_jobs to function.jobs and make it return Job objects #1480

Merged
merged 15 commits into from
Sep 11, 2024
3 changes: 2 additions & 1 deletion client/.pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ disable=raw-checker-failed,
suppressed-message,
useless-suppression,
deprecated-pragma,
use-symbolic-message-instead
use-symbolic-message-instead,
cyclic-import
Tansito marked this conversation as resolved.
Show resolved Hide resolved

# Enable the message, report, category or checker with the given id(s). You can
# either give multiple identifier separated by comma (,) or put this option
Expand Down
13 changes: 11 additions & 2 deletions client/qiskit_serverless/core/function.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def run(self, **kwargs):
config=config,
)

def get_jobs(self):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something that we probably should do before merge is to add a deprecation warning here instead to remove it. Just to avoid a breaking change in the catalog until we release a new version.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can create an additional PR solving this.

def jobs(self):
"""Run function

Raises:
Expand All @@ -127,6 +127,10 @@ def get_jobs(self):
Returns:
Job ids : job executed this function
"""
from qiskit_serverless.core.job import ( # pylint: disable=import-outside-toplevel
Tansito marked this conversation as resolved.
Show resolved Hide resolved
Job,
)

if self.job_client is None:
raise ValueError("No clients specified for a function.")

Expand All @@ -138,10 +142,15 @@ def get_jobs(self):
f"Function validation failed. Validation errors:\n {error_string}",
)

return self.job_client.get_jobs(
response = self.job_client.get_jobs(
title=self.title,
provider=self.provider,
)
jobs = [
Job(job_id=job.get("id"), job_client=self.job_client, raw_data=job)
for job in response
]
return jobs

def _validate_function(self) -> Tuple[bool, List[str]]:
"""Validate function arguments using schema provided.
Expand Down
4 changes: 4 additions & 0 deletions gateway/api/v1/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ def get_serializer_run_program(*args, **kwargs):
def get_serializer_run_job(*args, **kwargs):
return v1_serializers.RunJobSerializer(*args, **kwargs)

@staticmethod
def get_serializer_job(*args, **kwargs):
return v1_serializers.JobSerializer(*args, **kwargs)

@swagger_auto_schema(
operation_description="List author Qiskit Functions",
responses={status.HTTP_200_OK: v1_serializers.ProgramSerializer(many=True)},
Expand Down
18 changes: 11 additions & 7 deletions gateway/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
from .serializers import (
JobConfigSerializer,
RunJobSerializer,
JobSerializer,
RunProgramSerializer,
UploadProgramSerializer,
RetrieveCatalogSerializer,
Expand Down Expand Up @@ -105,6 +106,14 @@ def get_serializer_run_job(*args, **kwargs):

return RunJobSerializer(*args, **kwargs)

@staticmethod
def get_serializer_job(*args, **kwargs):
"""
This method returns the job serializer
"""

return JobSerializer(*args, **kwargs)

def get_serializer_class(self):
return self.serializer_class

Expand Down Expand Up @@ -412,13 +421,8 @@ def get_jobs(
jobs = Job.objects.filter(program=program)
else:
jobs = Job.objects.filter(program=program, author=request.user)
return Response(
list(
jobs.values(
"status", "result", "id", "created", "version", "arguments"
)
)
)
serializer = self.get_serializer_job(jobs, many=True)
return Response(serializer.data)


class JobViewSet(viewsets.GenericViewSet):
Expand Down
2 changes: 1 addition & 1 deletion tests/basic/06_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@
print(job.result())
print(job.logs())

jobs = my_function.get_jobs()
jobs = my_function.jobs()
print(jobs)