定义toffoli门的功能:
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()
~\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
我之前执行了这段代码并且有效。现在无论我在Jupyter笔记本中运行哪个代码,我都会在行中出现brokenprocesspool错误
job=execute(circuits,backend)
我无法理解如何删除此错误。我在Jupyter笔记本中运行的任何代码我在这一行中得到了相同的错误。我把这个代码发送给了一个朋友,并在他的jupyter笔记本中执行。请帮忙。
答案 0 :(得分:1)
我遇到了同样的问题。我重置了 Jupiter 笔记本的内核,然后修复了它。不是一个很好的答案,但至少是一些东西。
答案 1 :(得分:0)
看起来你在Windows上运行了。在Windows上运行时,如果顶级函数调用未包含在if __name__ == '__main__':
块中,则多线程Python代码(例如QISKit模拟器)有时会遇到问题。我不确定这是否能解决您在这里遇到的具体问题,但可能值得一试。
如果没有解决问题,您可以尝试使用 local_qasm_simulator_py 或 local_qasm_simulator_cpp 替换 local_qasm_simulator ,以显式尝试Python和模拟器的C ++版本,以防其中一个在您的机器上出现问题(如果安装了QISKit,则默认为C ++版本。)
希望有所帮助!
道格