Expand description
Semantic diff for OpenQASM 3 circuits.
Parses two programs with Qiskit’s oq3_semantics, lowers each to a
normalized stream of operations, and aligns the streams so that comment,
whitespace, and declaration-order changes do not count as differences.
This is the library behind the qcdiff CLI.
use qcdiff_core::{diff, extract_source};
let old = extract_source(
"OPENQASM 3.0; include \"stdgates.inc\"; qubit q; h q;",
Some("old.qasm"),
)
.unwrap();
let new = extract_source(
"OPENQASM 3.0; include \"stdgates.inc\"; qubit q; x q;",
Some("new.qasm"),
)
.unwrap();
let result = diff(&old, &new);
assert!(result.has_changes());Structs§
- Diff
Line - Diff
Result - Extracted
- Op
- One executable operation in source order.
- Parse
Errors - Diagnostics from one source, kept so the caller decides when to print. Boxed: the parse result is large and lives on the error path only.
- Summary
- Counts that describe a whole program, independent of the stream diff.
Enums§
Functions§
- diff
- Diff two streams. Alignment uses the parameter-free key so that a
parameter-only change pairs up and reports as
~instead of-/+. - extract
- extract_
source - Parse OpenQASM 3 source and extract its normalized operation stream.
nameis used in diagnostics only. - is_
qasm2 - True when the version statement declares major version 2. Decided on the parsed-out version line rather than substring search over the whole file.