Repository navigation
Conversation
A ket shorter or longer than the other kets for the same qubits (in one set, across "∪", or across pre.hsl and post.hsl) made the unit rewrite index past the end of the ket, and autoq aborted with an uncaught std::out_of_range. - In the rewrite pass, every ket of a tensor segment must have the same number of qubits as the first one; otherwise report "Not aligned" naming both kets. This covers shorter kets, longer kets and kets that end inside a constant unit. - Guard the unit loop against running out of characters. - Share the ket-length computation between the collect and rewrite passes (ket_units). A unit test checks that the three shapes from the issue, and a post.hsl shorter than pre.hsl, throw AutoQError, and that aligned input parses. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013gtFQRPe1eSSpmA7EJ2KNY
Checking that the alignment check is correctWhy the rule is right. Why the implementation computes the right length.
Differential test. A random generator (source below) builds
Each input runs with
Other checks.
|
Fixes #34.
Problem
AutoQ splits the kets for the same qubits into units once, using all of them together. That covers the kets in one set, across
∪, and acrosspre.hslandpost.hslinver. It then rewrites each ket by walking that split. A ket shorter or longer than the others ran off the end of its string, andautoqaborted with an uncaughtstd::out_of_range(SIGABRT, exit status 134) instead of reporting the misalignment.Changes
AutoQErrorthat names both kets, for example:{|0x> : |x|=1} ∪ {|0>}, or pre{|xy> : ...}with post{|0>});{|x> : |x|=1} ∪ {|00>});{|0x> : |x|=2} ∪ {|00>}).Not aligned!instead, as a second line of defence.ket_units.Behaviour change
The issue also notes that kets made only of constants, with different lengths across files, were not reported. For example, pre
{|00>}with post{|0>}madeverprint[failed]. These are now rejected with the sameNot alignederror, since the postcondition describes a different number of qubits than the precondition.{|x0> : |x|=1} ∪ {|0>}was already rejected, with "Two automata of different numbers of qubits cannot be unioned together". It now gets theNot alignedmessage as well.Testing
New unit test,
misaligned_kets_are_rejected:post.hslwithReadTwoAutomata, throwAutoQError;Without the fix, the test stops with the original
std::out_of_range. With it, the test passes.ctestpasses (2/2).Unchanged behaviour on the benchmarks: I compared
ver/exagainst the saved outputs of the cleanup PR (Repository cleanup: stray files, dead code and duplicated logic #63), 645 runs from every benchmark family.[OK]as before. The old build was just as slow under the same load.printon.hslfiles: identical output for every file that finished, acrossbenchmarks/,demo/,unit_tests/anddocs/. Many larger instances timed out with both builds.This branch merges cleanly with Playground: add the one-Grover-iteration demo #67–Fix inclusion into an automaton with no root states (#40) #70.
🤖 Generated with Claude Code
https://claude.ai/code/session_013gtFQRPe1eSSpmA7EJ2KNY