Solvedqiskit tutorials Error in notebook "quantum_emoticon": unable to get counts

Description

These are the steps I followed to get the error:

  1. Clone repo: git clone https://github.com/QISKit/qiskit-tutorial.git (commit 37faf8b)
  2. cd qiskit-tutorial/
  3. Create file: vi 0_hello_world/Qconfig.py:
APItoken = 'XXX...XXX'
config = {'url': 'https://quantumexperience.ng.bluemix.net/api'}

if 'APItoken' not in locals():
    raise Exception('Please set up your access token. See Qconfig.py.')
  1. pip install -r requirements.txt
  2. jupyter notebook index.ipynb
  3. Go to notebook "Quantum Emoticon"
  4. Run first piece of code to produce the measures and get the counts

I got the following errors:

WARNING:IBMQuantumExperience.IBMQuantumExperience:Got a 400 code response to https://quantumexperience.ng.bluemix.net/api/Jobs?access_token=XXX...XXX: {"error":{"status":400,"message":"Error parsing QASM. Error parsing qasm number 0. Gates after a measure are blocked","code":"QASM_NOT_VALID","statusCode":400}}
WARNING:IBMQuantumExperience.IBMQuantumExperience:Got a 400 code response to https://quantumexperience.ng.bluemix.net/api/Jobs?access_token=XXX...XXX: {"error":{"status":400,"message":"Error parsing QASM. Error parsing qasm number 0. Gates after a measure are blocked","code":"QASM_NOT_VALID","statusCode":400}}
WARNING:IBMQuantumExperience.IBMQuantumExperience:Got a 400 code response to https://quantumexperience.ng.bluemix.net/api/Jobs?access_token=XXX...XXX: {"error":{"status":400,"message":"Error parsing QASM. Error parsing qasm number 0. Gates after a measure are blocked","code":"QASM_NOT_VALID","statusCode":400}}
WARNING:IBMQuantumExperience.IBMQuantumExperience:Got a 400 code response to https://quantumexperience.ng.bluemix.net/api/Jobs?access_token=XXX...XXX: {"error":{"status":400,"message":"Error parsing QASM. Error parsing qasm number 0. Gates after a measure are blocked","code":"QASM_NOT_VALID","statusCode":400}}
WARNING:IBMQuantumExperience.IBMQuantumExperience:Got a 400 code response to https://quantumexperience.ng.bluemix.net/api/Jobs?access_token=XXX...XXX: {"error":{"status":400,"message":"Error parsing QASM. Error parsing qasm number 0. Gates after a measure are blocked","code":"QASM_NOT_VALID","statusCode":400}}

And this trace:

ResultError                               Traceback (most recent call last)
<ipython-input-1-72b078066956> in <module>()
     31 # run and get results
     32 results = qp.execute(["smiley_writer"], backend='ibmqx5', shots=1024)
---> 33 stats = results.get_counts("smiley_writer")

~/anaconda3/envs/QISKitenv/lib/python3.6/site-packages/qiskit/_result.py in get_counts(self, name)
    231         """
    232         try:
--> 233             return self.get_data(name)['counts']
    234         except KeyError:
    235             raise QISKitError('No counts for circuit "{0}"'.format(name))

~/anaconda3/envs/QISKitenv/lib/python3.6/site-packages/qiskit/_result.py in get_data(self, name)
    202             exception = self._result['result']
    203             if isinstance(exception, BaseException):
--> 204                 raise exception
    205             else:
    206                 raise QISKitError(str(exception))

~/anaconda3/envs/QISKitenv/lib/python3.6/site-packages/qiskit/_jobprocessor.py in _job_done_callback(self, future)
     97     def _job_done_callback(self, future):
     98         try:
---> 99             result = future.result()
    100         except Exception as ex:  # pylint: disable=broad-except
    101             result = Result({'job_id': '0', 'status': 'ERROR',

~/anaconda3/envs/QISKitenv/lib/python3.6/concurrent/futures/_base.py in result(self, timeout)
    423                 raise CancelledError()
    424             elif self._state == FINISHED:
--> 425                 return self.__get_result()
    426 
    427             self._condition.wait(timeout)

~/anaconda3/envs/QISKitenv/lib/python3.6/concurrent/futures/_base.py in __get_result(self)
    382     def __get_result(self):
    383         if self._exception:
--> 384             raise self._exception
    385         else:
    386             return self._result

~/anaconda3/envs/QISKitenv/lib/python3.6/concurrent/futures/thread.py in run(self)
     54 
     55         try:
---> 56             result = self.fn(*self.args, **self.kwargs)
     57         except BaseException as exc:
     58             self.future.set_exception(exc)

~/anaconda3/envs/QISKitenv/lib/python3.6/site-packages/qiskit/_jobprocessor.py in run_backend(q_job)
     52                 circuit['compiled_circuit'] = compiled_circuit
     53     backend = qiskit.backends.get_backend_instance(backend_name)
---> 54     return backend.run(q_job)
     55 
     56 

~/anaconda3/envs/QISKitenv/lib/python3.6/site-packages/qiskit/backends/_qeremote.py in run(self, q_job)
     98                                    hpc=hpc)
     99         if 'error' in output:
--> 100             raise ResultError(output['error'])
    101 
    102         logger.debug('Running on remote backend %s with job id: %s',

ResultError: QASM_NOT_VALID: Error parsing QASM. Error parsing qasm number 0. Gates after a measure are blocked

Your Environment

  • Tutorial branch: master
  • QISKit SDK version: QISKit-0.4.8
  • Python version: Python 3.6.4 :: Anaconda, Inc.
30 Answers

✔️Accepted Answer

Hi,
Thank you for pointing this. I also got the same error when running the notebook. It is due to a bug in compiler that swap measurement to the middle of the computation but the devices do not support such operation yet. I confirmed that I can avoid the error by inserting barrier before measurement, like:

#put barrier before measurement
qc.barrier(qr)
# measure
for j in range(16):
    qc.measure(qr[j], cr[j])

# run and get results
results = qp.execute(["smiley_writer"], backend='ibmqx5', shots=1024, timeout=240)
stats = results.get_counts("smiley_writer")

I cannot run the real device now because it is under maintenance though.

Related Issues:

4
qiskit tutorials Error in notebook "quantum_emoticon": unable to get counts
Hi Thank you for pointing this I also got the same error when running the notebook ...
111
react gh pages Code is deployed, but page is blank
Hi @indrawanadjie Thanks for providing all the information I requested Useful package i already foll...
46
webpack book Loading Images - example for creating img elements
What I ended up doing is this: I created a directory called images at the top level with all my imag...
31
howtographql Error: Not authenticated
The tutorial is missing a step In order to successfully execute the post mutation you need to includ...
7
serverless stack com Comments: Upload a File to S3
@alpiepho the policy allowing the Identity Pool to access S3 resources was defined in Create a Cogni...