Ejemplo n.º 1
0
class BackendConfigurationSchema(BaseSchema):
    """Schema for BackendConfiguration."""
    # Required properties.
    backend_name = String(required=True)
    backend_version = String(required=True,
                             validate=Regexp("[0-9]+.[0-9]+.[0-9]+$"))
    n_qubits = Integer(required=True, validate=Range(min=1))
    basis_gates = List(String(), required=True, validate=Length(min=1))
    gates = Nested(GateConfigSchema,
                   required=True,
                   many=True,
                   validate=Length(min=1))
    local = Boolean(required=True)
    simulator = Boolean(required=True)
    conditional = Boolean(required=True)
    memory = Boolean(required=True)
    max_shots = Integer(required=True, validate=Range(min=1))
    open_pulse = Boolean(required=True)

    # Optional properties.
    max_experiments = Integer(validate=Range(min=1))
    sample_name = String()
    coupling_map = List(List(Integer(), validate=Length(min=1)),
                        validate=Length(min=1),
                        allow_none=True)
    n_registers = Integer(validate=Range(min=1))
    register_map = List(List(Integer(validate=OneOf([0, 1])),
                             validate=Length(min=1)),
                        validate=Length(min=1))
    configurable = Boolean()
    credits_required = Boolean()
    online_date = DateTime()
    display_name = String()
    description = String()
    tags = List(String())
Ejemplo n.º 2
0
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
Ejemplo n.º 3
0
class NduvSchema(BaseSchema):
    """Schema for name-date-unit-value."""

    # Required properties.
    date = DateTime(required=True)
    name = String(required=True)
    unit = String(required=True)
    value = Number(required=True)
Ejemplo n.º 4
0
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)
Ejemplo n.º 5
0
class InfoQueueResponseSchema(BaseSchema):
    """Queue information schema, nested in StatusResponseSchema"""

    # Optional properties
    position = Integer(required=False, missing=None)
    _status = String(required=False, missing=None)
    estimated_start_time = DateTime(required=False, missing=None)
    estimated_complete_time = DateTime(required=False, missing=None)
    hub_priority = Float(required=False, missing=None)
    group_priority = Float(required=False, missing=None)
    project_priority = Float(required=False, missing=None)

    @pre_load
    def preprocess_field_names(self, data, **_):  # type: ignore
        """Pre-process the info queue response fields."""
        FIELDS_MAP = {  # pylint: disable=invalid-name
            'status': '_status',
            'estimatedStartTime': 'estimated_start_time',
            'estimatedCompleteTime': 'estimated_complete_time',
            'hubPriority': 'hub_priority',
            'groupPriority': 'group_priority',
            'projectPriority': 'project_priority'
        }
        return map_field_names(FIELDS_MAP, data)
Ejemplo n.º 6
0
class ResultSchema(BaseSchema):
    """Schema for Result."""

    # Required fields.
    backend_name = String(required=True)
    backend_version = String(required=True,
                             validate=Regexp('[0-9]+.[0-9]+.[0-9]+$'))
    qobj_id = String(required=True)
    job_id = String(required=True)
    success = Boolean(required=True)
    results = Nested(ExperimentResultSchema, required=True, many=True)

    # Optional fields.
    date = DateTime()
    status = String()
    header = Nested(ObjSchema)
Ejemplo n.º 7
0
class BackendPropertiesSchema(BaseSchema):
    """Schema for BackendProperties."""

    # Required properties.
    backend_name = String(required=True)
    backend_version = String(required=True,
                             validate=Regexp("[0-9]+.[0-9]+.[0-9]+$"))
    last_update_date = DateTime(required=True)
    qubits = List(Nested(NduvSchema, many=True, validate=Length(min=1)),
                  required=True,
                  validate=Length(min=1))
    gates = Nested(GateSchema,
                   required=True,
                   many=True,
                   validate=Length(min=1))
    general = Nested(NduvSchema, required=True, many=True)