Dimension of the gate's matrix, which corresponds to the number of basis states in the Hilbert space it acts upon. For a gate acting on n qubits, the size is 2^n.
This property is computed dynamically from the matrix dimensions, ensuring that the reported size is always consistent with the matrix.
The number of rows (which equals the number of columns) in the gate matrix.
Applies this quantum gate to a quantum state.
This is the primary, high-level method for quantum gate application. It transforms pure quantum states represented as state vectors through unitary matrix operations, ensuring proper quantum mechanical evolution.
The method creates a Q5mOperator from the gate's matrix and applies it to the quantum state using the state's apply() method.
This ensures proper quantum mechanical evolution while maintaining
type safety and performance optimizations specific to state vectors.
The complexity of this operation depends on the state's representation
(dense or sparse) but is generally O(2^n)
for an n-qubit gate on an n-qubit state.
The quantum state to be transformed. Its dimension must match the gate's size.
The transformed quantum state after the gate has been applied.
Applies this quantum gate directly to a state vector representation of a quantum state.
This method provides low-level access for direct state vector manipulation, performing the matrix-vector multiplication U|ψ⟩. It is primarily used internally by simulators and for compatibility with legacy code that operates directly on arrays of complex numbers.
This method performs the fundamental quantum gate operation by multiplying
the gate's unitary matrix with the input state vector. It validates that
the state vector has the correct dimension before applying the transformation.
The complexity of this operation is O(N^2)
where N is the size of the state vector.
This is the core mathematical operation underlying all quantum gate applications. The operation preserves fundamental quantum mechanical properties:
The quantum state vector (an array of quantum amplitudes) to transform.
The transformed state vector after gate application.
Returns a string representation of this quantum gate.
The string representation uses the gate's name
property, making it
useful for debugging, logging, circuit visualization, and serialization.
The gate's name as a string.
Get the global phase angle of this gate.
Get the underlying 2x2 unitary matrix that is applied when control is |1⟩
Static
fromCreate a controlled version of any single-qubit gate
Optional
name: stringStatic
fromStatic factory method to create a controlled unitary gate that transforms |10⟩ to the specified state.
A ControlledUnitaryGate that maps |10⟩ → α|10⟩ + β|11⟩ when control is |1⟩
Static
fromCreate controlled unitary from matrix elements
Static
fromCreate controlled rotation around arbitrary axis
Optional
globalPhase: numberReadonly
nameHuman-readable name of the quantum gate (e.g., "H", "CNOT", "RZ"). This name is used for debugging, logging, and circuit visualization. It should be a concise and descriptive identifier for the gate's operation. Must be implemented by all concrete gate subclasses.
Readonly
matrixUnitary matrix representation of the quantum gate. This matrix defines how the gate transforms quantum states according to the Schrödinger equation's evolution: |ψ'⟩ = U|ψ⟩. The matrix must be square and unitary (U†U = I) to ensure valid, reversible quantum operations that conserve probability. Must be implemented by all concrete gate subclasses.
Controlled Unitary Gate - applies a unitary transformation to target when control is |1⟩
This gate is constructed from two quantum amplitudes α and β, just like UnitaryGate, but applies the transformation only when the control qubit is |1⟩.
The unitary matrix is constructed from normalized α,β as: U = [α -β*] [β α*]
Matrix representation in computational basis |00⟩, |01⟩, |10⟩, |11⟩: [1 0 0 0 ] |00⟩ → |00⟩ [0 1 0 0 ] |01⟩ → |01⟩ [0 0 α -β*] |10⟩ → α|10⟩ - β*|11⟩ [0 0 β α*] |11⟩ → β|10⟩ + α*|11⟩
Where α and β are automatically normalized to ensure |α|² + |β|² = 1.