rigetti / pyquil

A Python library for quantum programming using Quil.
http://docs.rigetti.com
Apache License 2.0
1.4k stars 342 forks source link

Qubit alloc, time outs and Job Connections #148

Closed rasa97 closed 7 years ago

rasa97 commented 7 years ago
  1. Why is it that when i run
qubits = [p.alloc() for _ in range(2)]
print qvm.wavefunction(p)[0]

Sometimes I get (1+0j)|0>, and sometimes the operation times out? A) shouldn't I get two qubits allocated? B) why is that I frequently get connection timed out, and have to restart Wi-Fi to properly connect to Forest again? What is the best way to allocate user defined multi qubits and print their wavefunction?

  1. When should we use Job Connections and why? I get that we use it when we have a large program but how is it superior to ordinary connection?

Time our error:

raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPSConnectionPool(host='api.rigetti.com', port=443): Max retries exceeded with url: /qvm (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x10f4cea10>: Failed to establish a new connection: [Errno 60] Operation timed out',))
stevenheidel commented 7 years ago

When you allocate qubits, Pyquil checks to see which ones are actually being used at all in the computation. It will clean up any excess qubits to make things more efficient. In this case neither is being used so it defaults to 1. You can verify this by increasing to range(5) for example and notice that there is still only 1 unique qubit allocated.

Not sure about the timeout errors. It could be a problem on our end with serving requests. Do you have to restart Wi-Fi or is it sufficient to wait a while and try again? If you always have to restart your Wi-Fi then that indicates an unknown issue with your system. If the server just periodically times out with no changes on your end then that's an issue with our server.

To answer your question about Job Connections: they should be used for running programs where there are more than 16 qubits. For programs smaller than that it's faster to use the SyncConnection.