Skip to content
This repository has been archived by the owner on Dec 7, 2021. It is now read-only.

Commit

Permalink
improve typehints
Browse files Browse the repository at this point in the history
  • Loading branch information
Cryoris committed Aug 22, 2020
1 parent 06ebbbf commit a937d3e
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 18 deletions.
9 changes: 7 additions & 2 deletions qiskit/aqua/operators/operator_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,19 @@ def eval(self,
defined to be evaluated from Zero implicitly (i.e. it is as if ``.eval('0000')`` is already
called implicitly to always "indexing" from column 0).
If ``front`` is None, the matrix-represenation of the operator is returned.
Args:
front: The bitstring, dict of bitstrings (with values being coefficients), or
StateFn to evaluated by the Operator's underlying function.
StateFn to evaluated by the Operator's underlying function, or None.
Returns:
The output of the Operator's evaluation function. If self is a ``StateFn``, the result
is a float or complex. If self is an Operator (``PrimitiveOp, ComposedOp, SummedOp,
EvolvedOp,`` etc.), the result is a StateFn. If either self or front contain proper
EvolvedOp,`` etc.), the result is a StateFn.
If ``front`` is None, the matrix-representation of the operator is returned, which
is a ``MatrixOp`` for the operators and a ``VectorStateFn`` for state-functions.
If either self or front contain proper
``ListOps`` (not ListOp subclasses), the result is an n-dimensional list of complex
or StateFn results, resulting from the recursive evaluation by each OperatorBase
in the ListOps.
Expand Down
4 changes: 2 additions & 2 deletions qiskit/aqua/operators/primitive_ops/circuit_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,8 @@ def assign_parameters(self, param_dict: dict) -> OperatorBase:
return self.__class__(qc, coeff=param_value)

def eval(self,
front: Union[str, dict, np.ndarray,
OperatorBase] = None) -> Union[OperatorBase, float, complex]:
front: Optional[Union[str, Dict[str, complex], np.ndarray, OperatorBase]] = None
) -> Union[OperatorBase, float, complex]:
# pylint: disable=import-outside-toplevel
from ..state_fns import CircuitStateFn
from ..list_ops import ListOp
Expand Down
4 changes: 2 additions & 2 deletions qiskit/aqua/operators/primitive_ops/matrix_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ def __str__(self) -> str:
return "{} * {}".format(self.coeff, prim_str)

def eval(self,
front: Union[str, dict, np.ndarray,
OperatorBase] = None) -> Union[OperatorBase, float, complex]:
front: Optional[Union[str, Dict[str, complex], np.ndarray, OperatorBase]] = None
) -> Union[OperatorBase, float, complex]:
# For other ops' eval we return self.to_matrix_op() here, but that's unnecessary here.
if front is None:
return self
Expand Down
4 changes: 2 additions & 2 deletions qiskit/aqua/operators/primitive_ops/pauli_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@ def __str__(self) -> str:
return "{} * {}".format(self.coeff, prim_str)

def eval(self,
front: Union[str, dict, np.ndarray,
OperatorBase] = None) -> Union[OperatorBase, float, complex]:
front: Optional[Union[str, Dict[str, complex], np.ndarray, OperatorBase]] = None
) -> Union[OperatorBase, float, complex]:
if front is None:
return self.to_matrix_op()

Expand Down
4 changes: 2 additions & 2 deletions qiskit/aqua/operators/primitive_ops/primitive_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,8 @@ def __repr__(self) -> str:
return "{}({}, coeff={})".format(type(self).__name__, repr(self.primitive), self.coeff)

def eval(self,
front: Union[str, dict, np.ndarray,
OperatorBase] = None) -> Union[OperatorBase, float, complex]:
front: Optional[Union[str, Dict[str, complex], np.ndarray, OperatorBase]] = None
) -> Union[OperatorBase, float, complex]:
raise NotImplementedError

@property
Expand Down
4 changes: 2 additions & 2 deletions qiskit/aqua/operators/state_fns/circuit_state_fn.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,8 +275,8 @@ def assign_parameters(self, param_dict: dict) -> OperatorBase:
return self.__class__(qc, coeff=param_value, is_measurement=self.is_measurement)

def eval(self,
front: Union[str, dict, np.ndarray,
OperatorBase] = None) -> Union[OperatorBase, float, complex]:
front: Optional[Union[str, Dict[str, complex], np.ndarray, OperatorBase]] = None
) -> Union[OperatorBase, float, complex]:
if front is None:
vector_state_fn = self.to_matrix_op().eval()
vector_state_fn = cast(OperatorBase, vector_state_fn)
Expand Down
4 changes: 2 additions & 2 deletions qiskit/aqua/operators/state_fns/dict_state_fn.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,8 @@ def __str__(self) -> str:

# pylint: disable=too-many-return-statements
def eval(self,
front: Union[str, dict, np.ndarray,
OperatorBase] = None) -> Union[OperatorBase, float, complex]:
front: Optional[Union[str, Dict[str, complex], np.ndarray, OperatorBase]] = None
) -> Union[OperatorBase, float, complex]:
if front is None:
vector_state_fn = self.to_matrix_op().eval()
vector_state_fn = cast(OperatorBase, vector_state_fn)
Expand Down
4 changes: 2 additions & 2 deletions qiskit/aqua/operators/state_fns/state_fn.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,8 @@ def __repr__(self) -> str:
self.coeff, self.is_measurement)

def eval(self,
front: Union[str, dict, np.ndarray,
OperatorBase] = None) -> Union[OperatorBase, float, complex]:
front: Optional[Union[str, Dict[str, complex], np.ndarray, OperatorBase]] = None
) -> Union[OperatorBase, float, complex]:
raise NotImplementedError

@property
Expand Down
4 changes: 2 additions & 2 deletions qiskit/aqua/operators/state_fns/vector_state_fn.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ def __str__(self) -> str:

# pylint: disable=too-many-return-statements
def eval(self,
front: Union[str, dict, np.ndarray,
OperatorBase] = None) -> Union[OperatorBase, float, complex]:
front: Optional[Union[str, Dict[str, complex], np.ndarray, OperatorBase]] = None
) -> Union[OperatorBase, float, complex]:
if front is None: # this object is already a VectorStateFn
return self

Expand Down

0 comments on commit a937d3e

Please sign in to comment.