Skip to content

Commit

Permalink
Merge pull request #203 from BQSKit/small-updates
Browse files Browse the repository at this point in the history
Small updates
  • Loading branch information
edyounis authored Nov 13, 2023
2 parents e0632da + 0243f39 commit 839e0e3
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 19 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
4 changes: 2 additions & 2 deletions bqskit/qis/unitary/unitarymatrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ def get_distance_from(self, other: UnitaryLike, degree: int = 2) -> float:
are equal up to global phase and 1 means the two unitaries are
very unsimilar or far apart.
"""
other = UnitaryMatrix(other)
other = UnitaryMatrix(other, check_arguments=False)
num = np.abs(np.trace(self.conj().T @ other))
dem = self.dim
frac = min(num / dem, 1)
Expand Down Expand Up @@ -475,7 +475,7 @@ def __array_ufunc__(
)

if convert_back:
return UnitaryMatrix(out, self.radixes)
return UnitaryMatrix(out, self.radixes, False)

return out

Expand Down

0 comments on commit 839e0e3

Please sign in to comment.