SubSwapGate.calculate_level_swap_unitary

static SubSwapGate.calculate_level_swap_unitary(radix, level1, level2)[source]

Calculate the unitary for a qudit level swap.

Parameters:
  • radix (int) – The number of qudit levels (>=2).

  • level1 (tuple[int, int]) – The first qudit level to swap.

  • level2 (tuple[int, int]) – The second qudit level to swap.

Returns:

The unitary matrix for the qudit level swap.

Return type:

UnitaryMatrix

Raises:

ValueError – If any of the qudit levels integer represenation greater than or equal to radix.

Example

>>> from bqskit.ir.gates.constant.subswap import SubSwapGate
>>> u = SubSwapGate.calculate_level_swap_unitary(2, (1, 1), (1, 0))
>>> u
array([[1.+0.j, 0.+0.j, 0.+0.j, 0.+0.j],
       [0.+0.j, 1.+0.j, 0.+0.j, 0.+0.j],
       [0.+0.j, 0.+0.j, 0.+0.j, 1.+0.j],
       [0.+0.j, 0.+0.j, 1.+0.j, 0.+0.j]])
>>> from bqskit.ir.gates.constant.cx import CNOTGate
>>> u == CNOTGate().get_unitary()
True