QGate

Overview

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

import { QGate } from "@masabando/quantum-gates"

Constructor

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.

Applying a gate

Gates can be applied to a quantum state using apply.

const next = gate.apply(state)

Gate composition

Gates can be combined by matrix multiplication using multiply. The returned gate represents sequential application.

const combined = gateA.multiply(gateB)

Matrix operations

QGate provides common matrix-related operations.

  • dagger(): Hermitian conjugate
  • conjugate(): Complex conjugate
  • transpose(): Matrix transpose

Fidelity

Fidelity measures how close two quantum gates are. It is computed from the trace of U†V.

const f = gate.fidelity(idealGate)
/* 0 ≤ f ≤ 1 */

Notes

  • Internally, a QGate always represents a single-qubit operation as a 2×2 unitary matrix.
  • Methods such as multiply and dagger return newQGate instances and do not mutate the original object.