Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Rust-based OpenQASM 2 converter #9784

Merged
merged 28 commits into from
Apr 12, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
fccd043
Add Rust-based OpenQASM 2 converter
jakelishman Mar 11, 2023
5723864
Work around docs failure on Sphinx 5.3, Python 3.9
jakelishman Mar 14, 2023
ea9d7b8
Remove unused import
jakelishman Mar 15, 2023
d730709
Merge remote-tracking branch 'ibm/main' into qasm2/rust-parser
jakelishman Mar 15, 2023
02b3934
Tweak documentation
jakelishman Mar 17, 2023
203c7bb
More specific PyO3 usage
jakelishman Mar 17, 2023
f74c872
Use PathBuf directly for paths
jakelishman Mar 17, 2023
2fffb06
Merge remote-tracking branch 'ibm/main' into qasm2/rust-parser
jakelishman Mar 17, 2023
dedb720
Format
jakelishman Mar 17, 2023
b9b1276
Freeze dataclass
jakelishman Mar 18, 2023
a95e8e4
Use type-safe id types
jakelishman Mar 18, 2023
6048257
Documentation tweaks
jakelishman Mar 30, 2023
9c28c1e
Merge remote-tracking branch 'ibm/main' into qasm2/rust-parser
jakelishman Mar 30, 2023
2eb339a
Fix comments in lexer
jakelishman Mar 30, 2023
d5d7115
Fix lexing version number with separating comments
jakelishman Mar 30, 2023
3c0db61
Add test of pathological formatting
jakelishman Mar 30, 2023
46a62ea
Fixup release note
jakelishman Mar 30, 2023
fdc6a9d
Fix handling of u0 gate
jakelishman Mar 30, 2023
e9ffd41
Merge remote-tracking branch 'ibm/main' into qasm2/rust-parser
jakelishman Mar 30, 2023
af56d2b
Credit reviewers
jakelishman Mar 30, 2023
aebb86e
Add test of invalid gate-body statements
jakelishman Apr 3, 2023
0816bfb
Refactor custom built-in gate definitions
jakelishman Apr 4, 2023
1072db2
Merge remote-tracking branch 'ibm/main' into qasm2/rust-parser
jakelishman Apr 4, 2023
eaa0aab
Credit Sasha
jakelishman Apr 4, 2023
2c54a1a
Merge remote-tracking branch 'ibm/main' into qasm2/rust-parser
jakelishman Apr 12, 2023
bdd373e
Credit Matthew
jakelishman Apr 12, 2023
5f74f1e
Remove dependency on `lazy_static`
jakelishman Apr 12, 2023
f6f980b
Update PyO3 version
jakelishman Apr 12, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 18 additions & 17 deletions crates/qasm2/src/bytecode.rs
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other reviewers: this file looks good, outside of some small suggestions. I closely reviewed it.

Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use crate::error::QASM2ParseError;
use crate::expr::Expr;
use crate::lex;
use crate::parse;
use crate::parse::{ClbitId, CregId, GateId, ParamId, QubitId};
use crate::{CustomClassical, CustomInstruction};

/// The Rust parser produces an iterator of these `Bytecode` instructions, which comprise an opcode
Expand Down Expand Up @@ -71,7 +72,7 @@ pub struct ExprConstant {
#[derive(Clone)]
pub struct ExprArgument {
#[pyo3(get)]
pub index: usize,
pub index: ParamId,
}

/// A unary operation acting on some other part of the expression tree. This includes the `+` and
Expand Down Expand Up @@ -150,37 +151,37 @@ pub enum BinaryOpCode {
/// name and the index separately when we can use a simple single index.
pub enum InternalBytecode {
Gate {
id: usize,
id: GateId,
arguments: Vec<f64>,
qubits: Vec<usize>,
qubits: Vec<QubitId>,
},
ConditionedGate {
id: usize,
id: GateId,
arguments: Vec<f64>,
qubits: Vec<usize>,
creg: usize,
qubits: Vec<QubitId>,
creg: CregId,
value: usize,
},
Measure {
qubit: usize,
clbit: usize,
qubit: QubitId,
clbit: ClbitId,
},
ConditionedMeasure {
qubit: usize,
clbit: usize,
creg: usize,
qubit: QubitId,
clbit: ClbitId,
creg: CregId,
value: usize,
},
Reset {
qubit: usize,
qubit: QubitId,
},
ConditionedReset {
qubit: usize,
creg: usize,
qubit: QubitId,
creg: CregId,
value: usize,
},
Barrier {
qubits: Vec<usize>,
qubits: Vec<QubitId>,
},
DeclareQreg {
name: String,
Expand All @@ -195,9 +196,9 @@ pub enum InternalBytecode {
num_qubits: usize,
},
GateInBody {
id: usize,
id: GateId,
arguments: Vec<Expr>,
qubits: Vec<usize>,
qubits: Vec<QubitId>,
},
EndDeclareGate {},
DeclareOpaque {
Expand Down
6 changes: 3 additions & 3 deletions crates/qasm2/src/expr.rs
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other reviewers: I only closely reviewed the PyO3-relevant parts of this, such as the .with_gil() portion to evaluate the user-provided function. The PyO3 parts look good.

Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use crate::error::{
message_bad_eof, message_generic, message_incorrect_requirement, Position, QASM2ParseError,
};
use crate::lex::{Token, TokenContext, TokenStream, TokenType};
use crate::parse::{GateSymbol, GlobalSymbol};
use crate::parse::{GateSymbol, GlobalSymbol, ParamId};

/// Enum representation of the builtin OpenQASM 2 functions. The built-in Qiskit parser adds the
/// inverse trigonometric functions, but these are an extension to the version as given in the
Expand Down Expand Up @@ -125,7 +125,7 @@ enum Atom {
CustomFunction(PyObject, usize),
Op(Op),
Const(f64),
Parameter(usize),
Parameter(ParamId),
}

/// A tree representation of parameter expressions in OpenQASM 2. The expression
Expand All @@ -135,7 +135,7 @@ enum Atom {
/// of which parameter it is.
pub enum Expr {
Constant(f64),
Parameter(usize),
Parameter(ParamId),
Negate(Box<Expr>),
Add(Box<Expr>, Box<Expr>),
Subtract(Box<Expr>, Box<Expr>),
Expand Down
Loading