0
$\begingroup$

I try to run HHL algorithm on qasm_simulator. I took the example from here. I try to solve 8x8 random matrix and adjust some parameters in create_eigs.

aqua_globals.random_seed = 0
matrix = random_hermitian(8)
vector = matrix.dot(np.array([1, 2, 3, 4, 5, 6,7,8]))

orig_size = len(vector)
matrix, vector, truncate_powerdim, truncate_hermitian = HHL.matrix_resize(matrix, vector)

# Initialize eigenvalue finding module
eigs = create_eigs(matrix, 3, 10, False)
num_q, num_a = eigs.get_register_sizes()

# Initialize initial state module
init_state = Custom(num_q, state_vector=vector)

# Initialize reciprocal rotation module
reci = LookupRotation(negative_evals=eigs._negative_evals, evo_time=eigs._evo_time)

algo = HHL(matrix, vector, truncate_powerdim, truncate_hermitian, eigs,
           init_state, reci, num_q, num_a, orig_size)
result = algo.run(QuantumInstance(Aer.get_backend('qasm_simulator')))

Then, this error occur.

---------------------------------------------------------------------------
BrokenProcessPool                         Traceback (most recent call last)
<ipython-input-8-105a0b6b991d> in <module>
     18 algo = HHL(matrix, vector, truncate_powerdim, truncate_hermitian, eigs,
     19            init_state, reci, num_q, num_a, orig_size)
---> 20 result = algo.run(QuantumInstance(Aer.get_backend('qasm_simulator')))

~/.local/lib/python3.8/site-packages/qiskit/aqua/algorithms/quantum_algorithm.py in run(self, quantum_instance, **kwargs)
     69                 self.quantum_instance = quantum_instance
     70 
---> 71         return self._run()
     72 
     73     @abstractmethod

~/.local/lib/python3.8/site-packages/qiskit/aqua/algorithms/linear_solvers/hhl.py in _run(self)
    407         else:
    408             self.construct_circuit(measurement=False)
--> 409             self._state_tomography()
    410         # Adding a bit of general result information
    411         self._ret["matrix"] = self._resize_matrix(self._matrix)

~/.local/lib/python3.8/site-packages/qiskit/aqua/algorithms/linear_solvers/hhl.py in _state_tomography(self)
    341 
    342         # Extracting the probability of successful run
--> 343         results = self._quantum_instance.execute(tomo_circuits)
    344         probs = []
    345         for circ in tomo_circuits:

~/.local/lib/python3.8/site-packages/qiskit/aqua/quantum_instance.py in execute(self, circuits, had_transpiled)
    268         # maybe compile
    269         if not had_transpiled:
--> 270             circuits = self.transpile(circuits)
    271 
    272         # assemble

~/.local/lib/python3.8/site-packages/qiskit/aqua/quantum_instance.py in transpile(self, circuits)
    229                                   the length is one.
    230         """
--> 231         transpiled_circuits = compiler.transpile(circuits, self._backend, **self._backend_config,
    232                                                  **self._compile_config)
    233         if not isinstance(transpiled_circuits, list):

~/.local/lib/python3.8/site-packages/qiskit/compiler/transpile.py in transpile(circuits, backend, basis_gates, coupling_map, backend_properties, initial_layout, layout_method, routing_method, translation_method, scheduling_method, instruction_durations, dt, seed_transpiler, optimization_level, pass_manager, callback, output_name)
    241 
    242     # Transpile circuits in parallel
--> 243     circuits = parallel_map(_transpile_circuit, list(zip(circuits, transpile_args)))
    244 
    245     if len(circuits) == 1:

~/.local/lib/python3.8/site-packages/qiskit/tools/parallel.py in parallel_map(task, values, task_args, task_kwargs, num_processes)
    133             # Otherwise just reset parallel flag and error
    134             os.environ['QISKIT_IN_PARALLEL'] = 'FALSE'
--> 135             raise error
    136 
    137         Publisher().publish("terra.parallel.finish")

~/.local/lib/python3.8/site-packages/qiskit/tools/parallel.py in parallel_map(task, values, task_args, task_kwargs, num_processes)
    123                 future = executor.map(_task_wrapper, param)
    124 
--> 125             results = list(future)
    126             Publisher().publish("terra.parallel.done", len(results))
    127 

/usr/lib/python3.8/concurrent/futures/process.py in _chain_from_iterable_of_lists(iterable)
    482     careful not to keep references to yielded objects.
    483     """
--> 484     for element in iterable:
    485         element.reverse()
    486         while element:

/usr/lib/python3.8/concurrent/futures/_base.py in result_iterator()
    609                     # Careful not to keep a reference to the popped future
    610                     if timeout is None:
--> 611                         yield fs.pop().result()
    612                     else:
    613                         yield fs.pop().result(end_time - time.monotonic())

/usr/lib/python3.8/concurrent/futures/_base.py in result(self, timeout)
    430                 raise CancelledError()
    431             elif self._state == FINISHED:
--> 432                 return self.__get_result()
    433 
    434             self._condition.wait(timeout)

/usr/lib/python3.8/concurrent/futures/_base.py in __get_result(self)
    386     def __get_result(self):
    387         if self._exception:
--> 388             raise self._exception
    389         else:
    390             return self._result

BrokenProcessPool: A process in the process pool was terminated abruptly while the future was running or pending.

Please tell me how to fix this error.

$\endgroup$
1
$\begingroup$

Multiprocessing in Python 3.8 sometimes has some hiccups, especially when used in combination with Matplotlib and Qiskit. You could try several things:

  1. Run Python 3.7 instead of 3.8 (that's also likely to be faster since there's less overhead in the parallelization)
  2. Check if you used Matplotlib somewhere and try to avoid it before the running the algorithm.
  3. Disable parallelization by setting
    import os
    os.environ['QISKIT_IN_PARALLEL'] = True  # pretends the code already runs in parallel
    

The first option is probably the best. The third option disables parallelization so it will slow down the computation if the circuits are large!

$\endgroup$
1
  • $\begingroup$ I noticed a similar issue even with Python 3.7 (the circuit I was running was transpilation of randomized benchmarking circuits). My environment is Ubuntu 20 virtual machine with 6 cores and 16 GB ram on Win 10 host. $\endgroup$ Jan 18 at 3:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.