Skip to content

Commit

Permalink
Add a parameters method to the Operators (qiskit-community/qiskit-aqu…
Browse files Browse the repository at this point in the history
…a#1194)

Co-authored-by: Manoel Marques <Manoel.Marques@ibm.com>
Co-authored-by: Steve Wood <40241007+woodsp-ibm@users.noreply.github.com>
  • Loading branch information
3 people authored Aug 18, 2020
1 parent b5ceade commit dac8c0e
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 0 deletions.
9 changes: 9 additions & 0 deletions qiskit/aqua/operators/list_ops/list_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,15 @@ def __repr__(self) -> str:
self.coeff,
self.abelian)

@property
def parameters(self):
params = set()
for op in self.oplist:
params.update(op.parameters)
if isinstance(self.coeff, ParameterExpression):
params.update(self.coeff.parameters)
return params

def assign_parameters(self, param_dict: dict) -> OperatorBase:
param_value = self.coeff
if isinstance(self.coeff, ParameterExpression):
Expand Down
7 changes: 7 additions & 0 deletions qiskit/aqua/operators/operator_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,13 @@ def tensorpower(self, other: int) -> Union['OperatorBase', int]:
"""
raise NotImplementedError

@property
@abstractmethod
def parameters(self):
r""" Return a set of Parameter objects contained in the Operator.
"""
raise NotImplementedError

# Utility functions for parameter binding

@abstractmethod
Expand Down
9 changes: 9 additions & 0 deletions qiskit/aqua/operators/primitive_ops/primitive_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,15 @@ def eval(self,
OperatorBase] = None) -> Union[OperatorBase, float, complex]:
raise NotImplementedError

@property
def parameters(self):
params = set()
if isinstance(self.primitive, (OperatorBase, QuantumCircuit)):
params.update(self.primitive.parameters)
if isinstance(self.coeff, ParameterExpression):
params.update(self.coeff.parameters)
return params

def assign_parameters(self, param_dict: dict) -> OperatorBase:
param_value = self.coeff
if isinstance(self.coeff, ParameterExpression):
Expand Down
9 changes: 9 additions & 0 deletions qiskit/aqua/operators/state_fns/state_fn.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,15 @@ def eval(self,
OperatorBase] = None) -> Union[OperatorBase, float, complex]:
raise NotImplementedError

@property
def parameters(self):
params = set()
if isinstance(self.primitive, (OperatorBase, QuantumCircuit)):
params.update(self.primitive.parameters)
if isinstance(self.coeff, ParameterExpression):
params.update(self.coeff.parameters)
return params

def assign_parameters(self, param_dict: dict) -> OperatorBase:
param_value = self.coeff
if isinstance(self.coeff, ParameterExpression):
Expand Down

0 comments on commit dac8c0e

Please sign in to comment.