Creates a new unitary operator.
The unitary matrix (will be validated)
Optional
name: stringOptional name for the operator
Skip unitarity validation (use with caution)
Static
unitaryCreates a unitary Q5mOperator with validation.
The unitary matrix
Optional
name: stringOptional name for the operator
A new Q5mOperator
Static
hermitianCreates a Hermitian Q5mOperator with validation.
The Hermitian matrix
Optional
name: stringOptional name for the operator
A new Q5mOperator
Computes the time evolution operator U(t) = exp(-iHt/ℏ).
For simplicity, we set ℏ = 1 in our units. The time evolution operator is unitary and generates the time evolution of quantum states according to the Schrödinger equation.
The evolution time
Reduced Planck constant (default: 1 in natural units)
The unitary time evolution operator as a matrix
Scales the operator by a scalar value.
The scalar to multiply the operator by
A new scaled quantum operator
Adds another quantum operator to this one.
The operator to add
A new quantum operator representing the sum
Gets the inverse (conjugate transpose) of this operator.
For unitary operators, the inverse is the conjugate transpose: U⁻¹ = U†
A new Q5mOperator representing the conjugate transpose
Composes this operator with another (matrix multiplication).
The result is U₁U₂. The resulting matrix type depends on the operand types.
The other operator
A new Q5mOperator representing the composition
Static
fromCreates a Q5mOperator from a matrix, with optional validation.
The matrix to convert to an operator
Optional
name: stringOptional name for the operator
Whether to skip validation (default: false)
A new Q5mOperator
Static
identityCreates an identity operator of given dimension.
Static
HadamardCreates a Hadamard operator of the specified dimension.
The Hadamard operator is a fundamental quantum gate that creates superposition by transforming computational basis states. For a single qubit (dimension 2), it maps |0⟩ → (|0⟩ + |1⟩)/√2 and |1⟩ → (|0⟩ - |1⟩)/√2.
For higher dimensions, this creates a generalized Walsh-Hadamard transform. The matrix elements are H[i,j] = (1/√n) * (-1)^(i·j) where n is the dimension and i·j is the dot product of the binary representations of i and j.
The dimension of the Hadamard operator (must be a power of 2)
A new Q5mOperator representing the Hadamard transformation
Static
pauliStatic
pauliStatic
pauliStatic
phaseCreates a phase gate operator (Unitary).
The phase angle in radians
A new Q5mOperator representing the phase gate
Static
rotationCreates a rotation gate around the X axis (Unitary).
The rotation angle in radians
A new Q5mOperator representing Rx(angle)
Static
rotationCreates a rotation gate around the Y axis (Unitary).
The rotation angle in radians
A new Q5mOperator representing Ry(angle)
Static
rotationCreates a rotation gate around the Z axis (Unitary).
The rotation angle in radians
A new Q5mOperator representing Rz(theta)
Static
swapCreates a SWAP gate that exchanges quantum states between two qubits (Unitary).
The SWAP gate is a fundamental two-qubit gate that exchanges the quantum states of two qubits. It permutes the computational basis states as follows:
Matrix representation in computational basis |00⟩, |01⟩, |10⟩, |11⟩:
SWAP = [1 0 0 0]
[0 0 1 0]
[0 1 0 0]
[0 0 0 1]
Properties:
A new Q5mOperator representing the SWAP gate
Calculates the sparsity ratio of the operator matrix.
This method counts non-zero elements to determine how sparse the matrix is, which is crucial for selecting optimal computation algorithms. A sparsity ratio close to 0 indicates a very sparse matrix (few non-zeros), while a ratio close to 1 indicates a dense matrix.
Threshold for considering elements as zero (default: 1e-15)
Sparsity ratio between 0 and 1 (non-zero elements / total elements)
Determines if this operator is sparse enough to benefit from sparse algorithms.
This method uses a configurable threshold to classify matrices as sparse or dense. Sparse matrices can use specialized algorithms that skip zero elements.
Maximum sparsity ratio to consider sparse (default: 0.3 = 30% non-zero)
True if the matrix is below the sparsity threshold
Analyzes the structure of the operator matrix to identify common patterns.
This analysis detects quantum gate patterns that can benefit from specialized algorithms:
The analysis results can guide algorithm selection for specific gate structures.
Analysis object with structure information
Static
fromCreates a UnitaryOperator from a unitary matrix.
The unitary matrix
Optional
name: stringOptional name for the operator
Whether to skip validation (default: false)
A new UnitaryOperator
Gets the matrix representation of the operator.
A copy of the operator's matrix
Static
controlledCreates a controlled version of a unitary operator.
For a 2x2 unitary U, creates a 4x4 controlled-U gate: CU = |0⟩⟨0| ⊗ I + |1⟩⟨1| ⊗ U
The unitary operator to make controlled
A new UnitaryOperator representing the controlled version
Represents a unitary operator for quantum transformations.
Unitary operators are matrices U that satisfy U†U = UU† = I, where U† is the conjugate transpose and I is the identity matrix. They preserve the norm of quantum states and represent reversible quantum operations.
Key Properties: