Skip to content

fix(channel_ops): accept wrapped CP Kraus forms in kraus_to_choi - #1989

Open
G26karthik wants to merge 1 commit into
vprusso:masterfrom
G26karthik:fix/kraus-to-choi-wrapped-cp
Open

G26karthik wants to merge 1 commit into
vprusso:masterfrom
G26karthik:fix/kraus-to-choi-wrapped-cp

Conversation

@G26karthik

Copy link
Copy Markdown

Description

normalize_kraus documents three completely positive list forms that are accepted across the package: [K1, ..., Kr], [[K1], ..., [Kr]] and [[K1, ..., Kr]] (r > 2). The sys=2 fast path added to kraus_to_choi in #1643 does its own format check instead: anything that is not a flat list is read as [[A, B], ...] pairs. So [[K1], [K2], [K3]] raises IndexError, and [[K1, K2, K3]] is read as the single pair (K1, K2), which silently returns the Choi matrix of X -> K1 X K2^* and drops K3. The sys != 2 path goes through partial_channel, which already uses normalize_kraus, so only the default sys is affected.

Because is_completely_positive, choi_rank and other predicates call kraus_to_choi, they give wrong answers for these forms too. With K = [[[1, 0], [0, 0]], [[0, 1], [0, 0]], [[0, 0], [1, 0]] / 2] (flat list: CP, Choi rank 3):

master                                 this PR
[[K1], [K2], [K3]]
  kraus_to_choi  IndexError            equals flat-list result
  is_completely_positive  IndexError   True
  choi_rank      IndexError            3
[[K1, K2, K3]]
  kraus_to_choi  wrong matrix          equals flat-list result
  is_completely_positive  False        True
  choi_rank      1                     3

Changes

  • Classify the input with normalize_kraus in the sys=2 fast path, as partial_channel, apply_channel and channel_dim already do. For the CP forms the left stack is reused as the right one, as before. Flat lists, stacked 3-D arrays and [[A, B], ...] pairs take the same path as before.
  • Add a parametrized regression test for both wrapped forms, checked against the flat-list result. Both cases fail on master.

is_trace_preserving and dual_channel still do their own list dispatch, so I left them out of this PR to keep it to one concern (and away from the is_quantum_channel work in #1987). Happy to send that separately if you want it.

Checklist

  • Use ruff for errors related to code style and formatting. (ruff check and ruff format --check clean)
  • Verify all previous and newly added unit tests pass in pytest. (pytest toqito/channel_ops/tests/test_kraus_to_choi.py toqito/channel_ops/tests/test_partial_channel.py toqito/channel_props/tests/test_choi_rank.py toqito/channel_props/tests/test_is_completely_positive.py toqito/channels: 115 passed)
  • Check the documentation build does not lead to any failures. (no docs changed, not run)

The sys=2 fast path added in 1f5b094 (vprusso#1643) treated every nested
list as [A, B] pairs instead of using normalize_kraus. The wrapped CP
forms [[K1], [K2], ...] raised IndexError, and [[K1, K2, K3]] silently
returned the Choi matrix of X -> K1 X K2^*, dropping K3. This broke
is_completely_positive, choi_rank and the other predicates that call
kraus_to_choi.

Classify the input with normalize_kraus, as the general path does.
Output for the flat, stacked, and paired forms is unchanged.
Copilot AI balanced review requested due to automatic review settings October 18, 2026 16:53

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@codecov

codecov Bot commented Oct 18, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@G26karthik

Copy link
Copy Markdown
Author

@vprusso CI is green on this one. It lets kraus_to_choi accept wrapped CP Kraus forms. Could you take a look when you have time?

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants