Skip to content

Commit

Permalink
Embedded gate update
Browse files Browse the repository at this point in the history
  • Loading branch information
edyounis committed Nov 9, 2023
1 parent 025c968 commit 0243f39
Showing 1 changed file with 23 additions and 17 deletions.
40 changes: 23 additions & 17 deletions bqskit/ir/gates/composed/embedded.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def __init__(
self,
gate: Gate,
radixes: Sequence[int] | int,
level_maps: Sequence[int] | Sequence[Sequence[int]],
level_maps: None | Sequence[int] | Sequence[Sequence[int]] = None,
) -> None:
"""
Construct an EmbeddedGate.
Expand All @@ -71,21 +71,24 @@ def __init__(
if `radixes = 3`, then the gate will be embedded into a
qutrit gate.
level_maps (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.
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:
Expand Down Expand Up @@ -138,6 +141,9 @@ def __init__(
f' to be greater than 2, got {radixes=}.',
)

if level_maps is None:
level_maps = [list(range(levels)) for levels in gate.radixes]

if not is_sequence(level_maps):
raise TypeError(
'Expected level_maps to be a sequence of integers or a '
Expand Down Expand Up @@ -193,7 +199,7 @@ def __init__(
)

self.gate = gate
self.level_maps = [list(lmap) for lmap in level_maps]
self.level_maps = tuple([tuple(list(lmap)) for lmap in level_maps])
self._num_qudits = gate._num_qudits
self._name = 'Embedded(%s)' % self.gate.name # TODO: include radixes and level maps # noqa: E501
self._num_params = self.gate._num_params
Expand Down

0 comments on commit 0243f39

Please sign in to comment.