π€ AI text below π€
Problem statement
OpenQASM 3 accepts a classical register or a single classical bit as a boolean condition, with no explicit comparator:
if (c) x q[0];
if (c[0]) x q[0];
The debugger's parser (parseClassicConditionExpression in src/common/parsing/CodePreprocessing.cpp)
requires one of the six comparators (==, !=, <, <=, >, >=) and returns std::nullopt for these bare forms,
so the classic-controlled gate fails to parse.
mqt-core's IfElseOperation already models this shape (a single classical control with an implicit non-zero check),
so the simulation backend is ready. Only the debugger front-end needs to catch up.
Surfaced during the follow-up discussion of #168 (PR #456), which added support for the six non-equality comparators.
Proposed solution
Extend parseClassicConditionExpression to accept a bare register reference (c) or a bare bit reference (c[k]) as a valid condition
and evaluate it as "the value is non-zero".
The existing ClassicCondition and applyComparison(..., qc::Neq) machinery should be enough, so no evaluator change is expected.
Tests should cover both the satisfied and unsatisfied cases, the single-bit form,
and one backward-step case to mirror the coverage added in #456.
Out of scope
- Compound boolean expressions with
&&, ||, !.
OpenQASM 3 supports them, but mqt-core's parser does not; that work would start in mqt-core.
- Multi-instruction
if bodies, per-statement stepping, register slicing, and other extensions of if.
Covered by separate follow-up items.
π€ AI text below π€
Problem statement
OpenQASM 3 accepts a classical register or a single classical bit as a boolean condition, with no explicit comparator:
The debugger's parser (
parseClassicConditionExpressioninsrc/common/parsing/CodePreprocessing.cpp)requires one of the six comparators (
==,!=,<,<=,>,>=) and returnsstd::nulloptfor these bare forms,so the classic-controlled gate fails to parse.
mqt-core's
IfElseOperationalready models this shape (a single classical control with an implicit non-zero check),so the simulation backend is ready. Only the debugger front-end needs to catch up.
Surfaced during the follow-up discussion of #168 (PR #456), which added support for the six non-equality comparators.
Proposed solution
Extend
parseClassicConditionExpressionto accept a bare register reference (c) or a bare bit reference (c[k]) as a valid conditionand evaluate it as "the value is non-zero".
The existing
ClassicConditionandapplyComparison(..., qc::Neq)machinery should be enough, so no evaluator change is expected.Tests should cover both the satisfied and unsatisfied cases, the single-bit form,
and one backward-step case to mirror the coverage added in #456.
Out of scope
&&,||,!.OpenQASM 3 supports them, but mqt-core's parser does not; that work would start in mqt-core.
ifbodies, per-statement stepping, register slicing, and other extensions ofif.Covered by separate follow-up items.