Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
ikkoham committed Oct 26, 2020
1 parent f87a39a commit 5acedfb
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion qiskit/aqua/operators/converters/circuit_sampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from qiskit.providers import Backend
from qiskit.circuit import QuantumCircuit, Parameter, ParameterExpression
from qiskit import QiskitError
from qiskit.aqua import QuantumInstance
from qiskit.aqua import QuantumInstance, AquaError
from qiskit.aqua.utils.backend_utils import is_aer_provider, is_statevector_backend
from qiskit.aqua.operators.operator_base import OperatorBase
from qiskit.aqua.operators.list_ops.list_op import ListOp
Expand Down Expand Up @@ -165,6 +165,8 @@ def convert(self,
Returns:
The converted Operator with CircuitStateFns replaced by DictStateFns or VectorStateFns.
Raises:
AquaError: if extracted circuits are empty.
"""
if self._last_op is None or id(operator) != id(self._last_op):
# Clear caches
Expand All @@ -181,6 +183,11 @@ def convert(self,
if not self._circuit_ops_cache:
self._circuit_ops_cache = {}
self._extract_circuitstatefns(self._reduced_op_cache)
if not self._circuit_ops_cache:
raise AquaError(
'Circuits are empty. '
'Check the operator is a instance of CircuitStateFn or its ListOp.'
)

if params:
p_0 = list(params.values())[0] # type: ignore
Expand Down Expand Up @@ -243,7 +250,12 @@ def sample_circuits(self,
Returns:
The dictionary mapping ids of the CircuitStateFns to their replacement StateFns.
Raises:
AquaError: if extracted circuits are empty.
"""
if not circuit_sfns and not self._transpiled_circ_cache:
raise AquaError('CircuitStateFn is empty and there is no cache.')

if circuit_sfns or not self._transpiled_circ_cache:
if self._statevector:
circuits = [op_c.to_circuit(meas=False) for op_c in circuit_sfns]
Expand Down

0 comments on commit 5acedfb

Please sign in to comment.