qid_shape(val: Any, default: TDefault = 0) → Union[Tuple[int, …], TDefault]¶
- Returns a tuple describing the number of quantum levels of eachqubit/qudit/qid
val – The value to get the shape of.
default – Determines the fallback behavior when val doesn’t have a shape. If default is not set, a TypeError is raised. If default is set to a value, that value is returned.
If val has a _qid_shape_ method and its result is not NotImplemented, that result is returned. Otherwise, if val has a _num_qubits_ method, the shape with num_qubits qubits is returned e.g. (2,)*num_qubits. If neither method returns a value other than NotImplemented and a default value was specified, the default value is returned.
TypeError – val doesn’t have either a _qid_shape_ or a _num_qubits_ method (or they returned NotImplemented) and also no default value was specified.