QCDType#
qualtran.QCDType
View source on GitHub
|
The abstract interface for quantum/classical quantum computing data types.
Attributes
num_bitsnum_cbitsNumber of classical bits required to represent a single instance of this data type.
num_qubitsNumber of qubits required to represent a single instance of this data type.
Methods#
get_classical_domain
@abc.abstractmethodget_classical_domain() -> Iterable[Any]
Yields all possible classical (computational basis state) values representable by this type.
to_bits
@abc.abstractmethodto_bits( x ) -> List[int]
Yields individual bits corresponding to binary representation of x
to_bits_array
to_bits_array(
x_array: NDArray[Any]
) -> NDArray[np.uint8]
Yields an NDArray of bits corresponding to binary representations of the input elements.
Often, converting an array can be performed faster than converting each element individually.
This operation accepts any NDArray of values, and the output array satisfies
output_shape = input_shape + (self.bitsize,).
from_bits
@abc.abstractmethodfrom_bits( bits: Sequence[int] )
Combine individual bits to form x
from_bits_array
from_bits_array(
bits_array: NDArray[np.uint8]
)
Combine individual bits to form classical values.
Often, converting an array can be performed faster than converting each element individually.
This operation accepts any NDArray of bits such that the last dimension equals self.bitsize,
and the output array satisfies output_shape = input_shape[:-1].
assert_valid_classical_val
@abc.abstractmethodassert_valid_classical_val( val: Any, debug_str: str = 'val' )
Raises an exception if val is not a valid classical value for this type.
Args
valA classical value that should be in the domain of this QDType.
debug_strOptional debugging information to use in exception messages.
assert_valid_classical_val_array
assert_valid_classical_val_array(
val_array: NDArray[Any], debug_str: str = 'val'
)
Raises an exception if val_array is not a valid array of classical values for this type.
Often, validation on an array can be performed faster than validating each element individually.
Args
val_arrayA numpy array of classical values. Each value should be in the domain of this QDType.
debug_strOptional debugging information to use in exception messages.
is_symbolic
@abc.abstractmethodis_symbolic() -> bool
Returns True if this dtype is parameterized with symbolic objects.
iteration_length_or_zero
iteration_length_or_zero() -> qualtran.symbolics.SymbolicInt
Safe version of iteration length.
Returns the iteration_length if the type has it or else zero.
View source on GitHub