handle perfect powers gracefully
@@ -78,13 +78,14 @@ class Shor(QuantumAlgorithm):
if N < 1 or N % 2 == 0:
raise AquaError('The input needs to be an odd integer greater than 1.')
+ self._N = N
+ self._ret = {'factors': []}
+
# check if the input integer is a power
tf, b, p = is_power(N, return_decomposition=True)
if tf:
- raise NotImplementedError
-
- self._N = N
- self._ret = {'factors': []}
+ logger.warning(f'The input integer is a power: {N}={b}^{p}.')
+ self._ret['factors'].append(b)
@classmethod
def init_params(cls, params, algo_input):
@@ -479,6 +480,7 @@ class Shor(QuantumAlgorithm):
return True
def _run(self):
+ if not self._ret['factors']:
self._a = self._pick_coprime_a()
logger.debug('Running with N={} and a={}\n'.format(self._N, self._a))
