symop.polynomial.channels.unitaries.conventions

Matrix validation utilities.

Helper functions used by the unitary construction modules to validate matrix shape, dimensions, and optional unitarity constraints.

Functions

require_dim(U, *, n)

Raise ValueError unless U has shape (n, n).

require_square(U)

Raise ValueError unless U is a square matrix.

require_unitary_optional(U, *[, ...])

Optionally validate U is unitary, i.e. U^H U = I.

require_dim(U: ndarray, *, n: int) None

Raise ValueError unless U has shape (n, n).

Parameters:
  • U (ndarray) – Candidate matrix.

  • n (int) – Required dimension.

Raises:

ValueError – If shape mismatch.

Return type:

None

require_square(U: ndarray) None

Raise ValueError unless U is a square matrix.

Parameters:

U (ndarray) – Candidate matrix.

Raises:

ValueError – If U is not 2D or not square.

Return type:

None

require_unitary_optional(U: ndarray, *, check_unitary: bool = False, atol: float = 1e-10) None

Optionally validate U is unitary, i.e. U^H U = I.

This is deliberately optional because (a) it costs time, and (b) some uses may pass approximate numerics.

Parameters:
  • U (ndarray) – Candidate matrix.

  • check_unitary (bool) – If True, validate unitarity.

  • atol (float) – Absolute tolerance for np.allclose.

Raises:

ValueError – If check_unitary is True and U is not unitary within atol.

Return type:

None