Python Forum
error handling in multiprocessing /spawn.py
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
error handling in multiprocessing /spawn.py
#1
error handling in multiprocessing/spawn.py line 136

i am trying to run an example from squanch document file:///C:/Users/User/Anaconda3/squanch/squanch/1808.07047.pdf
i am student from qutech and would like to make quantum software.
al examples don't work after the frozen message

the lines :
# Make agent instances
out = Agent.shared_output()

is the start of the system interupt. child processes blocks???
who has a solution for me?

My OS is Windows 10 Pro 64-bit. Anaconda3 with Spyder 3.3.6 Python 3.7.4 64-bit | Qt 5.9.6 | PyQt5 5.9.2 | Windows 10
I wrote a simple script (t.py, see the attached file) with multiprocessing.Pool and run it by:
python t.py
in Windows Command Prompt.
I tried to interrupt the running script by pressing Ctrl+C keys. Python showed the message:

(base) PS C:\Users\User\anaconda3\squanch> python testxx4.py
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:\Users\User\Anaconda3\lib\multiprocessing\spawn.py", line 105, in spawn_main
exitcode = _main(fd)
File "C:\Users\User\Anaconda3\lib\multiprocessing\spawn.py", line 114, in _main
prepare(preparation_data)
File "C:\Users\User\Anaconda3\lib\multiprocessing\spawn.py", line 225, in prepare
_fixup_main_from_path(data['init_main_from_path'])
File "C:\Users\User\Anaconda3\lib\multiprocessing\spawn.py", line 277, in _fixup_main_from_path
run_name="__mp_main__")
File "C:\Users\User\Anaconda3\lib\runpy.py", line 263, in run_path
pkg_name=pkg_name, script_name=fname)
File "C:\Users\User\Anaconda3\lib\runpy.py", line 96, in _run_module_code
mod_name, mod_spec, pkg_name, script_name)
File "C:\Users\User\Anaconda3\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "C:\Users\User\anaconda3\squanch\testxx4.py", line 58, in <module>
out = Agent.shared_output()
File "C:\Users\User\anaconda3\squanch\squanch\agent.py", line 93, in shared_output
return multiprocessing.Manager().dict()
File "C:\Users\User\Anaconda3\lib\multiprocessing\context.py", line 56, in Manager
m.start()
File "C:\Users\User\Anaconda3\lib\multiprocessing\managers.py", line 563, in start
self._process.start()
File "C:\Users\User\Anaconda3\lib\multiprocessing\process.py", line 112, in start
self._popen = self._Popen(self)
File "C:\Users\User\Anaconda3\lib\multiprocessing\context.py", line 322, in _Popen
return Popen(process_obj)
File "C:\Users\User\Anaconda3\lib\multiprocessing\popen_spawn_win32.py", line 46, in __init__
prep_data = spawn.get_preparation_data(process_obj._name)
File "C:\Users\User\Anaconda3\lib\multiprocessing\spawn.py", line 143, in get_preparation_data
_check_not_importing_main()
File "C:\Users\User\Anaconda3\lib\multiprocessing\spawn.py", line 136, in _check_not_importing_main
is not going to be frozen to produce an executable.''')
RuntimeError:
An attempt has been made to start a new process before the
current process has finished its bootstrapping phase.

This probably means that you are not using fork to start your
child processes and you have forgotten to use the proper idiom
in the main module:

if __name__ == '__main__':
freeze_support()
...

The "freeze_support()" line can be omitted if the program
is not going to be frozen to produce an executable.
Traceback (most recent call last):
File "testxx4.py", line 58, in <module>
out = Agent.shared_output()
File "C:\Users\User\anaconda3\squanch\squanch\agent.py", line 93, in shared_output
return multiprocessing.Manager().dict()
File "C:\Users\User\Anaconda3\lib\multiprocessing\context.py", line 56, in Manager
m.start()
File "C:\Users\User\Anaconda3\lib\multiprocessing\managers.py", line 567, in start
self._address = reader.recv()
File "C:\Users\User\Anaconda3\lib\multiprocessing\connection.py", line 250, in recv
buf = self._recv_bytes()
File "C:\Users\User\Anaconda3\lib\multiprocessing\connection.py", line 306, in _recv_bytes
[ov.event], False, INFINITE)
KeyboardInterrupt
(base) PS C:\Users\User\anaconda3\squanch>



import numpy as np
import matplotlib.pyplot as plt
from multiprocessing import *
from squanch import *


import matplotlib.image as image
class Charlie(Agent):
'''Charlie sends Bell pairs to Alice and Bob.'''
def run(self):
for qsys in self.qstream:
a, b = qsys.qubits
H(a)
CNOT(a, b)
self.qsend(alice, a)
self.qsend(bob, b)
self.output({"t": self.time})

class Alice(Agent):

'''Alice sends Bob superdense-encoded bitstream'''
def run(self):
for _ in self.qstream:
bit1 = self.data.pop(0)
bit2 = self.data.pop(0)
q = self.qrecv(charlie)
# qubit could be lost to attenuation
if q is not None:
if bit2 == 1: X(q)
if bit1 == 1: Z(q)
self.qsend(bob, q)
self.output({"t": self.time})

class Bob(Agent):
'''Bob reconstructs Alice's data '''
def run(self):
bits = []
for _ in self.qstream:
a = self.qrecv(alice)
c = self.qrecv(charlie)
if a is not None and c is not None:
CNOT(a, c)
H(a)
bits.extend([a.measure(), c.measure()])
else:
# if qubits are lost
bits.extend([0,0])
self.output({"t":
self.time, "bits": bits})

# Load an image and serialize it to a bitstream
#img = image.imread("../docs/source/img/foundryLogo.bmp")
#img = image.imread("foundryLogo.bmp")
#bitstream = list(np.unpackbits(img))

def to_bits(string):
#Convert a string to a list of bits
result = []
for c in string:
bits = bin(ord©)[2:]
bits = '00000000'[len(bits):] + bits
result.extend([int(b) for b in bits])
return result

def from_bits(bits):
#Convert a list of bits to a string
chars = []
for b in range(int(len(bits) / 8)):
byte = bits[b*8:(b+1)*8]
chars.append(chr(int(''.join([str(bit) for bit in byte]), 2)))
return ''.join(chars)


msg = "Peter Shor once lived in Ruddock 238! But who was Airman?"
bits = to_bits(msg)
print(bits)

# Initialize QStream and Agents
#qstream = QStream(2, int(len(bitstream) / 2))

# Encode the message as spin eigenstates
qstream = QStream(9, len(bits))
# 9 qubits per encoded state
for bit, qsystem in zip(bits, qstream):
if bit == 1:
X(qsystem.qubit(0))

# Make agent instances
out = Agent.shared_output()
#

# Alice and Bob will use error correction
out = Agent.shared_output()
alice = Alice(qstream, out)
bob = Bob(qstream, out)
alice.qconnect(bob, ShorQChannel)

#alice = Alice(qstream, out, data = bitstream)
#bob = Bob(qstream, out)
#charlie = Charlie(qstream, out)

# Set 1ns photon transmission rate
alice.pulse_length = 1e-9
bob.pulse_length = 1e-9
charlie.pulse_length = 1e-9

# Connect the agents with simulated fiber optic lines
alice.qconnect(bob, FiberOpticQChannel, length=1.0)
charlie.qconnect(alice, FiberOpticQChannel, length=0.5)
charlie.qconnect(bob, FiberOpticQChannel, length=0.5)

# Run the agents
start = time.time()
Simulation(alice, bob, charlie).run()

# Print simulated time at end
print("Transmitted {} bits in {:.3f}s.".format(len(out["Bob"]), time.time() - start))
t_alice, t_bob, t_charlie = out["Alice"]["t"], out["Bob"]["t"], out["Charlie"]["t"]
print("Simulated time: Alice: {:.2e}s, Bob: {:.2e}s, Charlie: {:.2e}s" .format(t_alice, t_bob, t_charlie))


# >> Alice: 4.16e-04s # >> Bob: 4.20e-04s # >> Charlie: 4.15e-04s
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Issue with error handling Alberto 1 3,556 Jan-29-2018, 06:09 PM
Last Post: Msaad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020