Skip to content

Commit

Permalink
Native OpenQASM 3 importer (#11584)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>

* 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 <[email protected]>

* 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 <[email protected]>
Co-authored-by: Matthew Treinish <[email protected]>
  • Loading branch information
3 people authored Feb 1, 2024
1 parent 653b942 commit d2d0927
Show file tree
Hide file tree
Showing 18 changed files with 2,441 additions and 54 deletions.
596 changes: 557 additions & 39 deletions Cargo.lock

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,14 @@ edition = "2021"
rust-version = "1.70" # Keep in sync with README.md and rust-toolchain.toml.
license = "Apache-2.0"

# Shared dependencies that can be inherited. This just helps a little with
# making sure our crates don't directly depend on different versions of things,
# although we can't help it if our transitive dependencies pull in more.
#
# Each crate can add on specific features freely as it inherits.
[workspace.dependencies]
indexmap.version = "2.2.1"
hashbrown.version = "0.14.0"
# This doesn't set `extension-module` as a shared feature because we need to be able to disable it
# during Rust-only testing (see # https://github.com/PyO3/pyo3/issues/340).
pyo3 = { version = "0.20.2", features = ["abi3-py38"] }
Expand Down
2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
include LICENSE.txt
include requirements.txt
include qiskit/qasm/libs/*.inc
recursive-include qiskit/qasm/libs *.inc
include qiskit/VERSION.txt
include qiskit/visualization/circuit/styles/*.json
recursive-include qiskit/providers/fake_provider/backends *.json
Expand Down
4 changes: 2 additions & 2 deletions crates/accelerate/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ version = "^0.15.6"
features = ["rayon"]

[dependencies.hashbrown]
version = "0.14.0"
workspace = true
features = ["rayon"]

[dependencies.indexmap]
version = "2.2.1"
workspace = true
features = ["rayon"]

[dependencies.faer]
Expand Down
2 changes: 1 addition & 1 deletion crates/qasm2/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ default = ["extension-module"]
extension-module = ["pyo3/extension-module"]

[dependencies]
hashbrown = "0.14.0"
hashbrown.workspace = true
pyo3.workspace = true
21 changes: 21 additions & 0 deletions crates/qasm3/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[package]
name = "qiskit-qasm3"
version.workspace = true
edition.workspace = true
rust-version.workspace = true
license.workspace = true

[lib]
name = "qiskit_qasm3"
crate-type = ["cdylib"]

[features]
# This is a test-only shim removable feature. See the root `Cargo.toml`.
default = ["extension-module"]
extension-module = ["pyo3/extension-module"]

[dependencies]
pyo3.workspace = true
indexmap.workspace = true
hashbrown.workspace = true
oq3_semantics = "0.0.7"
7 changes: 7 additions & 0 deletions crates/qasm3/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# `qiskit._qasm3`

This crate is the Rust-level Qiskit interface to [a separately managed OpenQASM 3
parser](https://github.com/Qiskit/openqasm3_parser). In order to maintain a sensible separation of
concerns, and because we hope to expand the use of that parser outside Qiskit, the parsing side does
not depend on Qiskit, and this crate interfaces with it in a Qiskit-specific manner to produce
`QuantumCircuit`s.
Loading

0 comments on commit d2d0927

Please sign in to comment.