Skip to content

📝 Notice about subtleties of inversion semantics of ForStatement#545

Open
TooMuchDakka wants to merge 4 commits intomunich-quantum-toolkit:mainfrom
TooMuchDakka:loop_stmt_invr_notice
Open

📝 Notice about subtleties of inversion semantics of ForStatement#545
TooMuchDakka wants to merge 4 commits intomunich-quantum-toolkit:mainfrom
TooMuchDakka:loop_stmt_invr_notice

Conversation

@TooMuchDakka
Copy link
Copy Markdown
Collaborator

@TooMuchDakka TooMuchDakka commented Feb 26, 2026

Description

While we do mention that the inversion semantics of the UncallStatement in SyReC were inherited from its predecessor Janus, some subtleties about said semantics can easily be overlooked especially for ForStatements which in turn can result in unexpected errors with one example being shown here.

An additional warning section regarding this potentially unexpected behaviour during the inversion of a ForStatement will be added with this PR to the documentation of the semantics of the ForStatement.

Furthermore, with this PR the library documentation is updated by replacing the previously defined snake_cased identifiers of the generated python bindings with their correct PascalCased identifiers (introduced with #523) where appropriate.

Checklist:

  • The pull request only contains commits that are focused and relevant to this change.
  • I have added appropriate tests that cover the new/changed functionality.
  • I have updated the documentation to reflect these changes.
  • The changes follow the project's style guidelines and introduce no new warnings.
  • The changes are fully tested and pass the CI checks.
  • I have reviewed my own code changes.

…uring inversion of ForStatement during synthesis of UncallStatement
@TooMuchDakka TooMuchDakka added the documentation Improvements or additions to documentation label Feb 26, 2026
@TooMuchDakka TooMuchDakka marked this pull request as ready for review February 26, 2026 20:14
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Feb 26, 2026

📝 Walkthrough

Walkthrough

Documentation updates across multiple files transition public API references from snake_case to CamelCase naming conventions (e.g., qubit_label_typeQubitLabelType). Additionally, warning documentation about potential index-out-of-range errors in ForStatement uncalling is added, and navigation references are updated from "Parser" to "Program" in the library documentation structure.

Changes

Cohort / File(s) Summary
Public API Documentation Updates
docs/library/AnnotatableQuantumComputation.rst, docs/library/ConfigurableOptions.rst, docs/library/InlinedQubitInformation.rst, docs/library/NBitValuesContainer.rst, docs/library/Statistics.rst
Updated Sphinx autodoc references from snake_case to CamelCase public API names (e.g., qubit_label_typeQubitLabelType, configurable_optionsConfigurableOptions).
Navigation & Class Documentation
docs/library/Library.rst, docs/library/Program.rst
Updated toctree navigation entry from "Parser" to "Program" and updated corresponding class documentation header and autoclass directive.
Semantic Documentation
docs/syrec_language_semantics.md
Added detailed warning blocks describing potential index-out-of-range errors when uncalling modules containing ForStatements, including inversion semantics, examples with basicBitwiseIncr/invrBitwiseIncr modules, and illustrative error scenarios.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • PR #523: Renamed public API classes from snake_case to CamelCase (e.g., AnnotatableQuantumComputation, Program, QubitLabelType) which this PR's documentation updates now reference correctly.

Suggested reviewers

  • burgholzer

Poem

🐰 From snake\_case to CamelCase we hop,
Through docs we bounce, we'll never stop,
With warnings clear for loops that dare,
Our public API shines so fair!

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description check ✅ Passed The description follows the template structure with a detailed summary of changes and a completed checklist. It explains the main objectives (ForStatement warning and documentation updates) and references related issues.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Title check ✅ Passed The PR title specifically addresses the primary change: adding documentation about ForStatement inversion semantics subtleties, which aligns with the main objective of warning about index-out-of-range errors.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@docs/syrec_language_semantics.md`:
- Around line 303-305: The explanatory comment describing the inverted
ForStatement contains a typo: it uses `++b.$i` but elsewhere the
increment-assignment syntax is `++= b.$i`; update the comment to use `++= b.$i`
(and verify the paired decrement `--= a.$i` is correct) so the comment matches
the SyReC syntax and avoids confusion when referring to the loop variable `$i`
and the ForStatement inversion.

ℹ️ Review info

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 57559fd and ce39a85.

📒 Files selected for processing (1)
  • docs/syrec_language_semantics.md


- The value of the step size of a ForStatement cannot be defined as or evaluate to 0 to prevent an infinite loop.

````{warning}
Copy link
Copy Markdown

@Geremia Geremia Feb 27, 2026

Choose a reason for hiding this comment

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

@TooMuchDakka This seems to cause Markdown formatting issues:

Suggested change
````{warning}

(At least it doesn't render correctly here on GitHub.)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I do not see any markdown formatting issues (see screenshot below) when performing a local build of the docs via nox -s docs.

grafik

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

yeah, this is fine and typical nesting syntax

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@docs/library/Parser.rst`:
- Line 6: The docs file name is inconsistent: change Parser.rst to Program.rst
and update any references; specifically rename the file currently named
Parser.rst to Program.rst so it matches the documented class mqt.syrec.Program,
and search for/replace any cross-references or toctree entries that point to
"Parser" to point to "Program" instead (ensure the autoclass line "..
autoclass:: mqt.syrec.Program" remains unchanged).

ℹ️ Review info

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 987e2e5 and 3772bb2.

📒 Files selected for processing (6)
  • docs/library/AnnotatableQuantumComputation.rst
  • docs/library/ConfigurableOptions.rst
  • docs/library/InlinedQubitInformation.rst
  • docs/library/NBitValuesContainer.rst
  • docs/library/Parser.rst
  • docs/library/Statistics.rst

Copy link
Copy Markdown
Member

@burgholzer burgholzer left a comment

Choose a reason for hiding this comment

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

I am not sure whether this actually points to a bug. Maybe you can clarify.


- The value of the step size of a ForStatement cannot be defined as or evaluate to 0 to prevent an infinite loop.

````{warning}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

yeah, this is fine and typical nesting syntax

Comment on lines +280 to +307
Uncalling modules containing a _ForStatement_ could lead to unexpected index-out-of-range errors if one is not familiar with the semantics of how a _ForStatement_ or more specifically its value range is inverted, with the inversion semantics being inherited by SyReC from its reversible programming language predecessor Janus {cite:p}`yokoyama2007janus`.

A loop (_ForStatement_) defined as {math}`for \ e_1 \ to \ e_2 \ step \ s \ do \ s_1, s_2, \dots, s_n \ rof`
is inverted by inverting not only the sequence of statements in its loop body but also by inverting its value range thus the inversion of the given loop is equal to
{math}`for \ e_2 \ to \ e_1 \ step \ s \ do \ {s_n}^{-1}, \dots, {s_2}^{-1}, {s_1}^{-1} \ rof`.

The inversion result of the _ForStatement_ as well as its enclosing module `basicBitwiseIncr` is equal to the module `invrBasicBitwiseIncr` with both modules being shown in the example below:

```text
module basicBitwiseIncr(inout a(4), inout b(4))
for $i = 0 to #a do
++= a.$i;
--= b.$i
rof

// Inversion of basicBitwiseIncr equal to "uncall basicBitwiseIncr(a, b)"
module invrBasicBitwiseIncr(inout a(4), inout b(4))
for $i = #a to 0 do
++= b.$i;
--= a.$i
rof

module main(inout a(4), inout b(4))
// An index-out-of-range error would be reported here due to the value range of the ForStatement of the uncalled module
// being inverted with the loop variable $i being initialized with #a instead of 0 in the inverted ForStatement thus the assignments
// ++= b.$i and --= a.$i would both result in an index-out-of-range error.
uncall basicBitwiseIncr(a, b)
```
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is this really true? This seems like more of a bug to me.
shouldn't the reversed loop be from #a-1 to -1?
If the regular loop contains only valid indexing operations, then the inverse of that loop should as well.

@Geremia
Copy link
Copy Markdown

Geremia commented Feb 28, 2026

@burgholzer

````{warning}

Markdown syntax doesn't render properly for me.

@burgholzer
Copy link
Copy Markdown
Member

@burgholzer


````{warning}

Markdown syntax doesn't render properly for me.

It isn't supposed to if you just look at the markdown file itself. This file is rendered by MyST as part of the documentation build. As @TooMuchDakka has shown in his screenshot, this renders just fine in the resulting documentation.

@Geremia
Copy link
Copy Markdown

Geremia commented Mar 1, 2026

@burgholzer Oh interesting. I didn't know about MyST.

@denialhaag denialhaag changed the title 📝Notice about subtleties of inversion semantics of ForStatement 📝 Notice about subtleties of inversion semantics of ForStatement Mar 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants