UnitaryMatrix
- class UnitaryMatrix(input, radixes=[], check_arguments=True)[source]
Bases:
Unitary
,StateVectorMap
,NDArrayOperatorsMixin
A concrete representation of a unitary matrix.
- __init__(input, radixes=[], check_arguments=True)[source]
Constructs a UnitaryMatrix from the supplied unitary matrix.
- Parameters:
input (
UnitaryLike
) – The unitary matrix input.radixes (
Sequence[int]
) – A sequence with its length equal to the number of qudits this UnitaryMatrix can act on. Each element specifies the base, number of orthogonal states, for the corresponding qudit. By default, the constructor will attempt to calculate radixes from utry.check_arguments (
bool
) – If true, check arguments for type and value errors.
- Raises:
ValueError – If input is not unitary.
ValueError – If the dimension of input does not match the expected dimension from radixes.
RuntimeError – If radixes is not specified and the constructor cannot infer it.
Examples
>>> UnitaryMatrix( ... [ ... [0, 1], ... [1, 0], ... ], ... ) # Creates a single-qubit Pauli X unitary matrix. array([[0.+0.j, 1.+0.j], [1.+0.j, 0.+0.j]])
Attributes
The transpose of the unitary.
The conjugate transpose of the unitary.
The matrix dimension for this unitary.
The NumPy data type of the unitary.
The number of real parameters this unitary-valued function takes.
The number of qudits this unitary can act on.
The NumPy array holding the unitary.
The number of orthogonal states for each qudit.
The two-dimensional square shape of the unitary.
Methods
check_parameters
(params)Check parameters are valid and match the unitary.
closest_to
(M[, radixes])Calculate and return the closest unitary to a given matrix.
conj
()Return the complex conjugate unitary matrix.
from_file
(filename)Load a unitary from a file.
get_distance_from
(other[, degree])Return the distance between self and other.
get_statevector
(in_state)Calculate the output state after applying this unitary to in_state.
get_unitary
([params])Return the same object, satisfies the
Unitary
API.identity
(dim[, radixes])Construct an identity UnitaryMatrix.
Return true if this unitary doesn't take parameters.
Return true if this unitary is parameterized.
Return true if this unitary can only act on qubits.
is_qudit_only
(radix)Return true if this unitary can only act on radix-qudits.
Return true if this unitary can only act on qutrits.
is_self_inverse
([params])Checks whether the unitary is its own inverse.
Return true if this unitary is special.
is_unitary
(U[, tol])Check if U is a unitary matrix.
otimes
(*utrys)Calculate the tensor or kroneckor product with other unitaries.
random
(num_qudits[, radixes])Sample a random unitary from the haar distribution.
save
(filename)Save the unitary to a file.
Return a special unitary matrix verson of this one.