Run any desired version of Qiskit using a Python virtual environment.
Regarding the IBM Quantum Developer Certification Exam
IBM offers a certification exam related to Qiskit, which is introduced in this blog.
By obtaining this certification, you can prove your knowledge of Qiskit and quantum programming. For those aiming to achieve this certification, I have created a practice exams on the Udemy platform! I have made the explanations as clear as possible, so please make sure to take full advantage of the following practice exams as extra study material for exam preparation.
Practice exams
Amazon Braket Learning Course
I have also created a learning course on Amazon Braket, AWS’s quantum computing service.
This course is designed for those with no prior knowledge of quantum computing or AWS, and by the end, you’ll even be able to learn about quantum machine learning. Take advantage of this opportunity to build your skills in quantum technologies!
Running any version of Qiskit
Sample questions for the IBM certification related to quantum computers, IBM Certified Associate Developer - Quantum Computation using Qiskit v0.2X, have been published. The sample question set includes the following code.
from qiskit import QuantumCircuit, execute, BasicAer
backend = BasicAer.get_backend('qasm_simulator')
qc = QuantumCircuit(3)
execute(qc, backend, shots=1024, coupling_map=[[0,1], [1,2]])
When you run this, the following error occurs.
ImportError: cannot import name 'execute' from 'qiskit'
or
ImportError: cannot import name 'BasicAer' from 'qiskit'
When you run another code, the following error occurs.
from qiskit import QuantumCircuit, Aer, execute
from math import sqrt
qc = QuantumCircuit(2)
v = [1/sqrt(2), 0, 0, 1/sqrt(2)]
qc.initialize(v,[0,1])
simulator = Aer.get_backend('statevector_simulator')
result = execute(qc, simulator).result()
statevector = result.get_statevector()
print(statevector)
ImportError: cannot import name 'Aer' from 'qiskit'
This error occurs because the target module cannot be imported in Qiskit version 1.x or 2.x.
So, how can we actually try running the sample code?
Qiskit often encounters version-dependent errors, so it is recommended to create a Python virtual environment. If the version is too old, it may not be possible to install, so here is an example of installing and running version 0.46 where Aer exists.
In this example, we will attempt to run it from the command prompt on Windows 10. Python 3.9.9 is installed.
>python --version
Python 3.9.9
First, create a virtual environment. In this example, we are creating an environment named qis046
.
>python -m venv qis046
>
This will create qis046\Scripts\activate.bat
. Next, activate this environment.
>qis046\Scripts\activate.bat
(qis046) >
When you run pip list in this environment, you will see that only the essential packages are installed.
(qis046) >pip list
Package Version
---------- -------
pip 21.2.4
setuptools 58.1.0
Then, let’s install Qiskit 0.46.2 and other required packages using the command below. These will be installed only in the virtual environment.
(qis046) >pip install qiskit==0.46.2 matplotlib notebook qiskit-aer pylatexenc
Once the installation is complete, launch Jupyter Notebook and run the same code. Although some warnings may appear, the code should execute without any errors.
(qis046) >jupyter notebook
from qiskit import QuantumCircuit, execute, BasicAer
backend = BasicAer.get_backend('qasm_simulator')
qc = QuantumCircuit(3)
qc.measure_all()
r = execute(qc, backend, shots=1024, coupling_map=[[0,1], [1,2]])
print(r.result().get_counts())
# Output
{'000': 1024}
C:\Users\AppData\Local\Temp\ipykernel_15000\3520102656.py:1: DeprecationWarning: BasicAer is deprecated since Qiskit 0.46 and will be removed in Qiskit 1.0. The BasicAer (qiskit.providers.basicaer) module has been superseded by qiskit.providers.basic_provider, and all its classes have been renamed to follow a new naming convention. More information and migration guidelines can be found in the 0.46 API docs for BasicAer.
from qiskit import QuantumCircuit, execute, BasicAer
C:\Users\AppData\Local\Temp\ipykernel_15000\3520102656.py:5: DeprecationWarning: The function ``qiskit.execute_function.execute()`` is deprecated as of qiskit 0.46.0. It will be removed in the Qiskit 1.0 release. This function combines ``transpile`` and ``backend.run``, which is covered by ``Sampler`` :mod:`~qiskit.primitives`. Alternatively, you can also run :func:`.transpile` followed by ``backend.run()``.
r = execute(qc, backend, shots=1024, coupling_map=[[0,1], [1,2]])
Another example of code execution is shown below.
from qiskit import QuantumCircuit, Aer, execute
from math import sqrt
qc = QuantumCircuit(2)
v = [1/sqrt(2), 0, 0, 1/sqrt(2)]
qc.initialize(v,[0,1])
simulator = Aer.get_backend('statevector_simulator')
result = execute(qc, simulator).result()
statevector = result.get_statevector()
print(statevector)
# Output
Statevector([0.70710678+0.j, 0. +0.j, 0. +0.j,
0.70710678+0.j],
dims=(2, 2))
C:\Users\AppData\Local\Temp\ipykernel_10980\1691041731.py:6: DeprecationWarning: The 'qiskit.Aer' entry point is deprecated and will be removed in Qiskit 1.0. You should use 'qiskit_aer.Aer' directly instead.
simulator = Aer.get_backend('statevector_simulator')
C:\Users\AppData\Local\Temp\ipykernel_10980\1691041731.py:7: DeprecationWarning: The function ``qiskit.execute_function.execute()`` is deprecated as of qiskit 0.46.0. It will be removed in the Qiskit 1.0 release. This function combines ``transpile`` and ``backend.run``, which is covered by ``Sampler`` :mod:`~qiskit.primitives`. Alternatively, you can also run :func:`.transpile` followed by ``backend.run()``.
result = execute(qc, simulator).result()
As mentioned above, the program included in the sample questions were successfully executed! If version-related issues with Qiskit arise, make good use of Python virtual environments.
To exit the virtual environment, run deactivate.
(qis046) >deactivate
>
Regarding the IBM Quantum Developer Certification Exam
IBM offers a certification exam related to Qiskit, which is introduced in this blog.
By obtaining this certification, you can prove your knowledge of Qiskit and quantum programming. For those aiming to achieve this certification, I have created a practice exams on the Udemy platform! I have made the explanations as clear as possible, so please make sure to take full advantage of the following practice exams as extra study material for exam preparation.
Practice exams
Amazon Braket Learning Course
I have also created a learning course on Amazon Braket, AWS’s quantum computing service.
This course is designed for those with no prior knowledge of quantum computing or AWS, and by the end, you’ll even be able to learn about quantum machine learning. Take advantage of this opportunity to build your skills in quantum technologies!