Go to file
Jake Lishman d2d0927054
Native OpenQASM 3 importer (#11584)
* Begin work on new OpenQASM 3 importer

* Tidy up public interface construction

* Add load-from-file entry point

* Create public experimental interface

* Credit John

While I've been the author of the Qiskit side of this, John wrote the
separate Rust crates that this depends on, so in principle this
contribution to Qiskit is from both of us.

Co-authored-by: John Lapeyre <jlapeyre@users.noreply.github.com>

* Fix lint

* Bump version (git hash) of dependency on openqasm3_parser

The qasm3 crate fails to build on Windows. This commit should fix this.

* Add support for barrier

* Handle measurement with new parser version

Measures, including broadcasted measures, are now supported following
increased support on the parser side. The updated version also includes
changes to a few APIs, and the include-path settings are now
configurable at the entry point, so we switch to those.

* Fix Rust 1.75 code

* Depend on released version of oq3_seamntics

Change crates/qasm3/Cargo.toml to depend on a released version of the parser.
that is the crate oq3_semantics, rather than a commit of the github repo.
All of the commits added since the commit previously specified in the
dependency are either updating the README or tweaking the github actions.

* Add tests of interface successes

* Add dummy library to manifest

* Depend on lastest version, 0.0.7, of openqasm3_parser crates

This commit does two things
* Change the dependency on oq3_semantcis from 0.0.5 to 0.0.7

* Change in build.rs to reflect chang in API for gate modifiers from
`gatecall.modifier()` returning `Option<GateModifier>` to
`gatecall.modifiers()` returning `&[GateModifier]`

* Expand on readme

* Centralise dependencies

* Fix typing and error typing

* Credit Matt

Co-authored-by: Matthew Treinish <mtreinish@kortar.org>

* Fix clippy

* Clone using GIL

* Format

* Improve error for unexpected angle

* Add test of gate broadcasting

* Add additional warnings about experimental interface

* Add release note

* Add comment about diagnostics in docs

* Correct release series comment

---------

Co-authored-by: John Lapeyre <jlapeyre@users.noreply.github.com>
Co-authored-by: Matthew Treinish <mtreinish@kortar.org>
2024-02-01 02:21:49 +00:00
.azure Reconfigure CI pipelines for PR and merge queue (#11526) 2024-01-17 18:30:34 +00:00
.binder Add rust to binder configuration (#7732) 2022-03-04 02:32:17 +00:00
.cargo Implement multithreaded stochastic swap in rust (#7658) 2022-02-28 21:49:54 +00:00
.github Remove qiskit.org deploy (#11650) 2024-01-31 01:12:29 +00:00
crates Native OpenQASM 3 importer (#11584) 2024-02-01 02:21:49 +00:00
docs Rename `BasicAer` to `BasicProvider` and refactor interface to follow `BackendV2` (#11422) 2024-01-30 22:53:27 +00:00
examples Rename `BasicAer` to `BasicProvider` and refactor interface to follow `BackendV2` (#11422) 2024-01-30 22:53:27 +00:00
qiskit Native OpenQASM 3 importer (#11584) 2024-02-01 02:21:49 +00:00
releasenotes Native OpenQASM 3 importer (#11584) 2024-02-01 02:21:49 +00:00
test Native OpenQASM 3 importer (#11584) 2024-02-01 02:21:49 +00:00
tools Library of Unparameterizable Standard Gates Commutations (#11192) 2024-01-31 19:02:45 +00:00
.editorconfig Add .editorconfig (#6033) 2022-01-31 20:12:23 +00:00
.git-blame-ignore-revs Update git blame rev ignore list (#7620) 2022-02-03 21:31:01 +00:00
.gitignore Add GitHub Actions documentation-deployment pipeline (#10610) 2023-08-14 19:35:14 +00:00
.local-spellings speeling fixes (#5858) 2021-02-19 00:54:19 +00:00
.mailmap Update garrison's name in .mailmap (#7443) 2021-12-23 15:06:18 +00:00
.mergify.yml Bump main branch version post 0.45.0rc1 tag (#11059) 2023-10-19 23:54:07 +00:00
.stestr.conf Removes stestr's grouping configuration. (#6399) 2021-05-12 19:06:06 +00:00
CITATION.bib CITATION.md from metapackage (#10111) 2023-05-15 14:22:59 +00:00
CODE_OF_CONDUCT.md Add an example about spam to the code of conduct (Qiskit/qiskit-metapackage#1758) 2023-06-12 12:59:42 +02:00
CONTRIBUTING.md Documentation on building doc locally (#11073) 2023-12-19 14:09:47 +00:00
Cargo.lock Native OpenQASM 3 importer (#11584) 2024-02-01 02:21:49 +00:00
Cargo.toml Native OpenQASM 3 importer (#11584) 2024-02-01 02:21:49 +00:00
DEPRECATION.md Convert deprecation policy and maintainer guide to markdown (#11218) 2023-11-20 21:49:06 +00:00
LICENSE.txt Consistent license across all the project (#550) 2018-06-08 15:00:58 +02:00
MAINTAINING.md Convert deprecation policy and maintainer guide to markdown (#11218) 2023-11-20 21:49:06 +00:00
MANIFEST.in Native OpenQASM 3 importer (#11584) 2024-02-01 02:21:49 +00:00
Makefile Add ruff to local tests and CI (#10116) 2023-05-30 22:43:36 +00:00
README.md Bump MSRV to 1.70 (#11493) 2024-01-05 17:22:33 +00:00
SECURITY.md Add SECURITY.md to document security policy (#9589) 2023-02-16 11:26:57 -05:00
asv.conf.json Remove qiskit-experiments from asv benchmarks (#11225) 2024-01-24 19:08:05 +00:00
azure-pipelines.yml Reconfigure CI pipelines for PR and merge queue (#11526) 2024-01-17 18:30:34 +00:00
constraints.txt Relax CI constraint on `jsonschema` (#11489) 2024-01-04 16:42:42 +00:00
pyproject.toml Native OpenQASM 3 importer (#11584) 2024-02-01 02:21:49 +00:00
qiskit_bot.yaml Remove redundant entries from qiskit_bot yaml (#11516) 2024-01-08 20:32:02 +00:00
requirements-dev.txt Fix LaTeX equations for KaTeX (#11435) 2023-12-20 10:55:09 +00:00
requirements-optional.txt Remove deprecated IBMQ dependent functionality (#11513) 2024-01-11 12:39:27 +00:00
requirements.txt Token swapper permutation synthesis plugin (#10657) 2024-01-30 21:31:13 +00:00
rust-toolchain.toml Bump MSRV to 1.70 (#11493) 2024-01-05 17:22:33 +00:00
setup.py Native OpenQASM 3 importer (#11584) 2024-02-01 02:21:49 +00:00
tox.ini Fix `tox` configuration for optional packages pre-1.0 (#11621) 2024-01-23 19:30:26 +00:00

README.md

Qiskit

License 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 quantum operators.

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

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

Installation

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 them 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)

For further examples of using Qiskit you can look at the tutorials in the documentation here:

https://qiskit.org/documentation/tutorials.html

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.9.0 release here:

https://github.com/Qiskit/qiskit-terra/releases/tag/0.9.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. For example, you can find the release notes for the 0.9.0 release in the Qiskit documentation here:

https://qiskit.org/documentation/release_notes.html#terra-0-9

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