Skip to content

Commit 839e0e3

Browse files
authored
Merge pull request #203 from BQSKit/small-updates
Small updates
2 parents e0632da + 0243f39 commit 839e0e3

File tree

2 files changed

+25
-19
lines changed

2 files changed

+25
-19
lines changed

bqskit/ir/gates/composed/embedded.py

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def __init__(
5656
self,
5757
gate: Gate,
5858
radixes: Sequence[int] | int,
59-
level_maps: Sequence[int] | Sequence[Sequence[int]],
59+
level_maps: None | Sequence[int] | Sequence[Sequence[int]] = None,
6060
) -> None:
6161
"""
6262
Construct an EmbeddedGate.
@@ -71,21 +71,24 @@ def __init__(
7171
if `radixes = 3`, then the gate will be embedded into a
7272
qutrit gate.
7373
74-
level_maps (Sequence[int] | Sequence[Sequence[int]]): The level
75-
map for the embedding for each qudit. If a sequence of
76-
integers is given, then the level map is assumed to be
77-
the same for all qudits. For example, if `radixes = 3`
78-
and `level_maps = [0, 2]`, then the gate will be
79-
embedded into a qutrit gate by mapping the qubit levels
80-
0 and 1 to the qutrit levels 0 and 2, respectively. If a
81-
sequence of sequences is given, then the level map is
82-
assumed to be different for each qudit. For example, if
83-
`radixes = [3, 3]` and `level_maps = [[0, 2], [1, 2]]`,
84-
then the gate will be embedded into a two-qudit gate by
85-
mapping the first qubit's 0 and 1 levels to the first
86-
qutrit's 0 and 2 levels, respectively, and by mapping
87-
the second qubit's 0 and 1 levels to the second qutrit's
88-
1 and 2 levels, respectively.
74+
level_maps (None | Sequence[int] | Sequence[Sequence[int]]):
75+
The level map for the embedding for each qudit. If a
76+
sequence of integers is given, then the level map is
77+
assumed to be the same for all qudits. For example, if
78+
`radixes = 3` and `level_maps = [0, 2]`, then the gate
79+
will be embedded into a qutrit gate by mapping the qubit
80+
levels 0 and 1 to the qutrit levels 0 and 2,
81+
respectively. If a sequence of sequences is given, then
82+
the level map is assumed to be different for each qudit.
83+
For example, if `radixes = [3, 3]` and `level_maps =
84+
[[0, 2], [1, 2]]`, then the gate will be embedded into a
85+
two-qudit gate by mapping the first qubit's 0 and 1
86+
levels to the first qutrit's 0 and 2 levels,
87+
respectively, and by mapping the second qubit's 0 and 1
88+
levels to the second qutrit's 1 and 2 levels,
89+
respectively. This can also be set to `None`, which will
90+
embed the lower dimension gate in the lowest levels of
91+
the new radixes.
8992
9093
Raises:
9194
@@ -138,6 +141,9 @@ def __init__(
138141
f' to be greater than 2, got {radixes=}.',
139142
)
140143

144+
if level_maps is None:
145+
level_maps = [list(range(levels)) for levels in gate.radixes]
146+
141147
if not is_sequence(level_maps):
142148
raise TypeError(
143149
'Expected level_maps to be a sequence of integers or a '
@@ -193,7 +199,7 @@ def __init__(
193199
)
194200

195201
self.gate = gate
196-
self.level_maps = [list(lmap) for lmap in level_maps]
202+
self.level_maps = tuple([tuple(list(lmap)) for lmap in level_maps])
197203
self._num_qudits = gate._num_qudits
198204
self._name = 'Embedded(%s)' % self.gate.name # TODO: include radixes and level maps # noqa: E501
199205
self._num_params = self.gate._num_params

bqskit/qis/unitary/unitarymatrix.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ def get_distance_from(self, other: UnitaryLike, degree: int = 2) -> float:
212212
are equal up to global phase and 1 means the two unitaries are
213213
very unsimilar or far apart.
214214
"""
215-
other = UnitaryMatrix(other)
215+
other = UnitaryMatrix(other, check_arguments=False)
216216
num = np.abs(np.trace(self.conj().T @ other))
217217
dem = self.dim
218218
frac = min(num / dem, 1)
@@ -475,7 +475,7 @@ def __array_ufunc__(
475475
)
476476

477477
if convert_back:
478-
return UnitaryMatrix(out, self.radixes)
478+
return UnitaryMatrix(out, self.radixes, False)
479479

480480
return out
481481

0 commit comments

Comments
 (0)