Jupyter notebook always gives BrokenProcessPool error while executing qiskit code
Asked Answered
Z

2

0

defining function for toffoli gate:

def toffoli(qc,i1,i2,i3):
qc.h(i3)
qc.cx(i2,i3)
qc.tdg(i3)
qc.cx(i1,i3)
qc.t(i3)
qc.cx(i2,i3)
qc.tdg(i3)
qc.cx(i1,i3)
qc.t(i3)
qc.tdg(i2)
qc.cx(i1,i2)
qc.h(i3)
qc.tdg(i2)
qc.cx(i1,i2)
qc.t(i1)
qc.s(i2)    

Defining the registers:

qr=QuantumRegister(5)
cr=ClassicalRegister(5)
qc=QuantumCircuit(qr,cr)

to run the code:

qc.x(qr[0])
qc.x(qr[1])
toffoli(qc,qr[0],qr[1],qr[2])
qc.measure(qr[0],cr[0])
qc.measure(qr[1],cr[1])
qc.measure(qr[2],cr[2])
circuits=[qc]
job=execute(circuits,backend="local_qasm_simulator")
result=job.result()    

error:

BrokenProcessPool                         Traceback (most recent call last)
<ipython-input-10-47786bf8d782> in <module>()
      1 circuits=[qc]
----> 2 job=execute(circuits,backend) 
      3 job.status
      4 result=job.result()

~\Anaconda3\envs\QISKitenv\lib\site-packages\qiskit\wrapper\_wrapper.py in execute(circuits, backend, config, basis_gates, coupling_map,initial_layout, shots, max_credits, seed, qobj_id, hpc, skip_translation) 
    202     q_job = QuantumJob(qobj, backend=backend, preformatted=True, 
resources={
    203         'max_credits': qobj['config']['max_credits']})
--> 204     return backend.run(q_job)

 ~\Anaconda3\envs\QISKitenv\lib\site- 
   packages\qiskit\backends\local\qasm_simulator_cpp.py in run(self, q_job)
     83     def run(self, q_job):
     84         """Run a QuantumJob on the the backend."""
---> 85         return LocalJob(self._run_job, q_job)
     86 
     87     def _run_job(self, q_job):

~\Anaconda3\envs\QISKitenv\lib\site-packages\qiskit\backends\local\localjob.py in __init__(self, fn, q_job)
     44         self._q_job = q_job
     45         self._backend_name = q_job.backend.name
---> 46         self._future = self._executor.submit(fn, q_job)
     47 
     48     def result(self, timeout=None):

~\Anaconda3\envs\QISKitenv\lib\concurrent\futures\process.py in submit(self, 
fn, *args, **kwargs)
    450         with self._shutdown_lock:
    451             if self._broken:
--> 452                 raise BrokenProcessPool('A child process terminated 
'
    453                     'abruptly, the process pool is not usable 
anymore')
    454             if self._shutdown_thread:

BrokenProcessPool: A child process terminated abruptly, the process pool is 
not usable anymore

I executed this code earlier and it worked. now whichever code I run in Jupyter notebook, I get brokenprocesspool error in the line

 job=execute(circuits,backend)     

I am not able to understand how to remove this error. Any code i run in my Jupyter Notebook I get the same error in this line. I sent this code to a friend and it executed in his jupyter notebook. Please help.

Zippora answered 30/5, 2018 at 18:36 Comment(2)
Related: #48454176Infralapsarian
If you are running matplotlib in your code, that might be part of what is causing this error: github.com/Qiskit/qiskit-ignis/issues/419Blinding
R
1

I had this same problem. I reset the kernel of the Jupiter notebook, and that fixed it. Not a great answer, but it's at least something.

Roadstead answered 29/12, 2020 at 14:26 Comment(0)
D
-1

Looks like you're running on Windows. When running on Windows, multi-threaded Python code (such as the QISKit simulator) can sometimes run into problems if the top-level function call isn't enclosed in a if __name__ == '__main__': block. I'm not sure if that will fix the specific problem you're having here, but it may be worth a shot.

If that doesn't fix it, you might try replacing local_qasm_simulator with local_qasm_simulator_py or local_qasm_simulator_cpp to explicitly try both the Python and C++ versions of the simulator in case one of them has an issue on your machine (QISKit should default to the C++ one if it's installed).

Hope that helps!

Doug

Demoss answered 31/5, 2018 at 0:9 Comment(1)
Thanks for an early response but I still seem to have the same problem after making functions that include if name == 'main':Zippora

© 2022 - 2024 — McMap. All rights reserved.