Repository: Qiskit/qiskit

Issue:
Local qiskit simulator slow on Windows
<!--- Provide a general summary of the issue in the Title above -->
I have both a Mac and a PC, and when I try and run my code using the 'local_qiskit_simulator' as the backend, it's much faster on Mac than it is on Windows.  It seems like it built correctly (there's a qiskit_simulator.exe file in the backend folder), but it's still not as fast.  Is there a way to confirm that the existent .exe file is correctly compiled and that it's not falling back to the slower Python backend?

Any help would be greatly appreciated, thank you.

For context, my environment is:  
* pip version 9.0.1  
* python version 3.6.4 (Anaconda custom 64-bit)
* conda version 4.5.1
* qiskit version 0.4.14

QISKit was installed using pip.

Let me know if you need any more information!  Thanks.


Discussion:
Well, the simplest thing to do would be remove the exe and see if the timing remains unchanged.
`local_qiskit_simulator` does not fall back to python code, at least with the version you are running. (in the future we will make just one `local_qasm_simulator` that automatically selects the fastest available). so you do have the c++ installed.
When I delete qiskit_simulator.exe, the program simply fails to run. That means it is working, but it remains very slow. For every execution, a window flashes briefly on the screen (qiskit_simulator.exe), and the run time is no faster than the local_qasm_simulator. Is there anything else that could be wrong?
So, I looked into it last night, and it is not the simulator that is slow, but rather an issue with the `_JobProcessor` that handles things behind the scenes on Windows.  This is something that @ewinston should probably look into.
If you have any further updates or suggestions, I would love to try something. Thanks!
Hi @erikweis, I am trying to get a copy of Windows to test this out. Do I understand correctly that you get counts back after you delete the simulator executable but very slowly?
@ewinston To clarify, when I delete the executable I get back an error message and do not get results. When the executable is there, the executable does run and I definitely get counts back, but this process is very slow.  Please let me know if you have any more questions and thanks for your help!
Looking into the code, the `JobProcessor` is creating a new `Process`.  On Windows, it is known that creating a new `Process` is slow.  For example see the discussion here:

https://stackoverflow.com/questions/38236211/why-multiprocessing-process-behave-differently-on-windows-and-linux-for-global-o

In short, there is no `fork` command on Windows, and as  such, creating a new `Process`basically requires loading up a new Python interpreter.  Therefore, there is not much that can be done in QISKit to mitigate this.
@erikweis A possible work around (pre 0.5) for the issue @nonhermitian brought up, is to call the `run_backend(q_job)` method of the _jobprocessor.py module directly. This call is usually done by spawning a process or thread but you can also call directly.

Resolving patch:
diff --git a/qiskit/backends/local/localjob.py b/qiskit/backends/local/localjob.py
--- a/qiskit/backends/local/localjob.py
+++ b/qiskit/backends/local/localjob.py
@@ -25,7 +25,7 @@ class LocalJob(BaseJob):
         _executor (futures.Executor): executor to handle asynchronous jobs
     """
 
-    if sys.platform == 'darwin':
+    if sys.platform in ['darwin', 'win32']:
         _executor = futures.ThreadPoolExecutor()
     else:
         _executor = futures.ProcessPoolExecutor()


Test patch: