QGate represents a single-qubit quantum gate. Internally, a gate is stored as a 2×2 unitary matrix and can be applied to a quantum state, combined with other gates, or evaluated using fidelity.
import { QGate } from "@masabando/quantum-gates"A QGate can be constructed as a rotation around an arbitrary axis.
/* rotation angle (rad) and axis vector */const gate = new QGate(Math.PI / 2, [1, 0, 0])The axis vector is normalized internally. If a zero vector is given, an error is thrown.
Gates can be applied to a quantum state using apply.
const next = gate.apply(state)Gates can be combined by matrix multiplication using multiply. The returned gate represents sequential application.
const combined = gateA.multiply(gateB)QGate provides common matrix-related operations.
dagger(): Hermitian conjugateconjugate(): Complex conjugatetranspose(): Matrix transposeFidelity measures how close two quantum gates are. It is computed from the trace of U†V.
const f = gate.fidelity(idealGate)/* 0 ≤ f ≤ 1 */QGate always represents a single-qubit operation as a 2×2 unitary matrix.multiply and dagger return newQGate instances and do not mutate the original object.