Package: artur-qiskit-terra
QiskitQiskitis 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 quantum operators.For more details on how to use Qiskit, refer to the documentation located here:https://qiskit.org/documentation/InstallationWe encourage installing Qiskit viapip:pipinstallqiskitPip will handle all dependencies automatically and you will always install the latest (and well-tested) version.To install from source, follow the instructions in thedocumentation.Create your first quantum program in QiskitNow that Qiskit is installed, it's time to begin working with Qiskit. The essential parts of a quantum program are:Define and build a quantum circuit that represents the quantum stateDefine the classical output by measurements or a set of observable operatorsDepending on the output, use the primitive functionsamplerto sample outcomes or theestimatorto estimate values.Create an example quantum circuit using theQuantumCircuitclass:importnumpyasnpfromqiskitimportQuantumCircuit# 1. A quantum circuit for preparing the quantum state |000> + i |111>qc_example=QuantumCircuit(3)qc_example.h(0)# generate superpostionqc_example.p(np.pi/2,0)# add quantum phaseqc_example.cx(0,1)# 0th-qubit-Controlled-NOT gate on 1st qubitqc_example.cx(0,2)# 0th-qubit-Controlled-NOT gate on 2nd qubitThis simple example makes an entangled state known as aGHZ 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 withsampler,
we usemeasure_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 qubitsqc_measured=qc_example.measure_all(inplace=False)# 3. Execute using the Sampler primitivefromqiskit.primitives.samplerimportSamplersampler=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 is00050% of the time and11150% 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 therun()function, along with our quantum circuit. Note the Estimator requires a circuitwithoutmeasurement, so we use theqc_examplecircuit we created earlier.# 2. define the observable to be measuredfromqiskit.quantum_infoimportSparsePauliOpoperator=SparsePauliOp.from_list([("XXY",1),("XYX",1),("YXX",1),("YYY",-1)])# 3. Execute using the Estimator primitivefromqiskit.primitivesimportEstimatorestimator=Estimator()job=estimator.run(qc_example,operator,shots=1000)result=job.result()print(f" > Expectation values:{result.values}")Running this will give the outcome4. 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-providedqiskit.primitives.Samplerandqiskit.primitives.Estimatorwill 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 them to the basis gates and connectivity of the quantum hardware.
The tool that does this is thetranspilerand 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 thebasis_gates = ['cz', 'sx', 'rz']and a linear chain of qubits $0 \rightarrow 1 \rightarrow 2$ with thecoupling_map =[[0, 1], [1, 2]].fromqiskitimporttranspileqc_transpiled=transpile(qc_example,basis_gates=['cz','sx','rz'],coupling_map=[[0,1],[1,2]],optimization_level=3)For further examples of using Qiskit you can look at the tutorials in the documentation here:https://qiskit.org/documentation/tutorials.htmlExecuting your code on real quantum hardwareQiskit 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 ofsamplerandestimatorfor 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 implementsqiskit.primitives.BaseSamplerandqiskit.primitives.BaseEstimatorinterfaces. For example,
some packages that provide implementations of a runtime primitive implementation are:https://github.com/Qiskit/qiskit-ibm-runtimeQiskit also provides a lower-level abstract interface for describing quantum backends. This interface, located inqiskit.providers, defines an abstractBackendV2class 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:https://github.com/Qiskit/qiskit-ibm-providerhttps://github.com/qiskit-community/qiskit-ionqhttps://github.com/qiskit-community/qiskit-aqt-providerhttps://github.com/qiskit-community/qiskit-braket-providerhttps://github.com/qiskit-community/qiskit-quantinuum-providerhttps://github.com/rigetti/qiskit-rigettiYou can refer to the documentation of these packages for further instructions
on how to get access and use these systems.Contribution GuidelinesIf you'd like to contribute to Qiskit, please take a look at ourcontribution guidelines. By participating, you are expected to uphold ourcode of conduct.We useGitHub issuesfor tracking requests and bugs. Pleasejoin the Qiskit Slack communityfor discussion, comments, and questions.
For questions related to running or using Qiskit,Stack Overflow has aqiskit.
For questions on quantum computing with Qiskit, use theqiskittag in theQuantum Computing Stack Exchange(please, read first theguidelines on how to askin that forum).Authors and CitationQiskit is the work ofmany peoplewho contribute
to the project at different levels. If you use Qiskit, please cite as per the includedBibTeX file.Changelog and Release NotesThe 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 the0.9.0release here:https://github.com/Qiskit/qiskit-terra/releases/tag/0.9.0The changelog for the current release can be found in the releases tab: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.
For example, you can find the release notes for the0.9.0release in the
Qiskit documentation here:https://qiskit.org/documentation/release_notes.html#terra-0-9AcknowledgementsWe 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.LicenseApache License 2.0