EmbeddedGate

class EmbeddedGate[source]

Bases: ComposedGate, DifferentiableUnitary

An embedding of a gate into a higher-dimensional qudit gate.

For example, a qubit gate can be embedded into a qutrit gate by mapping all qubit levels to a subspace of the qutrit levels.

This transformation can be shown directly on unitaries. If we have an arbitrary single-qubit gate U given by the following matrix:

U = \begin{pmatrix}
    a & b \\
    c & d \\
\end{pmatrix}

and we want to embed this into the 0 and 2 levels of a qutrit gate, then we can do so by mapping the qubit levels 0 and 1 to the qutrit levels 0 and 2, respectively. This gives us the following matrix:

U_{embedded} = \begin{pmatrix}
    a & 0 & b \\
    0 & 1 & 0 \\
    c & 0 & d \\
\end{pmatrix}

This concept can be generalized to multiple qudits and even mixed-radix systems.

Note

  • Global phase inconsistencies in gates will become local phase

    inconsistencies in the embedded gate. For example, if the global phase difference between the U1Gate and the RZGate will become local phase differences in the corresponding subspaces when embedded into a higher-dimensional qudit.

__init__(gate, radixes, level_maps=None)[source]

Construct an EmbeddedGate.

Parameters:
  • gate (Gate) – The gate to embed in a higher-dimensional qudit gate.

  • radixes (Sequence[int] | int) –

    The target radixes of the higher-

    dimensional system. If an integer is given, then the radixes are assumed to be the same for all qudits. For example, if radixes = 3, then the gate will be embedded into a qutrit gate.

    level_maps (None | Sequence[int] | Sequence[Sequence[int]]):

    The level map for the embedding for each qudit. If a sequence of integers is given, then the level map is assumed to be the same for all qudits. For example, if radixes = 3 and level_maps = [0, 2], then the gate will be embedded into a qutrit gate by mapping the qubit levels 0 and 1 to the qutrit levels 0 and 2, respectively. If a sequence of sequences is given, then the level map is assumed to be different for each qudit. For example, if radixes = [3, 3] and level_maps = [[0, 2], [1, 2]], then the gate will be embedded into a two-qudit gate by mapping the first qubit’s 0 and 1 levels to the first qutrit’s 0 and 2 levels, respectively, and by mapping the second qubit’s 0 and 1 levels to the second qutrit’s 1 and 2 levels, respectively. This can also be set to None, which will embed the lower dimension gate in the lowest levels of the new radixes.

Raises:
  • ValueError – If any radix is less than 2.

  • ValueError – If radixes is given as a sequence and its length is not equal to the number of qudits in the gate.

  • ValueError – If any of the gate’s radixes are greater than the corresponding target radixes.

  • ValueError – If the level map is given as a sequence of sequences and its length is not equal to the number of qudits in the gate.

  • ValueError – If any of the individual qudit level maps are not the same length as the gate’s corresponding qudit radix.

  • ValueError – If any individual qudit level map has an invalid qudit level, i.e. too low (< 0) or too high (>= radix).

  • ValueError – If any individual qudit level map is not one-to-one, i.e. if any two qudit levels are mapped to the same target qudit level.

Examples: (#TODO update)
XGate for qutrits:

``` > x_qutrit_gate = ControlledGate(XGate(),[3],[0,2]) > x_qutrit_gate.get_unitary() > [[0, 0, sqrt(2)/2],

[0, 0, 0], [sqrt(2)/2, 0, 0]]

```

Attributes

dim

The matrix dimension for this unitary.

name

The name of this gate.

num_params

The number of real parameters this unitary-valued function takes.

num_qudits

The number of qudits this unitary can act on.

qasm_name

The qasm identifier for this gate.

radixes

The number of orthogonal states for each qudit.

Methods

check_parameters(params)

Check parameters are valid and match the unitary.

get_grad([params])

Return the gradient for this gate.

get_inverse()

Return the gate's inverse as a gate.

get_inverse_params([params])

Return the parameters that invert the gate.

get_qasm(params, location)

Returns the qasm string for this gate.

get_qasm_gate_def()

Returns a qasm gate definition block for this gate.

get_unitary([params])

Return the unitary for this gate, see Unitary for more.

get_unitary_and_grad([params])

Return the unitary and gradient for this gate.

is_constant()

Return true if this unitary doesn't take parameters.

is_differentiable()

Check if all sub gates are differentiable.

is_locally_optimizable()

Check if all sub gates are locally optimizable.

is_parameterized()

Return true if this unitary is parameterized.

is_qubit_only()

Return true if this unitary can only act on qubits.

is_qudit_only(radix)

Return true if this unitary can only act on radix-qudits.

is_qutrit_only()

Return true if this unitary can only act on qutrits.

is_self_inverse([params])

Checks whether the unitary is its own inverse.

with_all_frozen_params(params)

Freeze all of a gate's parameters so they don't change from optimization.

with_frozen_params(frozen_params)

Freeze some of a gate's parameters so they don't change from optimization.