Skip to content

feat(qaas): add model messages #1159

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions scaleway-async/scaleway_async/qaas/v1alpha1/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from .types import ListBookingsRequestOrderBy
from .types import ListJobResultsRequestOrderBy
from .types import ListJobsRequestOrderBy
from .types import ListModelsRequestOrderBy
from .types import ListPlatformsRequestOrderBy
from .types import ListProcessResultsRequestOrderBy
from .types import ListProcessesRequestOrderBy
Expand All @@ -31,13 +32,15 @@
from .types import Booking
from .types import JobResult
from .types import Job
from .types import Model
from .types import Platform
from .types import ProcessResult
from .types import Process
from .types import Session
from .types import CancelJobRequest
from .types import CancelProcessRequest
from .types import CreateJobRequest
from .types import CreateModelRequest
from .types import CreateProcessRequest
from .types import CreateSessionRequest
from .types import DeleteJobRequest
Expand All @@ -47,6 +50,7 @@
from .types import GetBookingRequest
from .types import GetJobCircuitRequest
from .types import GetJobRequest
from .types import GetModelRequest
from .types import GetPlatformRequest
from .types import GetProcessRequest
from .types import GetSessionRequest
Expand All @@ -58,6 +62,8 @@
from .types import ListJobResultsResponse
from .types import ListJobsRequest
from .types import ListJobsResponse
from .types import ListModelsRequest
from .types import ListModelsResponse
from .types import ListPlatformsRequest
from .types import ListPlatformsResponse
from .types import ListProcessResultsRequest
Expand Down Expand Up @@ -85,6 +91,7 @@
"ListBookingsRequestOrderBy",
"ListJobResultsRequestOrderBy",
"ListJobsRequestOrderBy",
"ListModelsRequestOrderBy",
"ListPlatformsRequestOrderBy",
"ListProcessResultsRequestOrderBy",
"ListProcessesRequestOrderBy",
Expand All @@ -107,13 +114,15 @@
"Booking",
"JobResult",
"Job",
"Model",
"Platform",
"ProcessResult",
"Process",
"Session",
"CancelJobRequest",
"CancelProcessRequest",
"CreateJobRequest",
"CreateModelRequest",
"CreateProcessRequest",
"CreateSessionRequest",
"DeleteJobRequest",
Expand All @@ -123,6 +132,7 @@
"GetBookingRequest",
"GetJobCircuitRequest",
"GetJobRequest",
"GetModelRequest",
"GetPlatformRequest",
"GetProcessRequest",
"GetSessionRequest",
Expand All @@ -134,6 +144,8 @@
"ListJobResultsResponse",
"ListJobsRequest",
"ListJobsResponse",
"ListModelsRequest",
"ListModelsResponse",
"ListPlatformsRequest",
"ListPlatformsResponse",
"ListProcessResultsRequest",
Expand Down
151 changes: 151 additions & 0 deletions scaleway-async/scaleway_async/qaas/v1alpha1/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
ListBookingsRequestOrderBy,
ListJobResultsRequestOrderBy,
ListJobsRequestOrderBy,
ListModelsRequestOrderBy,
ListPlatformsRequestOrderBy,
ListProcessResultsRequestOrderBy,
ListProcessesRequestOrderBy,
Expand All @@ -29,6 +30,7 @@
Application,
Booking,
CreateJobRequest,
CreateModelRequest,
CreateProcessRequest,
CreateSessionRequest,
CreateSessionRequestBookingDemand,
Expand All @@ -39,11 +41,13 @@
ListBookingsResponse,
ListJobResultsResponse,
ListJobsResponse,
ListModelsResponse,
ListPlatformsResponse,
ListProcessResultsResponse,
ListProcessesResponse,
ListSessionACLsResponse,
ListSessionsResponse,
Model,
Platform,
Process,
ProcessResult,
Expand All @@ -64,19 +68,22 @@
unmarshal_Application,
unmarshal_Booking,
unmarshal_Job,
unmarshal_Model,
unmarshal_Platform,
unmarshal_Process,
unmarshal_Session,
unmarshal_ListApplicationsResponse,
unmarshal_ListBookingsResponse,
unmarshal_ListJobResultsResponse,
unmarshal_ListJobsResponse,
unmarshal_ListModelsResponse,
unmarshal_ListPlatformsResponse,
unmarshal_ListProcessResultsResponse,
unmarshal_ListProcessesResponse,
unmarshal_ListSessionACLsResponse,
unmarshal_ListSessionsResponse,
marshal_CreateJobRequest,
marshal_CreateModelRequest,
marshal_CreateProcessRequest,
marshal_CreateSessionRequest,
marshal_UpdateBookingRequest,
Expand Down Expand Up @@ -331,6 +338,8 @@ async def create_job(
circuit: JobCircuit,
tags: Optional[List[str]] = None,
max_duration: Optional[str] = None,
model_id: Optional[str] = None,
parameters: Optional[str] = None,
) -> Job:
"""
Create a job.
Expand All @@ -340,6 +349,8 @@ async def create_job(
:param circuit: Quantum circuit that should be executed.
:param tags: Tags of the job.
:param max_duration: Maximum duration of the job.
:param model_id: Computation model ID to be executed by the job.
:param parameters: Execution parameters for this job.
:return: :class:`Job <Job>`

Usage:
Expand All @@ -362,6 +373,8 @@ async def create_job(
circuit=circuit,
tags=tags,
max_duration=max_duration,
model_id=model_id,
parameters=parameters,
),
self.client,
),
Expand Down Expand Up @@ -780,6 +793,7 @@ async def create_session(
tags: Optional[List[str]] = None,
deduplication_id: Optional[str] = None,
booking_demand: Optional[CreateSessionRequestBookingDemand] = None,
model_id: Optional[str] = None,
) -> Session:
"""
Create a session.
Expand All @@ -792,6 +806,7 @@ async def create_session(
:param tags: Tags of the session.
:param deduplication_id: Deduplication ID of the session.
:param booking_demand: A booking demand to schedule the session, only applicable if the platform is bookable.
:param model_id: Default computation model ID to be executed by job assigned to this session.
:return: :class:`Session <Session>`

Usage:
Expand All @@ -815,6 +830,7 @@ async def create_session(
tags=tags,
deduplication_id=deduplication_id,
booking_demand=booking_demand,
model_id=model_id,
),
self.client,
),
Expand Down Expand Up @@ -1655,3 +1671,138 @@ async def update_booking(

self._throw_on_error(res)
return unmarshal_Booking(res.json())

async def create_model(
self,
*,
project_id: Optional[str] = None,
payload: Optional[str] = None,
) -> Model:
"""
Create a new model.
Create and register a new model that can be executed through next jobs. A model can also be assigned to a Session.
:param project_id: Project ID to attach this model.
:param payload: The serialized model data.
:return: :class:`Model <Model>`

Usage:
::

result = await api.create_model()
"""

res = self._request(
"POST",
"/qaas/v1alpha1/models",
body=marshal_CreateModelRequest(
CreateModelRequest(
project_id=project_id,
payload=payload,
),
self.client,
),
)

self._throw_on_error(res)
return unmarshal_Model(res.json())

async def get_model(
self,
*,
model_id: str,
) -> Model:
"""
Get model information.
Retrieve information about of the provided **model ID**.
:param model_id: Unique ID of the model.
:return: :class:`Model <Model>`

Usage:
::

result = await api.get_model(
model_id="example",
)
"""

param_model_id = validate_path_param("model_id", model_id)

res = self._request(
"GET",
f"/qaas/v1alpha1/models/{param_model_id}",
)

self._throw_on_error(res)
return unmarshal_Model(res.json())

async def list_models(
self,
*,
project_id: Optional[str] = None,
page: Optional[int] = None,
page_size: Optional[int] = None,
order_by: Optional[ListModelsRequestOrderBy] = None,
) -> ListModelsResponse:
"""
List all models attached to the **project ID**.
Retrieve information about all models of the provided **project ID**.
:param project_id: List models belonging to this project ID.
:param page: Page number.
:param page_size: Maximum number of results to return per page.
:param order_by: Sort order of the returned results.
:return: :class:`ListModelsResponse <ListModelsResponse>`

Usage:
::

result = await api.list_models()
"""

res = self._request(
"GET",
"/qaas/v1alpha1/models",
params={
"order_by": order_by,
"page": page,
"page_size": page_size or self.client.default_page_size,
"project_id": project_id or self.client.default_project_id,
},
)

self._throw_on_error(res)
return unmarshal_ListModelsResponse(res.json())

async def list_models_all(
self,
*,
project_id: Optional[str] = None,
page: Optional[int] = None,
page_size: Optional[int] = None,
order_by: Optional[ListModelsRequestOrderBy] = None,
) -> List[Model]:
"""
List all models attached to the **project ID**.
Retrieve information about all models of the provided **project ID**.
:param project_id: List models belonging to this project ID.
:param page: Page number.
:param page_size: Maximum number of results to return per page.
:param order_by: Sort order of the returned results.
:return: :class:`List[Model] <List[Model]>`

Usage:
::

result = await api.list_models_all()
"""

return await fetch_all_pages_async(
type=ListModelsResponse,
key="models",
fetcher=self.list_models,
args={
"project_id": project_id,
"page": page,
"page_size": page_size,
"order_by": order_by,
},
)
Loading
Loading