Skip to main content
IBM Quantum Platform

Specification

class samplomatic.tensor_interface.Specification

GitHub

Bases: Generic[T]

A specification of an expected value inside of an interface.

Attributes Summary

Column 1
Column 2
descriptionA description of this specification.
free_dimensionsNamed dimensions whose sizes are free until an interface value binds their value.
nameThe name of this specification.
num_bytesThe number of bytes required to represent data for this specification.
optionalWhether this is an optional specification.

Methods Summary

Column 1
Column 2
describe()Return a human-readable description of this specification.
validate_and_coerce(value)Coerce a value into a correct type if valid.

Attributes Documentation

description

A description of this specification.

free_dimensions

Named dimensions whose sizes are free until an interface value binds their value.

Within a TensorInterface, all free dimensions of the same name must be consistently bound. This allows specification of dimensions of values that can be arbitrary, and that are only resolved once bound to an interface.

name

The name of this specification.

num_bytes

The number of bytes required to represent data for this specification.

Implementations of this attribute should not be overly concerned with accounting for memory required, say, for builtin Python container objects. They should be more interested in the large data limit where memory is dominated by sources like NumPy buffers.

If the specification has free_dimensions, implementations should return the number of bytes per unit of each free dimension. For example, if the specification has a free dimension "n" and requires 8 * n bytes, this property should return 8.

optional

Whether this is an optional specification.

Methods Documentation

describe

abstractmethod describe() → str

GitHub

Return a human-readable description of this specification.

validate_and_coerce

abstractmethod validate_and_coerce(value: Any) → tuple[T, dict[str, int]]

GitHub

Coerce a value into a correct type if valid.

Parameters

value – A value to validate and coerce with respect to this specification.

Raises

TypeError – If the value cannot be coerced into a valid type.

Returns

The coerced value, and a dictionary mapping each member of free_dimensions to a size implied by the value.

Was this page helpful?
Report a bug, typo, or request content on GitHub.