ket.qulib.gates

Quantum gate construction.

Functions ket.qulib.gates

diagonal(*angles[, up_to_global_phase])

Create a diagonal quantum gate.

ucz(angles, qubits, *[, _last])

Uniformly controlled z-axis rotation gate.

unitary(matrix[, up_to_global_phase])

Create a quantum gate from 2x2 unitary matrix.

diagonal(*angles, up_to_global_phase=True)

Create a diagonal quantum gate.

\[U = \sum_i \theta_i \left| i \right> \left< i \right|\]
Parameters:
  • angles – List of rotation angles \(\theta_i\).

  • up_to_global_phase – If True, the resulting unitary is equivalent up to a global phase.

ucz(angles, qubits, *, _last=True)

Uniformly controlled z-axis rotation gate.

Implements a uniformly controlled rotation around the z-axis, as proposed in https://arxiv.org/abs/quant-ph/0406176.

Parameters:
  • angles – List of rotation angles.

  • qubits – List of qubits to apply the gate to.

unitary(matrix: list[list[complex]], up_to_global_phase: bool = False) Callable[[Quant], Quant]

Create a quantum gate from 2x2 unitary matrix.

The provided unitary matrix is decomposed into a sequence of rotation gates, which together implement an equivalent unitary transformation. When the gate is used in a controlled operation, the resulting unitary is equivalent up to a global phase.

Parameters:
  • matrix – Unitary matrix in the format [[a, b], [c, d]].

  • up_to_global_phase – If True, the resulting unitary is equivalent up to a global phase even when the gate is not used in a controlled operation.

Returns:

Returns a new callable that implements the unitary operation.

Raises:

ValueError – If the input matrix is not unitary.