Package com.quantum4j.core.gates
Class TwoQubitGate
java.lang.Object
com.quantum4j.core.gates.TwoQubitGate
- All Implemented Interfaces:
Gate
- Direct Known Subclasses:
CHGate,CNOTGate,CZGate,ISWAPGate,StandardGates.CHGate,StandardGates.CNOTGate,StandardGates.CZGate,StandardGates.ISWAPGate,StandardGates.SWAPGate,SWAPGate
Abstract base class for two-qubit gates.
A two-qubit gate is represented by a 4×4 complex matrix in the local basis:
|q0 q1⟩ = |00⟩, |01⟩, |10⟩, |11⟩
where q0 is the FIRST qubit argument passed to
apply(StateVector, int, int)
and q1 is the SECOND.
Quantum4J uses LSB = qubit 0 in the global state index, but this class
does not sort or reorder the qubit indices – the matrix is always applied
with respect to the (q0, q1) order given by the caller.
This fixes:
- CNOT semantics: control = first argument, target = second
- CH / other asymmetric 2-qubit gates
- QASM Bell state tests-
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedTwoQubitGate(Complex[][] matrix) Construct a two-qubit gate with the given 4×4 matrix. -
Method Summary
Modifier and TypeMethodDescriptionvoidapply(StateVector state, int q0, int q1) Apply this gate to qubits (q0, q1) in that logical order.intarity()Get the arity (number of qubits) this gate acts upon.
-
Field Details
-
matrix
4×4 unitary matrix in local ordering |q0 q1⟩ = |00⟩,|01⟩,|10⟩,|11⟩.
-
-
Constructor Details
-
TwoQubitGate
Construct a two-qubit gate with the given 4×4 matrix.- Parameters:
matrix- a 4×4 complex matrix
-
-
Method Details
-
arity
public int arity()Description copied from interface:GateGet the arity (number of qubits) this gate acts upon. -
apply
Apply this gate to qubits (q0, q1) in that logical order. Local basis ordering: index 0 → |q0=0, q1=0⟩ index 1 → |q0=0, q1=1⟩ index 2 → |q0=1, q1=0⟩ index 3 → |q0=1, q1=1⟩
-