Giter VIP home page Giter VIP logo

qiskit-tutorials's Introduction

Qiskit

License Current Release Extended Support Release Downloads Coverage Status PyPI - Python Version Minimum rustc 1.70 Downloads DOI

Qiskit is an open-source SDK for working with quantum computers at the level of extended quantum circuits, operators, and primitives.

This library is the core component of Qiskit, which contains the building blocks for creating and working with quantum circuits, quantum operators, and primitive functions (Sampler and Estimator). It also contains a transpiler that supports optimizing quantum circuits, and a quantum information toolbox for creating advanced operators.

For more details on how to use Qiskit, refer to the documentation located here:

https://docs.quantum.ibm.com/

Installation

Warning

Do not try to upgrade an existing Qiskit 0.* environment to Qiskit 1.0 in-place. Read more.

We encourage installing Qiskit via pip:

pip install qiskit

Pip will handle all dependencies automatically and you will always install the latest (and well-tested) version.

To install from source, follow the instructions in the documentation.

Create your first quantum program in Qiskit

Now that Qiskit is installed, it's time to begin working with Qiskit. The essential parts of a quantum program are:

  1. Define and build a quantum circuit that represents the quantum state
  2. Define the classical output by measurements or a set of observable operators
  3. Depending on the output, use the primitive function sampler to sample outcomes or the estimator to estimate values.

Create an example quantum circuit using the QuantumCircuit class:

import numpy as np
from qiskit import QuantumCircuit

# 1. A quantum circuit for preparing the quantum state |000> + i |111>
qc_example = QuantumCircuit(3)
qc_example.h(0)          # generate superpostion
qc_example.p(np.pi/2,0)  # add quantum phase
qc_example.cx(0,1)       # 0th-qubit-Controlled-NOT gate on 1st qubit
qc_example.cx(0,2)       # 0th-qubit-Controlled-NOT gate on 2nd qubit

This simple example makes an entangled state known as a GHZ state $(|000\rangle + i|111\rangle)/\sqrt{2}$. It uses the standard quantum gates: Hadamard gate (h), Phase gate (p), and CNOT gate (cx).

Once you've made your first quantum circuit, choose which primitive function you will use. Starting with sampler, we use measure_all(inplace=False) to get a copy of the circuit in which all the qubits are measured:

# 2. Add the classical output in the form of measurement of all qubits
qc_measured = qc_example.measure_all(inplace=False)

# 3. Execute using the Sampler primitive
from qiskit.primitives.sampler import Sampler
sampler = Sampler()
job = sampler.run(qc_measured, shots=1000)
result = job.result()
print(f" > Quasi probability distribution: {result.quasi_dists}")

Running this will give an outcome similar to {0: 0.497, 7: 0.503} which is 000 50% of the time and 111 50% of the time up to statistical fluctuations. To illustrate the power of Estimator, we now use the quantum information toolbox to create the operator $XXY+XYX+YXX-YYY$ and pass it to the run() function, along with our quantum circuit. Note the Estimator requires a circuit without measurement, so we use the qc_example circuit we created earlier.

# 2. Define the observable to be measured 
from qiskit.quantum_info import SparsePauliOp
operator = SparsePauliOp.from_list([("XXY", 1), ("XYX", 1), ("YXX", 1), ("YYY", -1)])

# 3. Execute using the Estimator primitive
from qiskit.primitives import Estimator
estimator = Estimator()
job = estimator.run(qc_example, operator, shots=1000)
result = job.result()
print(f" > Expectation values: {result.values}")

Running this will give the outcome 4. For fun, try to assign a value of +/- 1 to each single-qubit operator X and Y and see if you can achieve this outcome. (Spoiler alert: this is not possible!)

Using the Qiskit-provided qiskit.primitives.Sampler and qiskit.primitives.Estimator will not take you very far. The power of quantum computing cannot be simulated on classical computers and you need to use real quantum hardware to scale to larger quantum circuits. However, running a quantum circuit on hardware requires rewriting to the basis gates and connectivity of the quantum hardware. The tool that does this is the transpiler, and Qiskit includes transpiler passes for synthesis, optimization, mapping, and scheduling. However, it also includes a default compiler, which works very well in most examples. The following code will map the example circuit to the basis_gates = ['cz', 'sx', 'rz'] and a linear chain of qubits $0 \rightarrow 1 \rightarrow 2$ with the coupling_map =[[0, 1], [1, 2]].

from qiskit import transpile
qc_transpiled = transpile(qc_example, basis_gates = ['cz', 'sx', 'rz'], coupling_map =[[0, 1], [1, 2]] , optimization_level=3)

Executing your code on real quantum hardware

Qiskit provides an abstraction layer that lets users run quantum circuits on hardware from any vendor that provides a compatible interface. The best way to use Qiskit is with a runtime environment that provides optimized implementations of sampler and estimator for a given hardware platform. This runtime may involve using pre- and post-processing, such as optimized transpiler passes with error suppression, error mitigation, and, eventually, error correction built in. A runtime implements qiskit.primitives.BaseSampler and qiskit.primitives.BaseEstimator interfaces. For example, some packages that provide implementations of a runtime primitive implementation are:

Qiskit also provides a lower-level abstract interface for describing quantum backends. This interface, located in qiskit.providers, defines an abstract BackendV2 class that providers can implement to represent their hardware or simulators to Qiskit. The backend class includes a common interface for executing circuits on the backends; however, in this interface each provider may perform different types of pre- and post-processing and return outcomes that are vendor-defined. Some examples of published provider packages that interface with real hardware are:

You can refer to the documentation of these packages for further instructions on how to get access and use these systems.

Contribution Guidelines

If you'd like to contribute to Qiskit, please take a look at our contribution guidelines. By participating, you are expected to uphold our code of conduct.

We use GitHub issues for tracking requests and bugs. Please join the Qiskit Slack community for discussion, comments, and questions. For questions related to running or using Qiskit, Stack Overflow has a qiskit. For questions on quantum computing with Qiskit, use the qiskit tag in the Quantum Computing Stack Exchange (please, read first the guidelines on how to ask in that forum).

Authors and Citation

Qiskit is the work of many people who contribute to the project at different levels. If you use Qiskit, please cite as per the included BibTeX file.

Changelog and Release Notes

The changelog for a particular release is dynamically generated and gets written to the release page on Github for each release. For example, you can find the page for the 0.46.0 release here:

https://github.com/Qiskit/qiskit/releases/tag/0.46.0

The changelog for the current release can be found in the releases tab: Releases The changelog provides a quick overview of notable changes for a given release.

Additionally, as part of each release, detailed release notes are written to document in detail what has changed as part of a release. This includes any documentation on potential breaking changes on upgrade and new features. See all release notes here.

Acknowledgements

We acknowledge partial support for Qiskit development from the DOE Office of Science National Quantum Information Science Research Centers, Co-design Center for Quantum Advantage (C2QA) under contract number DE-SC0012704.

License

Apache License 2.0

qiskit-tutorials's People

Contributors

1ucian0 avatar abbycross avatar ajavadia avatar attp avatar cryoris avatar danpuzzuoli avatar dcmckayibm avatar diego-plan9 avatar divshacker avatar huangjunye avatar jaygambetta avatar lcapelluto avatar manoelmarques avatar mrossinek avatar mtreinish avatar muneerqu avatar ng-glen avatar nonhermitian avatar omarcostahamido avatar pdc-quantum avatar pedrorrivero avatar quantumjim avatar rraymondhp avatar sathayen avatar shellygarion avatar sooluthomas avatar stefan-woerner avatar t-imamichi avatar taalexander avatar yaelbh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

qiskit-tutorials's Issues

Explain the concept of equivalence up to global phase

The initialize() in the tutorial does not produce the exact state as desired vector, but it only gives one that is equivalence up to global phase.
https://nbviewer.jupyter.org/github/QISKit/qiskit-tutorial/blob/master/reference/tools/quantum_gates_and_linear_algebra.ipynb#Arbitrary-initialization

Description

I think it is good to mention about the equivalence up to global phase here also (in addition to a single qubit case mentioned before).

Your Environment

  • QISKit version: 0.5.3
  • Python version: 3.6.x

[Checking]The qubits got permuted when running with real devices

Description

There is an issue of real-devices that permute the order of qubits. This will be solved with the next release of qiskit-sdk-py. Until that release, we have to provide a workaround of fixing the qubit order.

Your Environment

  • QISKit version:
  • Python version:

Generating Equilibrium file

Description

What is the easiest way to generate Equilibrium.txt files?

Your Environment

  • QISKit version: 0.4.12
  • Python version: Python 3.6.5

AttributeError: module 'qiskit' has no attribute 'unroll'

when i try to import the library
from qiskit import QuantumProgram
qp = QuantumProgram()

i get pesky error

` AttributeError Traceback (most recent call last)
in ()
----> 1 from qiskit import QuantumProgram
2 qp = QuantumProgram()

~/qiskit-sdk-py/qiskit/init.py in ()
8 from ._qiskitexception import QISKitException
9 import qiskit.extensions.standard
---> 10 from ._quantumprogram import QuantumProgram

~/qiskit-sdk-py/qiskit/_quantumprogram.py in ()
39 from . import unroll
40 from . import qasm
---> 41 from . import mapper
42
43 # Local Simulator Modules

~/qiskit-sdk-py/qiskit/mapper/init.py in ()
1 from ._coupling import Coupling
----> 2 from ._mapping import swap_mapper, direction_mapper, cx_cancellation, optimize_1q_gates

~/qiskit-sdk-py/qiskit/mapper/_mapping.py in ()
28 from qiskit import QISKitException
29 from qiskit.qasm import Qasm
---> 30 import qiskit.unroll as unroll
31
32 # Notes:

AttributeError: module 'qiskit' has no attribute 'unroll' `

Help please , Thanks

Type error in result.get_counts()

I've run a couple of circuits on the 'ibmqx5' backend but realised that the optimisation of the circuit is probably making it give out the wrong amplitudes. I've attempted to fix this by adding a few barriers and ran it again but (3 times in a row) an error message came up and I narrowed it down to being solely due to the get_counts() method. Here's the error message:

Traceback (most recent call last):
File "mbqc-simulation.py", line 232, in
plot_histogram(result.get_counts('MBQC'))
File "/Users/TheProtonCat/anaconda/lib/python3.5/site-packages/qiskit/_quantumprogram.py", line 1300, in get_counts
return self.get_data(name)['counts']
File "/Users/TheProtonCat/anaconda/lib/python3.5/site-packages/qiskit/_quantumprogram.py", line 1282, in get_data
return self.__result['result'][index]["data"]
TypeError: string indices must be integers

Since the method worked fine before I wonder if it might be the barriers that are inducing the error. I need to run this simulation for a project so any quick fix would be very much appreciated! (note that the method fails when I use it in different ways, like extracting my own values, not just when trying to plot the histogram).

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.

Avoid using local_qasm_simulator for 10 qubits or more

Description

The local_qasm_simulator is too slow and not efficient for simulating 10 or more qubits.
The alternative is to use the new ibmqx_hpc_qasm_simulator or ibmqx_qasm_simulator.

Your Environment

  • Tutorial branch (stable/master):
  • QISKit SDK version:
  • Python version:

ImportError: No module named 'Qconfig'

Description

Trying to run this code in the Jupyter notebook superposition_and_entanglement:

import sys
if sys.version_info < (3,5):
    raise Exception('Please use Python version 3.5 or greater.')
    
from qiskit import QuantumProgram
import Qconfig

Gives the following error:

ImportErrorTraceback (most recent call last)
<ipython-input-2-770624e829f1> in <module>()
      5 
      6 from qiskit import QuantumProgram
----> 7 import Qconfig

ImportError: No module named 'Qconfig'

Already added these code following the Readme before the cell where the error occurs:

!conda create -y -n QISKitenv python=3 pip scipy
!source activate QISKitenv
!pip install qiskit
APItoken = '<hidden>'
config = {'url': 'https://quantumexperience.ng.bluemix.net/api'}

if 'APItoken' not in locals():
    raise Exception('Please set up your access token. See Qconfig.py.')
!conda install -y jupyter 

The first two code cells run successfully, however the last one gives me a permission-denied error to write:

CondaIOError: Missing write permissions in: /usr/local/src/conda3_runtime/4.1.1
#
# You don't appear to have the necessary permissions to install packages
# into the install area '/usr/local/src/conda3_runtime/4.1.1'.
# However you can clone this environment into your home directory and
# then make changes to it.
# This may be done using the command:
#
# $ conda create -n my_root --clone="/usr/local/src/conda3_runtime/4.1.1"

And Qconfig is still not found.

Your Environment

  • Tutorial branch (stable/master): master, getting_started.ipynb, superposition_and_entanglement.ipynb, entanglement_revisited.ipynb
  • QISKit SDK version: Unknown at the moment, probably most recent as it was just downloaded
  • Python version: 3.5

Replace local_qasm_simulator with local_qiskit_simulator

Description

For local simulation of 10 qubits or more, the local_qiskit_simulator should be used.
Here is a comparison of running quantum_emoticon tutorial: local_qiskit_simulator takes 3.6 seconds vs local_qasm_simulator takes more than 1200 seconds.

import time
start_time = time.time()

backend = "local_qiskit_simulator" 
#backend = "local_qasm_simulator" 
shots_sim = 1000
results_sim = qp.execute(["smiley_writer"], backend=backend, shots = shots_sim, wait=5, timeout=300)
stats_sim = results_sim.get_counts("smiley_writer")

print("--- %s seconds ---" % (time.time() - start_time))

plot_histogram(stats_sim)

Your Environment

  • QISKit version: 0.4.13
  • Python version: 3.6
    MacBookAir MacOSX with 8GM RAM and 1.6GHz i5

Add path to Qconfig at all tutorials that import it

Description

There are many issues with tutorials cannot be run due to failure in importing Qconfig.
We need to make sure the Qconfig is installed on the path that is searched by the PYTHONPATH.

Your Environment

  • Tutorial branch (stable/master):
  • QISKit SDK version:
  • Python version:

How to use classical "if" control

I was trying the teleportation circuit, which requires control using classical registers. The code is the following:
`include "qelib1.inc";
qreg q[5];
creg c0[1];
creg c1[1];
creg c2[1];

h q[0];
t q[0];
h q[0];
cx q[0],q[1];
h q[0];
measure q[0] -> c0[0];
measure q[1] -> c1[0];
if (c0==1)
x q[2];
if (c1==1)
z q[2];
measure q[2] -> c2[0];
`
And I got error:

Error in line 14: Operations are disabled

Which refers to the "if" operation. How should I use a classical register to control a quantum gate?

Update Backends in tutorial

Hello, I'd like to update the notebook working_with_backends.ipynb with the latest backends.

What's the first step for me to make this contribution? Create my own branch?

Add a Binder badge

Description

You could add a Binder badge to launch the Jupyter notebooks in a cloud instance

Homepage: https://mybinder.org
Src: https://github.com/jupyterhub/binderhub
Docs: https://binderhub.readthedocs.io/en/latest/

Qiskit/qiskit#177

Your Environment

binder builds cloud containers with repo2docker.
repo2docker will install from requirements.txt and/or environment.yml
Docs: https://repo2docker.readthedocs.io/en/latest/samples.html#conda-mixed-requirements
Src: https://github.com/jupyter/repo2docker

symbolic link to qiskit tools not working under Windows

Expected Behavior

A symbolic link is in place in qiskit-sdk-py after moving tools into the folder qiskit.

Current Behavior

When checking out qiskit-sdk-py under Windows the symbolic link is being converted into a textfile. Hence I get a NotFoundError when loading any tools.

Possible Solution

Add "qiskit." to tools import statements.

Steps to Reproduce (for bugs)

  1. checkout qiskit-sdk-py under Windows
  2. try running Jupyter notebooks that are importing tools from qiskit-sdk-py

Your Environment

  • Operating System and version: Windows 7

ImportError: cannot import name 'Energy_Estimate_Exact' in Quantum Optimization Notebook

Import error when running the first code block:

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-1-69ab0bbfce01> in <module>()
     25 # import optimization tools
     26 from tools.apps.optimization import trial_circuit_ry, SPSA_optimization, SPSA_calibration
---> 27 from tools.apps.optimization import Energy_Estimate, make_Hamiltonian, Energy_Estimate_Exact
     28 from tools.qi.pauli import Pauli

ImportError: cannot import name 'Energy_Estimate_Exact'

Function missing from https://github.com/QISKit/qiskit-sdk-py/blob/master/tools/apps/optimization.py

Errors from "superposition_and_entanglement"

TypeError Traceback (most recent call last)
in ()
----> 1 plot_histogram(result.get_counts('ground'))

C:\Anaconda\Anaconda3\lib\site-packages\qiskit_quantumprogram.py in get_counts(self, name)
1298 """
1299 try:
-> 1300 return self.get_data(name)['counts']
1301 except KeyError:
1302 raise QISKitError('No counts for circuit "{0}"'.format(name))

C:\Anaconda\Anaconda3\lib\site-packages\qiskit_quantumprogram.py in get_data(self, name)
1280 for index in range(len(qobj["circuits"])):
1281 if qobj["circuits"][index]['name'] == name:
-> 1282 return self.__result['result'][index]["data"]
1283 except KeyError:
1284 raise QISKitError('No data for circuit "{0}"'.format(name))

TypeError: string indices must be integers


IndexError Traceback (most recent call last)
in ()
----> 1 plot_histogram(result.get_counts('excited'))

C:\Anaconda\Anaconda3\lib\site-packages\qiskit_quantumprogram.py in get_counts(self, name)
1298 """
1299 try:
-> 1300 return self.get_data(name)['counts']
1301 except KeyError:
1302 raise QISKitError('No counts for circuit "{0}"'.format(name))

C:\Anaconda\Anaconda3\lib\site-packages\qiskit_quantumprogram.py in get_data(self, name)
1280 for index in range(len(qobj["circuits"])):
1281 if qobj["circuits"][index]['name'] == name:
-> 1282 return self.__result['result'][index]["data"]
1283 except KeyError:
1284 raise QISKitError('No data for circuit "{0}"'.format(name))

IndexError: list index out of range

Error message while running Maxcut in ibmqx5 - 16 qubit from classical_optimization in application examples

Description

While trying to run simple Maxcut (for 4 qubits) with ibmqx5, get the following error:

WARNING:IBMQuantumExperience.IBMQuantumExperience:Got a 400 code response to {"error":{"status":400,"message":"Error parsing QASM. Error parsing qasm number 0. The qasm has no measures.","code":"QASM_NOT_VALID","statusCode":400}}

The same notebook runs ok with the simulator (local_qasm_simulator). I ran the classical_optimization example in 4_applications folder.

Your Environment

  • Tutorial branch (stable/master): Master
  • QISKit SDK version: 0.4.8
  • Python version: 3.5.3

reworking the tutorial so that it is easier to manage

We are going to split the tutorial into three sections.

We are going to add to a WIP PR that i will set up and if you want to help in the rework that would be great. Either you can help by commenting here or helping in the content. The names are the assigned people that are going to coordinate the different sections.

sections

  • Hello World: Since quantum computing is so new, we want to find the best Hello Quantum World program and welcome submissions here.
  • Reference: These notebooks demonstrate how to use QISKit and explore quantum information science, acting as a reference book for QISKit. They will be kept up to date with QISKit SDK updates. They are organised into various topics:
    1. Getting started with QISKit (me)
    • Getting started
    • Working with backends (including compiling and running)
    • Using different gates
    • Visualisation of quantum states
    1. Introduction to quantum information science @attp
    • Superposition and entanglement
    • Entanglement revisited
    • Quantum teleportation and superdense coding
    1. Understanding your quantum computer @dtmcclure
    • Relaxation and decoherence
    • Quantum tomography
    • Random Benchmarking # to be written
    1. Working an approximate quantum quantum computers @adcorcol
    • Variational Quantum Eigensolver
    • Small error correcting codes # to be written
    • Error mitigation # to be written
    1. Examples of quantum algorithms @rraymondhp
    • Phase estimation
    • Deutsch–Jozsa algorithm
    • Bernstein-Vazirani algorithm
    • Simon's algorithm
    • Grover's algorithm
    • Shor's algorithm
    1. Having fun with quantum computers
    • Battleships
  • Appendix This is where the rest of the tutorials are. They are not guaranteed to work with the latest version of the QISKit SDK. They are organised into various topics:
    1. Advanced QISKit features
    2. More on quantum information
    3. Further quantum algorithms and applications
    4. Everything else

Print the correct versions of qiskit, IBM Quantum Experience, and python version

Description

At the end of tutorials, add the following codes (or, compatible lines that do better).
The current version check just print the content of requirements.txt that might not be true anymore.

! pip list | grep "qiskit"
! pip list | grep "IBMQuantumExperience"
! python --version

Your Environment

  • QISKit version:
  • Python version:

Reduce traffic to backends

In many places in the tutorial the real backend to run on is hardcoded. When many users run tutorials, this creates a problem of overloading some backends and starving others.

The problem is aggravated when one of the overloaded backends goes offline for maintenance, creating very long queues.

A potential solution is to not hardcode the backends. Rather, the tutorial codes must query the backends for availability, and also randomize the backend selection so it gets distributed across users. (In particular, often the tutorials run on 5 qubits. But they could as well run on the 16 qubit device).

Description

Your Environment

  • Tutorial branch (stable/master):
  • QISKit SDK version:
  • Python version:

Problems with superposition and entanglement notebook

The current notebook of superposition_and_entanglement.ipynb does not work as desired if run on remote backends.

https://github.com/QISKit/qiskit-tutorial/blob/master/reference/qis/superposition_and_entanglement.ipynb

Description

  1. The current notebook runs ok with local simulators, but when backend=ibmqx_qasm_simulator it cannot be run anymore unless the lowest_pending_jobs() function is called.

  2. The circuit_drawer does not work (the image is misalign). Also, please provide the installation instruction of required packages for Linux, Mac, and Windows.
    misalign_drawing

Your Environment

  • QISKit version: 0.4.13
  • Python version: 3.6.2

Unreadable Notebook: qiskit-tutorial-master/1_introduction/getting_started.ipynb

On http://localhost:8888/notebooks/qiskit-tutorial-master/index.ipynb#section1

Link
Getting started with QISKit SDK - how to use QISKit SDK.

Obtained
Unreadable Notebook: /home/nnelson/environments/qiskit-tutorial-master/1_introduction/getting_started.ipynb NotJSONError('Notebook does not appear to be JSON: '\ufeff{\n "cells": [\n {\n "cell_typ...',)

New installation from instructions at
From https://github.com/QISKit/qiskit-sdk-py/blob/master/doc/install.rst

Using tutorial
https://github.com/QISKit/qiskit-tutorial/archive/master.zip

From python3 environment
pip install qiskit

Python 3.5.2

Xubuntu 16.04.3 LTS

The next link in section 1 works.
Understanding the different backends - how to get information about the connected backends.

jupyter --version
4.4.0

Set more credits (or no credit spend) for reviewers of the tutorials

Description

To review tutorials, the reviewers must test the experiments on real devices many times. They need more credits to do that. Either give them more credits or identify them so they do not need to spend credits for testing.

Your Environment

  • Tutorial branch (stable/master):
  • QISKit SDK version:
  • Python version:

Provide a way for checking the tutorials when a new qiskit version is released

Description

After some discussion spawned from #135 and the tutorials as a whole, it seems that having an easy, ideally single-shot way of checking if the tutorials are working against a new version of qiskit (or other dependencies in general) would facilitate keeping them in sync.

As a simple approach, a command that can be executed locally by a tutorial repository maintainer and clearly outputs which ones are working and which ones are not seems a good compromise. We can make use of the Python test framework for paving the way towards having a more integrated system in the future if needed.

Your Environment

  • QISKit version:
  • Python version:

Suggestion on managing API and URL via environment vars for real devices

Hey just started this tutorial, love that you are putting this together. One suggestion for the introduction when it comes to the real device configuration - have the users put their API key and the URL into environment variables instead of into local Python files. This removes the risk of people accidentally committing to public repos and exposing their keys.

The following would be changed:

  1. README - in section 4 instruct the user to setup an IBMAPI and IBMURL environment variable e.g. in their .bash_profile or similar using export statements.
  2. In the Introduction - Getting Started notebook change the imports to remove Qconfig and instead import os.
  3. In the Introduction - Getting Started notebook change the "Real Devices" section to get the environment variables instead e.g.
qp.set_api(os.getenv("IBMAPI"), os.getenv("IBMURL"))

'BinaryOp' object has no attribute 'sym' error

qp.compile fails

When running the getting started notebook :

backend = 'local_qasm_simulator' 
circuits = ['Circuit']  # Group of circuits to execute
qobj=qp.compile(circuits, backend) # Compile your program

I get the following error: 'BinaryOp' object has no attribute 'sym'

  • Tutorial branch (stable/master): master
  • QISKit SDK version: master version
  • Python version: 3.6

Gates after a measure are blocked in tutorial 0

Description

warning

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

stacktrace

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

/opt/conda/lib/python3.5/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))

/opt/conda/lib/python3.5/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))

/opt/conda/lib/python3.5/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',

/opt/conda/lib/python3.5/concurrent/futures/_base.py in result(self, timeout)
    396                 raise CancelledError()
    397             elif self._state == FINISHED:
--> 398                 return self.__get_result()
    399 
    400             self._condition.wait(timeout)

/opt/conda/lib/python3.5/concurrent/futures/_base.py in __get_result(self)
    355     def __get_result(self):
    356         if self._exception:
--> 357             raise self._exception
    358         else:
    359             return self._result

/opt/conda/lib/python3.5/concurrent/futures/thread.py in run(self)
     53 
     54         try:
---> 55             result = self.fn(*self.args, **self.kwargs)
     56         except BaseException as e:
     57             self.future.set_exception(e)

/opt/conda/lib/python3.5/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 

/opt/conda/lib/python3.5/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

Jupyter Notebook

  • Tutorial branch (stable/master):
    master
  • QISKit SDK version:
    0.4.9
  • Python version:
    Python 3

Running Algorithm on ibmqx5 DAG Circuit error

Description

I am trying to run the Grover's algorithm, it worked nicely on the local qasm simulator but when i change the backend on ibmqx5 i got the following error:
qiskit.dagcircuit._dagcircuiterror.DAGCircuitError: 'inequivalent gate definitions for cx'
and again when i changed the backend to ibmq_qasm_simulator i get the following error:
qiskit._resulterror.ResultError: DEVICE_NOT_FOUND: Device not found.
i have placed circuit.barrier(qr) in front of the oracle, diffusion as well as in measurement. and also i had changed the time out to 300
Thank you!!

Your Environment

  • QISKit version: 0.4.9
  • Python version:3.5

Strange error with simulators

Description

When running the following code, I got backend ... not available error.

backend = "ibmqx_hpc_qasm_simulator"
shots = 1000
results = Q_program.execute([circuitName], backend=backend, shots=shots)
answer = results.get_counts(circuitName)

plot_histogram(answer)

But when I queried the available backends, with pprint as below, I can run the code.

from pprint import pprint

pprint(Q_program.available_backends())
pprint(Q_program.get_backend_status('ibmqx_hpc_qasm_simulator'))
pprint(Q_program.get_backend_status('ibmqx_qasm_simulator'))


backend = "ibmqx_hpc_qasm_simulator"
shots = 1000
results = Q_program.execute([circuitName], backend=backend, shots=shots)
answer = results.get_counts(circuitName)

plot_histogram(answer)

Your Environment

  • IBMQuantumExperience 1.9.0
  • qiskit 0.4.12
  • python 3.6.2

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.