qrisp.Operation.get_unitary#
- Operation.get_unitary(decimals=-1)[source]#
Returns the unitary matrix (if applicable) of the Operation as a numpy array.
- Parameters:
- decimalsint, optional
Amount of decimals to return. By default, the full precision is returned.
- Returns:
- numpy.ndarray
The unitary matrix of the Operation.
- Raises:
- Exception
Could not calculate the unitary.
Examples
>>> from qrisp import CPGate >>> import numpy as np >>> CPGate(np.pi/2).get_unitary(decimals = 3) array([[1.+0.j, 0.+0.j, 0.+0.j, 0.+0.j], [0.+0.j, 1.+0.j, 0.+0.j, 0.+0.j], [0.+0.j, 0.+0.j, 1.+0.j, 0.+0.j], [0.+0.j, 0.+0.j, 0.+0.j, 0.+1.j]], dtype=complex64)