class JobResponseSchema(BaseSchema): """Schema for IBMQJob. Schema for an `IBMQJob`. The following conventions are in use in order to provide enough flexibility in regards to attributes: * the "Required properties" reflect attributes that will always be present in the model. * the "Optional properties with a default value" reflect attributes that are always present in the model, but might contain uninitialized values depending on the state of the job. * some properties are prepended by underscore due to name clashes and extra constraints in the IBMQJob class (for example, existing IBMQJob methods that have the same name as a response field). The schema is used for GET Jobs, GET Jobs/{id}, and POST Jobs responses. """ # pylint: disable=invalid-name # Required properties. _creation_date = DateTime(required=True) kind = Enum(required=True, enum_cls=ApiJobKind) _job_id = String(required=True) _api_status = Enum(required=True, enum_cls=ApiJobStatus) # Optional properties with a default value. _name = String(missing=None) shots = Integer(validate=Range(min=0), missing=None) _time_per_step = Dict(keys=String, values=String, missing=None) _result = Nested(ResultSchema, missing=None) _qobj = Nested(QobjSchema, missing=None) _error = Nested(JobResponseErrorSchema, missing=None) # Optional properties _backend_info = Nested(JobResponseBackendSchema) allow_object_storage = Boolean() error = String() @pre_load def preprocess_field_names(self, data, **_): # type: ignore """Pre-process the job response fields. Rename selected fields of the job response due to name clashes, and convert from camel-case the rest of the fields. TODO: when updating to terra 0.10, check if changes related to marshmallow 3 allow to use directly `data_key`, as in 0.9 terra duplicates the unknown keys. """ rename_map = {} for field_name in data: if field_name in FIELDS_MAP: rename_map[field_name] = FIELDS_MAP[field_name] else: rename_map[field_name] = to_python_identifier(field_name) for old_name, new_name in rename_map.items(): data[new_name] = data.pop(old_name) return data
class PulseHamiltonianSchema(BaseSchema): """Schema for PulseHamiltonian.""" # Required properties. h_str = List(String(), validate=Length(min=1), required=True) dim_osc = List(Integer(validate=Range(min=1)), required=True) dim_qub = List(Integer(validate=Range(min=2)), required=True) vars = Dict(validate=PatternProperties( {Regexp('^([a-z0-9])+$'): InstructionParameter()}), 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(BackendRequestSchema, required=True)
class JobsStatusFilterQueryParamRequestSchema(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.")
class JobResponseSchema(BaseSchema): """Schema for ``IBMQJob``. The following conventions are in use in order to provide enough flexibility in regards to attributes: * the "Required properties" reflect attributes that will always be present in the model. * the "Optional properties with a default value" reflect attributes that are always present in the model, but might contain uninitialized values depending on the state of the job. * some properties are prepended by underscore due to name clashes and extra constraints in the ``IBMQJob`` class (for example, existing ``IBMQJob`` methods that have the same name as a response field). The schema is used for ``GET /Jobs``, ``GET /Jobs/{id}``, and ``POST /Jobs`` responses. """ # pylint: disable=invalid-name # Required properties. _creation_date = DateTime(required=True) _job_id = String(required=True) _api_status = Enum(required=True, enum_cls=ApiJobStatus) # Optional properties with a default value. kind = Enum(enum_cls=ApiJobKind, missing=None) _name = String(missing=None) _time_per_step = Dict(keys=String, values=String, missing=None) _result = Nested(ResultSchema, missing=None) _qobj = Raw(missing=None) _error = Nested(JobResponseErrorSchema, missing=None) _tags = List(String, missing=[]) _run_mode = String(missing=None) # Optional properties _backend_info = Nested(JobResponseBackendSchema) allow_object_storage = Boolean() @pre_load def preprocess_field_names(self, data, **_): # type: ignore """Pre-process the job response fields. Rename selected fields of the job response due to name clashes, and convert the rest of the fields to Python convention. TODO: when updating to terra 0.10, check if changes related to marshmallow 3 allow to use directly `data_key`, as in 0.9 terra duplicates the unknown keys. """ return map_field_names(FIELDS_MAP, data)
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 GroupResponseSchema(BaseSchema): """Nested schema for GroupsResponseSchema""" # Required properties. projects = Dict(Nested(ProjectsResponseSchema), required=True)
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 FieldsFilterRequestSchema(BaseSchema): """Nested schema for SelfFilterQueryParamRequestSchema""" # Required properties fields = Dict(keys=String, values=Bool)
class BackendsResponseSchema(BaseSchema): """Schema for BackendResponse""" # Required properties backends = Dict(required=True, many=True)