Rust implementation of the QPY module (#14166)
Set up initial working version of new qpy rust library
Initial incomplete qpy writer, works for many standard gates
Add default rust path to qpy dump
Added initial parameter expression serialization
Partial implementation of conditional operations (still needs encoding for QuantumCircuit parameters)
Code now handles writing a full circuit
Code cleanup
Some refactoring + now correctly handles parameter subs
Custom instructions are now handled
Checkpoint commit with debug prints; most of the functionality is intact
Main tests are passing, can begin code cleanup
Initial code cleanup
Import cleanups
New expression and MCMT handling
Fix test to allow rust work with optionals.HAS_SYMENGINE
Bugfix in pack_custom_layout
Linting the rust code
Python linting
Initial commit: Correctly reads the circuit header
Basic circuit loading now works
Custom layout handling (incomplete)
Overhaul to symbol table formats
Code cleanup
Linting
Do not use rust for
loadby default since it’s not yet ready.Better handling of parameter expression data
Instructions with parameters are now handled
Add data structures for annotations
Added annotation serialization
Do not use rust with an older version of qpy as it is not currently supported
Annotation loading now works
Implemented final layout reading and partial custom instruction reading
Pauli Evolution Gate implementation and better handling for custom gates
Added support for conditionals and multiple circuits
Added support for custom controlled gate
Fix to work with the updated qiskit version
Support for standalone variables, better handling of param deserialization
Bug fixes in parameter handling
Bug fixes
Bugfixes and switching to rust dump/load by default
Bugfix
Code cleanup
Bugfix: the other version of
dumps_registeris required.Bugfix
Fixes according to the PR review
Quick fixes to accomodate the new parameter expression interface
Beginning to work on Python usage overhaul; WIP
Fixed version; should pass CI checks. Not all python-heavy code moved yet.
Split circuit.rs to reader and writer files
Returning a python-free version of
pack_instructiontocircuit_writerand removing manypy: PythonparamsBegining implementation of Expression handling
QPY Reader for expressions
Update
Cargo.lockwith safe versionsThis commits the changes to
Cargo.lockthat are newly added, and ensures that a compatible version ofhashbrowncontinues to be used by PyO3. By default,cargocan sometimes accidentally upgrade versions of interlinked packages in a way that causes trait-resolution failures.
The flows are running, but variable encoding based on QPY data is still missing
Expression read/write now works, and some code cleanup
WIP on ParameterExpression; reader works, but should also handle writer and avoid relying on python
Fixed the way parameters are saved, tests are now passing
Beginning code cleanup and exiled most of the python methods to the py_method file
Linting, hopefully will pass all checks now
Added support for PauliProductMeasurement in Rust, and took the oppurtunity to improve the interface for GenericValue
non-circuit registers are now correctly added
Bugfixes
Major refactoring of parameter handling, still has bugs and cleanup to do
Bugfixes; tests are now passing. Still needs cleanup
Code cleanup
Bug fixes
Bugfix: little endian correction was not applied to tuple params
Bugfix: Uint type was encoded wrong inside ExpressionTypePack
Added support for subs operation in parameter expression replay
Switch ParameterExpression packing from python-based to rust-based
Less python usage in unpack_parameter_vector
Partial simplification of pack_custom_layout to use less python; py_pack_register no longer required
Further simplification of pack_custom_layout
Fixes according to PR review
Update crates/qpy/src/circuit_reader.rs
Co-authored-by: Eli Arbel 46826214+eliarbel@users.noreply.github.com
- Update crates/qpy/src/circuit_reader.rs
Co-authored-by: Eli Arbel 46826214+eliarbel@users.noreply.github.com
- Update crates/qpy/src/circuit_reader.rs
Co-authored-by: Eli Arbel 46826214+eliarbel@users.noreply.github.com
- Update crates/qpy/src/circuit_writer.rs
Co-authored-by: Eli Arbel 46826214+eliarbel@users.noreply.github.com
- Update crates/qpy/src/circuit_writer.rs
Co-authored-by: Eli Arbel 46826214+eliarbel@users.noreply.github.com
- Update crates/qpy/src/circuit_writer.rs
Co-authored-by: Eli Arbel 46826214+eliarbel@users.noreply.github.com
Changes to circuit_writer according to PR review
Change the inputs of pack_standalone_vars according to PR review
Switch from mod to enum for data value types
Several fixes following the main branch merge; still has errors and debug prints
Implementation of handling for the rust-based ControlFlow in writer; still needs to do reader
Added handling for conditions and annotations in control flow serialization
ControlFlow handling done (?)
unpack_instruction is mostly done, still needs cleanup and debugging
Bugfixes and disabling control-flow tests for now since the new Rust ControlFlow code is not stable
Code cleanup
Temporarily disabling loop handling until the code stabilizes
Fixes according to PR review
Fixes according to PR review
Bugfix and the beginning of roundtrip test suite
Block handling in control flow instructions and bug fix in condition handling
Finish the implementation of control flow handling, and add pyerr propagation through binrw parsing
Now handles blocks as CircuitData
Added support for Sparse Observable in pauli evolution gates, and fixed a bug with integer parameter handling
Fix the naming of block subcircuits and remove use of Booly in symengine tests
Linting, return booly test with appropriate fix for the rust case, raise rust minimum version to 17 due to changes in the way conditionals are stored
Return support for python-based control flows reading for backwards compatability
linting
Additional handling for control flows saved from python, for backwards compatability
linting
Fixes according to PR review
Changes in ParameterExpressions according to PR review
Bugfix: After changing the default value of use_rust in read_circuit and write_circuit, we need to explicitly pass use_rust=False when they are called from within python
Documentation and some refactoring of formats.rs
Some more docs and refactoring
Fixes according to PR review
Added release notes, removed the
use_rustflag from the interfaceAdded qpy benchmarks and small fixes according to PR review
Some code refactoring according to PR review
Use dummy circuit data when packing the base gate of a custom instruction to avoid treating the main circuit data as mutable during writing
Small fixes
Removed the release note - not needed
Accomodating to codebase update
Small fix
Co-authored-by: Jake Lishman jake.lishman@ibm.com Co-authored-by: Eli Arbel 46826214+eliarbel@users.noreply.github.com
Qiskit
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://quantum.cloud.ibm.com/docs/
Installation
We encourage installing Qiskit via
pip: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:
Create an example quantum circuit using the
QuantumCircuitclass:This simple example creates 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 you will use. Starting with the Sampler, we use
measure_all(inplace=False)to get a copy of the circuit in which all the qubits are measured:Running this will give an outcome similar to
{'000': 497, '111': 503}which is00050% of the time and11150% of the time up to statistical fluctuations. To illustrate the power of the 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 that the Estimator requires a circuit without measurements, so we use theqccircuit we created earlier.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.StatevectorSamplerandqiskit.primitives.StatevectorEstimatorwill 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 thebasis_gates = ["cz", "sx", "rz"]and a bidirectional linear chain of qubits $0 \leftrightarrow 1 \leftrightarrow 2$ with thecoupling_map = [[0, 1], [1, 0], [1, 2], [2, 1]].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.BaseSamplerV2andqiskit.primitives.BaseEstimatorV2interfaces. 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 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: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 theqiskittag 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
1.2.0release here:https://github.com/Qiskit/qiskit/releases/tag/1.2.0
The 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. 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