From 025c9680597d6d2af269c8c36f529d52815ba3eb Mon Sep 17 00:00:00 2001 From: Ed Younis Date: Thu, 9 Nov 2023 11:02:28 -0500 Subject: [PATCH 1/2] Remove unnecessary is_unitary checks --- bqskit/qis/unitary/unitarymatrix.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bqskit/qis/unitary/unitarymatrix.py b/bqskit/qis/unitary/unitarymatrix.py index d3bd884b2..6c3f94679 100644 --- a/bqskit/qis/unitary/unitarymatrix.py +++ b/bqskit/qis/unitary/unitarymatrix.py @@ -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) @@ -475,7 +475,7 @@ def __array_ufunc__( ) if convert_back: - return UnitaryMatrix(out, self.radixes) + return UnitaryMatrix(out, self.radixes, False) return out From 0243f39870b2a09303395c6136338299fb833bde Mon Sep 17 00:00:00 2001 From: Ed Younis Date: Thu, 9 Nov 2023 11:06:25 -0500 Subject: [PATCH 2/2] Embedded gate update --- bqskit/ir/gates/composed/embedded.py | 40 ++++++++++++++++------------ 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/bqskit/ir/gates/composed/embedded.py b/bqskit/ir/gates/composed/embedded.py index 395c598cd..9e98d4636 100644 --- a/bqskit/ir/gates/composed/embedded.py +++ b/bqskit/ir/gates/composed/embedded.py @@ -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. @@ -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: @@ -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 ' @@ -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