ProjectQ-Framework / ProjectQ

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

Could not return the results.. #365

Closed Layne-wu closed 4 years ago

Layne-wu commented 4 years ago

Excuse me , I downloaded projectQ package, then try to run this example,but can't get the result, here's my code and the result on the terminal.


    def run_entangle(eng, num_qubits=4):
         qureg = eng.allocate_qureg(num_qubits)

        Entangle | qureg

        All(Measure) | qureg

        eng.flush()

        results = eng.backend.get_probabilities(qureg)
        for state in results:
            print("Measured {} with p = {}.".format(state, results[state]))
        return [int(q) for q in qureg]

    if __name__ == "__main__":
        from projectq.setups.ibm import get_engine_list
        from projectq.backends import IBMBackend
        from projectq.ops import Measure, Entangle, All
        from projectq import MainEngine

        eng = MainEngine(IBMBackend(use_hardware=True,
                                token='d8eec149cc158500f72eb4445fe6c10acb353c799829e47bfaac4ddd378ba1d75bd29e06a753a92c6e63d46427e64ff32304c22405caa162b6a5c1aae898ba1e',
                                num_runs=1024,
                                verbose=True, device='ibmq_london'),
                     engine_list=get_engine_list(device='ibmq_london',
                                                 token='d8eec149cc158500f72eb4445fe6c10acb353c799829e47bfaac4ddd378ba1d75bd29e06a753a92c6e63d46427e64ff32304c22405caa162b6a5c1aae898ba1e'),
                     verbose=True)
    print(run_entangle(eng))`
-----------------------------------------------------------------------------------------------------------
`- Authenticating...
user API token: d8eec149cc158500f72eb4445fe6c10acb353c799829e47bfaac4ddd378ba1d75bd29e06a753a92c6e63d46427e64ff32304c22405caa162b6a5c1aae898ba1e
- 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.0.5'}, '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.0.6'}, 'ibmq_vigo': {'nq': 5, 'coupling_map': [[0, 1], [1, 0], [1, 2], [1, 3], [2, 1], [3, 1], [3, 4], [4, 3]], 'version': '1.0.2'}, 'ibmq_ourense': {'nq': 5, 'coupling_map': [[0, 1], [1, 0], [1, 2], [1, 3], [2, 1], [3, 1], [3, 4], [4, 3]], 'version': '1.0.1'}, 'ibmq_london': {'nq': 5, 'coupling_map': [[0, 1], [1, 0], [1, 2], [1, 3], [2, 1], [3, 1], [3, 4], [4, 3]], 'version': '1.1.0'}, 'ibmq_burlington': {'nq': 5, 'coupling_map': [[0, 1], [1, 0], [1, 2], [1, 3], [2, 1], [3, 1], [3, 4], [4, 3]], 'version': '1.1.4'}, 'ibmq_essex': {'nq': 5, 'coupling_map': [[0, 1], [1, 0], [1, 2], [1, 3], [2, 1], [3, 1], [3, 4], [4, 3]], 'version': '1.0.1'}, 'ibmq_armonk': {'nq': 1, 'coupling_map': None, 'version': '1.1.0'}}
- Running code: {'json': [{'qubits': [1], 'name': 'u2', 'params': [0, 3.141592653589793]}, {'qubits': [1, 0], 'name': 'cx'}, {'qubits': [1, 2], 'name': 'cx'}, {'qubits': [1, 3], 'name': 'cx'}, {'qubits': [1], 'name': 'measure', 'memory': [1]}, {'qubits': [0], 'name': 'measure', 'memory': [0]}, {'qubits': [2], 'name': 'measure', 'memory': [2]}, {'qubits': [3], 'name': 'measure', 'memory': [3]}], 'nq': 4, 'shots': 523, 'maxCredits': 10, 'backend': {'name': 'ibmq_london'}}
- Waiting for results...
Waiting for results. [Job ID: 5e97cfca84d92e00196e5fbb]
- Failed to parse response:
'qObjectResult'
Traceback (most recent call last):
  File "C:\Users\77922\PycharmProjects\kfquantum\http\lib\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:
    ...........

  self.send([new_cmd])
  File "C:\Users\77922\PycharmProjects\kfquantum\http\lib\site-packages\projectq\cengines\_basics.py", line 185, in send
    self.next_engine.receive(command_list)
  File "C:\Users\77922\PycharmProjects\kfquantum\http\lib\site-packages\projectq\cengines\_swapandcnotflipper.py", line 159, in receive
    self.next_engine.receive([cmd])
  File "C:\Users\77922\PycharmProjects\kfquantum\http\lib\site-packages\projectq\cengines\_optimize.py", line 256, in receive
    self.send([cmd])
  File "C:\Users\77922\PycharmProjects\kfquantum\http\lib\site-packages\projectq\cengines\_basics.py", line 185, in send
    self.next_engine.receive(command_list)
  File "C:\Users\77922\PycharmProjects\kfquantum\http\lib\site-packages\projectq\backends\_ibm\_ibm.py", line 337, in receive
    self._run()
  File "C:\Users\77922\PycharmProjects\kfquantum\http\lib\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.

`
dbretaud commented 4 years ago

Yes it's a backend problem: the IBMQ machines have updated their new communication protocol. The problem was identified in #363 and a solution was proposed in #364. We just have to wait for the pull request to be accepted.