Package com.quantum4j.core.gates
Class SingleQubitGate
java.lang.Object
com.quantum4j.core.gates.SingleQubitGate
- All Implemented Interfaces:
Gate
- Direct Known Subclasses:
RXGate,RYGate,RZGate,StandardGates.HGate,StandardGates.RXGate,StandardGates.RYGate,StandardGates.RZGate,StandardGates.SGate,StandardGates.TGate,StandardGates.U1Gate,StandardGates.U2Gate,StandardGates.U3Gate,StandardGates.XGate,StandardGates.YGate,StandardGates.ZGate
Abstract base class for single-qubit gates.
A single-qubit gate is represented by a 2×2 complex matrix. Subclasses provide specific gate matrices (e.g., Hadamard, Pauli X, Y, Z).
-
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedSingleQubitGate(Complex[][] matrix) Construct a single-qubit gate with the given 2×2 matrix. -
Method Summary
Modifier and TypeMethodDescriptionvoidapply(StateVector state, int targetQubit) Apply this single-qubit gate to the specified target qubit in the given state.intarity()Get the arity (number of qubits) this gate acts upon.
-
Field Details
-
matrix
2x2 unitary matrix representing this gate
-
-
Constructor Details
-
SingleQubitGate
Construct a single-qubit gate with the given 2×2 matrix.- Parameters:
matrix- a 2×2 complex matrix- Throws:
IllegalArgumentException- if the matrix is not 2×2
-
-
Method Details
-
arity
public int arity()Description copied from interface:GateGet the arity (number of qubits) this gate acts upon. -
apply
Apply this single-qubit gate to the specified target qubit in the given state.This implementation performs sparse matrix-vector multiplication by updating only the amplitude pairs affected by the target qubit.
- Parameters:
state- the quantum state to modifytargetQubit- the index of the qubit to apply the gate to (0 = LSB)- Throws:
IllegalArgumentException- if targetQubit is out of range
-