Jupyter notebook 在执行 qiskit 代码时总是给出 Broken ProcessPool 错误



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)    

定义寄存器:

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

运行代码:

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()    

错误:

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()
~Anaconda3envsQISKitenvlibsite-packagesqiskitwrapper_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)
~Anaconda3envsQISKitenvlibsite- 
packagesqiskitbackendslocalqasm_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):
~Anaconda3envsQISKitenvlibsite-packagesqiskitbackendslocallocaljob.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):
~Anaconda3envsQISKitenvlibconcurrentfuturesprocess.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

我之前执行了这段代码,它有效。 现在无论我在 Jupyter 笔记本中运行哪个代码,我都会在行中出现损坏的进程池错误

job=execute(circuits,backend)     

我无法理解如何删除此错误。我在Jupyter Notebook中运行的任何代码都在此行中得到相同的错误。我把这段代码发给了朋友,它在他的jupyter笔记本中执行了。请帮忙。

我也有同样的问题。我重置了木星笔记本的内核,并修复了它。不是一个很好的答案,但至少是一些东西。

看起来你正在Windows上运行。在 Windows 上运行时,如果顶级函数调用未包含在if __name__ == '__main__':块中,则多线程 Python 代码(如 QISKit 模拟器(有时会遇到问题。我不确定这是否会解决您在这里遇到的特定问题,但可能值得一试。

如果这不能解决问题,您可以尝试将local_qasm_simulator替换为local_qasm_simulator_pylocal_qasm_simulator_cpp以显式尝试 Python 和 C++ 版本的模拟器,以防其中一个在您的计算机上出现问题(如果安装了 QISKit,则应默认为C++版本(。

希望对您有所帮助!

道格

最新更新