diff --git a/qiskit/aqua/operators/operator_base.py b/qiskit/aqua/operators/operator_base.py index 46bc428042..7a137ea951 100644 --- a/qiskit/aqua/operators/operator_base.py +++ b/qiskit/aqua/operators/operator_base.py @@ -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. diff --git a/qiskit/aqua/operators/primitive_ops/circuit_op.py b/qiskit/aqua/operators/primitive_ops/circuit_op.py index 4647307ee8..48187ef33a 100644 --- a/qiskit/aqua/operators/primitive_ops/circuit_op.py +++ b/qiskit/aqua/operators/primitive_ops/circuit_op.py @@ -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 diff --git a/qiskit/aqua/operators/primitive_ops/matrix_op.py b/qiskit/aqua/operators/primitive_ops/matrix_op.py index d860d34780..283f96cc21 100644 --- a/qiskit/aqua/operators/primitive_ops/matrix_op.py +++ b/qiskit/aqua/operators/primitive_ops/matrix_op.py @@ -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 diff --git a/qiskit/aqua/operators/primitive_ops/pauli_op.py b/qiskit/aqua/operators/primitive_ops/pauli_op.py index c6cf221ca8..c252086b0b 100644 --- a/qiskit/aqua/operators/primitive_ops/pauli_op.py +++ b/qiskit/aqua/operators/primitive_ops/pauli_op.py @@ -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() diff --git a/qiskit/aqua/operators/primitive_ops/primitive_op.py b/qiskit/aqua/operators/primitive_ops/primitive_op.py index 043d589057..01027e0b81 100644 --- a/qiskit/aqua/operators/primitive_ops/primitive_op.py +++ b/qiskit/aqua/operators/primitive_ops/primitive_op.py @@ -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 diff --git a/qiskit/aqua/operators/state_fns/circuit_state_fn.py b/qiskit/aqua/operators/state_fns/circuit_state_fn.py index 39dd6d0e39..fedea52a3f 100644 --- a/qiskit/aqua/operators/state_fns/circuit_state_fn.py +++ b/qiskit/aqua/operators/state_fns/circuit_state_fn.py @@ -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) diff --git a/qiskit/aqua/operators/state_fns/dict_state_fn.py b/qiskit/aqua/operators/state_fns/dict_state_fn.py index b5ac6a4506..d060c91d87 100644 --- a/qiskit/aqua/operators/state_fns/dict_state_fn.py +++ b/qiskit/aqua/operators/state_fns/dict_state_fn.py @@ -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) diff --git a/qiskit/aqua/operators/state_fns/state_fn.py b/qiskit/aqua/operators/state_fns/state_fn.py index 1c03f57c2e..ea25b79161 100644 --- a/qiskit/aqua/operators/state_fns/state_fn.py +++ b/qiskit/aqua/operators/state_fns/state_fn.py @@ -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 diff --git a/qiskit/aqua/operators/state_fns/vector_state_fn.py b/qiskit/aqua/operators/state_fns/vector_state_fn.py index 512fc07ccd..025a6fbed3 100644 --- a/qiskit/aqua/operators/state_fns/vector_state_fn.py +++ b/qiskit/aqua/operators/state_fns/vector_state_fn.py @@ -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