Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions qiskit/quantum_info/states/statevector.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
"""
Statevector quantum state class.
"""

import copy
import re
from numbers import Number
Expand Down Expand Up @@ -225,7 +224,7 @@ def __len__(self):
return len(self._data)

@property
def data(self):
def data(self) -> np.ndarray:
"""Return data."""
return self._data

Expand All @@ -238,7 +237,7 @@ def is_valid(self, atol=None, rtol=None):
norm = np.linalg.norm(self.data)
return np.allclose(norm, 1, rtol=rtol, atol=atol)

def to_operator(self):
def to_operator(self) -> Operator:
"""Convert state to a rank-1 projector operator"""
mat = np.outer(self.data, np.conj(self.data))
return Operator(mat, input_dims=self.dims(), output_dims=self.dims())
Expand Down
20 changes: 11 additions & 9 deletions qiskit/quantum_info/synthesis/xx_decompose/decomposer.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
"""
Driver for a synthesis routine which emits optimal XX-based circuits.
"""

from __future__ import annotations
import heapq
import math
from operator import itemgetter
from typing import Callable, Optional, Union
from typing import Callable

import numpy as np

Expand Down Expand Up @@ -78,10 +78,10 @@ class XXDecomposer:

def __init__(
self,
basis_fidelity: Union[dict, float] = 1.0,
basis_fidelity: dict | float = 1.0,
euler_basis: str = "U",
embodiments: Optional[dict] = None,
backup_optimizer: Optional[Callable] = None,
embodiments: dict[float, QuantumCircuit] | None = None,
backup_optimizer: Callable[..., QuantumCircuit] | None = None,
):
from qiskit.transpiler.passes.optimization.optimize_1q_decomposition import (
Optimize1qGatesDecomposition, # pylint: disable=cyclic-import
Expand All @@ -93,7 +93,9 @@ def __init__(
self.basis_fidelity = basis_fidelity

# expose one of the basis gates so others can know what this decomposer targets
embodiment_circuit = next(iter(self.embodiments.items()), ([], []))[1]
embodiment_circuit: list | QuantumCircuit = next(iter(self.embodiments.items()), ([], []))[
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't it be CircuitInstruction instead of QuantumCircuit?

Copy link
Contributor Author

@Randl Randl Feb 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at the code, it seems that

next(iter(self.embodiments.items()), ([], []))

should be a QuantumCircuit. But then embodiment_circuit is actually obtained by indexing into this object:

next(iter(self.embodiments.items()), ([], []))[1]

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self.embodiments is a dictionary, so self.embodiments.items() contains tuples, and thus indexing will return the second element of first tuple, i.e., circuit

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, ok. It seems this line can be significantly simplified by calling self.embodiments.values() instead of items. You can go ahead and make that change if you like, but it's not necessary.

1
]
for instruction in embodiment_circuit:
if len(instruction.qubits) == 2:
self.gate = instruction.operation
Expand Down Expand Up @@ -217,10 +219,10 @@ def _strength_to_infidelity(basis_fidelity, approximate=False):

def __call__(
self,
unitary: Union[Operator, np.ndarray],
basis_fidelity: Optional[Union[dict, float]] = None,
unitary: Operator | np.ndarray,
basis_fidelity: dict | float | None = None,
approximate: bool = True,
):
) -> QuantumCircuit:
"""
Fashions a circuit which (perhaps `approximate`ly) models the special unitary operation
`unitary`, using the circuit templates supplied at initialization as `embodiments`. The
Expand Down