class PulseBackendConfigurationSchema(QasmBackendConfigurationSchema): """Schema for pulse backend""" # Required properties. open_pulse = Boolean(required=True, validate=OneOf([True])) n_uchannels = Integer(required=True, validate=Range(min=0)) u_channel_lo = List( Nested(UchannelLOSchema, validate=Length(min=1), required=True, many=True)) meas_levels = List(Integer(), validate=Length(min=1), required=True) qubit_lo_range = List(List(Float(validate=Range(min=0)), validate=Length(equal=2)), required=True) meas_lo_range = List(List(Float(validate=Range(min=0)), validate=Length(equal=2)), required=True) dt = Float(required=True, validate=Range(min=0)) # pylint: disable=invalid-name dtm = Float(required=True, validate=Range(min=0)) rep_times = List(Float(validate=Range(min=0)), required=True) meas_kernels = List(String(), required=True) discriminators = List(String(), required=True) # Optional properties. meas_map = List(List(Integer(), validate=Length(min=1))) channel_bandwidth = List(List(Float(), validate=Length(equal=2))) acquisition_latency = List(List(Integer())) conditional_latency = List(List(Integer())) hamiltonian = PulseHamiltonianSchema()
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 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())
class BackendStatusSchema(BaseSchema): """Schema for BackendStatus.""" # Required properties. backend_name = String(required=True) backend_version = String(required=True, validate=Regexp("[0-9]+.[0-9]+.[0-9]+$")) operational = Boolean(required=True) pending_jobs = Integer(required=True, validate=Range(min=0)) status_msg = String(required=True)
class RunConfigSchema(BaseSchema): """Schema for RunConfig.""" # Required properties. # None # Optional properties. shots = Integer(validate=Range(min=1)) max_credits = Integer(validate=Range( min=3, max=10)) # TODO: can we check the range seed = Integer() memory = Boolean() # set default to be False
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 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)
class GateConfigSchema(BaseSchema): """Schema for GateConfig.""" # Required properties. name = String(required=True) parameters = List(String(), required=True) qasm_def = String(required=True) # Optional properties. coupling_map = List(List(Integer(), validate=Length(min=1)), validate=Length(min=1)) latency_map = List(List(Integer(validate=OneOf([0, 1])), validate=Length(min=1)), validate=Length(min=1)) conditional = Boolean() description = String()
class ExperimentResultSchema(BaseSchema): """Schema for ExperimentResult.""" # Required fields. shots = ByType([ Integer(), List(Integer(validate=Range(min=1)), validate=Length(equal=2)) ], required=True) success = Boolean(required=True) data = Nested(ExperimentResultDataSchema, required=True) # Optional fields. status = String() seed = Integer() meas_return = String(validate=OneOf(['single', 'avg'])) header = Nested(ObjSchema)
class ExperimentResultSchema(BaseSchema): """Schema for ExperimentResult.""" # Required fields. shots = ByType([Integer(), List(Integer(validate=Range(min=1)), validate=Length(equal=2))], required=True) success = Boolean(required=True) data = Nested(ExperimentResultDataSchema, required=True) # Optional fields. status = String() seed = Integer() meas_level = Integer(validate=Range(min=0, max=2)) meas_return = String(validate=OneOf(choices=(MeasReturnType.AVERAGE, MeasReturnType.SINGLE))) header = Nested(ObjSchema)
class ProjectResponseSchema(BaseSchema): """Nested schema for ProjectsResponseSchema""" # Required properties. isDefault = Boolean(required=True)
class QasmBackendConfigurationSchema(BackendConfigurationSchema): """Schema for Qasm backend.""" open_pulse = Boolean(required=True, validate=OneOf([False]))