Skip to main content

Crate qcdiff_core

Crate qcdiff_core 

Source
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§

DiffLine
DiffResult
Extracted
Op
One executable operation in source order.
ParseErrors
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§

Change
Error
Why a source could not be turned into an operation stream.

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. name is 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.