From ae5ea7d152046a50871169d8b90fae030dcd96a2 Mon Sep 17 00:00:00 2001 From: Daniyar Yeralin Date: Wed, 21 Aug 2019 14:16:57 -0400 Subject: [PATCH 1/7] Introduce root endpoints schemas --- .../ibmq/api_v2/rest/schemas/root.py | 167 ++++++++++++++++++ 1 file changed, 167 insertions(+) create mode 100644 qiskit/providers/ibmq/api_v2/rest/schemas/root.py diff --git a/qiskit/providers/ibmq/api_v2/rest/schemas/root.py b/qiskit/providers/ibmq/api_v2/rest/schemas/root.py new file mode 100644 index 000000000..0d522ddd8 --- /dev/null +++ b/qiskit/providers/ibmq/api_v2/rest/schemas/root.py @@ -0,0 +1,167 @@ +# -*- coding: utf-8 -*- + +# This code is part of Qiskit. +# +# (C) Copyright IBM 2017, 2019. +# +# This code is licensed under the Apache License, Version 2.0. You may +# obtain a copy of this license in the LICENSE.txt file in the root directory +# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0. +# +# Any modifications or derivative works of this code must retain this +# copyright notice, and modified files need to carry a notice indicating +# that they have been altered from the originals. + +"""Schemas for root.""" + +from marshmallow.validate import OneOf +from qiskit.providers import JobStatus +from qiskit.providers.models.backendconfiguration import BackendConfigurationSchema +from qiskit.providers.ibmq.apiconstants import ApiJobKind +from qiskit.validation import BaseSchema +from qiskit.validation.fields import String, Dict, Nested, Boolean, List, Number + + +# Helper schemas. + +class ProjectResponseSchema(BaseSchema): + """Nested schema for ProjectsResponseSchema""" + + # Required properties. + isDefault = Boolean(required=True) + + +class ProjectsResponseSchema(BaseSchema): + """Nested schema for GroupResponseSchema""" + + # Required properties. + project_name = String(required=True) + project = Nested(ProjectResponseSchema, required=True) + + +class GroupResponseSchema(BaseSchema): + """Nested schema for GroupsResponseSchema""" + + # Required properties. + projects = Dict(Nested(ProjectsResponseSchema), required=True) + + +class GroupsResponseSchema(BaseSchema): + """Nested schema for HubsResponseSchema""" + + # Required properties. + group_name = String(required=True) + group = Nested(GroupResponseSchema, required=True) + + +class CircuitErrorResponseSchema(BaseSchema): + """Nested schema for CircuitResponseSchema""" + + # Required properties + code = String(required=True, validate=OneOf(['GENERIC_ERROR', 'HUB_NOT_FOUND'])) + + +class BackendRequestSchema(BaseSchema): + """Nested schema for JobsRequestSchema""" + + # Required properties + name = String(required=True, description="the name of the backend.") + + +class JobsStatusFilterRequestSchema(BaseSchema): + """Nested schema for JobsStatusRequestSchema""" + + # Optional properties + where = Dict(attribute="extra_filter", required=False, + description="additional filtering passed to the query.") + + # Required properties + order = String(required=True, default="creationDate DESC") + limit = Number(required=True, description="maximum number of items to return.") + skip = Number(required=True, description="offset for the items to return.") + + +# Endpoint schemas. + +class HubsResponseSchema(BaseSchema): + """Schema for HubsResponse""" + + # Required properties. + name = String(required=True) + groups = Dict(Nested(GroupsResponseSchema), required=True) + + +class VersionResponseSchema(BaseSchema): + """Schema for VersionResponse""" + pass + + +class CircuitRequestSchema(BaseSchema): + """Schema for CircuitRequest""" + + # Required properties + name = String(required=True, description="name of the Circuit.") + params = Dict(required=True, description="arguments for the Circuit.") + + +class CircuitResponseSchema(BaseSchema): + """Schema for CircuitResponse""" + # pylint: disable=invalid-name + + # Optional properties + error = Dict(Nested(CircuitErrorResponseSchema), required=False) + + # Required properties + id = String(required=True, description="the job ID of an already submitted job.") + creationDate = String(required=True, description="when the job was run.") + status = String(required=True, description="`status` field directly from the API response.") + + +class BackendsResponseSchema(BaseSchema): + """Schema for BackendResponse""" + + # Required properties + backends = List(Nested(BackendConfigurationSchema, required=True)) + + +class JobsRequestSchema(BaseSchema): + """Schema for JobsRequest""" + + # Optional properties + name = String(required=False, description="custom name to be assigned to the job.") + + # Required properties + qObject = Dict(required=True, description="the Qobj to be executed, as a dictionary.") + backend = Nested(BackendConfigurationSchema, required=True) + shots = Number(required=True) + + +class JobsResponseSchema(BaseSchema): + """Schema for JobsResponse""" + # pylint: disable=invalid-name + + # Optional properties + error = String(required=False) + + # Required properties + id = String(required=True) + status = String(required=True, validate=OneOf([status.name for status in JobStatus])) + creationDate = String(required=True) + + +class JobsStatusRequestSchema(BaseSchema): + """Schema for JobsStatusRequest""" + + # Required properties + filter = Nested(JobsStatusFilterRequestSchema, required=True) + + +class JobsStatusResponseSchema(BaseSchema): + """Schema for JobsStatusResponse""" + # pylint: disable=invalid-name + + # Required properties + id = String(required=True, description="the job ID of an already submitted job.") + kind = String(required=True, validate=OneOf([kind.name for kind in ApiJobKind])) + creationDate = String(required=True, description="when the job was run.") + status = String(required=True) From 78951ddfd0f9c0a93b53863eaaf40d85f4395370 Mon Sep 17 00:00:00 2001 From: Daniyar Yeralin Date: Fri, 23 Aug 2019 14:57:31 -0400 Subject: [PATCH 2/7] Use Enum.value instead of Enum.name --- qiskit/providers/ibmq/api_v2/rest/schemas/root.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qiskit/providers/ibmq/api_v2/rest/schemas/root.py b/qiskit/providers/ibmq/api_v2/rest/schemas/root.py index 0d522ddd8..b5c567e20 100644 --- a/qiskit/providers/ibmq/api_v2/rest/schemas/root.py +++ b/qiskit/providers/ibmq/api_v2/rest/schemas/root.py @@ -145,7 +145,7 @@ class JobsResponseSchema(BaseSchema): # Required properties id = String(required=True) - status = String(required=True, validate=OneOf([status.name for status in JobStatus])) + status = String(required=True, validate=OneOf([status.value for status in JobStatus])) creationDate = String(required=True) From c27fa387481f3693f5fcf4cddd7cce4297fe4489 Mon Sep 17 00:00:00 2001 From: Daniyar Yeralin Date: Wed, 4 Sep 2019 09:52:34 -0400 Subject: [PATCH 3/7] Replace backend field from Nested to String --- qiskit/providers/ibmq/api_v2/rest/schemas/root.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qiskit/providers/ibmq/api_v2/rest/schemas/root.py b/qiskit/providers/ibmq/api_v2/rest/schemas/root.py index b5c567e20..9d5152a31 100644 --- a/qiskit/providers/ibmq/api_v2/rest/schemas/root.py +++ b/qiskit/providers/ibmq/api_v2/rest/schemas/root.py @@ -132,7 +132,7 @@ class JobsRequestSchema(BaseSchema): # Required properties qObject = Dict(required=True, description="the Qobj to be executed, as a dictionary.") - backend = Nested(BackendConfigurationSchema, required=True) + backend = String(required=True, description="the name of the backend.") shots = Number(required=True) From e910ca9e4a9b98c50bc188ebf137f0b3da1d5a5a Mon Sep 17 00:00:00 2001 From: Daniyar Yeralin Date: Wed, 4 Sep 2019 12:24:46 -0400 Subject: [PATCH 4/7] Replace String field with Nested field of BackendRequestSchema --- qiskit/providers/ibmq/api_v2/rest/schemas/root.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qiskit/providers/ibmq/api_v2/rest/schemas/root.py b/qiskit/providers/ibmq/api_v2/rest/schemas/root.py index 9d5152a31..e91ca4c76 100644 --- a/qiskit/providers/ibmq/api_v2/rest/schemas/root.py +++ b/qiskit/providers/ibmq/api_v2/rest/schemas/root.py @@ -132,7 +132,7 @@ class JobsRequestSchema(BaseSchema): # Required properties qObject = Dict(required=True, description="the Qobj to be executed, as a dictionary.") - backend = String(required=True, description="the name of the backend.") + backend = Nested(BackendRequestSchema, required=True) shots = Number(required=True) From 4806459b8661486076320a900f8f3b52e12b767a Mon Sep 17 00:00:00 2001 From: Daniyar Yeralin Date: Wed, 4 Sep 2019 12:26:25 -0400 Subject: [PATCH 5/7] Rename JobsStatusFilterRequest schema to JobsStatusFilterQueryParam It is done to highlight this schema being used with GET request (using query parameters). --- qiskit/providers/ibmq/api_v2/rest/schemas/root.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/qiskit/providers/ibmq/api_v2/rest/schemas/root.py b/qiskit/providers/ibmq/api_v2/rest/schemas/root.py index e91ca4c76..ff67283a5 100644 --- a/qiskit/providers/ibmq/api_v2/rest/schemas/root.py +++ b/qiskit/providers/ibmq/api_v2/rest/schemas/root.py @@ -68,7 +68,7 @@ class BackendRequestSchema(BaseSchema): name = String(required=True, description="the name of the backend.") -class JobsStatusFilterRequestSchema(BaseSchema): +class JobsStatusFilterQueryParamRequestSchema(BaseSchema): """Nested schema for JobsStatusRequestSchema""" # Optional properties @@ -153,7 +153,7 @@ class JobsStatusRequestSchema(BaseSchema): """Schema for JobsStatusRequest""" # Required properties - filter = Nested(JobsStatusFilterRequestSchema, required=True) + filter = Nested(JobsStatusFilterQueryParamRequestSchema, required=True) class JobsStatusResponseSchema(BaseSchema): From e76843f7fd246f2f041ed41e4654514d51bc9133 Mon Sep 17 00:00:00 2001 From: Daniyar Yeralin Date: Wed, 4 Sep 2019 14:53:17 -0400 Subject: [PATCH 6/7] Remove dummy VersionResponseSchema --- qiskit/providers/ibmq/api_v2/rest/schemas/root.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/qiskit/providers/ibmq/api_v2/rest/schemas/root.py b/qiskit/providers/ibmq/api_v2/rest/schemas/root.py index ff67283a5..e27b3762b 100644 --- a/qiskit/providers/ibmq/api_v2/rest/schemas/root.py +++ b/qiskit/providers/ibmq/api_v2/rest/schemas/root.py @@ -91,11 +91,6 @@ class HubsResponseSchema(BaseSchema): groups = Dict(Nested(GroupsResponseSchema), required=True) -class VersionResponseSchema(BaseSchema): - """Schema for VersionResponse""" - pass - - class CircuitRequestSchema(BaseSchema): """Schema for CircuitRequest""" From 60f5e549d394d9a905aa0d758d6c732c55509507 Mon Sep 17 00:00:00 2001 From: Daniyar Yeralin Date: Thu, 5 Sep 2019 11:50:15 -0400 Subject: [PATCH 7/7] Turn HubsResponseSchema into a dummy schema temporarily --- qiskit/providers/ibmq/api_v2/rest/schemas/root.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/qiskit/providers/ibmq/api_v2/rest/schemas/root.py b/qiskit/providers/ibmq/api_v2/rest/schemas/root.py index e27b3762b..397a37b5a 100644 --- a/qiskit/providers/ibmq/api_v2/rest/schemas/root.py +++ b/qiskit/providers/ibmq/api_v2/rest/schemas/root.py @@ -85,10 +85,14 @@ class JobsStatusFilterQueryParamRequestSchema(BaseSchema): class HubsResponseSchema(BaseSchema): """Schema for HubsResponse""" + pass + # pylint: disable=pointless-string-statement + """ Commented out until https://github.com/Qiskit/qiskit-terra/issues/3021 is addressed # Required properties. name = String(required=True) groups = Dict(Nested(GroupsResponseSchema), required=True) + """ class CircuitRequestSchema(BaseSchema):