Skip to content

Add tests for channels for util.py's gate_approx_eq#1028

Open
mhucka wants to merge 3 commits intotensorflow:masterfrom
mhucka:add-tests-gate-approx-eq
Open

Add tests for channels for util.py's gate_approx_eq#1028
mhucka wants to merge 3 commits intotensorflow:masterfrom
mhucka:add-tests-gate-approx-eq

Conversation

@mhucka
Copy link
Copy Markdown
Member

@mhucka mhucka commented Mar 27, 2026

gate_approx_eq in tensorflow_quantum/python/util.py had logic to handle quantum channels via _channel_approx_eq, but this path was not tested in util_test.py.

This PR adds tests for the following scenarios:

  • All supported channels: DepolarizingChannel, AsymmetricDepolarizingChannel, GeneralizedAmplitudeDampingChannel, AmplitudeDampingChannel, ResetChannel, PhaseDampingChannel, PhaseFlipChannel, and BitFlipChannel.

  • Exact equality for each channel type.

  • Approximate equality within and outside the atol tolerance.

  • Type mismatches between different channels and between channels and non-channel gates.

Note: this PR was created with the help of Jules.

`gate_approx_eq` in `tensorflow_quantum/python/util.py` had logic to
handle quantum channels via `_channel_approx_eq`, but this path was not
tested in `util_test.py`.

This PR adds tests for the following scenarios:

- All supported channels: `DepolarizingChannel`,
  `AsymmetricDepolarizingChannel`, `GeneralizedAmplitudeDampingChannel`,
  `AmplitudeDampingChannel`, `ResetChannel`, `PhaseDampingChannel`,
  `PhaseFlipChannel`, and `BitFlipChannel`.

- Exact equality for each channel type.

- Approximate equality within and outside the `atol` tolerance.

- Type mismatches between different channels and between channels and
  non-channel gates.
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a new test suite for verifying the approximate equality of various quantum channels and modifies an existing error message's string formatting. Feedback suggests reverting the string formatting change to use f-strings for better readability and refactoring the new test method to reduce code duplication by using a parameterized approach with self.subTest.

mhucka added 2 commits March 27, 2026 05:20
Update error message, and streamline test code
@mhucka mhucka marked this pull request as ready for review March 27, 2026 06:05
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.

1 participant