ProjectQ-Framework / ProjectQ

ProjectQ: An open source software framework for quantum computing
https://projectq.ch
Apache License 2.0
888 stars 274 forks source link

Problems running an example notebook #396

Closed LuigiGiuffrida98 closed 3 years ago

LuigiGiuffrida98 commented 3 years ago

Hi everibody, I'm having some issues trying to run this notebook, I set the token of my IBMq account, but still getting this exception: Failed to run the circuit. Aborting.

How can I get this work? Thanks everibody

Takishima commented 3 years ago

Could you try running the circuit and pass verbose=True to the MainEngine and then post the full log here?

If doing this in the notebook is too complicated, you could simply run the code below (same as the notebook you mentioned) either on the Python command line or as a Pythons script

import projectq.setups.ibm
from projectq.backends import IBMBackend
from projectq.ops import Measure, Entangle, All
from projectq import MainEngine

def run_entangle(eng, num_qubits):
    # allocate a quantum register of 5 qubits
    qureg = eng.allocate_qureg(num_qubits)

    # entangle the qureg
    Entangle | qureg

    # measure; should be all-0 or all-1
    All(Measure) | qureg

    # run the circuit
    eng.flush()

    # access the probabilities via the back-end:
    # results = eng.backend.get_probabilities(qureg)
    # for state in results:
    #     print("Measured {} with p = {}.".format(state, results[state]))
    # or plot them directly:
    histogram(eng.backend, qureg)
    plt.show()

    # return one (random) measurement outcome.
    return [int(q) for q in qureg]

eng = MainEngine(IBMBackend(use_hardware=True, num_runs=1024,
                            verbose=True, device='ibmqx4'),
                 engine_list=projectq.setups.ibm.get_engine_list())

run_entangle(eng, num_qubits=5)  # run it
LuigiGiuffrida98 commented 3 years ago

I got this error:

Traceback (most recent call last): File "pro.py", line 16, in eng = MainEngine(IBMBackend(use_hardware=True, num_runs=1024, verbose=True, device='ibmqx4'), engine_list=projectq.setups.ibm.get_engine_list()) File "/home/thesis/luigi.giuffrida/.local/lib/python3.6/site-packages/projectq/setups/ibm.py", line 42, in get_engine_list raise DeviceOfflineError('Error when configuring engine list: device ' projectq.setups.ibm.DeviceOfflineError: Error when configuring engine list: device requested for Backend not connected

Then, changing the device (selecting ibmq_qasm_simulator) and adding it as a parameter to get_engine_list() method the script starts (maybe now ibmqx4 is offline) and I get this output (I removed my token from the report):

- Authenticating... user API token: ------------------------------------------------------------------ - List of IBMQ devices available: {'ibmq_qasm_simulator': {'nq': 32, 'coupling_map': None, 'version': '0.1.547'}, 'ibmqx2': {'nq': 5, 'coupling_map': [[0, 1], [0, 2], [1, 0], [1, 2], [2, 0], [2, 1], [2, 3], [2, 4], [3, 2], [3, 4], [4, 2], [4, 3]], 'version': '2.3.6'}, 'ibmq_16_melbourne': {'nq': 15, 'coupling_map': [[0, 1], [0, 14], [1, 0], [1, 2], [1, 13], [2, 1], [2, 3], [2, 12], [3, 2], [3, 4], [3, 11], [4, 3], [4, 5], [4, 10], [5, 4], [5, 6], [5, 9], [6, 5], [6, 8], [7, 8], [8, 6], [8, 7], [8, 9], [9, 5], [9, 8], [9, 10], [10, 4], [10, 9], [10, 11], [11, 3], [11, 10], [11, 12], [12, 2], [12, 11], [12, 13], [13, 1], [13, 12], [13, 14], [14, 0], [14, 13]], 'version': '2.3.24'}, 'ibmq_armonk': {'nq': 1, 'coupling_map': None, 'version': '2.4.10'}, 'ibmq_athens': {'nq': 5, 'coupling_map': [[0, 1], [1, 0], [1, 2], [2, 1], [2, 3], [3, 2], [3, 4], [4, 3]], 'version': '1.3.19'}, 'ibmq_santiago': {'nq': 5, 'coupling_map': [[0, 1], [1, 0], [1, 2], [2, 1], [2, 3], [3, 2], [3, 4], [4, 3]], 'version': '1.3.22'}, 'ibmq_lima': {'nq': 5, 'coupling_map': [[0, 1], [1, 0], [1, 2], [1, 3], [2, 1], [3, 1], [3, 4], [4, 3]], 'version': '1.0.11'}, 'ibmq_belem': {'nq': 5, 'coupling_map': [[0, 1], [1, 0], [1, 2], [1, 3], [2, 1], [3, 1], [3, 4], [4, 3]], 'version': '1.0.12'}, 'ibmq_quito': {'nq': 5, 'coupling_map': [[0, 1], [1, 0], [1, 2], [1, 3], [2, 1], [3, 1], [3, 4], [4, 3]], 'version': '1.1.2'}, 'simulator_statevector': {'nq': 32, 'coupling_map': None, 'version': '0.1.547'}, 'simulator_mps': {'nq': 100, 'coupling_map': None, 'version': '0.1.547'}, 'simulator_extended_stabilizer': {'nq': 63, 'coupling_map': None, 'version': '0.1.547'}, 'simulator_stabilizer': {'nq': 5000, 'coupling_map': None, 'version': '0.1.547'}, 'ibmq_manila': {'nq': 5, 'coupling_map': [[0, 1], [1, 0], [1, 2], [2, 1], [2, 3], [3, 2], [3, 4], [4, 3]], 'version': '1.0.1'}} - Running code: {'json': [{'qubits': [0], 'name': 'u2', 'params': [0, 3.141592653589793]}, {'qubits': [0, 1], 'name': 'cx'}, {'qubits': [0, 2], 'name': 'cx'}, {'qubits': [0, 3], 'name': 'cx'}, {'qubits': [0, 4], 'name': 'cx'}, {'qubits': [0], 'name': 'measure', 'memory': [0]}, {'qubits': [1], 'name': 'measure', 'memory': [1]}, {'qubits': [2], 'name': 'measure', 'memory': [2]}, {'qubits': [3], 'name': 'measure', 'memory': [3]}, {'qubits': [4], 'name': 'measure', 'memory': [4]}], 'nq': 5, 'shots': 1024, 'maxCredits': 10, 'backend': {'name': 'ibmq_qasm_simulator'}} - Failed to parse response: 'downloadQObjectUrlEndpoint' Traceback (most recent call last): File "pro.py", line 18, in run_entangle(eng, num_qubits=5) File "pro.py", line 10, in run_entangle eng.flush() File "/home/thesis/luigi.giuffrida/.local/lib/python3.6/site-packages/projectq/cengines/_main.py", line 304, in flush self.receive([Command(self, FlushGate(), ([WeakQubitRef(self, -1)],))]) File "/home/thesis/luigi.giuffrida/.local/lib/python3.6/site-packages/projectq/cengines/_main.py", line 266, in receive self.send(command_list) File "/home/thesis/luigi.giuffrida/.local/lib/python3.6/site-packages/projectq/cengines/_main.py", line 288, in send raise compact_exception # use verbose=True for more info Exception: Failed to run the circuit. Aborting. raised in: ' File "/home/thesis/luigi.giuffrida/.local/lib/python3.6/site-packages/projectq/backends/_ibm/_ibm.py", line 323, in _run' ' raise Exception("Failed to run the circuit. Aborting.")'

Reading the report I noticed that, maybe, ibmqx4 is not available. The fact that I have a "- Failed to parse response" point looks suspicious.

Thank you for your disponibility.

Takishima commented 3 years ago

Hmmm seems like something changed recently on the Qiskit API. I will try to look into it next week.

In the meantime, could you run the second example also with verbose=True?

LuigiGiuffrida98 commented 3 years ago

I tried, I'm getting exactly the same output with a different JSON decription of the circuit.

Takishima commented 3 years ago

That is not possible, you cannot get this part of the output if you have verbose=True passed to the MainEngine:

File "/home/thesis/luigi.giuffrida/.local/lib/python3.6/site-packages/projectq/cengines/_main.py", line 288, in send
raise compact_exception # use verbose=True for more info
Exception: Failed to run the circuit. Aborting.
raised in:
' File "/home/thesis/luigi.giuffrida/.local/lib/python3.6/site-packages/projectq/backends/_ibm/_ibm.py", line 323, in _run'
' raise Exception("Failed to run the circuit. Aborting.")'

I need to have the full error log in order to better understand what is happening.

LuigiGiuffrida98 commented 3 years ago

I'm really sorry, I did not noticed that I put verbose=True just in the backend and not in the engine too.

This is what I get running the example (I'm on a different computer, but the behaviour is the same).

\- Authenticating...
user API token: --------------------------------------------------------------------
\- List of IBMQ devices available:
{'ibmq_qasm_simulator': {'nq': 32, 'coupling_map': None, 'version': '0.1.547'}, 'ibmqx2': {'nq': 5, 'coupling_map': [[0, 1], [0, 2], [1, 0], [1, 2], [2, 0], [2, 1], [2, 3], [2, 4], [3, 2], [3, 4], [4, 2], [4, 3]], 'version': '2.3.6'}, 'ibmq_16_melbourne': {'nq': 15, 'coupling_map': [[0, 1], [0, 14], [1, 0], [1, 2], [1, 13], [2, 1], [2, 3], [2, 12], [3, 2], [3, 4], [3, 11], [4, 3], [4, 5], [4, 10], [5, 4], [5, 6], [5, 9], [6, 5], [6, 8], [7, 8], [8, 6], [8, 7], [8, 9], [9, 5], [9, 8], [9, 10], [10, 4], [10, 9], [10, 11], [11, 3], [11, 10], [11, 12], [12, 2], [12, 11], [12, 13], [13, 1], [13, 12], [13, 14], [14, 0], [14, 13]], 'version': '2.3.24'}, 'ibmq_armonk': {'nq': 1, 'coupling_map': None, 'version': '2.4.10'}, 'ibmq_athens': {'nq': 5, 'coupling_map': [[0, 1], [1, 0], [1, 2], [2, 1], [2, 3], [3, 2], [3, 4], [4, 3]], 'version': '1.3.19'}, 'ibmq_santiago': {'nq': 5, 'coupling_map': [[0, 1], [1, 0], [1, 2], [2, 1], [2, 3], [3, 2], [3, 4], [4, 3]], 'version': '1.3.22'}, 'ibmq_lima': {'nq': 5, 'coupling_map': [[0, 1], [1, 0], [1, 2], [1, 3], [2, 1], [3, 1], [3, 4], [4, 3]], 'version': '1.0.11'}, 'ibmq_belem': {'nq': 5, 'coupling_map': [[0, 1], [1, 0], [1, 2], [1, 3], [2, 1], [3, 1], [3, 4], [4, 3]], 'version': '1.0.12'}, 'ibmq_quito': {'nq': 5, 'coupling_map': [[0, 1], [1, 0], [1, 2], [1, 3], [2, 1], [3, 1], [3, 4], [4, 3]], 'version': '1.1.2'}, 'simulator_statevector': {'nq': 32, 'coupling_map': None, 'version': '0.1.547'}, 'simulator_mps': {'nq': 100, 'coupling_map': None, 'version': '0.1.547'}, 'simulator_extended_stabilizer': {'nq': 63, 'coupling_map': None, 'version': '0.1.547'}, 'simulator_stabilizer': {'nq': 5000, 'coupling_map': None, 'version': '0.1.547'}, 'ibmq_manila': {'nq': 5, 'coupling_map': [[0, 1], [1, 0], [1, 2], [2, 1], [2, 3], [3, 2], [3, 4], [4, 3]], 'version': '1.0.1'}}
\- Running code: {'json': [{'qubits': [0], 'name': 'u2', 'params': [0, 3.141592653589793]}, {'qubits': [0], 'name': 'measure', 'memory': [0]}], 'nq': 1, 'shots': 1024, 'maxCredits': 10, 'backend': {'name': 'ibmq_qasm_simulator'}}
\- Failed to parse response:
'downloadQObjectUrlEndpoint'
Traceback (most recent call last):
  File "/home/luigi/.local/lib/python3.8/site-packages/projectq/backends/_ibm/_ibm.py", line 290, in _run
    counts = res['data']['counts']
TypeError: 'NoneType' object is not subscriptable

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "quantum_random_numbers_ibm.py", line 19, in <module>
    eng.flush()
  File "/home/luigi/.local/lib/python3.8/site-packages/projectq/cengines/_main.py", line 304, in flush
    self.receive([Command(self, FlushGate(), ([WeakQubitRef(self, -1)],))])
  File "/home/luigi/.local/lib/python3.8/site-packages/projectq/cengines/_main.py", line 266, in receive
    self.send(command_list)
  File "/home/luigi/.local/lib/python3.8/site-packages/projectq/cengines/_main.py", line 275, in send
    self.next_engine.receive(command_list)
  File "/home/luigi/.local/lib/python3.8/site-packages/projectq/cengines/_replacer/_replacer.py", line 215, in receive
    self.send([cmd])
  File "/home/luigi/.local/lib/python3.8/site-packages/projectq/cengines/_basics.py", line 185, in send
    self.next_engine.receive(command_list)
  File "/home/luigi/.local/lib/python3.8/site-packages/projectq/cengines/_tagremover.py", line 58, in receive
    self.send([cmd])
  File "/home/luigi/.local/lib/python3.8/site-packages/projectq/cengines/_basics.py", line 185, in send
    self.next_engine.receive(command_list)
  File "/home/luigi/.local/lib/python3.8/site-packages/projectq/cengines/_replacer/_replacer.py", line 72, in receive
    self.next_engine.receive(command_list)
  File "/home/luigi/.local/lib/python3.8/site-packages/projectq/cengines/_optimize.py", line 256, in receive
    self.send([cmd])
  File "/home/luigi/.local/lib/python3.8/site-packages/projectq/cengines/_basics.py", line 185, in send
    self.next_engine.receive(command_list)
  File "/home/luigi/.local/lib/python3.8/site-packages/projectq/cengines/_replacer/_replacer.py", line 215, in receive
    self.send([cmd])
  File "/home/luigi/.local/lib/python3.8/site-packages/projectq/cengines/_basics.py", line 185, in send
    self.next_engine.receive(command_list)
  File "/home/luigi/.local/lib/python3.8/site-packages/projectq/cengines/_tagremover.py", line 58, in receive
    self.send([cmd])
  File "/home/luigi/.local/lib/python3.8/site-packages/projectq/cengines/_basics.py", line 185, in send
    self.next_engine.receive(command_list)
  File "/home/luigi/.local/lib/python3.8/site-packages/projectq/cengines/_replacer/_replacer.py", line 72, in receive
    self.next_engine.receive(command_list)
  File "/home/luigi/.local/lib/python3.8/site-packages/projectq/cengines/_optimize.py", line 256, in receive
    self.send([cmd])
  File "/home/luigi/.local/lib/python3.8/site-packages/projectq/cengines/_basics.py", line 185, in send
    self.next_engine.receive(command_list)
  File "/home/luigi/.local/lib/python3.8/site-packages/projectq/cengines/_replacer/_replacer.py", line 215, in receive
    self.send([cmd])
  File "/home/luigi/.local/lib/python3.8/site-packages/projectq/cengines/_basics.py", line 185, in send
    self.next_engine.receive(command_list)
  File "/home/luigi/.local/lib/python3.8/site-packages/projectq/cengines/_tagremover.py", line 58, in receive
    self.send([cmd])
  File "/home/luigi/.local/lib/python3.8/site-packages/projectq/cengines/_basics.py", line 185, in send
    self.next_engine.receive(command_list)
  File "/home/luigi/.local/lib/python3.8/site-packages/projectq/cengines/_replacer/_replacer.py", line 72, in receive
    self.next_engine.receive(command_list)
  File "/home/luigi/.local/lib/python3.8/site-packages/projectq/cengines/_optimize.py", line 256, in receive
    self.send([cmd])
  File "/home/luigi/.local/lib/python3.8/site-packages/projectq/cengines/_basics.py", line 185, in send
    self.next_engine.receive(command_list)
  File "/home/luigi/.local/lib/python3.8/site-packages/projectq/cengines/_basicmapper.py", line 87, in receive
    self._send_cmd_with_mapped_ids(cmd)
  File "/home/luigi/.local/lib/python3.8/site-packages/projectq/cengines/_basicmapper.py", line 83, in _send_cmd_with_mapped_ids
    self.send([new_cmd])
  File "/home/luigi/.local/lib/python3.8/site-packages/projectq/cengines/_basics.py", line 185, in send
    self.next_engine.receive(command_list)
  File "/home/luigi/.local/lib/python3.8/site-packages/projectq/backends/_ibm/_ibm.py", line 337, in receive
    self._run()
  File "/home/luigi/.local/lib/python3.8/site-packages/projectq/backends/_ibm/_ibm.py", line 323, in _run
    raise Exception("Failed to run the circuit. Aborting.")
Exception: Failed to run the circuit. Aborting.
Takishima commented 3 years ago

Thanks for the full log, I will try to have a look at this next week as I am busy with other projects right now.

Takishima commented 3 years ago

Could I ask you which version of ProjectQ you are currently running? Did you try with the one from the develop branch of the repository?

LuigiGiuffrida98 commented 3 years ago

I just tried the one in the develop branch, it works! Fantastic! Thank you a lot!

Takishima commented 3 years ago

Awesome. FYI I will be releasing the develop branch to Pypi in the coming days.