fix setting of i_objective
@@ -37,9 +37,6 @@ class AmplitudeEstimationBase(QuantumAlgorithm):
self._q_factory = q_factory
self.i_objective = i_objective
- if q_factory is not None and i_objective is None:
- raise AquaError('i_objective must be set for custom q_factory')
-
super().__init__()
@property
@@ -55,25 +52,8 @@ class AmplitudeEstimationBase(QuantumAlgorithm):
return self._q_factory
@q_factory.setter
- def q_factory(self, q_factory_and_i_objective):
- """
- Setter using
- ae.q_factory = (q_factory, i_objective)
- """
- try:
- self._q_factory, self.i_objective = q_factory_and_i_objective
- except ValueError:
- raise ValueError("Pass an iterable (q_factory, i_objective)")
-
- def set_q_factory(self, q_factory, i_objective):
- """
- Oldschool setter using
- ae.set_q_factory(q_factory, i_objective)
- """
- if i_objective is None:
- raise AquaError('i_objective must be set for custom q_factory')
- self.q_factory = q_factory
- self.i_objective = i_objective
+ def q_factory(self, q_factory):
+ self._q_factory, self.i_objective = q_factory
def check_factories(self):
"""
@@ -88,7 +68,7 @@ class AmplitudeEstimationBase(QuantumAlgorithm):
if self._q_factory is None:
self.i_objective = self.a_factory.num_target_qubits - 1
self._q_factory = QFactory(self._a_factory, self.i_objective)
-
- # check if i_objective has been set if a custom Q factory is used
- elif self.i_objective is None:
- raise AquaError('i_objective must be set for custom q_factory')
+ # set i_objective if has not been set
+ else:
+ if self.i_objective is None:
+ self.i_objective = self._q_factory.i_objective
