Skip to content

ChunkReflow.verify() fails on test_from_auto_rewrite_xyz and message missformat #1097

Description

@AlMrvn

In stimflow/_chunk/_chunk_reflow_test.py, the existing test test_from_auto_rewrite_xyz tests creating an N-to-1
reflow chunk where Logical $X$ and $Z$ inputs combine into a $Y$ output:

def test_from_auto_rewrite_xyz():
    result = stimflow.ChunkReflow.from_auto_rewrite(
        inputs=[stimflow.PauliMap({"X": [2, 3]}), stimflow.PauliMap({"Z": [2, 3]})],
        out2in={stimflow.PauliMap({"Y": [2, 3]}): "auto"},
    )
    assert result == stimflow.ChunkReflow(
        out2in={
            stimflow.PauliMap({"Y": [2, 3]}): [stimflow.PauliMap({"X": [2, 3]}), stimflow.PauliMap({"Z": [2, 3]})]
        }
    )

If you add result.verify() to the end of test_from_auto_rewrite_xyz, it crashes with:

 ValueError: not enough values to unpack (expected 2, got 1)

The issue come ChunkReflow.verify() (around line 299), .verify() asserts:

if len(self.out2in) != len(self.removed_inputs):
    ...
    raise ValueError("\n".join(msg))

on top, there is a small bug, when len(self.out2in) != len(self.removed_inputs) fails and verify() attempts to format the exception message, lines 301 and 305 execute:

  for ps, obs in self.out2in:
      msg.append(f"    {ps}, obs={obs}")

it's missing a .items() and this lead to the Value Error instead of the actual helpful message about the size of the out2in and removed inputs

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions